|
7 | 7 | import matplotlib.pyplot as plt |
8 | 8 | import xarray as xr |
9 | 9 | import yaml |
| 10 | +from _script_utils import plot_with_zero_separate |
10 | 11 |
|
11 | 12 |
|
12 | 13 | @click.command() |
@@ -55,22 +56,23 @@ def get_area_potential( |
55 | 56 | # Start with the configured pixel area as a base |
56 | 57 | potential_da = ds[config["initial_area"]].squeeze(drop=True) # Drop `band` |
57 | 58 |
|
58 | | - # Drop pixels from binary layers with share 0 from potential_da |
| 59 | + # Zero out pixels from binary layers with share 0 from potential_da |
59 | 60 | binary_layers = config.get("binary_layers", {}) |
60 | 61 | zero_binary_layers = [layer for layer, value in binary_layers.items() if value == 0] |
61 | 62 | for layer in zero_binary_layers: |
62 | 63 | if layer in ds: |
63 | | - potential_da = potential_da.where(~(ds[layer] > 0)) |
| 64 | + potential_da = potential_da.where(~(ds[layer] > 0), other=0) |
64 | 65 | else: |
65 | 66 | print(f"Warning: Layer '{layer}' not found in dataset. Skipping.") |
66 | 67 |
|
67 | | - # Apply the continuous_layers criteria to drop additional pixels |
| 68 | + # Apply the continuous_layers criteria to zero out additional pixels |
68 | 69 | continuous_layers = config.get("continuous_layers", {}) |
69 | 70 | for layer, layer_config in continuous_layers.items(): |
70 | 71 | if layer in ds: |
71 | 72 | # Apply the min-max criteria |
72 | 73 | potential_da = potential_da.where( |
73 | | - (ds[layer] <= layer_config["max"]) & (ds[layer] >= layer_config["min"]) |
| 74 | + (ds[layer] <= layer_config["max"]) & (ds[layer] >= layer_config["min"]), |
| 75 | + other=0, |
74 | 76 | ) |
75 | 77 | # If a share is defined, multiply the pixel area by the share |
76 | 78 | if "share" in layer_config: |
@@ -111,7 +113,8 @@ def get_area_potential( |
111 | 113 | potential_da = potential_da.transpose("band", "y", "x") |
112 | 114 | potential_da.rio.write_crs(ds.rio.crs, inplace=True) |
113 | 115 |
|
114 | | - potential_da.plot() |
| 116 | + fig, ax = plt.subplots(1, 1) |
| 117 | + ax = plot_with_zero_separate(ax=ax, da=potential_da) |
115 | 118 | plt.savefig(plot_path, bbox_inches="tight") |
116 | 119 |
|
117 | 120 | # Fill NaN with a nodata value only after plotting |
|
0 commit comments