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