Closed ThomasHaine closed 1 year ago
Thanks @ThomasHaine I will look into this. Can you share what the p
values are, so that I can reproduce the error?
Sorry, I don't follow. What p
values?
Nevermind! I just saw that these are written in your message (p
-values are lats and lons used to compute arrays).
p1 = [{"type":"LineString","coordinates":[[-27.550652911045805,68.60723990897543],[-26.783621229652017,67.4686818705328],[-24.284903450280915,67.12069825754523],[-22.93272404606945,66.47294135507451]]}]
Here is a plot of the resulting mooring array superimposed over the model's Depth
from the resulting cutout. Definitely a bug. The trajectory of the mooring array revisits certain coordinates (even though there are no repeated coords since I am removing any repeated ones).
I am not 100% sure the error is associated with the weird trajectory of the array. But it certainly doesn't help. I will take a look into this starting from here.
Sorry for the late reply (I had to go to DC kind of unexpectedly). I figured out what is causing the error:
In the ECCO
dataset, the variable time_bnds
with dimensions (time:312, nv:2)
causes the error above when computing mass flux i.e. the integration along all the dataset's dimensions (time, Z, mooring, X, Y, Xp1, Yp1
).
Removing the variable before the integration solves this issue. For example:
# OGCM_dataset = 'ECCO'
OGCM_dataset = 'ECCO'
od = ospy.open_oceandataset.from_catalog(OGCM_dataset)
if OGCM_dataset == 'LLC4320':
# LLC4320 cutout requires this:
od._ds = od._ds.drop_vars({'k', 'k_u', 'k_p1', 'k_l'})
co_list = [var for var in od._ds.variables if "time" not in od._ds[var].dims]
od._ds = od._ds.set_coords(co_list)
else:
od._ds = od._ds.drop_vars({'k', 'k_u', 'k_p1', 'k_l', 'time_bnds'})
ds = od.dataset
ds['Temp'] = ds['THETA']
od = ospy.OceanDataset(ds)
The variable is not present in the LLC4320 dataset, and so there is no error there.
Nonetheless, I worked out a way to solve the weirdness of the array above. I will run some extra checks tomorrow to make sure it doesn't happen again.
Thanks @Mikejmnez. It now works without an error. Please can you share the code to make the figure of the mooring path above. I'll make some more checks.
closed by #361
There are two ways to make the horizontal maps of depth with mooring array. Which one you use depends on the particulars of the cutout and or mooring array... This is a consequence of the complex topology and the removal of face as dimension during cutout.
I ran the following snippets in Sciserver. Took about 1-2 minutes to complete.
# import packages
import oceanspy as ospy
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = 12, 8
from dask.distributed import Client client = Client() client
od = ospy.open_oceandataset.from_catalog('ECCO') od._ds = od._ds.drop_vars({'k', 'k_u', 'k_p1', 'k_l', 'time_bnds', 'ETAN_snap'}) co_list = [var for var in od._ds.variables if "time" not in od._ds[var].dims] od._ds = od._ds.set_coords(co_list)
p1 = [{"type":"LineString","coordinates":[[-27.550652911045805,68.60723990897543],[-26.783621229652017,67.4686818705328],[-24.284903450280915,67.12069825754523],[-22.93272404606945,66.47294135507451]]}] lon, lat = ospy.utils.viewer_to_range(p1)
args = { "XRange": lon, "YRange": lat, } cut_od = od.subsample.cutout(**args)
od_moor = od.subsample.mooring_array(Xmoor=lon, Ymoor=lat) Xmoor = od_moor.dataset['XC'].squeeze().values Ymoor = od_moor.dataset['YC'].squeeze().values
fig = plt.figure(figsize=(12, 5)) ax = cut_od.plot.horizontal_section(varName="Depth", cmap='Greys_r') ax.plot(lon, lat, 'b') # original data line = ax.plot(Xmoor, Ymoor, "r.", ls='--'); # mooring
The above works well if:
a) there are no `NANs` in the coordinates (`XC` and `YC`). Nans can happen in the LLC dataset after cutout transformation due to complex topology.
b) Mooring array does not involve jump singularities in the longitude, like it can happen in the Pacific Ocean.
2. In the case of any of a) or b) above, you can still visualize the data by plotting in INDEX space, since in the transformed dataset the axes `X, Y` are roughly aligned with `lon` and `lat` respectively. So for the same dataset and mooring array, you can plot instead as:
```python
fig = plt.figure(figsize=(10, 5))
plt.contourf(cut_od._ds['Depth'], levels = np.linspace(0, 5000, 250), cmap='Greys_r')
plt.plot(od_moor.dataset['Xind'].squeeze().values, od_moor.dataset['Yind'].squeeze().values, 'r-.', marker='o', markersize=5)
plt.show()
The following
compute.integral
works for LLC4320 but errors for ECCO (on SciServer):The ECCO error is: