AntSimi / py-eddy-tracker

Eddy identification and tracking
https://py-eddy-tracker.readthedocs.io/en/latest/
GNU General Public License v3.0
132 stars 55 forks source link

grid_count and grid_stat error #232

Closed berzinastella closed 8 months ago

berzinastella commented 9 months ago

grid_count and grid_stat error

Hi, I'm trying to calculate eddy count per pixel and eddy geographical statistics. The example notebooks for that seem to not be working anymore also with the demo data (https://py-eddy-tracker.readthedocs.io/en/stable/python_module/10_tracking_diagnostics/pet_geographic_stats.html#sphx-glr-python-module-10-tracking-diagnostics-pet-geographic-stats-py and https://py-eddy-tracker.readthedocs.io/en/stable/python_module/10_tracking_diagnostics/pet_pixel_used.html#sphx-glr-python-module-10-tracking-diagnostics-pet-pixel-used-py)

and give me an error of

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[5], line 12
      9 ax_ratio.set_title("Ratio cyclonic / Anticyclonic")
     11 # Count pixel used for each contour
---> 12 g_a = a.grid_count(bins, intern=True)
     13 g_a.display(ax_a, **kwargs_pcolormesh)
     14 g_c = c.grid_count(bins, intern=True)

File ~/.conda/envs/py39/lib/python3.9/site-packages/py_eddy_tracker/observations/observation.py:2239, in EddiesObservations.grid_count(self, bins, intern, center, filter)
   2236 grid = ma.zeros((x_bins.shape[0] - 1, y_bins.shape[0] - 1), dtype="u4")
   2237 from ..dataset.grid import RegularGridDataset
-> 2239 regular_grid = RegularGridDataset.with_array(
   2240     coordinates=("lon", "lat"),
   2241     datas=dict(
   2242         count=grid,
   2243         lon=(x_bins[1:] + x_bins[:-1]) / 2,
   2244         lat=(y_bins[1:] + y_bins[:-1]) / 2,
   2245     ),
   2246     variables_description=dict(
   2247         count=dict(long_name="Number of times the pixel is within an eddy")
   2248     ),
   2249     centered=True,
   2250 )
   2251 if center:
   2252     x, y = (self.longitude[filter] - x0) % 360 + x0, self.latitude[filter]

File ~/.conda/envs/py39/lib/python3.9/site-packages/py_eddy_tracker/dataset/grid.py:1241, in RegularGridDataset.with_array(cls, coordinates, datas, variables_description, **kwargs)
   1239 vd = dict() if variables_description is None else variables_description
   1240 x_name, y_name = coordinates[0], coordinates[1]
-> 1241 obj = cls("array", x_name, y_name, unset=True, **kwargs)
   1242 obj.x_dim = (x_name,)
   1243 obj.y_dim = (y_name,)

File ~/.conda/envs/py39/lib/python3.9/site-packages/py_eddy_tracker/dataset/grid.py:1215, in RegularGridDataset.__init__(self, *args, **kwargs)
   1214 def __init__(self, *args, **kwargs):
-> 1215     super().__init__(*args, **kwargs)
   1216     self._is_circular = None

File ~/.conda/envs/py39/lib/python3.9/site-packages/py_eddy_tracker/dataset/grid.py:306, in GridDataset.__init__(self, filename, x_name, y_name, centered, indexs, unset, nan_masking, nc4file)
    304 self.vars = dict()
    305 self.indexs = dict() if indexs is None else indexs
--> 306 self.nc4file = Dataset(filename, "r") if nc4file is None else nc4file
    307 if centered is None:
    308     logger.warning(
    309         "We assume pixel position of grid is centered for %s", filename
    310     )

File src/netCDF4/_netCDF4.pyx:2469, in netCDF4._netCDF4.Dataset.__init__()

File src/netCDF4/_netCDF4.pyx:2028, in netCDF4._netCDF4._ensure_nc_success()

FileNotFoundError: [Errno 2] No such file or directory: 'array'

Is it a package version issue? Thanks, Stella

AntSimi commented 8 months ago

When i try on this 2 example on binder, all things work. This line look like a custom code, it doesn't exist in official repository:

self.nc4file = Dataset(filename, "r") if nc4file is None
berzinastella commented 8 months ago

When i try on this 2 example on binder, all things work. This line look like a custom code, it doesn't exist in official repository:

self.nc4file = Dataset(filename, "r") if nc4file is None

Hi, yes, sorry, you are right. The issue was from our custom py-eddy-tracker version. You can close the issue, because the issue was us.