Skip to content
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

SP3 to netCDF conversion: 't0' attribute serialization problem #95

Closed
linustan opened this issue Jan 25, 2023 · 1 comment
Closed

SP3 to netCDF conversion: 't0' attribute serialization problem #95

linustan opened this issue Jan 25, 2023 · 1 comment

Comments

@linustan
Copy link
Contributor

linustan commented Jan 25, 2023

fixed by #96

xarray gets grumpy when trying to serialize the t0 attribute in the SP3 dataset generated by load_sp3, as it is a datetime object, but xarray cannot handle it because it wants a string, number, or list-like type.

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/linus/.pyenv/versions/local/lib/python3.11/site-packages/georinex/read/__main__.py", line 51, in <module>
    data = gr.load(
           ^^^^^^^^
  File "/Users/linus/.pyenv/versions/local/lib/python3.11/site-packages/georinex/base.py", line 83, in load
    return load_sp3(rinexfn, outfn)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/linus/.pyenv/versions/local/lib/python3.11/site-packages/georinex/sp3.py", line 113, in load_sp3
    ds.to_netcdf(outfn, mode="w", encoding=enc)
  File "/Users/linus/.pyenv/versions/local/lib/python3.11/site-packages/xarray/core/dataset.py", line 1912, in to_netcdf
    return to_netcdf(  # type: ignore  # mypy cannot resolve the overloads:(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/linus/.pyenv/versions/local/lib/python3.11/site-packages/xarray/backends/api.py", line 1185, in to_netcdf
    _validate_attrs(dataset, invalid_netcdf=invalid_netcdf and engine == "h5netcdf")
  File "/Users/linus/.pyenv/versions/local/lib/python3.11/site-packages/xarray/backends/api.py", line 203, in _validate_attrs
    check_attr(k, v, valid_types)
  File "/Users/linus/.pyenv/versions/local/lib/python3.11/site-packages/xarray/backends/api.py", line 195, in check_attr
    raise TypeError(
TypeError: Invalid value for attr 't0': datetime.datetime(2023, 1, 23, 22, 29, 50). For serialization to netCDF files, its value must be of one of the following types: str, Number, ndarray, number, list, tuple

It seems that the library is not handling this case, and it should have a mechanism to handle this case by converting the datetime object to a string, or a number before writing it to the netCDF file.

Repro:

> python -m georinex.read -o out.nc in.sp3
@linustan
Copy link
Contributor Author

PR to fix this issue: #96

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

No branches or pull requests

1 participant