Raster
- class CreateNetCDF(fp, title, source, institution, n_timesteps, lons, lats, epsg, varname, units, dtype, chunksizes, fill_value, compression_level, comment=None)[source]
Class to create easy create a spatial NetCDF-file.
- Parameters:
fn – Filepath.
title (
str
) – Title of NetCDF.source (
str
) – Source of data.institution (
str
) – Institution where data was created.n_timesteps (
Optional
[int
]) – Number of timesteps in NetCDF. None if NetCDF should not have time dimension.lons (
ndarray
) – Array of longitudes.lats (
ndarray
) – Array of latitudes.epsg (
int
) – EPSG code.varname (
str
) – Name of variable to store.units (
str
) – Unit of variable.dtype (
str
) – NetCDF dtype. See NetCDF documentation for valid dtypes: https://unidata.github.io/netcdf4-python/chunksizes (
tuple
[int
]) – Sizes of datachunks. (time, lat, lon) if time dimension exists, otherwise (lat, lon).fill_value (
Union
[float
,int
]) – Value to represent nodata.compression_level (
int
) – NetCDF compression level (1-9)comment (
str
) – Optional dataset comment.
- clip_to_other(array, src_profile, other_profile)[source]
Clip array to rasterio profile.
- Parameters:
array (
ndarray
) – Array to clip.src_profile (
Profile
) – Rasterio profile of source array.other_profile (
Profile
) – Rasterio profile of array to clip to.
- Returns:
outarray – Clipped array.
profile – Updated profile.
- Return type:
tuple
[ndarray
,Profile
]
- clip_to_xy_bounds(src, profile, array, xmin, xmax, ymin, ymax)[source]
Clips rasterio dataset to given bounds.
- Parameters:
src (
DatasetReader
) – Rasterio dataset.profile (
Profile
) – Rasterio profile of dataset.array (
ndarray
) – Array to clip.xmin (
int
) – Minimum xbound.xmax (
int
) – Maximum xbound.ymin (
int
) – Minimum ybound.ymax (
int
) – Maximum ybound.
- Returns:
profile – Updated profile for cut array.
array – Array data.
- Return type:
ndarray
- coord_to_pixel(coord, gt)[source]
Converts coordinate to pixel (x, y) for given geotransformation.
- Parameters:
coord (
ndarray
) – the coordinate (lon, lat) that need to be transformed to pixelgt (
tuple
[float
,float
,float
,float
,float
,float
]) – the geotransformation. Must be unrotated
- Returns:
array – tuple of pixel (x, y)
- Return type:
tuple
[int
,int
]
- coords_to_pixels(coords, gt, dtype=<class 'numpy.uint32'>)[source]
Converts array of coordinates to array of pixels for given geotransformation.
- Parameters:
coords – the coordinates (lon, lat) that need to be transformed to pixels (shape: 2, n)
gt (
tuple
) – the geotransformation. Must be unrotated
- Returns:
array – 2d-array of pixels per coordinate (shape: 2, n)
- Return type:
tuple
[ndarray
,ndarray
]
- pixel_to_coord(px, py, gt)[source]
Converts pixel (x, y) to coordinate (lon, lat) for given geotransformation. Uses the upper left corner of the pixel. To use the center, add 0.5 to input pixel. :rtype:
Tuple
[float
,float
]- Parameters:
pixel: the pixel (x, y) that need to be transformed to coordinate gt: the geotransformation. Must be unrotated
- Returns:
array: the coordinate (lon, lat)
- pixels_to_coords(pixels, gt)[source]
Converts pixels (x, y) to coordinates (lon, lat) for given geotransformation. Uses the upper left corner of the pixels. To use the centers, add 0.5 to input pixels. :rtype:
ndarray
- Parameters:
pixels: the pixels (x, y) that need to be transformed to coordinates (shape: 2, n) gt: the geotransformation. Must be unrotated
- Returns:
array: the coordinates (lon, lat) (shape: 2, n)
- reproject_pixel(gt_from, gt_to, px_in, py_in)[source]
Reproject pixel.
- Parameters:
gt_from (
tuple
[float
,float
,float
,float
,float
,float
]) – Orginal geotransformation.gt_to (
tuple
[float
,float
,float
,float
,float
,float
]) – Target geotransformation.px_in (
int
) – Input xpixel.py_in (
int
) – Input ypixel.
- Return type:
tuple
[int
,int
]
- sample_from_map(array, coords, gt)[source]
Sample coordinates from a map. Can handle multiple dimensions.
- Parameters:
array (
ndarray
) – the map to sample from (2+n dimensions)coords (
ndarray
) – the coordinates used to sample (shape: 2, m)gt (
tuple
[float
,float
,float
,float
,float
,float
]) – the geotransformation. Must be unrotated
- Returns:
array – values per coordinate
- Return type:
ndarray
- upscale(array, src_profile, factor)[source]
“Upscale array and rasterio profile by x amount.
- Parameters:
array (
ndarray
) – Array to upscale.src_profile (
ndarray
) – Rasterio profile of source array.factor (
ndarray
) – Factor by which to upscale.
- Returns:
array – Upscaled array.
profile – Updated rasterio profile.
- Return type:
tuple
[ndarray
,Profile
]
- write_to_array(array, values, coords, gt)[source]
Write values using coordinates to a map. If multiple coordinates map to a single cell, the values are added. The operation is inplace
- Parameters:
array: the 2-dimensional array to write to values: the values to write (shape: n) coords: the coordinates of the values (shape: 2, n) gt: the geotransformation. Must be unrotated
- Returns:
array: the array with the values added (operation is inplace)