2

I am using the R raster package to import a tiny sample netcdf file, available here: https://www.dropbox.com/s/fht4g52p948vxva/persiann.ncml.nc?dl=0. The main data website is: https://www.ncdc.noaa.gov/cdr/atmospheric/precipitation-persiann-cdr.

The sample is a time series of 32 days of a single variable (precipitation) on a 19 row x 32 column lat/long grid.

I import the file as a raster brick with 32 layers: b <- brick(".../persiann.ncml.nc", varname="precipitation")

projection(b) returns NA.

When I try plotting b, or just a single layer:

plot(b) or plot(b[[3]])

everything is correct, except that it plots latitude on the horizontal axis and longitude on the vertical axis. I used netcdf4 to check the coordinates and the numbers all seem to be correct (i.e., the latitude is really latitude, the longitude is really longitude, and each layer in the stack is a different day), but the orientation of the plot is sideways. Also, gdalinfo produces two warnings:
Warning 1: dimension #2 (lat) is not a Longitude/X dimension.
Warning 1: dimension #1 (lon) is not a Latitude/Y dimension.

I tried setting the projection, based on what I saw in gdalinfo:
projection(b)<-"+proj=longlat +datum=WGS84"
but that made things worse. I am wondering whether the order of the variables in the original netcdf file needs to change, or if there's a way to deal with it?

print(b) returns

File     /....<snip>/persiann.ncml.nc (NC_FORMAT_CLASSIC):

 1 variables (excluding dimension variables):
    float precipitation[lat,lon,time]   
        missing_value: -9999
        standard_name: precipitation_amount
        long_name: NOAA Climate Data Record of PERSIANN-CDR daily precipitation
        units: mm
        valid_max: 999999
        valid_min: 0
        cell_method: sum
        _FillValue: -1
        coordinates: time lat lon lat lon

 3 dimensions:
    time  Size:32
        standard_name: time
        long_name: time
        units: days since 1979-01-01 0:0:0
        _CoordinateAxisType: Time
    lon  Size:32
        standard_name: longitude
        long_name: longitude
        units: degrees_east
        valid_max: 360
        valid_min: 0
        bounds: lon_bnds
        _CoordinateAxisType: Lon
    lat  Size:19
        standard_name: latitude
        long_name: latitude
        units: degrees_north
        valid_max: 60
        valid_min: -60
        bounds: lat_bnds
        _CoordinateAxisType: Lat

38 global attributes:
    datetime: 2015-12-30
    Conventions: CF-1.0
    title: NOAA Climate Data Record (CDR) of Precipitation Estimation from Remotely Sensed Information using Artificial Neural Networks (PERSIANN-CDR), Version 1 Revision 1
    comment: Daily PERSIANN-CDR precipitation estimates for long-term data record. [NOTE: v01r01 replaces v01r00]
    source: GRIDSAT-B1.2015.12.30.00.v02r01.nc,GRIDSAT-B1.2015.12.30.03.v02r01.nc,GRIDSAT-B1.2015.12.30.06.v02r01.nc,GRIDSAT-B1.2015.12.30.09.v02r01.nc,GRIDSAT-B1.2015.12.30.12.v02r01.nc,GRIDSAT-B1.2015.12.30.15.v02r01.nc,GRIDSAT-B1.2015.12.30.18.v02r01.nc,GRIDSAT-B1.2015.12.30.21.v02r01.nc,gpcpv23_m1512.bin
    Metadata_Conventions: CF-1.6,Unidata Dataset Discovery v1.0, NOAA CDR v1.0, GDS v2.0
    standard_name_vocabulary: CF Standard Name Table (v26, 08 November 2013)
    id: PERSIANN-CDR_v01r01_20151230_c20160324.nc
    naming_authority: gov.noaa.ncdc
    date_created: 2016-03-24T17:22:38Z
    license: No constraints on data access or use.
    summary: Daily near global precipitation estimates at 0.25 deg resolution over 30-year record. [NOTE: v01r01 replaces v01r00]
    keywords: EARTH SCIENCE > ATMOSPHERE > PRECIPITATION
    keywords_vocabulary: GCMD Keywords, Version 8.0.0.0.0
    cdm_data_type: Grid
    project: Satellite Data Support for Hydrologic and Water Resources Planning and Management.  Sponsor: NOAA
    creator_name: Dan Braithwaite
    creator_email: dbraithw@uci.edu
    creator_url: http://www.chrs.web.uci.edu/
    institution: UC-IRVINE/CHRS, Center for Hydrometeorology and Remote Sensing, University of California, Irvine
    geospatial_lat_min: -60
    geospatial_lat_max: 60
    geospatial_lon_min: 0
    geospatial_lon_max: 360
    geospatial_lat_units: degrees_north
    geospatial_lat_resolution: 0.25
    geospatial_lon_units: degrees_east
    geospatial_lon_resolution: 0.25
    time_coverage_start: 2015-12-30T00:00Z
    time_coverage_end: 2015-12-30T23:59Z
    contributor_name: Soroosh Sorooshian, Kuolin Hsu, Hamed Ashouri, Dan Braithwaite
    contributor_role: PrincipalInvestigator, Professor, Author, Author
    cdr_program: NOAA Climate Data Record Program
    cdr_variable: precipitation
    metadata_link: gov.noaa.ncdc:C00854
    product_version: v01r01
    spatial_resolution: 0.25 degrees
    History: Translated to CF-1.0 Conventions by Netcdf-Java CDM (NetcdfCFWriter)

Original Dataset = file:/san/ftp/cdr/persiann/persiann.ncml; Translation Date = Mon Apr 25 08:33:13 EDT 2016

1

Solution: I changed the order of the coordinates in the netcdf file, using the NCO operators (http://nco.sourceforge.net/nco.html#ncpdq-netCDF-Permute-Dimensions-Quickly)

ncpdq -a lat,lon in.nc out.nc

I am guessing that the R raster package expects the latitude variable to come before the longitude variable, although I haven't run across that in the documentation.

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.