Skip to content

Commit 3bea0c9

Browse files
authored
Merge pull request #3 from EstebanAce/master
dynamic island boundary
2 parents c2eaab3 + 72da5e9 commit 3bea0c9

File tree

6 files changed

+397
-330
lines changed

6 files changed

+397
-330
lines changed

adascape/fastscape_ext.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import xsimlab as xs
55
from adascape.base import IR12SpeciationModel
66
from orographic_precipitation.fastscape_ext import OrographicPrecipitation, OrographicDrainageDischarge
7-
7+
from scipy.spatial import ConvexHull
88

99
@xs.process
1010
class Speciation:
@@ -47,11 +47,10 @@ class Speciation:
4747
grid_x = xs.foreign(UniformRectilinearGrid2D, "x")
4848
grid_y = xs.foreign(UniformRectilinearGrid2D, "y")
4949

50-
disp_boundary = xs.variable(default=None, description="dispersal boundaries as an xr.DataArray "
51-
"with vertices [[x,y],...] of bounded area "
52-
"with dimensions p and d",
53-
static=True, dims=[(), ('p', 'd')])
54-
50+
disp_boundary = xs.variable(default=None, description="dispersal boundary value to define minimum elevation of the island," \
51+
" where individuals can disperse. Default None, no boundary is applied.",
52+
static=True)
53+
5554
_model = xs.any_object(description="speciation model instance")
5655
_individuals = xs.any_object(description="speciation model state dictionary")
5756

@@ -127,6 +126,8 @@ class IR12Speciation(Speciation):
127126
description="individual's fitness value"
128127
)
129128

129+
topo_elevation = xs.foreign(SurfaceTopography, "elevation")
130+
130131
def _get_model_params(self):
131132
return {
132133
"r": self.r,
@@ -173,9 +174,20 @@ def run_step(self):
173174
self.abundance = self._model.abundance
174175
self._model.evaluate_fitness()
175176

177+
def _island_boundary(self):
178+
xx, yy = np.meshgrid(self.grid_x, self.grid_y)
179+
island_mask = self.topo_elevation > self.disp_boundary
180+
island_grid = np.column_stack((xx[island_mask], yy[island_mask]))
181+
cvhull = ConvexHull(island_grid)
182+
return island_grid[cvhull.vertices]
183+
176184
@xs.runtime(args='step_delta')
177185
def finalize_step(self, dt):
178-
self._model.update_individuals(dt, self.disp_boundary)
186+
if self.disp_boundary is not None:
187+
boundary_points = self._island_boundary()
188+
self._model.update_individuals(dt, boundary_points)
189+
else:
190+
self._model.update_individuals(dt)
179191

180192
@fitness.compute
181193
def _get_fitness(self):

adascape/tests/test_fastscape_ext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def specIR12_process(trait_funcs):
3232
return IR12Speciation(env_field=env_field, grid_x=x, grid_y=y,
3333
init_trait_funcs=init_trait_funcs,
3434
opt_trait_funcs=opt_trait_funcs,
35+
topo_elevation=env_field,
3536
**params)
3637

3738

notebooks/1.basic_execution_ecoevomodel.ipynb

Lines changed: 26 additions & 26 deletions
Large diffs are not rendered by default.

notebooks/2.Lineages_reconstruction.ipynb

Lines changed: 45 additions & 45 deletions
Large diffs are not rendered by default.

notebooks/3.coupled_ecoevomodel_LEM.ipynb

Lines changed: 176 additions & 198 deletions
Large diffs are not rendered by default.

notebooks/4.ecoevo_island.ipynb

Lines changed: 130 additions & 54 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)