2

I am working with monthly rainfall data from University of Delaware which is available as a NetCDF from NOAA and raw text from UDel's homepage. I would prefer to use the NetCDF format but when I extract values, these don't match what the ones in the raw data files.

Can you suggest why the comparison might not be working?

# Extract data
from netCDF4 import Dataset
ncfile =  "C:/precip.mon.total.v401.nc"
fnc = Dataset(ncfile, 'r')
print fnc.variables
lat = fnc.variables['lat']
lon = fnc.variables['lon']
monthyear = fnc.variables['time']
rain = fnc.variables['precip']
# Manually check values / example one
print lat[37] # 71.250 
print lon[0]-180 # -179.750 (need to subtract 180 because the lon values in the nc file range from 0 to 360)
print rain[0:12, 37, 0]*10
# Wrong output: [-- -- -- -- -- -- -- -- -- -- -- --]
# Another example
print lat[46] # 66.750 
print lon[54]-180 # -152.750 (need to subtract 180 because the lon values in the nc file range from 0 to 360)
print rain[0:12, 46, 54]*10
# Wrong output: [26.6   30.5   23.6   27.1   29.7   26.1   101.9   44.4   31.   79.8   49.9   29.7]

Acc to the raw data the values corresponding to lon -179.750 and lat 71.250 are:

0.0     5.4     0.0     4.0     7.3     3.9    33.5    63.2     9.4     4.0     8.0    23.6 

In case of lon -152.75 and lat 66.75, the extracted data should have been:

11.6    11.4    26.4    28.5    14.3    31.7    30.5    67.0    59.6    22.9     9.1    33.3

(The netCDF may be downloaded from https://www.dropbox.com/s/6zi0imr5i1qlqgs/precip.mon.total.v401.nc?dl=0 and the raw data file is available here https://www.dropbox.com/s/6klwmj37kvwj46w/precip.1900?dl=0)

1

Why are you subtracting 180 from the lon values, e.g., "print lon[0]-180"? As I understand the NC file, the left edge of the data grid is 0.25, not -179.75. Which suggests you are extracting values 180 degrees away from where you think you are.

| improve this answer | |
  • You are right that the left edge is 0.25. But since lon values in the nc file range from 0 to 360, I was merely pointing out that lon[0] corresponds to -179.750 (in the raw data the lon values range from -180 to +180). – user26750 Jun 27 '16 at 3:11
  • 1
    No, you are wrong in that. Take a look at the pictures at the university site: They start at Greenwich meridian, not the pacific. So half of the world has the right longitude, and the other half needs 360 to be subtracted. – AndreJ Jun 27 '16 at 5:28
  • Look at a CDL representation of the NC file metadata; it says "lon:actual_range = 0.25f, 359.75f ;" and if you do an ncdump on the file, you will see that lon = 0.25, 0.75, 1.25, 1.75, 2.25, 2.75, 3.25, etc. – R. Schmunk Jun 27 '16 at 5:57
0

@AndreJ's hint was key in solving the issue. If one plots the data, one realizes that the map is centered at the pacific and not at (0, 0)

import matplotlib.pylab as plt
imgplot = plt.imshow(rain[1, :, :])
imgplot.set_cmap('RdYlGn')
plt.colorbar()
plt.show

Applying the correct transformation i.e. (lon + 180)*2 + 360 for all east longitudes and (lon)*2 for all west longitudes solves the problem.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.