custom ssh plugin
joseph-daddezio opened this issue · 4 comments
Trying to make an ssh plugin that reads some netcdf files.
Used aviso.py as a template, which may be a mistake. Error below. I've attached my new 'ncom.py' and my 'conf.py' file. Thanks for your help!!!
jmdaddez@stout[/u/oot/jmdaddez/S-MODE/swot_simulator]$ /home/jmdaddez/anaconda3/bin/swot_simulator conf.py --first-date 2019-01-01 --last-date 2019-01-31
[E - 128.160.8.61 - Jul 20 20:53:16 - launcher] RuntimeError - Traceback (most recent call last):
/home/jmdaddez/anaconda3/lib/python3.8/site-packages/swot_simulator/launcher.py in main
503 try:
504 parameters = settings.Parameters(
----> 505 settings.eval_config_file(args.settings.name))
506
507 # Keep track of the overriden parameters
/home/jmdaddez/anaconda3/lib/python3.8/site-packages/swot_simulator/settings.py in eval_config_file
70 "called sys.exit()") from err
71 except Exception as err:
----> 72 raise RuntimeError(
73 "There is a programmable error in your configuration "
74 f"file:\n\n{traceback.format_exc()}") from err
RuntimeError: There is a programmable error in your configuration file:
Traceback (most recent call last):
File "/home/jmdaddez/anaconda3/lib/python3.8/site-packages/swot_simulator/settings.py", line 62, in eval_config_file
execfile_(filename, namespace)
File "/home/jmdaddez/anaconda3/lib/python3.8/site-packages/swot_simulator/settings.py", line 38, in execfile_
exec(code, _globals)
File "conf.py", line 101, in
ssh_plugin = swot_simulator.plugins.ssh.NCOM("/u/GoM_4dvar/SWOT-cal-val/model/OoT/raw/ssha")
File "/home/jmdaddez/anaconda3/lib/python3.8/site-packages/swot_simulator/plugins/ssh/ncom.py", line 20, in init
loader = data_handler.NetcdfLoader(
File "/home/jmdaddez/anaconda3/lib/python3.8/site-packages/swot_simulator/plugins/data_handler.py", line 200, in init
self.time_delta = self._calculate_time_delta(self.time_series["date"])
File "/home/jmdaddez/anaconda3/lib/python3.8/site-packages/swot_simulator/plugins/data_handler.py", line 102, in _calculate_time_delta
raise RuntimeError(
RuntimeError: Time series does not have a constant step between two grids: {numpy.timedelta64(0,'s'), numpy.timedelta64(172800,'s'), numpy.timedelta64(86400,'s')} seconds
[E - 128.160.8.61 - Jul 20 20:53:16 - launcher] End of processing.
I think your plugin is working correctly. The error message says that the time gap between two consecutive grids is not constant. If this is normal, you can comment out the verification line.
Got further. Thank you! It's trying to interpolate the ssh data:
<xarray.DataArray 'ssh' (time: 2, lat: 1222, lon: 1066)>
dask.array<concatenate, shape=(2, 1222, 1066), dtype=float64, chunksize=(1, 1222, 1066), chunktype=numpy.ndarray>
Coordinates:
- lon (lon) float64 233.0 233.0 233.0 233.0 ... 244.5 244.5 244.5 244.5
- lat (lat) float64 28.0 28.01 28.02 28.03 ... 38.96 38.97 38.98 38.99
- time (time) datetime64[ns] 2019-01-01T01:00:00 2019-01-01T01:00:00
Attributes:
long_name: NCOM OoT Sea Surface Height Anomaly (tides removed) (m)
The data have type and dimensions:
<class 'xarray.core.dataarray.DataArray'>
(2, 1222, 1066) (time, lat, lon)
Getting this error during interpolation:
/home/jmdaddez/anaconda3/lib/python3.8/site-packages/swot_simulator/plugins/ssh/ncom.py in interpolate
37 print(type(dataset.ssh))
38 print(np.shape(dataset.ssh))
----> 39 interpolator = pyinterp.backends.xarray.Grid3D(dataset.ssh)
40 ssh = interpolator.trivariate(
41 dict(lon=lon, lat=lat, time=dates),
/home/jmdaddez/anaconda3/lib/python3.8/site-packages/pyinterp/backends/xarray.py in __init__
279 dtype = data_array.coords[z].dtype
280 if "datetime64" in dtype.name:
----> 281 self._datetime64 = z, axis.TemporalAxis(
282 data_array.coords[z].values)
283 else:
/home/jmdaddez/anaconda3/lib/python3.8/site-packages/pyinterp/axis.py in __init__
81 """
82 self._assert_issubdtype(values.dtype)
----> 83 super().__init__(values.astype("int64"))
84 self.dtype = values.dtype
85 self.object = self._object(self.dtype)
ValueError: axis values are not ordered
You have to sort the grids you use to interpolate the SSH. The error tells you that you are trying to build the time axis (needs to select the grids around a point) from a vector that is not sorted.
From what I see in your example, the dates of both grids are identical: 2019-01-01T01:00:00
Normally you have to read a different date for each grid in order to build the time axis:
Time for each grids: t_0 -- t_1 -- t_2 -- t_3 -- ... - t_n
Great eye, thank you! It's running now :)