Skip to main content

hydro_raster

Python code to process raster data for hydrological or hydrodynamic modelling, e.g., SynxFlow or HiPIMS-CUDA. The style of this package follows the Google Python Style Guide.

Full documentation about how to install and use is here.

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)
index_array = index_array>=0
  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

Metadata

Release files for hydro-raster 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hydro-raster 0.0.11
File Size Uploaded
hydro_raster-0.0.11.tar.gz 1.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for hydro-raster 0.0.11
File Interpreter ABI Platform
hydro_raster-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 2.8 MB

Release files / hydro_raster-0.0.11.tar.gz

Download URL hydro_raster-0.0.11.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
be56be00bc44ae4e30eef2a82de93c0cea08bccb85eef52fc70ee03f41e2da38
BLAKE2b-256 checksum
How to use checksums
06262a246b946a34bcf9a50c63343a186dd6b8f80bc2417fef53db119cf63a32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.3

Release files / hydro_raster-0.0.11-py3-none-any.whl

Download URL hydro_raster-0.0.11-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
5ef0cbb89c513cb0099deefdd41556807240eef34a73ad47d9d7f7c3866f3061
BLAKE2b-256 checksum
How to use checksums
c8029c4f9ca6936464fb26606eb5ae501d73ad3e37663490f48b0859ee49b7bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page