NREL / floris

A controls-oriented engineering wake model.
http://nrel.github.io/floris
BSD 3-Clause "New" or "Revised" License
215 stars 156 forks source link

Give more helpful error when n_findex = 0 #1011

Open paulf81 opened 3 weeks ago

paulf81 commented 3 weeks ago

Give more helpful error when n_findex = 0

Working with FLORIS and FLASC, it can sometimes happen that FLORIS is set to have n_findex = 0 (for example there are no rows in the FlascDataframe that is being assigned to FLORIS. In this cases, it could be useful for FLORIS to give a more helpful error. Right now this code (run in the examples folder)


import numpy as np

from floris import FlorisModel

fmodel = FlorisModel("inputs/gch.yaml")
fmodel.set(
    wind_directions=np.array([]), wind_speeds=np.array([]), turbulence_intensities=np.array([])
)
print(f"NFINDEX: {fmodel.n_findex}\n")
fmodel.run()

Has output:

pfleming$ python 001_opening_floris_computing_power.py 
NFINDEX: 0

Traceback (most recent call last):
  File "/Users/pfleming/Projects/FLORIS/floris/examples/001_opening_floris_computing_power.py", line 14, in <module>
    fmodel.run()
  File "/Users/pfleming/Projects/FLORIS/floris/floris/floris_model.py", line 490, in run
    self.core.initialize_domain()
  File "/Users/pfleming/Projects/FLORIS/floris/floris/core/core.py", line 147, in initialize_domain
    self.farm.initialize(self.grid.sorted_indices)
  File "/Users/pfleming/Projects/FLORIS/floris/floris/core/farm.py", line 260, in initialize
    self.awc_modes_sorted = np.take_along_axis(
                            ^^^^^^^^^^^^^^^^^^^
  File "/Users/pfleming/opt/anaconda3/envs/floris/lib/python3.11/site-packages/numpy/lib/shape_base.py", line 166, in take_along_axis
    axis = normalize_axis_index(axis, arr.ndim)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy.exceptions.AxisError: axis 1 is out of bounds for array of dimension 1

Proposed solution

Raise an error on run() when n_findex = 0?