To process raster data for hydro-logical/dynamic modelling
Project description
hydro_raster
Python code to process raster data for hydroligical or hydrodynamic modelling, e.g., HiPIMS flood model. The codes are also included in the HiPIMS python API Pypims. The style of this package follows the Google Python Style Guide.
Python version: >=3.6. To use the full function of this package for processing raster and feature files, rasterio and pyshp are required.
The CRS of both DEM and Shapfiles must be projected crs whose map unit is meter.
Functions included in this package:
- merge raster files
- edit raster cell values based on shapefile
- convert cross-section lines to river bathymetry raster
- remove overhead buildings/bridges on raster
- read, write, and visualise raster file
To install hydro_raster from command window/terminal:
pip install hydro_raster
To install using github repo:
git clone https://github.com/mingxiaodong/hydro-raster
cd hydro-raster
pip install .
Tutorial
A jupyter-notebook file is available to show a more detailed tutorial with outputs/plots of its codes.
- Read a raster file
from hydro_raster.Raster import Raster
from hydro_raster import get_sample_data
tif_file_name = get_sample_data('tif')
ras_obj = Raster(tif_file_name)
- Visualize a raster file
ras_obj.mapshow()
ras_obj.rankshow(breaks=[0, 10, 20, 30, 40, 50])
- Clip raster file
clip_extent = (340761, 341528, 554668, 555682) # left, right, bottom, top
ras_obj_cut = ras_obj.rect_clip(clip_extent) # raster can aslo be cut by a shapfile using 'clip' function
ras_obj_cut.mapshow()
- Rasterize polygons on a raster and return an index array with the same dimension of the raster array
shp_file_name = get_sample_data('shp')
index_array = ras_obj_cut.rasterize(shp_file_name)
- Change raster cell values within the polygons by adding a fixed value
ras_obj_new = ras_obj_cut.duplicate()
ras_obj_new.array[index_array] = ras_obj_cut.array[index_array]+20
- Show the edited raster with the shapefile polygons
import matplotlib.pyplot as plt
from hydro_raster.grid_show import plot_shape_file
fig, ax = plt.subplots(1, 2)
ras_obj_cut.mapshow(ax=ax[0])
plot_shape_file(shp_file_name, ax=ax[0], linewidth=1)
ras_obj_new.mapshow(ax=ax[1])
plot_shape_file(shp_file_name, ax=ax[1], linewidth=1)
# values can also be changed based on the attributes of each shapefile features
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hydro_raster-0.0.7.tar.gz
.
File metadata
- Download URL: hydro_raster-0.0.7.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eba4b8a0e2b02fce3b9348292024413bb57cd687fd2dc9e39ee3de98b703b843 |
|
MD5 | b305b1a3e158793efe61a6348cbca7ba |
|
BLAKE2b-256 | f85f75fa3f56b5fdf4342ea7222b18a540cd82502132412ee392ac1ae21d818c |
File details
Details for the file hydro_raster-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: hydro_raster-0.0.7-py3-none-any.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9faf9e96a90ab8ba206b4803d4747fe28e69dce0f54a8734fdd40ea92a5e349 |
|
MD5 | 8ae5d14d14c3b1c93e5129a4e8918529 |
|
BLAKE2b-256 | a374f3642d1149b04035210ec9a73bef78ba05953d8ffeee1c15cd2288a2aaa2 |