0

Need help. Please have a look and suggest a solution. Note that I'm a beginner.

I have a netcdf file named 'Lw_15_21.nc' 
netcdf Lw_15_21 {
dimensions:
        longitude = 135 ;
        latitude = 129 ;
        expver = 2 ;
        time = 54247 ;
variables:
        float longitude(longitude) ;
                longitude:units = "degrees_east" ;
                longitude:long_name = "longitude" ;
        float latitude(latitude) ;
                latitude:units = "degrees_north" ;
                latitude:long_name = "latitude" ;
        int expver(expver) ;
                expver:long_name = "expver" ;
        int time(time) ;
                time:units = "hours since 1900-01-01 00:00:00.0" ;
                time:long_name = "time" ;
                time:calendar = "gregorian" ;
        short str(time, expver, latitude, longitude) ;
                str:scale_factor = 22.4949414798651 ;
                str:add_offset = -574761.74747074 ;
                str:_FillValue = -32767s ;
                str:missing_value = -32767s ;
                str:units = "J m**-2" ;
                str:long_name = "Surface net thermal radiation" ;
                str:standard_name = "surface_net_upward_longwave_flux" ;

And I want to delete the variable expver (since it prevents merging with other *.nc files). Even after deleting (using nco's command ncks -C -O -x -v expver Lw_15_21.nc test.nc), the expver still remains in dimension and in varible str.

netcdf test {
dimensions:
        latitude = 129 ;
        longitude = 135 ;
        time = 54247 ;
        expver = 2 ;
variables:
        float latitude(latitude) ;
                latitude:units = "degrees_north" ;
                latitude:long_name = "latitude" ;
        float longitude(longitude) ;
                longitude:units = "degrees_east" ;
                longitude:long_name = "longitude" ;
        short str(time, expver, latitude, longitude) ;
                str:scale_factor = 22.4949414798651 ;
                str:add_offset = -574761.74747074 ;
                str:_FillValue = -32767s ;
                str:missing_value = -32767s ;
                str:units = "J m**-2" ;
                str:long_name = "Surface net thermal radiation" ;
                str:standard_name = "surface_net_upward_longwave_flux" ;
        int time(time) ;
                time:units = "hours since 1900-01-01 00:00:00.0" ;
                time:long_name = "time" ;
                time:calendar = "gregorian" ;

How to remove the expver from dimension and variable str while keeping others constant. I also tried ncwa -a but got a segmentation fault (core dumped) error. That means I would like to get the following output.

Assuming the file name test1.nc

netcdf test1 {
dimensions:
        latitude = 129 ;
        longitude = 135 ;
        time = 54247 ;
variables:
        float latitude(latitude) ;
                latitude:units = "degrees_north" ;
                latitude:long_name = "latitude" ;
        float longitude(longitude) ;
                longitude:units = "degrees_east" ;
                longitude:long_name = "longitude" ;
        short str(time, latitude, longitude) ;
                str:scale_factor = 22.4949414798651 ;
                str:add_offset = -574761.74747074 ;
                str:_FillValue = -32767s ;
                str:missing_value = -32767s ;
                str:units = "J m**-2" ;
                str:long_name = "Surface net thermal radiation" ;
                str:standard_name = "surface_net_upward_longwave_flux" ;
        int time(time) ;
                time:units = "hours since 1900-01-01 00:00:00.0" ;
                time:long_name = "time" ;
                time:calendar = "gregorian" ;

Thank you.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Soumik Das
  • 9
  • 2
  • 5

2 Answers2

1

Note that you can also use python xarray to drop the coordinate. Example:

import xrray as xr

read the data

data = xr.open_dataset("test.nc)

drop the expver coordinate

data = data.drop("expver")

And if the expver coordinate contains different values, you can also select one with the datarray.sel method, example:

data = data.sel(expver=1)

And you can use the previous code to drop the expver coordinate.

Dan-Boat
  • 21
  • 4
0

I also experience this issue. As for now (Mar 2023) the data with expver dimension only available in Dec 2022, with expver=1 is final (1 Dec 2022) and expver=5 is near real-time (2-31 Dec 2022).

Let say from https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-land?tab=form I have downloaded daily precipitation data at 00:00 for December 2022, and I got data_202212.nc

Following suggestion from Robert the above comment to use reduce_dim, I did the following step:

# reduce the expver dimension
cdo --reduce_dim -sellevel,1 data_202212.nc data_202212_expver1.nc
cdo --reduce_dim -sellevel,5 data_202212.nc data_202212_expver5.nc
# get only for 1 Dec as other date is no data
cdo seldate,2022-12-01 data_202212_expver1.nc data_202212_expver1_a.nc
# delete date with 1 Dec
cdo -delete,month=12,day=1 data_202212_expver5.nc data_202212_expver5_a.nc
# merge together
cdo mergetime data_202212_expver1_a.nc data_202212_expver5_a.nc data_202212_final.nc
user97103
  • 235
  • 1
  • 7