python-3.xncopynco

Compressing a netCDF file with the pynco package


I'm interested in compressing a NetCDF file in python using the pynco package. From the command line, I would usually use:

nccopy -d 3 input_file.nc output_file.nc

In python, I have tried the following:

from nco import Nco
Nco.nccopy(input='input_file.nc', output='output_file.nc', options=['-d 1'])

This produces an attribute error 'Nco' has no attribute 'nccopy'. Is nccopy supported within pynco?


Solution

  • nccopy is a netCDF command, not an NCO command. However, ncks can do nearly everything nccopy does, and a whole lot else. To compress as in your example, try

    Nco.ncks(input='input_file.nc', output='output_file.nc', options=['-7 -L 1'])