ukis_pysat.raster¶
-
class
ukis_pysat.raster.
Image
(data, dimorder='first', crs=None, transform=None, nodata=None)¶ Bases:
object
Parameters: - data – rasterio.io.DatasetReader or path to raster or np.ndarray of shape (bands, rows, columns)
- dimorder – Order of channels or bands ‘first’ or ‘last’ (default: ‘first’)
- crs – Coordinate reference system used when creating form array. If ‘data’ is np.ndarray this is required (default: None)
- transform – Affine transformation mapping the pixel space to geographic space. If ‘data’ is np.ndarray this is required (default: None)
- nodata – nodata value only used when creating from np.ndarray, otherwise this has no effects, optional (default: None)
-
arr
¶ array property
-
close
()¶ closes Image
-
da_arr
= None¶
-
dn2toa
(platform, mtl_file=None, mtd_file=None, wavelengths=None)¶ This method converts digital numbers to top of atmosphere reflectance, like described here: https://www.usgs.gov/land-resources/nli/landsat/using-usgs-landsat-level-1-data-product
Parameters: - platform – image platform, possible Platform.Landsat[5, 7, 8] or Platform.Sentinel2 (<enum ‘Platform’>).
- mtl_file – path to Landsat MTL file that holds the band specific rescale factors (str).
- mtd_file – path to Sentinel-2 MTD file that holds the band specific rescale factors (str).
- wavelengths – like [“Blue”, “Green”, “Red”, “NIR”, “SWIR1”, “TIRS”, “SWIR2”] for Landsat-5 (list of str).
-
get_subset
(tile, band=0)¶ Get slice of array.
Parameters: - tile – rasterio.windows.Window tile from get_tiles().
- band – Band number (default: 0).
Returns: Sliced numpy array, bounding box of array slice.
-
get_tiles
(width=256, height=256, overlap=0)¶ Calculates rasterio.windows.Window, idea from https://stackoverflow.com/a/54525931
Parameters: - width – int, optional (default: 256). Tile size in pixels.
- height – int, optional (default: 256). Tile size in pixels.
- overlap – int, optional (default: 0). Overlap in pixels.
Yields: window of tile
-
get_valid_data_bbox
(nodata=0)¶ bounding box covering the input array’s valid data pixels.
Parameters: nodata – nodata value, optional (default: 0) Returns: tuple with valid data bounds
-
mask
(bbox, crop=True, fill=False, mode='constant', constant_values=0)¶ Mask raster to bbox.
Parameters: - bbox – bounding box of type tuple or Shapely Polygon
- crop – bool, see rasterio.mask. Optional, (default: True)
- fill – enforce raster to cover bbox. if raster extent is smaller than bbox it will be filled according to mode and constant_values parameters. Optional (default: False)
- mode – str, how to fill, see rasterio.pad. Optional (default: ‘constant’)
- constant_values – nodata value, padding should be filled with, optional (default: 0)
-
pad
(pad_width, mode='constant', constant_values=0)¶ Pad raster in all directions.
Parameters: - pad_width – pad width in pixels, int.
- mode – str, how to pad, see rasterio.pad. Optional (default: ‘constant’)
- constant_values – nodata value, padding should be filled with, optional (default: 0)
Returns: closed, buffered dataset in memory
-
to_dask_array
(chunk_size=(1, 6000, 6000))¶ transforms numpy to dask array
Parameters: chunk_size – tuple, size of chunk, optional (default: (1, 6000, 6000)) Returns: dask array
-
warp
(dst_crs, resampling_method=0, num_threads=4, resolution=None, nodata=None, target_align=None)¶ Reproject a source raster to a destination raster.
Parameters: - dst_crs – CRS or dict, Target coordinate reference system.
- resampling_method – Resampling algorithm, int, defaults to 0 (Nearest) numbers: https://github.com/mapbox/rasterio/blob/master/rasterio/enums.py#L28
- num_threads – int, number of workers, optional (default: 4)
- resolution – tuple (x resolution, y resolution) or float, optional. Target resolution, in units of target coordinate reference system.
- target_align – raster to which to align resolution, extent and gridspacing, optional (Image).
- nodata – nodata value of source, int or float, optional.
-
write_to_file
(path_to_file, dtype, driver='GTiff', nodata=None, compress=None, kwargs=None)¶ Write a dataset to file. :param path_to_file: str, path to new file :param dtype: datatype, like np.uint16, ‘float32’ or ‘min’ to use the minimum type to represent values
Parameters: - driver – str, optional (default: ‘GTiff’)
- nodata – nodata value, e.g. 255 (default: None, means nodata value of dataset will be used)
- compress – compression, e.g. ‘lzw’ (default: None)
- kwargs – driver specific keyword arguments, e.g. {‘nbits’: 1, ‘tiled’: True} for GTiff (default: None) for more keyword arguments see gdal driver specifications, e.g. https://gdal.org/drivers/raster/gtiff.html