Unidata / netcdf-java

The Unidata netcdf-java library
https://docs.unidata.ucar.edu/netcdf-java/current/userguide/index.html
BSD 3-Clause "New" or "Revised" License
150 stars 71 forks source link

Units for false_easting and false_northing get converted to km #1375

Open iteubner opened 3 months ago

iteubner commented 3 months ago

Versions impacted by the bug

We are using the latest release of thredds-docker (version 5.5), based on this commit, I assume it is version 5.6.0 or 5.6.1-SNAPSHOT. I was not able to identify the version in the container.

What went wrong?

Using thredds-docker, when subsetting a netcdf that has non-zero false_easting and false_norting and units m (https://epsg.io/3416), e.g. NetcdfSubset in catalog, the units for false_easting and falsenorthing get converted to km. But the projection{x|y}_coordinates (and specifications in the esri_pe_string for the data variables) are still in m.

Definition of projection and projection coordinates in the original file:

char lambert_conformal_conic;
  :semi_major_axis = 6378137.0; // double
  :latitude_of_projection_origin = 47.5; // double
  :inverse_flattening = 298.257222101; // double
  :longitude_of_central_meridian = 13.3333333333333; // double
  :standard_parallel = 49.0, 46.0; // double
  :false_northing = 400000.0; // double
  :grid_mapping_name = "lambert_conformal_conic";
  :semi_minor_axis = 6356752.31414036; // double
  :false_easting = 400000.0; // double

double x(x=585);
  :units = "m";
  :long_name = "x coordinate of projection";
  :standard_name = "projection_x_coordinate";
  :axis = "X";

double y(y=314);
  :long_name = "y coordinate of projection";
  :standard_name = "projection_y_coordinate";
  :axis = "Y";
  :units = "m";

Values after subsetting (with projection coordinates added again for completeness):

int lambert_conformal_conic;
  :grid_mapping_name = "lambert_conformal_conic";
  :latitude_of_projection_origin = 47.5; // double
  :longitude_of_central_meridian = 13.3333333333333; // double
  :standard_parallel = 49.0, 46.0; // double
  :false_easting = 400.0; // double
  :false_northing = 400.0; // double
  :units = "km";
  :semi_major_axis = 6378137.0; // double
  :inverse_flattening = 298.257222101; // double

double x(x=585);
  :units = "m";
  :long_name = "x coordinate of projection";
  :standard_name = "projection_x_coordinate";
  :axis = "X";

double y(y=314);
  :long_name = "y coordinate of projection";
  :standard_name = "projection_y_coordinate";
  :axis = "Y";
  :units = "m";

According to CF, as also stated here https://github.com/Unidata/netcdf-java/blob/a7c05d8a2799a3a87982e18c399eb1d5de25b506/cdm/core/src/main/java/ucar/nc2/dataset/transform/AbstractTransformBuilder.java#L33-L37, the unit of false_easting and falsenorting should be the same unit as the projection{x|y}_coordinates. Them not beeing the same causes the data to be displayed horizontally shifted, when opening the data for example in Panoply.

Original: image

Subsetted: image

Could it be related to this line? https://github.com/Unidata/netcdf-java/blob/a7c05d8a2799a3a87982e18c399eb1d5de25b506/cdm/core/src/main/java/ucar/nc2/dataset/transform/AbstractTransformBuilder.java#L80

Relevant stack trace

No response

Relevant log messages

No response

If you have an example file that you can share, please attach it to this issue.

If so, may we include it in our test datasets to help ensure the bug does not return once fixed? Note: the test datasets are publicly accessible without restriction.

Yes

Code of Conduct

tdrwenski commented 3 months ago

Thanks for reporting this and including all the info. Definitely sounds like a bug, we will have a look!