NOAA-ORR-ERD / LibGOODS

Library for accessing data useful for the NOAA / GNOME model
https://libgoods.readthedocs.io/en/latest/
Other
1 stars 2 forks source link

NetCDF mover example #16

Open yosoyjay opened 2 years ago

yosoyjay commented 2 years ago

I tried to slightly change simple_script.py from PyGNOME to use a NetCDF file as a current source, but unfortunately I couldn't quite figure out the right method.

It looks like docs do not align with the PyGNOME installed from the main brach. There are lots of different options, but no clear one to use and the few that I tried(GridCurrentMover, GridCurrent, PyGridCurrentMover) failed due to import errors or None for some variable on the call to model.full_run().

What's the canonical way to do this? @ChrisBarker-NOAA @AmyMacFadyen

AmyMacFadyen commented 2 years ago

Yeah, this is confusing and I was working on rewriting the docs and doing some renaming to make things more clear -- but I got stalled out.

First, the "GridCurrentMover" is deprecated. That calls old C++ code. That shouldn't be imported into the scripting name space anymore and has been renamed to c_GridCurrentMover to try to make it more obscure.

That leaves the newer version "PyCurrentMover". The newer Python movers are based on environment objects which can be created separated (that's what GridCurrent is). You can explicity create these environment objects (e.g. in the case you may want to create multiple movers or weatherers based on it). But in the typically case, you can just create the mover directly and the associated environment object will be created. The environment object contains the data (in this case velocity vectors and understands the grid and how to do interpolation to the particle position). So the "mover" can just ask the environment object for information at the particle location and then apply whatever algorithms are part of the mover.

So that's a lot of background. But to just add a NetCDF file as a current mover, you can do: import gnome.scripting as gs model = gs.Model() curr_mover = gs.PyCurrentMover.from_netCDF('file.nc') model.movers += curr_mover ...

yosoyjay commented 2 years ago

Result from end-to-end.sh

Error:curl error: Error in the HTTP2 framing layer curl error details: Warning:oc_open: Could not read url Running simulation /Users/jesse/src/PyGnome/py_gnome/gnome/init.py:62: UserWarning: ERROR: The adios_db package, version >= 1.0.0 needs to be installed: Only required to use the ADIOS Database JSON format for oil data. warnings.warn(msg) /Users/jesse/mambaforge-x86/envs/gnome/lib/python3.8/site-packages/gridded/depth.py:507: RuntimeWarning: Unable to automatically determine depth system so reverting to surface-only mode. Please verify the index of the surface is correct. warnings.warn('''Unable to automatically determine depth system so reverting to surface-only mode. Please verify the index of the surface is correct.''', RuntimeWarning) Traceback (most recent call last): File "simple_script.py", line 53, in model.full_run() File "/Users/jesse/src/PyGnome/py_gnome/gnome/model.py", line 1186, in full_run results = self.step() File "/Users/jesse/src/PyGnome/py_gnome/gnome/model.py", line 1109, in step self.move_elements() File "/Users/jesse/src/PyGnome/py_gnome/gnome/model.py", line 916, in move_elements delta = m.get_move(sc, self.time_step, self.model_time) File "/Users/jesse/src/PyGnome/py_gnome/gnome/movers/py_current_movers.py", line 281, in get_move res = self.delta_method(num_method)(sc, time_step, File "/Users/jesse/src/PyGnome/py_gnome/gnome/movers/movers.py", line 255, in get_delta_RK2 v0 = vel_field.at(pos, t) File "/Users/jesse/src/PyGnome/py_gnome/gnome/environment/environment_objects.py", line 506, in at value = super(GridCurrent, self).at(points, time, File "/Users/jesse/src/PyGnome/py_gnome/gnome/environment/gridded_objects_base.py", line 896, in at value = super(VectorVariable, self).at(points, time, units=units, *args, *kwargs) File "/Users/jesse/mambaforge-x86/envs/gnome/lib/python3.8/site-packages/gridded/variable.py", line 1077, in at value = np.column_stack([var.at(points=points, File "/Users/jesse/mambaforge-x86/envs/gnome/lib/python3.8/site-packages/gridded/variable.py", line 1077, in value = np.column_stack([var.at(points=points, File "/Users/jesse/src/PyGnome/py_gnome/gnome/environment/gridded_objects_base.py", line 609, in at value = super(Variable, self).at(points, time, args, kwargs) File "/Users/jesse/mambaforge-x86/envs/gnome/lib/python3.8/site-packages/gridded/variable.py", line 549, in at value = self._time_interp(pts, time, extrapolate, _mem=_mem, _hash=_hash, kwargs) File "/Users/jesse/mambaforge-x86/envs/gnome/lib/python3.8/site-packages/gridded/variable.py", line 615, in _time_interp return val_func(points, time, extrapolate, slices=(0,), kwargs) File "/Users/jesse/mambaforge-x86/envs/gnome/lib/python3.8/site-packages/gridded/variable.py", line 650, in _depth_interp return val_func(points, time, extrapolate, slices=slices + (self.depth.surface_index,), kwargs) File "/Users/jesse/mambaforge-x86/envs/gnome/lib/python3.8/site-packages/gridded/variable.py", line 585, in _xy_interp value = self.grid.interpolate_var_to_points(points[:, 0:2], File "/Users/jesse/mambaforge-x86/envs/gnome/lib/python3.8/site-packages/gridded/pysgrid/sgrid.py", line 957, in interpolate_var_to_points idxs = self.apply_padding_to_idxs(ind.copy(), padding=padding) File "/Users/jesse/mambaforge-x86/envs/gnome/lib/python3.8/site-packages/gridded/pysgrid/sgrid.py", line 639, in apply_padding_to_idxs for dim, typ in enumerate(padding): TypeError: 'NoneType' object is not iterable