Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vboussange committed Feb 20, 2025
1 parent abadf6e commit 6824dda
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 16 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ plt.imshow(quality)
plt.axis("off")
```

<div align="center"><img src="examples/moving_windows/quality_raster.png" alt="Sensitivities" width="400"></div>
<div align="center"><img src="examples/moving_windows/quality_raster.png" alt="Sensitivities" width="600"></div>

To calculate the landscape connectivity, we need to define a disperal range for the species we consider, in terms of the maximum number of pixels an individual (or offspring) of this species can theoretically cross, should the permeability be 1 (highest).

Expand Down Expand Up @@ -180,11 +180,14 @@ cbar = plt.colorbar(shrink=0.5)
cbar.set_label('Elasticity w.r.t permeability')
```

<div align="center"><img src="examples/sensitivity_analysis/elasticity_permeability.png" alt="Sensitivities" width="400"></div>
<div align="center"><img src="examples/sensitivity_analysis/elasticity_permeability.png" alt="Sensitivities" width="600"></div>

**❓ How can I use this for prioriation❓**

You want to prioritize pixels with high elasticity! Let's say that we have a certain budget to improve the permeability of the landscape, by incrasing each of the selected site by `improved_permeability = 0.4`. We compare two priorization scenarios: one where we select sites randomly, and one where we select sites based on their elasticity w.r.t permeability.

<details>
<summary>Click to see the code</summary>

```python
threshold = jnp.percentile(elasticity, 95) # Get the 99th percentile value excluding NaNs
Expand All @@ -198,14 +201,14 @@ random_coords = jnp.unravel_index(random_indices, quality_raster.shape)
modified_quality_raster = quality_raster.at[random_coords].add(improved_permeability)

def run_connectivity_analysis(raster):
connectivity_prob = ConnectivityAnalysis(quality_raster=quality_raster,
permeability_raster=raster,
distance=distance,
proximity=proximity,
coarsening_factor=0.,
dependency_range=D,
batch_size=50)
return connectivity_prob.run(q_weighted=True)
connectivity_prob = ConnectivityAnalysis(quality_raster=quality_raster,
permeability_raster=raster,
distance=distance,
proximity=proximity,
coarsening_factor=0.,
dependency_range=D,
batch_size=50)
return connectivity_prob.run(q_weighted=True)

base_connectivity = run_connectivity_analysis(quality_raster)
connectivity_improved = run_connectivity_analysis(improved_quality_raster)
Expand All @@ -216,6 +219,8 @@ print(f"- based on priorization with elasticity: {(connectivity_improved - base_
print(f"- based on random priorization: {((connectivity_improved_randomly - base_connectivity) / base_connectivity * 100):.2f}%")
```

</details>

```
Landscape connectivity gain
- based on priorization with elasticity: 11.53%
Expand Down Expand Up @@ -246,7 +251,7 @@ for i, (xy, w) in enumerate(window_op.lazy_iterator(quality_padded)):
ax.imshow(w)
ax.axis("off")
```
<div align="center"><img src="examples/moving_windows/windows.png" alt="Sensitivities" width="400"></div>
<div align="center"><img src="examples/moving_windows/windows.png" alt="Sensitivities" width="600"></div>

```python
# eager iterator
Expand Down
6 changes: 3 additions & 3 deletions examples/moving_windows/moving_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

plt.imshow(quality)
plt.axis("off")
plt.savefig("quality_raster.png", dpi=300)
plt.savefig("quality_raster.png", dpi=300, bbox_inches="tight")

buffer_size=10
window_size=50
Expand All @@ -28,7 +28,7 @@
ax.set_title(f"xy = {xy}")
ax.imshow(w)
ax.axis("off")
plt.savefig("windows.png", dpi=300)
plt.savefig("windows.png", dpi=300, bbox_inches="tight")

# eager iterator
xy, windows = window_op.eager_iterator(quality)
Expand All @@ -40,4 +40,4 @@
new_raster = window_op.update_raster_with_focal_window(xy[2], quality_padded, new_window)
plt.imshow(new_raster)
plt.axis("off")
plt.savefig("new_raster.png", dpi=300)
plt.savefig("new_raster.png", dpi=300, bbox_inches="tight")
Binary file modified examples/moving_windows/new_raster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/moving_windows/quality_raster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/moving_windows/windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/sensitivity_analysis/bottlenecks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/sensitivity_analysis/elasticity_permeability.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions examples/sensitivity_analysis/sensitivity_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def proximity(dist):
plt.axis("off")
cbar = plt.colorbar(shrink=0.5)
cbar.set_label('Elasticity w.r.t permeability')
plt.savefig("elasticity_permeability.png")
plt.savefig("elasticity_permeability.png", bbox_inches="tight")

# To spot bottleneck, a good idea is to compare the elasticity to a perfect landscape
# with no resistance to movement
Expand All @@ -73,6 +73,7 @@ def proximity(dist):
elasticity_ideal = sensitivity_permeability_ideal * quality_raster
elasticity_ideal = jnp.nan_to_num(elasticity_ideal, nan=0.0)

plt.figure()
plt.imshow(elasticity_ideal - elasticity + 1e-2,
cmap="plasma",
# vmax=1e2,
Expand All @@ -81,7 +82,7 @@ def proximity(dist):
plt.axis("off")
cbar = plt.colorbar(shrink=0.5)
cbar.set_label('Bottlenecks')
plt.savefig("bottlenecks.png")
plt.savefig("bottlenecks.png", bbox_inches="tight")

# want to prioritize the landscape?
improved_permeability = 0.4
Expand Down

0 comments on commit 6824dda

Please sign in to comment.