Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions adascape/fastscape_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import xsimlab as xs
from adascape.base import IR12SpeciationModel
from orographic_precipitation.fastscape_ext import OrographicPrecipitation, OrographicDrainageDischarge

from scipy.spatial import ConvexHull

@xs.process
class Speciation:
Expand Down Expand Up @@ -47,11 +47,10 @@ class Speciation:
grid_x = xs.foreign(UniformRectilinearGrid2D, "x")
grid_y = xs.foreign(UniformRectilinearGrid2D, "y")

disp_boundary = xs.variable(default=None, description="dispersal boundaries as an xr.DataArray "
"with vertices [[x,y],...] of bounded area "
"with dimensions p and d",
static=True, dims=[(), ('p', 'd')])

disp_boundary = xs.variable(default=None, description="dispersal boundary value to define minimum elevation of the island," \
" where individuals can disperse. Default None, no boundary is applied.",
static=True)

_model = xs.any_object(description="speciation model instance")
_individuals = xs.any_object(description="speciation model state dictionary")

Expand Down Expand Up @@ -127,6 +126,8 @@ class IR12Speciation(Speciation):
description="individual's fitness value"
)

topo_elevation = xs.foreign(SurfaceTopography, "elevation")

def _get_model_params(self):
return {
"r": self.r,
Expand Down Expand Up @@ -173,9 +174,20 @@ def run_step(self):
self.abundance = self._model.abundance
self._model.evaluate_fitness()

def _island_boundary(self):
xx, yy = np.meshgrid(self.grid_x, self.grid_y)
island_mask = self.topo_elevation > self.disp_boundary
island_grid = np.column_stack((xx[island_mask], yy[island_mask]))
cvhull = ConvexHull(island_grid)
return island_grid[cvhull.vertices]

@xs.runtime(args='step_delta')
def finalize_step(self, dt):
self._model.update_individuals(dt, self.disp_boundary)
if self.disp_boundary is not None:
boundary_points = self._island_boundary()
self._model.update_individuals(dt, boundary_points)
else:
self._model.update_individuals(dt)

@fitness.compute
def _get_fitness(self):
Expand Down
1 change: 1 addition & 0 deletions adascape/tests/test_fastscape_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def specIR12_process(trait_funcs):
return IR12Speciation(env_field=env_field, grid_x=x, grid_y=y,
init_trait_funcs=init_trait_funcs,
opt_trait_funcs=opt_trait_funcs,
topo_elevation=env_field,
**params)


Expand Down
52 changes: 26 additions & 26 deletions notebooks/1.basic_execution_ecoevomodel.ipynb

Large diffs are not rendered by default.

90 changes: 45 additions & 45 deletions notebooks/2.Lineages_reconstruction.ipynb

Large diffs are not rendered by default.

374 changes: 176 additions & 198 deletions notebooks/3.coupled_ecoevomodel_LEM.ipynb

Large diffs are not rendered by default.

184 changes: 130 additions & 54 deletions notebooks/4.ecoevo_island.ipynb

Large diffs are not rendered by default.

Loading