Skip to content

Commit

Permalink
Klimaat pgb index (#104)
Browse files Browse the repository at this point in the history
* nodata van pgb labels naar -9999

De schadekaart heeft nodata =0. In de pgb kwam die index ook voor, waardoor dit pgb niet meekwam in de nabewerking klimaatsommen.

* fix np.bool deprecated

* labels nodata to var

* add deps to fix tests

* Update environment_test.yml
  • Loading branch information
wvangerwen authored Jul 2, 2024
1 parent 85e554d commit 4ef1c81
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions envs/environment_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dependencies:
# - exceptiongroup=1.1.1 #pytest dependency
- iniconfig=2.0.0 #pytest dependency
- tqdm=4.64.0
- rioxarray=0.15.0 #higher versions need python >=3.10
- pyogrio=0.9.0


- xarray=2024.3.0
Expand Down
2 changes: 1 addition & 1 deletion hhnk_threedi_tools/core/climate_scenarios/maskerkaart.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def classify_nodes(node_id_2d, groups, lines1d2d_active, lines1d2d_valid):
# that have valid 1D lines
node_id_2d_valid_1d = np.intersect1d(node_id_2d_active_1d, lines1d2d_valid.line.ravel())
# create boolean arrays for fast lookup
is2d = np.zeros(node_id_2d.max() + 1, dtype=np.bool)
is2d = np.zeros(node_id_2d.max() + 1, dtype=bool)
is2d[node_id_2d] = True
has1d_active = np.zeros_like(is2d)
has1d_active[node_id_2d_active_1d] = True
Expand Down
7 changes: 4 additions & 3 deletions hhnk_threedi_tools/core/climate_scenarios/peilgebieden.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ def rasterize_peilgebieden(
pgb_gdf = input_peilgebieden.load()
pgb_gdf.reset_index(drop=False, inplace=True)

labels_nodata = -9999
# Rasterize areas, giving each region a unique id.
labels_array = hrt.gdf_to_raster(
gdf=pgb_gdf,
value_field="index",
raster_out="",
nodata=input_raster.nodata,
nodata=labels_nodata,
metadata=input_raster.metadata,
driver="MEM",
)
Expand All @@ -41,7 +42,7 @@ def rasterize_peilgebieden(
)

# Apply mask to labels. Use DEM.
labels_array[mask_array != 1] = input_raster.nodata
labels_array[mask_array != 1] = labels_nodata

hrt.save_raster_array_to_tiff(
output_file=output_file.path,
Expand All @@ -52,7 +53,7 @@ def rasterize_peilgebieden(

print(f"{output_file.name} created")

unique_labels = np.unique(labels_array[labels_array != input_raster.nodata])
unique_labels = np.unique(labels_array[labels_array != labels_nodata])

pgb_masked = pgb_gdf.loc[unique_labels][["index", "peil_id", "code", "name", "geometry"]]

Expand Down

0 comments on commit 4ef1c81

Please sign in to comment.