OceanParcels / Parcels

Main code for Parcels (Probably A Really Computationally Efficient Lagrangian Simulator)
https://www.oceanparcels.org
MIT License
295 stars 136 forks source link

Dimension `trajectory` conflicts with variable `trajectory` #334

Closed willirath closed 6 years ago

willirath commented 6 years ago

Currently, https://github.com/OceanParcels/parcels/blob/master/parcels/particlefile.py#L44_L52 defines a dimension trajectory and a variables trajectory that has more than one dimension. This collides with the concept of "coordinate variables" defined in the CF conventions. This causes problems whenever a tools relies on the notion of coordinate variables (xarray does, and NCO does partly).

Opening a particlefile with Xarray results in

MissingDimensionsError: 'trajectory' has more than 1-dimension and the same name
as one of its dimensions ('trajectory', 'obs'). xarray disallows such variables because
they conflict with the coordinates used to label dimensions.

Current workaround (rename the dimension to, e.g., "traj"):

from shutil import copy
import netCDF4 as nc4
import xarray as xr

orig_file = "some_particlefile.nc"
dest_file = "some_particlefile_with_renamed_dim.nc"

copy(source_file, dest_file)

with nc4.Dataset(dest_file, mode="a") as tmp_ds:
    tmp_ds.renameDimension("trajectory", "traj")

particle_dataset = xr.open_dataset(dest_file)

As far as I see, fixing this could be as easy as modifying "trajectory" to "traj" in particlefile.py. But I'm not sure if I missed something.

erikvansebille commented 6 years ago

Fixed in #335