Skip to main content

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:

  1. merge raster files
  2. edit raster cell values based on shapefile
  3. convert cross-section lines to river bathymetry raster
  4. remove overhead buildings/bridges on raster
  5. 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.

  1. 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)
  1. Visualize a raster file
ras_obj.mapshow()
ras_obj.rankshow(breaks=[0, 10, 20, 30, 40, 50])
  1. 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()
  1. 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)
  1. 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
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hydro_raster-0.0.6.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hydro_raster-0.0.6-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file hydro_raster-0.0.6.tar.gz.

File metadata

  • Download URL: hydro_raster-0.0.6.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

Hashes for hydro_raster-0.0.6.tar.gz
Algorithm Hash digest
SHA256 cad56f7e0afe161d2cf21bec8e57b98f34314685df944fa99661e11e30f5116b
MD5 3d9248706987cedc964418265e8a532e
BLAKE2b-256 1fe5d9966681a83c2fea366a42c62c7b0b57621696e9f72ad295a9fec48b82ad

See more details on using hashes here.

File details

Details for the file hydro_raster-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: hydro_raster-0.0.6-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

Hashes for hydro_raster-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c63c86abc4ab0be7b1155687891a37cc8b9c9aa31309c42dc7c0f149ca29130b
MD5 3925f81d756c79646f620aa07dcaaac4
BLAKE2b-256 99f4804e5af385c2e3d14e9bdd1517a11295379cefe1338bb39311e63c83bcd8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page