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

ncks -A -v [5.2.4] replace attribute _FillValue by eulaVlliF_ #283

Open
EnlNovius opened this issue May 11, 2024 · 1 comment
Open

ncks -A -v [5.2.4] replace attribute _FillValue by eulaVlliF_ #283

EnlNovius opened this issue May 11, 2024 · 1 comment

Comments

@EnlNovius
Copy link

A rather strange situation I've encountered when performing a ncks -A -v from one file to another:
the _FillValue attribute of the variable associated with the dimension on which the variable I'm copying depends is replaced by an eulaVlliF_ attribute.


Reproduction code:

  • First step: create two files, a source file and a destination file.
import numpy as np
import netCDF4 as nc
import os

os.makedirs('debug', exist_ok=True)

with nc.Dataset('debug/from.nc', 'w') as file:
    file.createDimension('new_latitude', 22)
    file.createDimension('new_longitude', 52)

    Chi_2 = file.createVariable('Chi_2', 'f8', ('new_latitude'), fill_value=nc.default_fillvals['f8'])
    new_latitude = file.createVariable('new_latitude', 'f4', ('new_latitude',), fill_value=nc.default_fillvals['f4'])
    new_longitude = file.createVariable('new_longitude', 'f4', ('new_longitude',), fill_value=nc.default_fillvals['f4'])

    Chi_2[:] = np.random.rand(22).astype(np.float64)
    new_latitude[:] = np.arange(22).astype(np.float32)
    new_longitude[:] = np.arange(52).astype(np.float32)
    
with nc.Dataset('debug/destination.nc', 'w') as file:
    file.createDimension('new_latitude', 22)
    file.createDimension('new_longitude', 52)

    new_latitude = file.createVariable('new_latitude', 'f4', ('new_latitude',), fill_value=nc.default_fillvals['f4'])
    new_longitude = file.createVariable('new_longitude', 'f4', ('new_longitude',), fill_value=nc.default_fillvals['f4'])

    new_latitude[:] = np.arange(22).astype(np.float32)
    new_longitude[:] = np.arange(52).astype(np.float32)
  • The destination file:
with nc.Dataset('debug/destination.nc', 'r') as file:
    for var in file.variables:
        print(var, file[var].ncattrs())
>>> new_latitude ['_FillValue']
>>> new_longitude ['_FillValue']

Everything is fine here.

  • Running the ncks command:
ncks -h -A -v Chi_2 debug/from.nc debug/destination.nc
  • Result:
with nc.Dataset('debug/destination.nc', 'r') as file:
    for var in file.variables:
        print(var, file[var].ncattrs())
>>> new_latitude ['eulaVlliF_']
>>> new_longitude ['_FillValue']
>>> Chi_2 ['_FillValue']

And here we have our new attribute eulaVlliF_ for new_latitude.


Environment:

  • python 3.12.3
  • nco 5.2.4
  • netcdf4 1.6.5
@czender
Copy link
Member

czender commented May 14, 2024

Thank you for reporting this. It must indeed look strange from your perspective. NCO has a "workaround" to netCDF library restrictions for modifying the _FillValue attribute after variable creation. The workaround temporarily reverses the name of the attribute. Apparently, you have found a behavior in which the reversed attributes is never un-reversed. I will look into this as soon as I can.

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

2 participants