James,
Here are the minimal georeferencing requirements for common climate
software:
* The NetCDF file must contain separate 1-dimensional latitude and
longitude coordinate variables, in addition to the data variables.
* Names of coordinate variables must be the same as their dimension names,
for example lat(lat).
* Coordinate variables and data variables must share the same dimension
names for corresponding dimensions. For example, water(time, lon, lat)
would require lon(lon) and lat(lat). This is the ONLY georef. requirement
on the data variable itself.
* Lat and lon coordinate variables must have corresponding "units"
attributes of "degrees_north" and "degrees_east". There are several
acceptable alternate values, see CF conventions.
* The units attribute must be type character, not type string, for
compatibility with much older software and versions still in use.
It is helpful to emulate real examples. Check out these, starting with
smaller CDL files near the top:
http://www.unidata.ucar.edu/software/netcdf/examples/files.html
Different softwares have different requirements. The various conventions
do not make perfect compatibility. GIS and OSGeo requirements are more
detailed. Your real question may be more specific, "Why doesn't my file
show up as Geo2D type in Panoply", in which case you should try a Panoply
support forum. HTH.
--Dave A.
NOAA/PSD/CIRES
On Fri, Mar 27, 2015 at 9:33 AM, James Adams <monocongo@xxxxxxxxx> wrote:
> I have a variable that I've created in a file which I want to be able to
> read as a georeferenced data set, i.e. using something like this with the
> Java API:
>
> GridDataset gridDataset = GridDataset.open(netcdfFile);
> GeoGrid geoGrid = gridDataset.findGridByShortName(variableName);
>
> Currently the NetCDF variable looks like this (from ncdump):
>
> float available_water_capacity(time=1, lon=1385, lat=596);
> :_FillValue = -999.9f; // float
> :least_significant_digit = 3; // int
> :_ChunkSize = 1, 1385, 596; // int
>
> I assume that I have not set either sufficient attributes and/or
> dimensions on the data variable (available_water_capacity), so I'm fishing
> for ideas as to how I can flesh this out when creating/writing the files in
> my Python code. The NetCDF file is currently created like so:
>
> # open the output file for writing, set its dimensions and variables
> output_dataset = netCDF4.Dataset(output_file, 'w')
> output_dataset.createDimension('time', None)
> output_dataset.createDimension('lon', len(input_lon_dimension))
> output_dataset.createDimension('lat', len(input_lat_dimension))
>
> # create lon dimension variable
> output_lon_variable =
> output_dataset.createVariable('lon','f4',('lon',))
> if 'units' in input_lon_variable.ncattrs():
> output_lon_variable.units = input_lon_variable.units
> output_lon_variable[0:len(input_lon_dimension):1] =
> input_lon_variable[0:len(input_lon_dimension):1]
>
> # create lat dimension variable
> output_lat_variable =
> output_dataset.createVariable('lat','f4',('lat',))
> if 'units' in input_lat_variable.ncattrs():
> output_lat_variable.units = input_lat_variable.units
> output_lat_variable[0:len(input_lat_dimension):1] =
> input_lat_variable[0:len(input_lat_dimension):1]
>
> # create a time variable with a single value
> output_time_variable =
> output_dataset.createVariable('time','i4',('time',))
> output_time_variable.units = 'days since 1900-01-01 00:00:00'
> output_time_variable[0:1:1] = numpy.array([0])
>
> # create the soil constant variable
> output_soil_variable =
> output_dataset.createVariable('available_water_capacity','f4',('time',
> 'lon', 'lat'),
>
> fill_value=fill_value,
> zlib=True,
>
> least_significant_digit=3)
>
> attributeDictionary = { "Conventions":"CF-1.3" }
> output_dataset.setncatts(attributeDictionary)
>
>
> The trouble is that when I read this NetCDF file in Java code which uses
> the approach outlined above it does not find the variable as a grid in the
> GridDataset, however I'm using this approach with other NetCDF variables
> which are correctly georeferenced (they show up as Geo2D types in Panoply),
> so I assume that I've failed to completely flesh out this variable so that
> it'll be recognized as a grid. What more might I add in order to make this
> variable discoverable as a georeferenced grid?
>
> Thanks in advance if anyone has suggestions on this.
>
> --James
>