-
Notifications
You must be signed in to change notification settings - Fork 71
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
Some coordinate system dimensions can be lost if unnamed #951
Comments
This workaround does not completely solve the problem because a fix relative to `ucar.nc2.dataset.CoordinateSystem` is also needed. Unidata/netcdf-java#951
Hi Martin: Thanks for the comments. The only way that a coordinate can be associated with a data variable is with shared dimensions. I agree that allowing unnamed dimensions is questionable, but I dont see any practical effects on coordinate variables or systems. Unshared dimensions have been allowed for NetcdfFile for legacy datasets; the idea is that this would be fixed with CoordinateBuilders so that NetcdfDataset and GridDataset can georeference. Regards, |
Hello John. Thanks for the reply. I'm reading a GCOM-C file from JAXA in HDF5 format. My test file is 1.3 Mb, which is why I didn't attached it to this issue. I get the Maybe an easy fix would be to change the type of the |
HI Martin, can you send me the file in question? Thanks |
Sure, I will send it by private email in a few minutes. A
The following Java code reproduces the problem: import ucar.nc2.dataset.CoordinateSystem;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.dataset.NetcdfDatasets;
final class Test {
public static void main(String[] args) throws Exception {
try (NetcdfDataset file = NetcdfDatasets.openDataset("GC1SG1_202105251107C25504_L2SG_SSTDK_2000.h5")) {
for (CoordinateSystem cs : file.getCoordinateSystems()) {
System.out.println(cs.getDomain().size());
}
}
}
} Above code prints |
I thought that I had your email address, but couldn't find it back. Is there a place where I can upload a 1.3 MB file? |
You should be able to attach the file to this issue as long as it is compressed (.zip or .gz) |
Hi Martin: I agree that something better could be done. What version of the library are you using? |
I'm using 5.4.2 downloaded from UCAR Maven repository. |
The problem is that we have 4 anonymous dimensions, and we have to know that the dim0 and dim1 are the same for the two variables Latitude and Longitude, but dim0 != dim1. That is plain to see by inspection of the Dim0 and Dim1 attributes:
By design, this kind of dataset specific knowledge is placed in a CoordSysBuilder. Is there a good reason to not do so here? |
No reason to not use |
Yes it does use CoordSystemBuilder, what I meant to say is that we want to make a JAXA specific subclass that can key in on the :DimX attributes and assign shared dimensions. Since the data variables are also using the same names, there will be two identically named dimensions in each group (Geometry_data and Image_data) with different lengths:
I guess your software knows all about that and is doing coordinate interpolation? One could place that into the CoordSystemBuilder also. The original idea was that people could add their own CoordSystemBuilderFactory class and add it at runtime. But it never caught on, too complicated i think. |
PS: thanks for the note on NPE in compare(), im changing so nulls arent used (in version 8, not sure about backporting). |
Ive prototyped adding a JAXA CoordSystemBuilder. However, you dont get any CoordinateSystems because the Coordinate Variables (Latitude, Longiture, Time) dont match the data Variables (Cloud_probability, QA_flag, SST). to do that we would have to include the interpolation code and generate Latitude(Line_grids=1242, Pixel_grids=1250), Longitude(Line_grids=1242, Pixel_grids=1250) etc. |
The current ncdump with prototyped JAXA CoordSystemBuilder:
|
A JAXA |
The problem is that there is no CoordinateSystem assigned, because there are no Coordinate Axes that match the data values' dimensions (domain). We could assign it anyway, but standard tools would break on it.
Perhaps I should ask what functionality do you get out of the CoordinateSystem being assigned to the data variable? Do you want standard tools to work (eg TDS' WMS and Coverage server)? |
Actually I do not use the import ucar.nc2.dataset.CoordinateSystem;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.dataset.NetcdfDatasets;
final class Test {
public static void main(String[] args) throws Exception {
try (NetcdfDataset file = NetcdfDatasets.openDataset("GC1SG1_202105251107C25504_L2SG_SSTDK_2000.h5")) {
for (CoordinateSystem cs : file.getCoordinateSystems()) {
System.out.println(cs.getDomain().size());
}
}
}
} It seems to me that the problem could be solved by updating this field, by replacing the |
CoordinateSystem's depend on knowing the unique set of Dimensions, which is their "domain". The problem is in Dimension.equals() for unshared Dimensions. Im experimenting with changing that so that unshared Dimensions dont equal anything but themselves. Really the problem is that HDF5 doesnt have a coherent syntax for shared dimensions and/or the dataset writer doesnt use what HDF5 does provide (Dimension scales) and instead uses a bespoke Convention. Which is supposed to be fixed by a bespoke CoordSysBuilder. Which we could do except that we dont handle the interpolated satellite case. I think Id like to add the interpolated satellite case to version 8 as a CoordSysBuilder, and do some minimal thing for ver5.
thanks |
Sure you are welcome to incorporate the interpolation code :-). But it may be a significant work. The interpolation from grid to geographic coordinates is relatively easy, but the inverse interpolation (from geographic coordinates to grid) is much more difficult. I will ask for including a JAXA file in unit test and will report back on this issue. Note: about above-cited difficulty with interpolation, in the particular case of those JAXA data, interpolations become easier if we convert the geographic coordinates to a Universal Transverse Mercator (UTM) projection. The reason is that the grid is highly non-linear when coordinates are expressed in latitude/longitude, but become much more linear (i.e. it looks more like a regular grid) after coordinates are projected to UTM. I mention that as a point worth to keep in mind when designing the software (i.e. to have the capability to project the coordinates to another Coordinate Reference System before to use them for interpolations). |
Seems reasonable to convert to UTM. Can you send me a pointer to your code? Any tests you have would be helpful. |
Sure. The way interpolation is implemented, an initial step is to compute a linear approximation of the interpolation. This is the work of A helper class used by After we got an The code doing the interpolation itself is The inverse transform is handled by the I realize that the above is quite complex. The above-cited code is designed for integrating into a chain of ISO 19111 There is some JUnit tests for the above classes, but not for the specific case of JAXA file for data licensing reason. |
About including the GCOM-C file in JUnit test suite, my contact said that JAXA is positive about that, but would like to know if the following conditions are okay for UCAR. The terms of use are given in GCOM-C Data Provision Policy PDF document on JAXA G-Portal web site, section 10 at page 5:
Redistribution under above condition is allowed by:
|
By constructor contract,
Dimension.shortName
can be null if the dimension is not shared (i.e. when a dimension is private to a variable). When this is the case, then the only criterion left for allowingDimension.equals(Object)
to differentiate two dimensions is the dimension length. If by coincidence two unnamed dimensions have the same length, then they are considered equal.In the
CoordinateSystem
class, dimensions are stored in aHashSet
. Consequently if a coordinate system have two dimensions like below:shortName
and a length of 200.shortName
and a length of 200.Then the two above dimensions are considered equal and the
domain
contains only one element. It causes user code to believe that the coordinate system is one-dimensional.Side note: there is a potential
NullPointerException
incompareTo(Dimension)
.The text was updated successfully, but these errors were encountered: