Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give more helpful error when n_findex = 0 #1011

Open
paulf81 opened this issue Oct 29, 2024 · 3 comments
Open

Give more helpful error when n_findex = 0 #1011

paulf81 opened this issue Oct 29, 2024 · 3 comments

Comments

@paulf81
Copy link
Collaborator

paulf81 commented Oct 29, 2024

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?

@misi9170
Copy link
Collaborator

I was originally going to suggest a warning, rather than an error, might be most appropriate; but finally, anyone calling run() will then want to call on of the postprocessing calls, and those calls won't work properly (or worse, may extract a previous run()'s results) if an error is not raised. So, I'm in favor of raising an error (possibly a RuntimeError?) in this situation. Any external algorithm that calls run() (but possibly with n_findex = 0) can then have a try/except clause built in to catch the error and deal with it.

@misi9170
Copy link
Collaborator

misi9170 commented Feb 4, 2025

How closely is this linked to #1007? Could it be addressed in that PR?

@paulf81
Copy link
Collaborator Author

paulf81 commented Feb 4, 2025

They could be made to be related, but that one is focused on adding error checks to WindData objects and this one to FlorisModel. We could however make #1007 more general and include fixes to that as well since they are both about dealing with NaNs and then NaNs leading to 0-length inputs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants