NetcdfGridDumper¶
Dumps a grid of a NetCDF file to GeoTIFFs, one for every timestep of a range, for example the days of a climate scenario. The values come out in their physical units, with the scale factor and offset of the file applied and the missing values as novalue.
The grids whose crs is written in the file, as those of GDAL and of RasterToNetcdf, keep their projection and cells unchanged. All the others are resampled to lat/long WGS84 with the nearest cell, as the lat/long grids of most climate data and the grids whose projection has no EPSG code, as the sinusoidal tiles of MODIS.
Details¶
The grid is the one with the given full name, as listed by NetcdfInfo, or the first one whose name contains the inclusion text and not the exclusion one, or else the first grid of the file. Of grids with a vertical dimension only the first level is read. The x and y axes have to be one dimensional: grids with two dimensional latitude and longitude, as the swaths of satellites, are not supported.
The values are the physical ones: the scale factor and offset of the variable are applied, so a MODIS temperature stored as integers comes out in kelvin, and the fill and missing values become the novalue -9999 of the output.
Projected grids whose crs is in the file, as an EPSG code or a WKT in the attributes epsg_code, crs_wkt or spatial_ref of their grid mapping variable, as GDAL and RasterToNetcdf write them, keep their grid and crs: the cells are copied as they are, with the rows ordered from north to south. Set doLatLon to resample them to lat/long anyway.
All the other grids, the lat/long ones and the projected ones without a known crs, as the sinusoidal tiles of MODIS, are resampled to lat/long WGS84. The output has the same number of rows and columns of the grid, over the lat/long bounds of its cells: the center of every output cell is projected back to the grid and takes the value of the cell it falls in, a nearest neighbour resampling with no holes, which matches the one of GDAL. The cells outside the grid, as the corners of the bounds of a sinusoidal tile, are novalue. Longitudes from 0 to 360 are supported.
The axes of the HDF-EOS grids, as the MODIS tiles, are moved by half a cell: netcdf-java gives the upper left corners of their cells instead of the centers.
The corrections of false easting, false northing and rotated pole are applied to the projection of the file before reading it, to fix files with wrong projection parameters.
The dumped files are named after the input file, the UTC timestamp of the timestep (left out if the grid has no time) and the name of the grid.
Parameters¶
Dumps the timesteps of a NetCDF grid to GeoTIFFs: projected grids of known crs keep it, the others are resampled to lat/long WGS84.
Toolbox folder: NetCDF
Status: Certified
Keywords: IO, NetCDF, HDF, MODIS, Raster, Time series, Reading
Authors: Antonello Andrea
Class: org.hortonmachine.modules.NetcdfGridDumper
Inputs
Parameter |
Type |
Unit |
Default |
Description |
|---|---|---|---|---|
|
file |
The netcdf file or url to dump. |
||
|
String |
The full name of the grid to dump, as listed by NetcdfInfo. |
||
|
String |
In case of no grid name, the first grid whose name contains this text is dumped. |
||
|
String |
In case of no grid name, grids whose name contains this text are skipped. |
||
|
Integer |
|
The index of the first timestep to dump. |
|
|
Integer |
The index of the timestep at which to stop, excluded. If not set, only the start timestep is dumped. |
||
|
Double |
An optional correction on the false easting. |
||
|
Double |
An optional correction on the false northing. |
||
|
Double |
An optional correction of the north pole longitude of a rotated pole grid. |
||
|
Double |
An optional correction of the north pole latitude of a rotated pole grid. |
||
|
boolean |
|
If true, projected grids are resampled to lat/long WGS84 also when their crs is known. |
Outputs
Parameter |
Type |
Unit |
Description |
|---|---|---|---|
|
output folder |
The output folder in which to store the dumped rasters. |
|
|
File |
The name of the converted file. |
Example¶
The example dumps the daytime land surface temperature of the sample MODIS tile, with the grid name printed by NetcdfInfo:
import org.hortonmachine.modules.NetcdfGridDumper
// the folder with the MODIS tile: change it to yours
var folder = "/data/modis/"
// the daytime land surface temperature of the tile, in kelvin, resampled to lat/long WGS84
var dumper = new NetcdfGridDumper()
dumper.inPath = folder + "MOD11A2.A2024201.h18v04.061.2024211134014.hdf"
dumper.pGridName = "MODIS_Grid_8Day_1km_LST/Data_Fields/LST_Day_1km"
dumper.outFolder = folder + "modis_lst"
dumper.process()
The tile has no time axis, so a single GeoTIFF is written, named after the date of the tile: MOD11A2.A2024201.h18v04.061.2024211134014__20240719_000000__MODIS_Grid_8Day_1km_LST_Data_Fields_LST_Day_1km.tif in the folder modis_lst. The sinusoidal tile, resampled to lat/long, has slanted east and west borders, outside which the cells are novalue. The Alps are the coolest land, the Po valley and the coasts the hottest; the sea and the cloudy cells, without data, are white:
The values are in kelvin: Mapcalc converts them to degrees Celsius by subtracting 273.15.
The second example reads back the NetCDF of the sample elevation model written by RasterToNetcdf. The file has its crs, so the GeoTIFF dtm_back/dtm_flanginec__elevation.tif has the projection, the cells and the values of the original elevation model:
import org.hortonmachine.modules.NetcdfGridDumper
// the folder with the NetCDF of the elevation model, written by RasterToNetcdf: change it to yours
var folder = "/data/flanginec/"
// the elevation back to a GeoTIFF, in its own projection, since the file has its crs
var dumper = new NetcdfGridDumper()
dumper.inPath = folder + "dtm_flanginec.nc"
dumper.pGridName = "elevation"
dumper.outFolder = folder + "dtm_back"
dumper.process()