hainegroup / oceanspy

A Python package to facilitate ocean model data analysis and visualization.
https://oceanspy.readthedocs.io
MIT License
101 stars 32 forks source link

Quick start tutorial can't find OceanDataset in potential_density_anomaly() #404

Closed robertlandlord closed 7 months ago

robertlandlord commented 9 months ago

Description

I was following the quick start tutorial at: https://oceanspy.readthedocs.io/en/latest/quick.html

It seems the cutout that was created using od.subsample.cutout doesn't have doesn't have the "OceanDataset" attribute which is being used by the potential_density_anomaly() method. Is this method deprecated or broken?

What I Did

Using sciserver, I spun up the oceanography jupyter notebook and ran the following:

import oceanspy as ospy
od = ospy.open_oceandataset.from_catalog('get_started')

# subsample of geodata
od_cutout = od.subsample.cutout(YRange=[69.6, 71.4], XRange=[-21, -15], ZRange=[0, -100])
# weighted mean temperature
ax = od_cutout.plot.horizontal_section(varName='Temp', meanAxes=['Z', 'time'], center=False)
# potential density anomaly
od_cutout = od_cutout.compute.potential_density_anomaly()

# to netcdf file
# od_cutout.to_netcdf('filename.nc')
# to open from netcdf
# od_cutout = ospy.open_oceandataset.from_netcdf('filename.nc')

# animate
anim = od_cutout.animate.TS_diagram(colorName='Sigma0', meanAxes='Z')

Error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 9
      7 ax = od_cutout.plot.horizontal_section(varName='Temp', meanAxes=['Z', 'time'], center=False)
      8 # potential density anomaly
----> 9 od_cutout = od_cutout.compute.potential_density_anomaly()
     11 # to netcdf file
     12 # od_cutout.to_netcdf('filename.nc')
     13 # to open from netcdf
     14 # od_cutout = ospy.open_oceandataset.from_netcdf('filename.nc')
     15 
     16 # animate
     17 anim = od_cutout.animate.TS_diagram(colorName='Sigma0', meanAxes='Z')

File ~/mambaforge/envs/Oceanography/lib/python3.10/site-packages/oceanspy/compute.py:2927, in _computeMethods.potential_density_anomaly(self, overwrite, **kwargs)
   2925 @_functools.wraps(potential_density_anomaly)
   2926 def potential_density_anomaly(self, overwrite=False, **kwargs):
-> 2927     ds = potential_density_anomaly(self._od, **kwargs)
   2928     return self._od.merge_into_oceandataset(ds, overwrite=overwrite)

File ~/mambaforge/envs/Oceanography/lib/python3.10/site-packages/oceanspy/compute.py:1167, in potential_density_anomaly(od)
   1164 # Create ds
   1165 ds = _xr.Dataset({"Sigma0": Sigma0}, attrs=od.dataset.attrs)
-> 1167 return _ospy.OceanDataset(ds).dataset

AttributeError: module 'oceanspy' has no attribute 'OceanDataset'
ThomasHaine commented 9 months ago

Hi @robertlandlord, thanks for opening this issue. I'm able to run the Quick start tutorial on SciServer OK. Are you sure you selected an Oceanography kernel when you created your notebook? (see upper right kernel name on screenshot below).

Screenshot 2023-12-29 at 8 55 30 AM
Mikejmnez commented 9 months ago

Just confirming that I too was able produce the animation / figure above from a fresh container, the most recent Oceanography environment with most recent version of OceanSpy, and the "Ocean Circulation" data volume.

I created the interactive SciServer container as follows:

Screen Shot 2023-12-29 at 12 26 07 PM
ThomasHaine commented 7 months ago

Close this issue? Seems like it's out of date.

robertlandlord commented 7 months ago

Apologies for the delayed response - been busy with other responsibilities since opening this last year.

I opened up a new Oceanography notebook on a new compute and it seemed to work this time. Maybe the image that the old container was started up with was missing some dependencies or running an older commit of oceanspy?

In any case, I can't reproduce this issue anymore, so will close. Thanks for checking here! I appreciate the help :)