equi7grid package
Subpackages
Submodules
equi7grid.copernicusgrid module
equi7grid.equi7grid module
equi7grid.image2equi7grid module
Code for resampling image raster data to the Equi7Grid, yielding tiled raster images organised in folders for a) in the continental zones + grid sampling b) the subgrid tiling
The module should help to easily bring your raster images to the Equi7Grid spatial reference, using the Equi7TilingSystem() for the file tiling.
- class equi7grid.image2equi7grid.GdalImage(gdaldataset, filepath)[source]
Bases:
object
A sample class to access a image with GDAL library
- get_band_nodata(band_idx=1)[source]
get band nodata value.
- Parameters:
band_idx (int) – the band index starting from 1
- Returns:
nodata value if it’s available, otherwise it will return None
- Return type:
nodata
- get_raster_nodata()[source]
get the nodata value for all bands in a list this is compatible with the write_image’s nodata parameter
- Returns:
no data values in a list if it’s available, otherwise it will return None
- Return type:
nodata
- property shape
- equi7grid.image2equi7grid.call_gdal_util(util_name, gdal_path=None, src_files='', src_band=None, dst_file=None, options={})[source]
- call gdal utility to run the operation.
- Parameters:
util_name (string) – pre-defined name of the utility (e.g. “gdal_translate”: convert raster data between different formats, potentially performing some operations like subsettings, resampling, and rescaling pixels in the process.)
src_files (string or list of strings) – The source dataset name(s). It can be either file name(s), URL of data source or subdataset name for multi-dataset files.
dst_file (string) – The destination file name.
gdal_path (string) – It the path where your gdal installed. If gpt command can not found by the os automatically, you should give this path.
options (dict) – A dictionary of options. You can find all options at http://www.gdal.org/gdal_utilities.html
- equi7grid.image2equi7grid.equi72lonlat(e7grid, image, output_dir, gdal_path=None, subgrid_ids=None, accurate_boundary=True, e7_folder=True, ftiles=None, roi=None, outshortname=None, withtilenameprefix=False, withtilenamesuffix=True, compress=True, compresstype='LZW', resampling_type='bilinear', overwrite=False, image_nodata=None, tile_nodata=None, tiledtiff=True, blocksize=512)[source]
- equi7grid.image2equi7grid.image2equi7grid(e7grid, image, output_dir, gdal_path=None, inband=None, subgrid_ids=None, accurate_boundary=True, e7_folder=True, ftiles=None, coverland=True, roi=None, naming_convention=None, compress_type='LZW', resampling_type='bilinear', subfolder=None, overwrite=False, data_type=None, image_nodata=None, tile_nodata=None, scale=None, offset=None, tiled=True, blocksize=512)[source]
Resample an raster image to tiled images in the Equi7Grid. Currently only GTiff is supported as output format.
- Parameters:
e7grid (Equi7Grid) – Equi7Grid object defining output projection and sampling.
image (str) – Image file path.
output_dir (str) – Output directory path.
gdal_path (str) – Path to GDAL utilities location.
inband (str, optional) – Name of the band for multi-band inputs, e.g. NETCDF.
subgrid_ids (list, optional) – Only resample to the specified continents. Default is to resample to all continents.
accurate_boundary (bool, optional) – If true (default), the accurate raster boundary of the input image is retrieved. If false, only the extent is used.
e7_folder (bool, optional) – If true (default), the output data will be stored in the Equi7Grid folder structure, i.e. “subgrid/tilename”.
ftiles (list, optional) – List of full name of tiles to which data should be resampled. If it is not set, all tiles are used.
coverland (bool, optional) – If true (default), only tiles oovering land should be resampled.
roi (ogr.Geometry, optional) – Region of interest defined by a ogr.Geometry. roi will be ignored if ftiles is provided.
naming_convention (SmartFilename, optional) – If provided, the keys “grid_name” and “tile_name” of the file naming convention are filled with the corresponding values of the resampled tile. The file naming convention is then used to specify the file name of the resampled files.
compress_type (str, optional) – GeoTIFF compression type. Defaults to “LZW”.
resampling_type (str, optional) – GDAL resampling method. Defaults to “bilinear”.
subfolder (str, optional) – If it’s set, it creates the sub-folder within the tile folder where the image will be resampled to.
overwrite (bool, optional) – Overwrite the old tile or not (defaults to false).
data_type (str, optional) – Force the output image bands to have a specific data type supported by the driver, which may be one of the following: Byte, UInt16, Int16, UInt32, Int32, Float32, Float64, CInt16, CInt32, CFloat32 or CFloat64.
image_nodata (float, optional) – The no data value of the input image. If it is not set, the no data value is automatically taken from the input image (default).
tile_nodata (float, optional) – The no data value of the tile. If it is not set, the no data value is automatically taken from the input image (default).
scale (float, optional) – Scale factor that should be applied to the pixel values.
offset (float, optional) – Offset value that should be applied to the pixel values.
tiled (bool, optional) – If true, tiled blocks are used for the GeoTIFF file (default), else stripped blocks.
blocksize (integer, optional) – Sets the GeoTIFF block size (defaults to 512). If tiled=True, the block size is used for both X and Y dimensions. If tiled=False, then stripped GeoTIFF files are created, where blocksize specifies the block size in Y direction.
- equi7grid.image2equi7grid.retrieve_raster_boundary(infile, gdal_path=None, nodata=None, resize_factor=None)[source]
Retrieve the boundary of raster image excluding the nodata
- Parameters:
infile (filepath) – input raster image file
gdal_path (string) – gdal utilities path
nodata (number) – value of no data / background value
resize_factor (number) – factor for downsampling infile for the quicklook
- Return type:
a multipolygon geometry object
Note
- The accurate boundary is retrieved via the following steps:
create the quicklook (an overview)
using morphological operaton to fill the samll gaps in the quicklook
using gdalpolgonize function to get the geometry