Project

General

Profile

cdo manipulation leads to errors in R raster

Added by Lisa Kettemer over 3 years ago

Hi,

I use CDO's intntime and sellonbox to interpolate from 5-daily to daily, and adjust the longitudinal extent from 20-420 to -180-180. This all seems to work fine, however when I try to read the output files into a raster stack in R, I get errors, where before the manipulation things were working fine. The error messages are different after each operation. Opening them as netcdf in R still works fine, and before using the cdo commands the original file was read into raster with no problems.

Can anyone help me to understand what changes about the file that might lead to these errors in R raster?

I am working on 1/3 degree OSCAR ocean current data (output from R ncdf4::nc_open):

File /var/folders/__/ff6z1q2x2n3bjdf02bsy0rz199srvw/T//RtmpPAtcWG/oscar2019-3873ecf957c.nc (NC_FORMAT_CLASSIC):

4 variables (excluding dimension variables):
double u[longitude,latitude,depth,time]
units: meter/sec
long_name: Ocean Surface Zonal Currents
missing_value: NaN
double v[longitude,latitude,depth,time]
units: meter/sec
long_name: Ocean Surface Meridional Currents
missing_value: NaN
double um[longitude,latitude,depth,time]
units: meter/sec
long_name: Ocean Surface Zonal Currents Maximum Mask
missing_value: NaN
double vm[longitude,latitude,depth,time]
units: meter/sec
long_name: Ocean Surface Meridional Currents Maximum Mask
missing_value: NaN
5 dimensions:
time Size:59
units: day since 1992-10-05 00:00:00
long_name: Day since 1992-10-05 00:00:00
year Size:59
units: time in years
long_name: Time in fractional year
depth Size:1
units: meter
long_name: Depth
latitude Size:481
units: degrees-north
long_name: Latitude
longitude Size:1201
units: degrees-east
long_name: Longitude
15 global attributes:
VARIABLE: Ocean Surface Currents
DATATYPE: 1/72 YEAR Interval
DATASUBTYPE: unfiltered
GEORANGE: 20 to 420 -80 to 80
PERIOD: Jan.01,2019 to Oct.22,2019
year: 2019
description: OSCAR Third Degree Sea Surface Velocity
CREATION_DATE: 02:48 24-Oct-2019
version: 2009
source: Gary Lagerloef, ESR (lager@esr.org) and Kathleen Dohan, ESR (kdohan@esr.org)
contact: Kathleen Dohan (kdohan@esr.org) or John T. Gunn (gunn@esr.org)
company: Earth & Space Research, Seattle, WA
reference: Bonjean F. and G.S.E. Lagerloef, 2002 ,Diagnostic model and analysis of the surface currents in the tropical Pacific ocean, J. Phys. Oceanogr., 32, 2,938-2,954
note1: Maximum Mask velocity is the geostrophic component at all points + any concurrent Ekman and buoyancy components
note2: Longitude extends from 20 E to 420 E to avoid a break in major ocean basins. Data repeats in overlap region.

---------------
cdo intntime,5 infile.nc outfile.nc

Error message in R raster (v_stack <- raster::stack(path_to_file, varname="v"):

Error in data.frame(values = unlist(unname(x)), ind, stringsAsFactors = FALSE) :
arguments imply differing number of rows: 10288, 20

---------------
cdo -sellonlatbox,-180,180,-90,90 infile.nc outfile.nc

Error message in R raster (v_stack <- raster::stack(path_to_file, varname="v"):

Error in .rasterObjectFromCDF(x, type = objecttype, band = band, ...) :
cells are not equally spaced; you should extract values as points

---------------
If I use sellonlatbox and then intntime subsequently, I only receive the error message corresponding to the most recent manipulation.

Here is the summary after I do the manipulations:
- added global attributes
- dimension 'year' was removed

File /var/folders/__/ff6z1q2x2n3bjdf02bsy0rz199srvw/T//RtmpPAtcWG/daily_shift_oscar2019.nc (NC_FORMAT_CLASSIC):

4 variables (excluding dimension variables):
double u[longitude,latitude,depth,time]
long_name: Ocean Surface Zonal Currents
units: meter/sec
_FillValue: NaN
missing_value: NaN
double v[longitude,latitude,depth,time]
long_name: Ocean Surface Meridional Currents
units: meter/sec
_FillValue: NaN
missing_value: NaN
double um[longitude,latitude,depth,time]
long_name: Ocean Surface Zonal Currents Maximum Mask
units: meter/sec
_FillValue: NaN
missing_value: NaN
double vm[longitude,latitude,depth,time]
long_name: Ocean Surface Meridional Currents Maximum Mask
units: meter/sec
_FillValue: NaN
missing_value: NaN
4 dimensions:
time Size:291 * is unlimited *
standard_name: time
long_name: Day since 1992-10-05 00:00:00
units: day since 1992-10-05 00:00:00
calendar: standard
axis: T
longitude Size:1201
standard_name: longitude
long_name: Longitude
units: degrees-east
axis: X
latitude Size:481
standard_name: latitude
long_name: Latitude
units: degrees-north
axis: Y
depth Size:1
long_name: Depth
units: meter
axis: Z
19 global attributes:
CDI: Climate Data Interface version 1.9.8 (https://mpimet.mpg.de/cdi)
Conventions: CF-1.6
history: Mon Aug 17 17:51:02 2020: cdo -sellonlatbox,-180,180,-90,90 daily_oscar_2019.nc daily_shift_oscar2019.nc
Mon Aug 17 16:58:12 2020: cdo intntime,5 oscar2019-3873ecf957c.nc daily_oscar_2019.nc
source: Gary Lagerloef, ESR (lager@esr.org) and Kathleen Dohan, ESR (kdohan@esr.org)
VARIABLE: Ocean Surface Currents
DATATYPE: 1/72 YEAR Interval
DATASUBTYPE: unfiltered
GEORANGE: 20 to 420 -80 to 80
PERIOD: Jan.01,2019 to Oct.22,2019
year: 2019
description: OSCAR Third Degree Sea Surface Velocity
CREATION_DATE: 02:48 24-Oct-2019
version: 2009
contact: Kathleen Dohan (kdohan@esr.org) or John T. Gunn (gunn@esr.org)
company: Earth & Space Research, Seattle, WA
reference: Bonjean F. and G.S.E. Lagerloef, 2002 ,Diagnostic model and analysis of the surface currents in the tropical Pacific ocean, J. Phys. Oceanogr., 32, 2,938-2,954
note1: Maximum Mask velocity is the geostrophic component at all points + any concurrent Ekman and buoyancy components
note2: Longitude extends from 20 E to 420 E to avoid a break in major ocean basins. Data repeats in overlap region.
CDO: Climate Data Operators version 1.9.8 (https://mpimet.mpg.de/cdo)

I'd be thankful for any hints on what I'm missing here.

Best,

Lisa