Re: [netcdfgroup] NetCDF Dimensions As Variables

  • To: Ashley Ballard <ashleyta@xxxxxx>
  • Subject: Re: [netcdfgroup] NetCDF Dimensions As Variables
  • From: Dave Allured - NOAA Affiliate <dave.allured@xxxxxxxx>
  • Date: Wed, 16 May 2018 17:37:00 -0600
Ashley,

There are a couple strange things about the coordinates in this
"navigation" file.  Latitudes and longitudes are stored as 2-dimensional
arrays.  However, each row in "latitude" contains all identical values, and
each column in "longitude" also contains all identical values.

This means that 2-D coordinate arrays are not necessary for this particular
data set, unless you have some specialized software that requires 2-D
coordinates.  Adding 1-D coordinate arrays to a data file is simpler,
results in 1/3 the file size, and is more easily supported by common netcdf
analysis tools.  You can easily get 1-D arrays by peeling off a single
column of "latitude", and a single row of "longitude".

The other strangeness is that the longitudes are non-monotonic.  Some
analysis tools can't handle that.  More seriously, it looks like a possible
calculation mistake in the given longitudes.  Values 1-10019 run smoothly
from -179.9865 to +179.9865.  However, the last value #10020 wraps back
unexpectedly to -179.9776, which lies oddly between the first and second
values.  So it isn't even a clean wrap-around.  I suggest consulting with
the data source about a possible mistake here, including a possible
accumulating offset error.

Attached is a demo NCL script that writes 1-D coordinate arrays into the
sample data file, in case it would be of any help.  It includes a kludgy
correction to make the longitudes monotonic and well behaved.  I found that
the original dimension names worked fine, and it was not necessary to
rename them.  The same operations could be done with NCO utilities or some
other language with netcdf capability.

--Dave


On Wed, May 16, 2018 at 9:31 AM, Ashley Ballard <ashleyta@xxxxxx> wrote:

> Great thank you! I am working on this idea now. It is not only the
> attribute name that needs to be changed from "elem" and "lines" to "lat"
> and "lon," but the values are different as well. I have added the lat and
> lon variables to the same netcdf file that contains the rainfall data. This
> gives me a Netcdf file with "elem" and "lines" dimensions with variables
> "lat", "lon","elem","lines", and "rain." Now I need to make the dimensions
> the lat lon variables instead of the elem and lines. If you have any
> additional feedback on this let me know, I am still working through it, but
> could use some additional guidance.
>
> Thank you,
> Ashley
>
> On Wed, May 16, 2018 at 2:25 AM, Kaduk, Jorg D. (Dr.) <
> jk61@xxxxxxxxxxxxxxx> wrote:
>
>> Hello Ashley,
>>
>> I do not know about the projection, but to manipulate netcdf files, I
>> would recommend the netcdf operators nco, THey allow you to change variable
>> names.
>>
>> Else you can change the header with a combination of ncdump and ncgen,
>> see:
>>
>> https://www.unidata.ucar.edu/software/netcdf/workshops/2009/
>> utilities/index.html
>> Best wishes,
>>
>> Joerg
>> ------------------------------
>> *From:* netcdfgroup-bounces@xxxxxxxxxxxxxxxx <
>> netcdfgroup-bounces@xxxxxxxxxxxxxxxx> on behalf of Ashley Ballard <
>> ashleyta@xxxxxx>
>> *Sent:* 15 May 2018 23:56:43
>> *To:* netcdfgroup@xxxxxxxxxxxxxxxx
>> *Subject:* [netcdfgroup] NetCDF Dimensions As Variables
>>
>> Good afternoon,
>>
>> I am working with the 15 minute Hydro Estimator data (netCDF files). The
>> 15 minute NC files are available here:
>> ftp://satepsanone.nesdis.noaa.gov/HydroEst/GHE The dimensions of these
>> files are "elem" and "lines" not the typical "lat" and "lon." Instead the
>> "lat and "lon" values are stored in a Navigation file here:
>> ftp://satepsanone.nesdis.noaa.gov/HydroEst/NPR.GEO.
>> GHE.v1.Navigation.netcdf.gz
>>  In this Navigation file the dimensions match the 15 minute files ("elem"
>> and "lines), but store the "lat" and "lon" values as variables. How can I
>> relate these two files and basically replace the "elems" and "lines" in the
>> hydro estimator netcdfs with the "lat" and "lon" values from the Navigation
>> file and give a Mercator Projection?
>>
>> Best,
>> Ashley Ballard
>> --
>> *Ashley Ballard*
>> Meteorologist / Geospatial Analyst at MetCon <http://mymetcon.com/>
>>
>> Ph: (434) 228-3242
>> Ashleyta@xxxxxx
>>
>
begin
  coord_file = "NPR.GEO.GHE.v1.Navigation.netcdf"

  if (.not. isdefined ("outfile")) then
    dq = str_get_dq ()
    print ("*** Please specify outfile=\"+dq+"file.nc\"+dq+" on command line.")
    status_exit (1)
  end if

  print ("Read 1-D coordinates from coordinate file.")
  cf = addfile (coord_file, "r")
  lats = cf->latitude(:,0)
  lons = cf->longitude(0,:)

  print ("Apply monotonic correction to last latitude value.")

  nlons     = dimsizes (lons)
  corrected = 0.1 * lons(nlons-2) + 0.9 * 180

  print ("  Uncorrected = " + lons(nlons-1))
  print ("  Corrected   = " + corrected)

  lons(nlons-1) = corrected

  print ("Add CF standard metadata.")

  lats!0     = "lines"                  ; matching dimension names
  lons!0     = "elems"

  lats@units = "degrees_north"          ; standard unit strings
  lons@units = "degrees_east"

  lats&lines = lats                     ; crutch for NCL
  lons&elems = lons

  print ("Write 1-D coordinate variables to data file.")
  print ("Use existing dimension names.")

  df = addfile (outfile, "w")

  df->lines = lats
  df->elems = lons

  print ("File update complete.")
end
  • 2018 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: