Project

General

Profile

netcdf file can't be read by cdo

Added by CHENG-TA CHEN 7 months ago

I have downloaded data from a convection-permitting model from UK data archive.
The data structure of file is not supported by cdo. The effort massage I got with "cdo sinfo data.nc" is as follows:

cdi warning (cdf_set_var): Inconsistent variable definition for pr!
cdi warning (cdf_check_variables): Unsupported data type (char/string), skipped variable yyyymmdd!
cdi warning (cdfInqContents): Coordinates variable ensemble_member_id can't be assigned!
cdi warning (cdfInqContents): Coordinates variable month_number can't be assigned!
cdi warning (cdfInqContents): Coordinates variable year can't be assigned!
File format : NetCDF4 classic
-1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter ID
1 : unknown UKCP18 c instant 1 1 43920 1 F32 : -1
Grid coordinates :
1 : curvilinear : points=43920 (180x244)
longitude : -12.77376 to 3.406438 degrees_east
latitude : 49.31371 to 60.52668 degrees_north
mapping : transverse_mercator
projection_x_coordinate : -197500 to 697500 by 5000 m
projection_y_coordinate : -32500 to 1182500 by 5000 m
available : cellbounds
Vertical coordinates :
1 : generic : levels=1
ensemble_member : 1 1
Time coordinate :
time : 31 steps
RefTime = 1970-01-01 00:00:00 Units = hours Calendar = 360_day Bounds = true
YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss
1980-12-02 12:00:00
cdo sinfo: Processed 1 variable over 1 timestep [0.02s 30MB]

Attached please find the output data.txt when I use "ncdump -h data.nc" and the data file data.nc.

How can I modify the netcdf file so that it can be read by cdo?

Cheng-Ta

data.txt (4.14 KB) data.txt output from ncdump -h data.nc
data.nc (5.91 MB) data.nc netcdf file

Replies (1)

RE: netcdf file can't be read by cdo - Added by Karin Meier-Fleischer 7 months ago

Hi Cheng-Ta,

the netCDF file is not CF-conform and you have to do some work before you can use it with CDO. The best is to write a script like the following one:

#!/usr/bin/env sh

infile="data.nc" 

#-- save variables that will be deleted by ncap2
ncks -O -v latitude,longitude,time,transverse_mercator $infile keep_variables.nc

#-- delete one-element dimension ensemble_member
ncap2 -O -v -s 'pr[$time, $projection_y_coordinate, $projection_x_coordinate]=pr(0,:,:,:)' \
                $infile data1.nc

#-- set correct coordinates attribute of variable pr
ncatted -O -a coordinates,pr,o,c,'latitude longitude' data1.nc data2.nc

#-- add saved variables to data2.nc
ncks -A keep_variables.nc data2.nc
    (1-1/1)