1

I am trying to convert annual temperature and rainfall data from the Indian Met Office from .grd to netcdf using CDO in Linux. However when I import the netcdf file into R & inspect the dates, there is no value for Jan 1st for a given year & either a value for the following year or a duplicate date depending on the file (I have the correct total number of dates in each case). I want to ensure that this is a labelling issue & that the ordering is correct, and not a problem with the conversion or underlying data.

Steps to reproduce:

  1. Download the binary max-temperature file for 1951 from http://www.imdpune.gov.in/Clim_Pred_LRF_New/Grided_Data_Download.html#

  2. Create a ctl file (Maxtemp_MaxT_1951.ctl) with the following text, based on their example:

    DSET Maxtemp_MaxT_1951.GRD
    TITLE 1 degree analyzed grids
    UNDEF 99.9
    XDEF 31 LINEAR 67.5 1
    YDEF 31 LINEAR 7.5 1
    ZDEF 1 Linear 1 1
    TDEF 365 LINEAR 1JAN1994 1DY
    VARS 1
    T 0 99 DAILYTEMP
    ENDVARS
  1. Run the following in bash to generate the .nc file
    cdo -f nc import_binary Maxtemp_MaxT_1951.ctl Maxtemp_MaxT_1951.nc
  1. Import the netcdf into R
    library(raster)
    library(ncdf4)
    
    netcdf_example <- "my_path//Maxtemp_MaxT_1951.nc"
    brick_test <- brick(netcdf_example,varname="t")
    head(brick_test@z)

The first listed date-time is "1951-01-02 23:56:02" and the last is "1952-01-01 23:56:02"

Per comment below, the issue appears to be on the raster import (dates show up properly when called from CDO). Also in case it's relevant I'm doing the conversion in Linux then syncing the .nc files via Dropbox, then importing using R for Windows.

  • 1
    What does `cdo showdate Maxtemp_MaxT_1951.ctl Maxtemp_MaxT_1951.nc` show? I'd check the dates there in case raster could not decode the times correctly – Robert Wilson Sep 16 '20 at 14:24
  • Thank you Robert. Calling `cdo showdate Maxtemp_MaxT_1951.nc` returns a list with the correct dates (1951-01-01... 1951-12-31. Calling the same on the control file throws an error (Unsupported file type). So I'm inferring that they are correct in the nc file, but as you say raster is not decoding correctly. I can obviously re-label in R, but I want to be sure the ordering is correct. – Mike Murphy Sep 16 '20 at 17:24
  • 1
    You also might be able to fix it by changing the calendar using CDO. Calendar is likely non standard. First response here should fix things in R: https://code.mpimet.mpg.de/boards/1/topics/3613 – Robert Wilson Sep 16 '20 at 18:51
  • Second option on the link did the job- many thanks Robert! – Mike Murphy Sep 16 '20 at 19:23

1 Answers1

1

Per Robert's comment above, running

cdo -a setcalendar,standard ifile ofile

in CDO resolved the problem on R import