poets.image package — poets 0.3.2 documentation

# poets.image package

## Submodules

## poets.image.geotiff module

GeoTIFF operations.

`poets.image.geotiff.` `lonlat2px_gt`(img, lon, lat, lon_min, lat_min, lon_max, lat_max)

  Converts a pair of lon and lat to its corresponding pixel value in an geotiff image file.

  img : Image File, e.g. PNG, TIFF
    Input image file
  lon : float
    Longitude
  lat : float
    Latitude
  lon_min, lat_min : float
    lower left coordinate of geotiff
  lon_max, lat_max : float
    upper right coordinate of geotiff
  Row : float
    corresponding pixel value
  Col : float
    corresponding pixel value

`poets.image.geotiff.` `px2lonlat_gt`(img, lon_px, lat_px, lon_min, lat_min, lon_max, lat_max)

  Converts two arrays of row and column pixels into their corresponding longitude and latitude arrays

  img : Image file
    Image which the pixel values refer to
  lon_px : np.array
    array of column pixels
  lat_px : np.array
    array of row pixels
  lon_new : np.array
    List of corresponding longitude values
  lat_new: np.array
    List of corresponding latitude values
  lon_min, lat_min : float
    lower left coordinate of geotiff
  lon_max, lat_max : float
    upper right coordinate of geotiff

## poets.image.hdf5 module

This module provides functions for loading from HDF5 files.

`poets.image.hdf5.` `read_image`(source_file, variables=None)

  Reads data out of hdf5 file and returns it as numpy.ndarray

  source_file : str
    Path to source file.
  variables : list of str, optional
    Variables to read from file, reads all variables if not set.
  data : dict of numpy.arrays
    Source file.
  lon : numpy.array
    Longitudes of the source file.
  lat : numpy.array
    Latitudes of the source file.
  timestamp : datetime.date
    Timestamp of image.
  metadata : dict of strings
    Metadata from source netCDF file.

## poets.image.imagefile module

This module provides functions for converting lonlat-information to pixels in an image file (eg. PNG, TIFF) and for calculating a country bounding box.

`poets.image.imagefile.` `bbox_img`(source_file, region, fileExtension, shapefile=None)

  Clips bounding box out of image file and returns data as numpy.ndarray

  source_file : str
    Path to source file.
  region : str
    Identifier of the region in the shapefile. If the default shapefile is used, this would be the FIPS country code.
  fileExtension : str
    Filetype (e.g. png, tif).
  shapefile : str, optional
    Path to shape file, uses “world country admin boundary shapefile” by default.
  data : dict of numpy.arrays
    Clipped image (grey values).
  lon_new : numpy.array
    Longitudes of the clipped image.
  lat_new : numpy.array
    Latitudes of the clipped image.
  timestamp : datetime.date
    Timestamp of the image.
  metadata : dict of strings
    Metadata from source netCDF file.

`poets.image.imagefile.` `dateline_country`(country)

  Min and max longitude for countries that spread across the international dateline.

  lon_min : float
    Minimum longitude.
  lon_max : float
    Maximum longitude.

`poets.image.imagefile.` `get_layer_extent`(filepath)

  Returns extent of imagefile as minimum and maximum longitudes and latitudes.

  filepath : str
    Path to image file.
  lon_min : float
    Minimum longitude.
  lat_min : float
    Minimum latitude.
  lon_max : float
    Maximum longitude.
  lat_max : float
    Maximum latitude.

`poets.image.imagefile.` `lonlat2px`(img, lon, lat)

  Converts a pair of lon and lat to its corresponding pixel value in an image file.

  img : PIL image
    Input image file, e.g. PNG, TIFF.
  lon : float
    Longitude.
  lat : float
    Latitude.
  Row : float
    Corresponding pixel value.
  Col : float
    Corresponding pixel value.

`poets.image.imagefile.` `lonlat2px_rearr`(img, lon, lat)

  Converts a pair of lon and lat to its corresponding pixel value in a rearranged image file (see rearrange_img).

  img : PIL image
    Input image file, e.g. PNG, TIFF.
  lon : float
    Longitude
  lat : float
    Latitude
  Row : float
    corresponding pixel value
  Col : float
    corresponding pixel value

`poets.image.imagefile.` `px2lonlat`(img, lon_px, lat_px)

  Converts two arrays of row and column pixels into their corresponding lon and lat arrays.

  img : PIL image
    Input image file, e.g. PNG, TIFF.
  lon_px : np.array
    Array of column pixels.
  lat_px : np.array
    Array of row pixels.
  lon_new : np.array
    List of corresponding longitude values.
  lat_new: np.array
    List of corresponding latitude values.

`poets.image.imagefile.` `px2lonlat_rearr`(img, lon_px, lat_px)

  Converts two arrays of row and column pixels into their corresponding lon and lat arrays

  img : PIL image
    Image which the pixel values refer to (rearranged image)
  lon_px : np.array
    Array of column pixels.
  lat_px : np.array
    Array of row pixels.
  lon_new : np.array
    List of corresponding longitude values.
  lat_new: np.array
    List of corresponding latitude values.

`poets.image.imagefile.` `rearrange_img`(img)

  Rearranges image so that 0 degree Meridian is on the very left. Used when area around the +- 180 degree Meridian is of interest (eastern Russia, Alaska, New Zealand...).

  img : PIL image
    Image to be rearranged.
  img2 : Image file
    Rearranged image.

## poets.image.netcdf module

This module provides functions for loading from and writing to NetCDF4 files.

