Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netCDF structured domains with masked coordinates lead to pixelsize == 0 #1436

Open
lencart opened this issue Oct 31, 2024 · 2 comments
Open

Comments

@lencart
Copy link

lencart commented Oct 31, 2024

Framing

While writing a structured netCDF reader for Delft3D-Flow outputs, I found out that the pixel size and bounding box are calculated wrong due to the masked coordinates.

Delft3D-Flow places masks not only on the variables but in the coordinates where the domain is not defined.

Possible causes

  1. The x, y max min is changed inside structured.py (line 57) based on self.lon and self.lat shapes ignoring the mask. This overrides the setting of the extreme pixels inside the delft3d reader. Plus, it seems to switch the coordinate dimensions.

  2. Because opendrift is looking for a bounding box of a masked array, some of the bounding box values can be mapped into the closest NaN by scipy.ndmimage.map_coordinates.

Test files

The delft3d-flow reader can be found here. You may want to look at the standard variable mapping at the top of the module so that you are able to extract the correct variables from the netCDF files that you can find here for the unprojected wgs84 and here for the projected in epgsg:28992

@knutfrode
Copy link
Collaborator

knutfrode commented Oct 31, 2024

You can define a dedicated pixelsize method in this specific reader,

def pixelsize(self):
    return 1

If I temorarily do this in structured.py, it is possibly to create a generic Reader for the unprojected file, with some mapping of standard_name:

from opendrift.readers.reader_netCDF_CF_generic import Reader
r = Reader('trim-f34_wgs84.nc', standard_name_mapping={'U1': 'x_sea_water_velocity', 'V1': 'y_sea_water_velocity'})
print(r)

===========================
Reader: trim-f34_wgs84.nc
Projection: 
  None
Coverage: [pixels]
  xmin: 0.000000   xmax: 21.000000   step: 1   numx: 22
  ymin: 0.000000   ymax: 14.000000   step: 1   numy: 15
  Corners (lon, lat):
    (  0.00,   0.00)  (  0.00,   0.00)
    (  0.00,   0.00)  (  0.00,   0.00)
Vertical levels [m]: 
  Not specified
Available time range:
  start: 1990-08-05 12:30:00   end: 1990-08-06 01:00:00   step: 0:15:00
    51 times (0 missing)
Variables:
  longitude
  latitude
  x_sea_water_velocity
  y_sea_water_velocity
  sea_water_speed - derived from ['x_sea_water_velocity', 'y_sea_water_velocity']
===========================

But it remains to deal with the lon- and lat- arrays containing 0 values where they should be masked.
OpenDrift does presently not handle lon- lat arrays with masked values, but perhaps this could be implemented in a delft-reader, overriding existing methods in parent reader classes.
Later, and ideally, these features/changes could be moved to the parent classes, removing the need for a dedicated Delft-reader.

@lencart
Copy link
Author

lencart commented Oct 31, 2024

Thanks for looking into it.
Could you please point me to which parent class methods I need to override?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants