poets.image package — poets 0.1.0 documentation

### Navigation

- index
- modules |
- next |
- previous |
- poets 0.1.0 documentation »
- poets package »

# poets.image package

## Submodules

## 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, shapefile=None)

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

  Parameters: | 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. shapefile : str, optional Path to shape file, uses “world country admin boundary shapefile” by default.
  Returns: | 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.

  Returns: | lon_min, lon_max : float Min and max longitude.

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

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

  Parameters: | img : Image File, e.g. PNG, TIFF Input image file lon : float Longitude lat : float Latitude
  Returns: | 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).

  Parameters: | img : Image File, e.g. PNG, TIFF Input image file lon : float Longitude lat : float Latitude
  Returns: | 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

  Parameters: | 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
  Returns: | 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

  Parameters: | img : Image file 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
  Returns: | 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...).

  Parameters: | img : Image File, e.g. PNG, TIFF Image to be rearranged
  Returns: | img : 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`(source_file, lon_min, lat_min, lon_max, lat_max)

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

  Parameters: | source_file : str Path to 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.
  Returns: | data : dict of numpy.arrays Clipped image. lon_new : numpy.array Longitudes of the clipped image. lat_new : numpy.array Latgitudes of the clipped image. timestamp : datetime.date Timestamp of image. metadata : dict of strings Metadata from source netCDF file.

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

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

  Parameters: | src_file : str Path to NetCDF file.
  Returns: | 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, 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

  Parameters: | 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.
  Returns: | 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')

  Saves numpy.ndarray images as multidimensional netCDF4 file.

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

  Parameters: | 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. 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.

`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.

  Parameters: | 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. 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 ndimensional masked arrays to one image

  Parameters: | image : numpy.ma.MaskedArray Input image to average.
  Returns: | avg_img : numpy.ma.MaskedArray Averaged image.

`poets.image.resampling.` `resample_to_gridpoints`(source_file, region, sp_res, shapefile=None)

  Resamples image to predefined gridpoints.

  Parameters: | source_file : str Path to source file. region : str Latitudes of source image. sp_res : int or float Spatial resolution of the shape-grid. shapefile : str, optional Path to shape file, uses “world country admin boundary shapefile” by default.
  Returns: | dframe : pandas.DataFrame Resampled data with gridpoints as index.

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

  Resamples images and clips country boundaries

  Parameters: | 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. 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 shapefile : str, optional Path to shape file, uses “world country admin boundary shapefile” by default.
  Returns: | data : dict of numpy.arrays resampled image lons : numpy.array longitudes of the points in the resampled image lats : numpy.array latitudes of the points in the resampled image gpis : numpy.array grid point indices timestamp : datetime.date date of the image

## Module contents

### Navigation

- index
- modules |
- next |
- previous |
- poets 0.1.0 documentation »
- poets package »