NCAR / NCAR/wrf-python

use to_netcdf() : save value to netcdf file

Open
#91 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug enhancement support
Dominant language
Python
Stars
498
Forks
178
PR merge metrics
No merged PRs in 30d

Description

Here is a value:

<xarray.DataArray 'height_interp' (Time: 24, south_north: 282, west_east: 540)>

array([[[146.38087, 146.36438, ..., 150.47563, 150.22495],
[146.31306, 146.33267, ..., 150.4368 , 150.4107 ],
...,
[144.736 , 144.68318, ..., 147.91237, 147.94415],
[146.47084, 144.24289, ..., 147.98172, 148.00264]],
[[146.63193, 146.64368, ..., 150.74966, 150.60242],
[146.59207, 146.61151, ..., 150.64212, 150.65385],
...,
[145.27626, 145.13568, ..., 147.51866, 147.48692],
[145.96034, 144.85298, ..., 147.57097, 147.56674]],
...,
[[146.64447, 146.59451, ..., 149.74435, 149.65564],
[146.64937, 146.62129, ..., 149.73277, 149.69064],
...,
[145.3436 , 145.35204, ..., 144.83829, 144.81752],
[145.42519, 145.33458, ..., 144.85371, 144.82965]],
...,
[[146.03555, 146.10979, ..., 149.63452, 149.66908],
[146.15005, 146.14072, ..., 149.64066, 149.6417 ],
...,
[145.02827, 144.96996, ..., 145.09335, 145.08134],
[144.8737 , 144.95973, ..., 145.12323, 145.0956 ]]], dtype=float32)
Coordinates:
XLONG (south_north, west_east) float32 79.74786 79.82733 ... 134.49786
XLAT (south_north, west_east) float32 14.181648 14.207611 ... 39.589397

  • Time (Time) datetime64[ns] 2013-06-01 ... 2013-06-01T23:00:00
    datetime (Time) datetime64[ns] 2013-06-01 ... 2013-06-01T23:00:00
    level int64 850
    Dimensions without coordinates: south_north, west_east
    Attributes:
    FieldType: 104
    units: dm
    stagger:
    coordinates: XLONG XLAT
    projection: LambertConformal(stand_lon=105.81999969482422, moad_cen_l...
    missing_value: 9.969209968386869e+36
    _FillValue: 9.969209968386869e+36
    vert_units: hPa

hgt_850.to_netcdf("hgt_850.nc")

TypeError Traceback (most recent call last)
in
----> 1 hgt_850.to_netcdf("hgt_850.nc")

~/soft/anaconda2/envs/py3/lib/python3.6/site-packages/xarray/core/dataarray.py in to_netcdf(self, *args, **kwargs)
1759 dataset = self.to_dataset()
1760
-> 1761 return dataset.to_netcdf(*args, **kwargs)
1762
1763 def to_dict(self, data=True):

~/soft/anaconda2/envs/py3/lib/python3.6/site-packages/xarray/core/dataset.py in to_netcdf(self, path, mode, format, group, engine, encoding, unlimited_dims, compute)
1321 engine=engine, encoding=encoding,
1322 unlimited_dims=unlimited_dims,
-> 1323 compute=compute)
1324
1325 def to_zarr(self, store=None, mode='w-', synchronizer=None, group=None,

~/soft/anaconda2/envs/py3/lib/python3.6/site-packages/xarray/backends/api.py in to_netcdf(dataset, path_or_file, mode, format, group, engine, encoding, unlimited_dims, compute, multifile)
769 # validate Dataset keys, DataArray names, and attr keys/values
770 _validate_dataset_names(dataset)
--> 771 _validate_attrs(dataset)
772
773 try:

~/soft/anaconda2/envs/py3/lib/python3.6/site-packages/xarray/backends/api.py in _validate_attrs(dataset)
167 for variable in dataset.variables.values():
168 for k, v in variable.attrs.items():
--> 169 check_attr(k, v)
170
171

~/soft/anaconda2/envs/py3/lib/python3.6/site-packages/xarray/backends/api.py in check_attr(name, value)
158 'a string, an ndarray or a list/tuple of '
159 'numbers/strings for serialization to netCDF '
--> 160 'files'.format(value))
161
162 # Check attrs on the dataset itself

TypeError: Invalid value for attr: LambertConformal(stand_lon=105.81999969482422, moad_cen_lat=30.45999526977539, truelat1=30.0, truelat2=60.0, pole_lat=90.0, pole_lon=0.0) must be a number, a string, an ndarray or a list/tuple of numbers/strings for serialization to netCDF files

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The failure path is DataArray.to_netcdf(), Dataset.to_netcdf(), and xarray/backends/api.py::_validate_attrs; start there and inspect handling of the LambertConformal attribute. Reproduce with the shown DataArray and consider the work done when hgt_850.to_netcdf("hgt_850.nc") completes and writes a readable NetCDF file.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.