error using cdfextract in R (clim.pact package)

112 views Asked by At

I am fairly new at using R and I am currently trying to use it to extract data for a specific region of a netCDF file and convert it to a csv. Ultimately I would like to have a timeseries for each variable over my area of interest.

I've downloaded the packages ncdf and clim.pact for R, and as my netCDF file is quite large (daily data for 25 years) I think I should be able to extract a the data for my region of interest using cdfextract, and then I will convert that smaller file to a csv. Howver, I keep getting the same error when I try to run it. This is the script I've been using and the error that comes up:

cdfextract("file.nc","tas", x.rng=c(-93, -85), y.rng=c(16, 23),t.rng=c(1, 9125))

[1] "time.origin= 01 Jan 0850" Error in system("rm -f cdfcont.txt", intern = TRUE) : 'rm' not found

Where my file is file.nc and the variable of interest is tas. I think it may have something to do with the time format, but when I check the time units of the file it says it is in "days since 01 Jan 0850" so I think the units are right.

Anyways any comments on this issue would be very welcome! Thank you!

1

There are 1 answers

3
N1B4 On BEST ANSWER

If you don't have to use R, you can use ncks from the NCO package: http://nco.sourceforge.net/nco.html#ncks-netCDF-Kitchen-Sink

ncks is a wonderful command-line tool for extracting data from netCDF files. In general, you can extract a variable over certain lat/lon bands and then output that data into a .csv file using something like:

ncks -v tas -d lat,16.,23. -d lon,-93.,-85. -s '%f\n' file.nc > output.csv

I couldn't tell if you wanted an area-average of tas first and then a time series of that area-averaged quantity in the .csv file. If so, you'll need to use ncwa to perform the area averaging first: http://nco.sourceforge.net/nco.html#Averaging