Skip to content

Add Pystp netcdf driver#1

Open
RichardHitier wants to merge 7 commits intoSciQLop:mainfrom
RichardHitier:pystp_netcdf
Open

Add Pystp netcdf driver#1
RichardHitier wants to merge 7 commits intoSciQLop:mainfrom
RichardHitier:pystp_netcdf

Conversation

@RichardHitier
Copy link
Copy Markdown

No description provided.

@sonarqubecloud
Copy link
Copy Markdown

@jeandet jeandet requested review from brenard-irap and jeandet April 28, 2026 16:54
@jeandet jeandet added the enhancement New feature or request label Apr 28, 2026
@jeandet
Copy link
Copy Markdown
Member

jeandet commented May 6, 2026

Code review

Found 1 issue:

  1. cdf_type() is inconsistent with values() for CDF_EPOCH variables. values() calls _get_units() which checks both 'units' and 'UNITS', and routes through _is_cdf_epoch() to return datetime64[ns]. cdf_type() only calls v.getncattr('units') (lowercase) and only handles the CF time ('since' in units) branch — there is no CDF_EPOCH branch at all. Verified against the bundled tests/resources/ac_h2s_mfi_cdaweb.nc (whose Epoch has UNITS='ms'): values('Epoch').dtype is datetime64[ns] while cdf_type('Epoch') returns 'CDF_DOUBLE'. Downstream consumers that key off cdf_type to identify time axes will misclassify the epoch.

def cdf_type(self, var):
v = self._ds[var]
# CF time variable: float with a "units" attribute containing "since"
try:
units = v.getncattr('units')
if isinstance(units, str) and 'since' in units:
return 'CDF_TIME_TT2000'
except AttributeError:
pass
if v.dtype == str:
return 'CDF_CHAR'
dtype_str = v.dtype.str.lstrip('<>=!')
return self._DTYPE_TO_CDF.get(dtype_str, f'CDF_UNKNOWN_{dtype_str}')

Suggest reusing _get_units() and adding a _is_cdf_epoch(var) branch returning 'CDF_EPOCH' (mirroring values()).

Other items considered but not flagged: netCDF4.Dataset is never closed (no close()/context manager) and the _DTYPE_TO_CDF 'S' key is unreachable (v.dtype.str.lstrip('<>=!') leaves the leading |) — both real but lower-impact; worth a follow-up.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants