Dataset Spatial operation methods¶
In [1]:
Copied!
# NBVAL_IGNORE_OUTPUT
from pyramids.dataset import Dataset
path = "../../../examples/data/dem/DEM5km_Rhine_burned_fill.tif"
# NBVAL_IGNORE_OUTPUT
from pyramids.dataset import Dataset
path = "../../../examples/data/dem/DEM5km_Rhine_burned_fill.tif"
2026-03-26 23:38:04 | INFO | pyramids.base.config | Logging is configured.
In [2]:
Copied!
dataset = Dataset.read_file(path)
dataset = Dataset.read_file(path)
In [3]:
Copied!
print(dataset)
print(dataset)
Top Left Corner: (32239263.70388, 5756081.42235)
Cell size: 5000.0
Dimension: 125 * 93
EPSG: 4647
Number of Bands: 1
Band names: ['Band_1']
Band colors: {0: 'gray_index'}
Band units: ['']
Scale: [1.0]
Offset: [0]
Mask: -3.4028234663852886e+38
Data type: float32
File: ../../examples/data/dem/DEM5km_Rhine_burned_fill.tif
In [4]:
Copied!
dataset.plot(vmin=0, title="Rhine River Basin", cbar_label="Elevation(m)")
dataset.plot(vmin=0, title="Rhine River Basin", cbar_label="Elevation(m)")
Matplotlib backend set to inline for static plots in Jupyter notebook
Out[4]:
<cleopatra.array_glyph.ArrayGlyph at 0x1ee2ed927b0>
Resampling¶
In [5]:
Copied!
print(f"Cell size: {dataset.cell_size}")
print(f"Cell size: {dataset.cell_size}")
Cell size: 5000.0
In [6]:
Copied!
dataset_8km = dataset.resample(cell_size=8000, method="bilinear")
dataset_8km = dataset.resample(cell_size=8000, method="bilinear")
In [7]:
Copied!
dataset_8km.plot(
vmin=0, title="Rhine River Basin (resampled to 8 km)", cbar_label="Elevation(m)"
)
dataset_8km.plot(
vmin=0, title="Rhine River Basin (resampled to 8 km)", cbar_label="Elevation(m)"
)
Out[7]:
<cleopatra.array_glyph.ArrayGlyph at 0x1ee2ee9cb90>
Reproject¶
In [8]:
Copied!
print(f"EPSG: {dataset.epsg}")
print(f"Coordinate reference system: {dataset.crs}")
print(f"Dataset dimensions: {dataset.shape}")
print(f"EPSG: {dataset.epsg}")
print(f"Coordinate reference system: {dataset.crs}")
print(f"Dataset dimensions: {dataset.shape}")
EPSG: 4647 Coordinate reference system: PROJCS["ETRS89 / UTM zone 32N (zE-N)",GEOGCS["ETRS89",DATUM["European_Terrestrial_Reference_System_1989",SPHEROID["GRS 1980",6378137,298.257222101004,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6258"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4258"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",32500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","4647"]] Dataset dimensions: (1, 125, 93)
In [9]:
Copied!
resampled_dataset = dataset.to_crs(4326)
resampled_dataset = dataset.to_crs(4326)
In [10]:
Copied!
print(resampled_dataset)
print(resampled_dataset)
Top Left Corner: (5.210230290109742, 51.9554111793825)
Cell size: 0.05475332958287695
Dimension: 104 * 123
EPSG: 4326
Number of Bands: 1
Band names: ['Band_1']
Band colors: {0: 'gray_index'}
Band units: ['']
Scale: [1.0]
Offset: [0.0]
Mask: -3.4028234663852886e+38
Data type: float32
File:
In [11]:
Copied!
resampled_dataset.plot(
vmin=0, title="Rhine River Basin (reprojected to WGS 84)", cbar_label="Elevation(m)"
)
resampled_dataset.plot(
vmin=0, title="Rhine River Basin (reprojected to WGS 84)", cbar_label="Elevation(m)"
)
Out[11]:
<cleopatra.array_glyph.ArrayGlyph at 0x1ee2f2742d0>
Crop/Clip¶
In [12]:
Copied!
path = "../../../examples/data/geotiff/noah-precipitation-1979-europe.tif"
meteo_data = Dataset.read_file(path)
path = "../../../examples/data/geotiff/noah-precipitation-1979-europe.tif"
meteo_data = Dataset.read_file(path)
In [13]:
Copied!
print(meteo_data)
print(meteo_data)
Top Left Corner: (-5.0, 55.0)
Cell size: 0.5
Dimension: 25 * 40
EPSG: 4326
Number of Bands: 4
Band names: ['Band_1', 'Band_2', 'Band_3', 'Band_4']
Band colors: {0: 'gray_index', 1: 'undefined', 2: 'undefined', 3: 'undefined'}
Band units: ['', '', '', '']
Scale: [1.0, 1.0, 1.0, 1.0]
Offset: [0, 0, 0, 0]
Mask: -9.969209968386869e+36
Data type: float32
File: ../../examples/data/geotiff/noah-precipitation-1979-europe.tif
In [14]:
Copied!
array_glyph = meteo_data.plot(
band=0,
figsize=(10, 5),
title="Noah daily Precipitation 1979-01-01",
cbar_label="Raindall mm/day",
vmax=30,
cbar_length=0.85,
)
array_glyph = meteo_data.plot(
band=0,
figsize=(10, 5),
title="Noah daily Precipitation 1979-01-01",
cbar_label="Raindall mm/day",
vmax=30,
cbar_length=0.85,
)
In [15]:
Copied!
meteo_data_r = meteo_data.to_crs(4647)
meteo_data_r = meteo_data.to_crs(4647)
In [16]:
Copied!
meteo_data_r.plot(band=0)
meteo_data_r.plot(band=0)
Out[16]:
<cleopatra.array_glyph.ArrayGlyph at 0x1ee2f241940>
In [17]:
Copied!
rhine_meteo_data = meteo_data_r.crop(dataset)
rhine_meteo_data = meteo_data_r.crop(dataset)
In [18]:
Copied!
rhine_meteo_data.plot(band=0)
rhine_meteo_data.plot(band=0)
Out[18]:
<cleopatra.array_glyph.ArrayGlyph at 0x1ee2ee528d0>
In [19]:
Copied!
rhine_meteo_data
rhine_meteo_data
Out[19]:
Driver: MEM/In Memory raster, vector and multidimensional raster
Files: none associated
Size is 10, 14
Coordinate System is:
PROJCRS["ETRS89 / UTM zone 32N (zE-N)",
BASEGEOGCRS["ETRS89",
DATUM["European Terrestrial Reference System 1989",
ELLIPSOID["GRS 1980",6378137,298.257222101,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4258]],
CONVERSION["unnamed",
METHOD["Transverse Mercator",
ID["EPSG",9807]],
PARAMETER["Latitude of natural origin",0,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",9,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["Scale factor at natural origin",0.9996,
SCALEUNIT["unity",1],
ID["EPSG",8805]],
PARAMETER["False easting",32500000,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",0,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["easting",east,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["northing",north,
ORDER[2],
LENGTHUNIT["metre",1]],
ID["EPSG",4647]]
Data axis to CRS axis mapping: 1,2
Origin = (32245507.838841650635004,5757822.720829151570797)
Pixel Size = (42702.672181714879116,-42702.672181714879116)
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left (32245507.839, 5757822.721) ( 5d17'58.19"E, 51d54'46.43"N)
Lower Left (32245507.839, 5159985.310) ( 5d40'49.82"E, 46d32'42.88"N)
Upper Right (32672534.561, 5757822.721) ( 11d30'37.11"E, 51d56'39.56"N)
Lower Right (32672534.561, 5159985.310) ( 11d15' 5.45"E, 46d34'16.57"N)
Center (32459021.200, 5458904.016) ( 8d26'11.60"E, 49d16'53.46"N)
Band 1 Block=10x1 Type=Float32, ColorInterp=Undefined
NoData Value=-9.96921e+36
Band 2 Block=10x1 Type=Float32, ColorInterp=Undefined
NoData Value=-9.96921e+36
Band 3 Block=10x1 Type=Float32, ColorInterp=Undefined
NoData Value=-9.96921e+36
Band 4 Block=10x1 Type=Float32, ColorInterp=Undefined
NoData Value=-9.96921e+36