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

Raise Error when readers are discarded #1325

Open
poplarShift opened this issue Jun 21, 2024 · 3 comments
Open

Raise Error when readers are discarded #1325

poplarShift opened this issue Jun 21, 2024 · 3 comments

Comments

@poplarShift
Copy link
Contributor

poplarShift commented Jun 21, 2024

This:

raise ValueError('Copernicus Marine Client is not installed')
is a nice thought, but this:
self.discard_reader(reader, reason='could not be initialized')

inside a try/except clause makes it only emit a warning and continue with missing data. I guess this should be part of the general error cleanup you mentioned the other day.

On a more general note, OpenDrift would (as far as I am concerned) be more restrictive about trying to continue - e.g. if one gets the projection wrong and hence the reader gets the domain wrong, OpenDrift will still continue with zero velocities (i.e. particles not moving). But I recognize that this is harder to handle (because relevant particles may be seeded later, or drift into the domain).

@poplarShift poplarShift changed the title Raise Error when readers are discarded or only available Raise Error when readers are discarded Jun 21, 2024
@knutfrode
Copy link
Collaborator

For operational processing chains (e.g. search & rescue and oil drift) the priorities are different. Then you add several backup ocean and atmospheric models, and if one returns an error for whatever reason, the simulation shall continue by using a secondary reader for the same variables.

If you want the simulation to stop when some variable (e.g. current) is missing, you should instead set the corresponding fallback value to None. In OpenOil and Leeway this is None by default, as running without currents does generally not produce a valid result:
https://github.com/OpenDrift/opendrift/blob/master/opendrift/models/openoil/openoil.py#L221

However, for the OceanDrift model fallback value of winds and currents is 0, as it might be of interest e.g. for sensitivity studies to run without either of these.
https://github.com/OpenDrift/opendrift/blob/master/opendrift/models/oceandrift.py#L70

Thus if you want to abort a simulation if current is missing, you should do:

o.set_config('environment:constant:x_sea_water_velocity', None)
o.set_config('environment:constant:y_sea_water_velocity', None)

If you are making your own module, you may also set the default fallback value to None in your class definition, such as shown for OpenOil above.

Btw, if you updated your OpenDrift with git pull to use copernicusmarineclient, you must also remember to update the environment:
https://opendrift.github.io/install.html

@poplarShift
Copy link
Contributor Author

Thanks, good to know that None triggers an abort.

It's just something I came across while debugging. I seemed to circumvent the original problem by explicitly instantiating an xarray Dataset, then passing that to the generic netCDF reader, instead of using the shorter version (passing the dataset ID directly). I am not sure why that did not work though.

@knutfrode
Copy link
Collaborator

Yes, if you create the reader explicitly before adding it to OpenDrift (e.g. with reader_copernicusmarine), you should get the error message (and abort) immediately, and not possibly "masked" by the internal try-except.

Btw: if you add lazy=False to add_readers_from_list, the readers will be initialized immediately. The default (lazy=True) if convenient if you have a long list of readers (e.g. as backup for a operational contingency simulation), so that you don't need to spend a lot of time to initiate several readers that might not be needed eventually.
The convenience method add_readers_from_list tries to open the provided filenames/URLs/product_id's with serveral different readers, using the internal method reader_from_url

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