Skip to content

Add new net_cdf4 codec#288

Open
RichardHitier wants to merge 10 commits into
SciQLop:mainfrom
co-libri-org:netcdf_codec
Open

Add new net_cdf4 codec#288
RichardHitier wants to merge 10 commits into
SciQLop:mainfrom
co-libri-org:netcdf_codec

Conversation

@RichardHitier
Copy link
Copy Markdown
Contributor

See #209

Comment thread speasy/core/codecs/bundled_codecs/istp/__init__.py Fixed
- eliminate duplication moving helpers into istp/__init__.py
- create istp/cdf.py and istp/netcdf.py
Comment thread speasy/core/codecs/bundled_codecs/istp/__init__.py Fixed
RichardHitier and others added 6 commits May 4, 2026 15:06
        accept timedelta

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- _write_variable: return type was bool but never returned a value, changed to None
- _already_in_cdf: already returns _ax.name (str), so a.name was a bug, use a directly
- save_variables: replace hasattr(file, 'write') with isinstance(file, io.IOBase) for Pylance narrowing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
 copy/paste issue inherited from istp/ refactoring

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
def _try_set_attr(nc_var, key, value):
try:
setattr(nc_var, key, value)
except Exception:
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Copy Markdown
Collaborator

@brenard-irap brenard-irap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Richard.
I really appreciate the code factorization.
My remarks are mostly aligned with those in SciQLop/PyISTP#1
I'll try to find some additional files for testing.

if dim_name not in ds.variables:
var = ds.createVariable(dim_name, 'f8', (dim_name,))
var.units = "seconds since 1970-01-01T00:00:00"
var.VAR_TYPE = "support_data"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth considering whether multiple options for the time format should be supported here.
The ISTP specification tends to recommend TT2000, but I’m not convinced it is necessarily more appropriate than a Unix timestamp.

if (var is not None) and (var.values.shape[0] == var.axes[0].values.shape[0]):
time_axis_name = var.axes[0].name
return _valid_variable_or_none(SpeasyVariable(
axes=[VariableTimeAxis(values=var.axes[0].values.copy(),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding what I mentioned in SciQLop/PyISTP#1 (review), this would be the right place to delegate to the codec the interpretation and conversion of the time variable data into datetime64.

from speasy.core.codecs import get_codec

AC_MFI = os.path.join(os.path.dirname(__file__), "resources", "ac_h2s_mfi_cdaweb.nc")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll try to provide you with additional test cases.
However, there are far fewer publicly available datasets in netCDF compared to CDF...

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

Successfully merging this pull request may close these issues.

3 participants