Add Pystp netcdf driver#1
Conversation
|
Code reviewFound 1 issue:
PyISTP/pyistp/drivers/netcdf.py Lines 128 to 141 in ec4e33c Suggest reusing Other items considered but not flagged: 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
brenard-irap
left a comment
There was a problem hiding this comment.
I have a few remarks, mostly related to design.
We should find some time in the coming days to discuss them together.
| def load(file=None, buffer=None, master_file=None, master_buffer=None) -> _ISTPLoader: | ||
| return _ISTPLoader(file=file, buffer=buffer, master_file=master_file, master_buffer=master_buffer) | ||
|
|
||
|
|
There was a problem hiding this comment.
The distinction between the load (for CDF) and load_netcdf methods based on the file format bothers me.
I would have preferred to keep a single load method.
The selection of the driver to use could be handled in the constructor of ISTPLoaderImpl (as is already partially done for the CDF driver type: pycdfpp or spacepy).
The format detection could be implemented by inspecting the first 4 bytes that define the magic number, for example.
Additionally, in load_netcdf, we lose the ability to provide a master file, which I find problematic (see examples below).
I would also like the reading of the data file and the reading of the master file to be independent, meaning they could potentially use different drivers.
Example 1 – ICON mission from CDAWeb:
The master file is provided in CDF: https://cdaweb.gsfc.nasa.gov/pub/software/cdawlib/0MASTERS/icon_l2-6_euv_00000000_v01.cdf
The data files are in netCDF: https://spdf.gsfc.nasa.gov/pub/data/icon/l2/l2-6_euv/
The data files look like ISTP-compliant files, but they are not actually compliant.
For example, in the netCDF data files, Var_Type is used to specify whether a variable is data or support_data.
However, the specification (https://github.com/IHDE-Alliance/ISTP_metadata/blob/main/ISTP_metadata_guidelines/docs/05_metadata-variable-attributes.md#istp-variable-attributes) clearly states: "Note that attribute names are case sensitive, and the names of the ISTP variable attributes must match the case as shown."
Therefore, VAR_TYPE should have been used for the netCDF files to be directly ISTP-compliant.
The master file, on the other hand, is properly ISTP-compliant and does use VAR_TYPE to define the data type.
Example 2 - AMDA:
For AMDA, we are considering decommissioning our DDSERVER data server and replacing it with Speasy.
The data in this database is in netCDF and is not ISTP-compliant.
Regenerating the entire database is not an option (several million files and multiple terabytes in volume).
What I would like to do instead is generate CDF/ISTP-compliant master files for each dataset.
This would put us in a situation similar to the ICON mission from CDAWeb:
- master file in CDF / ISTP-compliant
- data files in non-ISTP-compliant netCDF
This would avoid the need for AMDA-specific development, which would be ideal.
| driver_factory = current_driver | ||
| if file is not None: | ||
| log.debug(f"Loading {file}") | ||
| self.cdf = current_driver(file or buffer) |
There was a problem hiding this comment.
As mentioned in another comment, I would like to take into account the fact that the driver used to read the master file may differ from the one used to read the data file.
| return (unix_ms * 1_000_000).astype('datetime64[ns]') | ||
|
|
||
| def values(self, var, is_metadata_variable=False): # NOSONAR | ||
| v = self._ds[var] |
There was a problem hiding this comment.
In my opinion, it is not the responsibility of the pyistp driver to interpret the data and convert it into datetime64; this should instead be handled by the consuming tool (in our case, the Speasy codec).
The data should be provided as-is, exactly as they appear in the file.
The pyistp library should only identify which variable contains the time information for the other variables.
This seems even more important given that, in the case of netCDF, the type of a time variable is not always clearly defined (unlike CDF, which uses CDF_EPOCH, CDF_EPOCH16, or TT2000).
As stated in the specification:
https://github.com/IHDE-Alliance/ISTP_metadata/blob/main/ISTP_metadata_guidelines/docs/04_metadata-variables.md#netcdf-times
NetCDF files can include the CDF time variables, with CDF_TIME_TT2000 especially recommended, but will require using the CDF library time routines for conversion. Otherwise, netCDF times are typically something like seconds from some specific time epoch, with UNITS = "seconds from 2000-01-01 UTC" or similar. In either case, the ISTP time variable attributes should be added.
If we move this interpretation logic into Speasy, we will be able to adapt it more easily depending on the provider.
For example, in AMDA / DDSERVER, the netCDF data files in our local database use a time format called DDTIME (which is not used anywhere else - for historical reasons).
It would not make sense to implement support for this format in pyistp, whereas in Speasy we could provide a callback mechanism in the netCDF codec to handle such very specific cases.
| "Programming Language :: Python :: 3.12", | ||
| ] | ||
| dependencies = ['pycdfpp>=0.6.0'] | ||
|
|
There was a problem hiding this comment.
Why make this dependency optional?
| except ImportError: | ||
| pytest.skip("netcdf driver not implemented yet", allow_module_level=True) | ||
|
|
||
|
|
There was a problem hiding this comment.
I’ll try to provide you with additional test cases.
However, there are far fewer publicly available datasets in netCDF compared to CDF...



No description provided.