parcels
parcels copied to clipboard
Issue creating fieldset from netCDF
Hello, I am loading in a NetCDF of ocean currents into a fieldset but getting the following error
-------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [47], in <cell line: 1>()
----> 1 fieldset = FieldSet.from_netcdf(filenames, variables, dimensions)
File ~/miniconda3/envs/parcels/lib/python3.10/site-packages/parcels/fieldset.py:287, in FieldSet.from_netcdf(cls, filenames, variables, dimensions, indices, mesh, timestamps, allow_time_extrapolation, time_periodic, deferred_load, **kwargs)
285 kwargs['dataFiles'] = fields[procvar].dataFiles
286 break
--> 287 fields[var] = Field.from_netcdf(paths, (var, name), dims, inds, grid=grid, mesh=mesh, timestamps=timestamps,
288 allow_time_extrapolation=allow_time_extrapolation,
289 time_periodic=time_periodic, deferred_load=deferred_load, **kwargs)
290 u = fields.pop('U', None)
291 v = fields.pop('V', None)
File ~/miniconda3/envs/parcels/lib/python3.10/site-packages/parcels/field.py:210, in Field.from_netcdf(cls, filenames, variable, dimensions, indices, grid, mesh, timestamps, allow_time_extrapolation, time_periodic, deferred_load, **kwargs)
207 variable = (variable, variable)
208 assert len(variable) == 2, 'The variable tuple must have length 2. Use FieldSet.from_netcdf() for multiple variables'
--> 210 data_filenames = cls.get_dim_filenames(filenames, 'data')
211 lonlat_filename = cls.get_dim_filenames(filenames, 'lon')
212 if isinstance(filenames, dict):
File ~/miniconda3/envs/parcels/lib/python3.10/site-packages/parcels/field.py:143, in Field.get_dim_filenames(cls, filenames, dim)
141 @classmethod
142 def get_dim_filenames(cls, filenames, dim):
--> 143 if isinstance(filenames, str) or not isinstance(filenames, collections.Iterable):
144 return [filenames]
145 elif isinstance(filenames, dict):
AttributeError: module 'collections' has no attribute 'Iterable'
The neetcdf looks like this in xarray
I am trying to replicate a tutorial, and my code is
fname = '/Users/gracecolverd/river_app/particle_flow/dataset-omega-3d*.nc'
filenames = {'U': fname, 'V': fname}
variables = {'U': 'uo', 'V': 'vo'}
dimensions = {'U': {'lat': 'lat', 'lon': 'lon', 'time': 'time', 'depth' : 'depth'},
'V': {'lat': 'lat', 'lon': 'lon', 'time': 'time', 'depth' : 'depth' }}
fieldset = FieldSet.from_netcdf(filenames, variables, dimensions)
Seems like this issue was fixed in PR #666, and would be in parcels v2.1.3
onwards. Could you print(parcels.__version__)
to check which version, and update as required?
Thanks! I have version 2.0. I'm having trouble updating - originally I had to pip install as none of the conda channels work. Nor does 'conda create -n py3_parcels -c conda-forge parcels jupyter cartopy ffmpeg ' - I get a '``` packagesNotFoundError: The following packages are not available from current channels:
- parcels
Could you try conda config --append channels conda-forge
(which will add the conda-forge
channel to conda).
Then conda create -n py3_parcels -c conda-forge parcels jupyter cartopy ffmpeg
should work.
I already have the conda forge channel I think -
Current channels:
- https://conda.anaconda.org/conda-forge/osx-arm64
- https://conda.anaconda.org/conda-forge/noarch
- https://repo.anaconda.com/pkgs/main/osx-arm64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/osx-arm64
- https://repo.anaconda.com/pkgs/r/noarch
I tried re running your two commands but still didnt work
Ah I see. Looking at the channels, I think that you're running off Apple's new CPU (hence osx-arm64
and not osx-64) and parcels isn't listed on their conda forge as supporting this architecture.
From the end of discussion #1080, it seems that there shouldn't be anything preventing parcels from working off the new architecture. Maybe @erikvansebille could shed some more light onto this?
Sorry, I don't know enough to devise a workaround for you in the meanwhile 😢
Thanks for posting out that osx-arm is not listed at https://anaconda.org/conda-forge/parcels; perhaps @willirath can help us to support that too? I'll look into it as well
In the meantime, v2.0 is far too old to work with so not surprising that you're running into problems, @graceebc9. There are two things you can try to install a newer version until we've added osx-arm to the conda-forge:
- Install the 'developer' version of Parcels, per the 'Installation for developers' section at https://oceanparcels.org/#installing
- Install the prerelease-version of parcels v2.3.1 via pip (see the discussion at https://github.com/OceanParcels/parcels/pull/1163#issuecomment-1194071257)
Thanks! I installed the developer version and field set is now working :)