`poets.image.netcdf.` `clip_bbox`(data, lon, lat, lon_min, lat_min, lon_max, lat_max)

  Clips bounding box out of numpy.array and returns data as numpy.ndarray

  data : dict of numpy.arrays
    Source file.
  lon : numpy.array
    Longitudes of source file
  lat : numpy.array
    Latitudes of source file
  lon_min : float
    Min longitude of bounding box.
  lat_min : float
    Min latitude of bounding box.
  lon_max : float
    Max longitude of bounding box.
  lat_max : float
    Max latitude of bounding box.
  data_new : dict of numpy.arrays
    Clipped image.
  lon_new : numpy.array
    Longitudes of the clipped image.
  lat_new : numpy.array
    Latitudes of the clipped image.

`poets.image.netcdf.` `get_properties`(src_file)

  Gets variables, dimensions and time period from a netCDF file.

  src_file : str
    Path to NetCDF file.
  variables : list of str
    List of variables.
  dimensions : list of str
    Dimensions of the NetCDF file.
  period : list of datetime.datetime
    Date of first and last image in source file.

`poets.image.netcdf.` `read_image`(source_file, variables=None)

  Reads data out of netCDF file and returns it as numpy.ndarray

  source_file : str
    Path to source file.
  variables : list of str, optional
    Variables to read from file, reads all variables if not set
  data : dict of numpy.arrays
    Source file.
  lon : numpy.array
    Longitudes of the source file.
  lat : numpy.array
    Latitudes of the source file.
  timestamp : datetime.date
    Timestamp of image.
  metadata : dict of strings
    Metadata from source netCDF file.

`poets.image.netcdf.` `read_variable`(source_file, variable, date, date_to=None)

  Gets images from a netCDF file.

  Reads the image for a specific date. If date_to is given, it will return multiple images in a multidimensional numpy.ndarray

  source_file : str
    Path to source file.
  variable : str
    Requested variable of image.
  date : datetime.datetime
    Date of the image, start date of data cube if date_to is set.
  date_to : datetime.date, optional
    End date of data cube to slice from NetCDF file.
  image : numpy.ndarray
    Image for a specific date.
  lon : numpy.array
    Longitudes of the image.
  lat : numpy.array
    Latgitudes of the image.
  metadata : dict of strings
    Metadata from source netCDF file.

`poets.image.netcdf.` `save_image`(image, timestamp, region, metadata, dest_file, start_date, sp_res, nan_value=-99, shapefile=None, temp_res='dekad', compression=False)

  Saves numpy.ndarray images as multidimensional netCDF4 file.

  Creates a datetimeindex over the whole period defined in the settings file

  image : dict of numpy.ndarrays
    Input image.
  timestamp : datetime.datetime
    Timestamp of image.
  region : str, optional
    Identifier of the region in the shapefile. If the default shapefile is used, this would be the FIPS country code.
  metadata : dict
    NetCDF metadata from source file.
  dest_file : str
    Path to the output file.
  start_date : datetime.datetime
    First date of available data.
  sp_res : int or float
    Spatial resolution of the grid.
  nan_value : int, optional
    Not a number value for dataset, defaults to -99.
  shapefile : str, optional
    Path to shape file, uses “world country admin boundary shapefile” by default.
  temp_res : string or int, optional
    Temporal resolution of the output NetCDF4 file, defaults to dekad.
  compression : bool, optional
    If True, ncfile compression is active.

`poets.image.netcdf.` `write_tmp_file`(image, timestamp, region, metadata, dest_file, start_date, sp_res, nan_value=-99, shapefile=None)

  Saves numpy.ndarray images as multidimensional netCDF4 file.

  image : dict of numpy.ndarrays
    Input image.
  timestamp : datetime.datetime
    Timestamp of image.
  region : str, optional
    Identifier of the region in the shapefile. If the default shapefile is used, this would be the FIPS country code.
  metadata : dict
    NetCDF metadata from source file.
  dest_file : str
    Path to the output file.
  start_date : datetime.datetime
    First date of available data.
  sp_res : int or float
    Spatial resolution of the grid.
  nan_value : int, optional
    Not a number value for dataset, defaults to -99.
  shapefile : str, optional
    Path to shape file, uses “world country admin boundary shapefile” by default.

## poets.image.resampling module

`poets.image.resampling.` `average_layers`(image, dest_nan_value)

  Averages image layers, given as n-dimensional masked arrays to one image.

  image : numpy.ma.MaskedArray
    Input image to average.
  dest_nan_value : int
    NaN value to be used.
  avg_img : numpy.ma.MaskedArray
    Averaged image.

`poets.image.resampling.` `resample_to_shape`(source_file, region, sp_res, grid, prefix=None, nan_value=None, dest_nan_value=None, variables=None, shapefile=None)

  Resamples images and clips country boundaries

  source_file : str
    Path to source file.
  region : str
    Identifier of the region in the shapefile. If the default shapefile is used, this would be the FIPS country code.
  sp_res : int or float
    Spatial resolution of the shape-grid.
  grid : poets.grid.RegularGrid or poets.grid.ShapeGrid
    Grid to resample data to.
  prefix : str, optional
    Prefix for the variable in the NetCDF file, should be name of source
  nan_value : int, float, optional
    Not a number value of the original data as given by the data provider
  dest_nan_value : int or float, optional
    NaN value used in the final NetCDF file.
  variables : list of str, optional
    Variables to resample from original file.
  shapefile : str, optional
    Path to shape file, uses “world country admin boundary shapefile” by default.
  res_data : dict of numpy.arrays
    resampled image
  dest_lon : numpy.array
    longitudes of the points in the resampled image
  dest_lat : numpy.array
    latitudes of the points in the resampled image
  gpis : numpy.array
    grid point indices
  timestamp : datetime.date
    date of the image
  metadata : dict
    Metadata derived from input file.

## Module contents