You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I use Ocetrac with a dataset that has dimension names that aren't lat or lon (for example, y and x) I get the error TypeError: Only 2-D and 3-D images supported.. I specified the different dimension names using xdim and ydim.
When I traced this back it seems like what is going on is that when you specify an xdim or ydim that aren't lat or lon, lat and lon still get added as new dimensions and the user specified xdim and ydim don't get removed. That is why the resulting error is scolding you for not having 2 or 3 dimensions, because you now have 5 (time, x, y, lat, lon).
Example
This example uses a subset of the MUR SST dataset from AWS. I manually changed the dimension names to x and y to demonstrate the error.
The example takes about 1 minute to run. You need s3fs installed to open the data.
Example Code
importfsspecimportxarrayasxrimportocetrac# Load zarr SST (NASA MUR)ikey=fsspec.get_mapper('s3://mur-sst/zarr', anon=True)
mur_full=xr.open_zarr(ikey, consolidated=True)
mur=mur_full['analysed_sst']
# Get a small area for this testmur_subset=mur.sel(lat=slice(32, 32.5), lon=slice(121.4, 122.2))
# Compute the climatologyclimatology=mur_subset.groupby(mur_subset.time.dt.month).mean()
# Calculate the anomaly (with only a month's worth of data)mur_2018_subset=mur_subset.sel(time='2018-06')
anomaly=mur_2018_subset.groupby(mur_2018_subset.time.dt.month) -climatologyanomaly=anomaly.load()
# Create a land maskmask=xr.where(mur_2018_subset.isel(time=0) <=270, 0, 1)
mask=mask.load()
# Calculate the 90th percentile valuespercentile=0.9threshold=mur_subset.groupby(mur_subset.time.dt.month).quantile(percentile, dim='time', keep_attrs=True, skipna=True, )
# Use the threhold values to mask out values that are not marine heatwavehot_water=anomaly.where(mur_2018_subset.groupby(mur_2018_subset.time.dt.month)>threshold)
hot_water=hot_water.load()
# Change the dimensions from lat, lon to x, y (in order to show the error)hot_water=hot_water.rename({'lon': 'x', 'lat': 'y'})
# Run OcetracTracker=ocetrac.Tracker(hot_water, mask, radius=2, min_size_quartile=0.75, timedim='time', xdim='x', ydim='y', positive=True)
blobs=Tracker.track()
Removing the line hot_water = hot_water.rename({'lon': 'x', 'lat': 'y'}) and using Tracker = ocetrac.Tracker(hot_water, mask, radius=2, min_size_quartile=0.75, timedim = 'time', xdim = 'lon', ydim='lat', positive=True) instead works fine. (No objects are found, but we get past the dimension error)
I am happy to work on a fix for this. I think the dimension is getting added either in the _apply_mask() or _filter_area() area functions. If anyone has additional thoughts on where to start I definitely welcome those, otherwise I'll post updates here. I am assuming the behavior we want is to use the user specified xdim and ydim and avoid the behavior where lat and lon get added to the Dataset.
Also, if I am just using Ocetrac wrong and this isn't actually a bug please let me know!
The text was updated successfully, but these errors were encountered:
What's happening
When I use Ocetrac with a dataset that has dimension names that aren't
lat
orlon
(for example,y
andx
) I get the errorTypeError: Only 2-D and 3-D images supported.
. I specified the different dimension names usingxdim
andydim
.ocetrac.Tracker(hot_water, mask, radius=2, min_size_quartile=0.75, timedim = 'time', xdim = 'x', ydim='y', positive=True)
Guess about the problem
When I traced this back it seems like what is going on is that when you specify an
xdim
orydim
that aren'tlat
orlon
,lat
andlon
still get added as new dimensions and the user specifiedxdim
andydim
don't get removed. That is why the resulting error is scolding you for not having 2 or 3 dimensions, because you now have 5 (time, x, y, lat, lon).Example
This example uses a subset of the MUR SST dataset from AWS. I manually changed the dimension names to
x
andy
to demonstrate the error.The example takes about 1 minute to run. You need
s3fs
installed to open the data.Example Code
Removing the line
hot_water = hot_water.rename({'lon': 'x', 'lat': 'y'})
and usingTracker = ocetrac.Tracker(hot_water, mask, radius=2, min_size_quartile=0.75, timedim = 'time', xdim = 'lon', ydim='lat', positive=True)
instead works fine. (No objects are found, but we get past the dimension error)Full Traceback
Status
I am happy to work on a fix for this. I think the dimension is getting added either in the
_apply_mask()
or_filter_area()
area functions. If anyone has additional thoughts on where to start I definitely welcome those, otherwise I'll post updates here. I am assuming the behavior we want is to use the user specifiedxdim
andydim
and avoid the behavior wherelat
andlon
get added to the Dataset.Also, if I am just using Ocetrac wrong and this isn't actually a bug please let me know!
The text was updated successfully, but these errors were encountered: