Skip to content

Update bivalvelarvae.py with habitat settlement#1

Open
RomainChaput wants to merge 5 commits into
simonweppe:masterfrom
RomainChaput:patch-1
Open

Update bivalvelarvae.py with habitat settlement#1
RomainChaput wants to merge 5 commits into
simonweppe:masterfrom
RomainChaput:patch-1

Conversation

@RomainChaput

Copy link
Copy Markdown

I tried to add the ability to settlement particles in a shapefile (representing a suitable environment). When settlement_in_habitat is True, elements are only deactivated if they are old enough to settle and if they are within the boundaries of an element of the shapefile.
To activate in a script add these lines before running OpenDrift:

###############################

Define habitat

###############################
shp, bins = o.habitat('./habitat/Test_habitat.shp') # Location of the shapefile with the habitat

###############################

Type of settlement

###############################
o.set_config('drift:settlement_in_habitat', True)
o.set_config('drift:max_age_seconds', max_PLD) # maximum duration of PLD without settlement
o.set_config('drift:min_settlement_age_seconds', min_PLD) # Beginning of the competency period

I tried to add the ability to settlement particles in a shapefile (representing a suitable environment). When settlement_in_habitat is True, elements are only deactivated if they are old enough to settle and if they are within the boundaries of an element of the shapefile.
To activate in a script add these lines before running OpenDrift:

###############################
# Define habitat
###############################
shp, bins = o.habitat('./habitat/Test_habitat.shp') # Location of the shapefile with the habitat

###############################
# Type of settlement
###############################
o.set_config('drift:settlement_in_habitat', True)
o.set_config('drift:max_age_seconds', max_PLD) # maximum duration of PLD without settlement
o.set_config('drift:min_settlement_age_seconds', min_PLD) # Beginning of the competency period
Comment thread opendrift/models/bivalvelarvae.py Outdated
in_habitat = pt.within(poly)
if in_habitat == True:
#import pdb; pdb.set_trace()
self.environment.land_binary_mask[old_enough[i]] = 1

@RomainChaput RomainChaput Apr 29, 2021

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work better:

self.environment.land_binary_mask[old_enough[i]] = 6

Comment thread opendrift/models/bivalvelarvae.py Outdated

# Deactivate elements that are within a polygon and old enough to settle
# ** function expects an array of size consistent with self.elements.lon
self.deactivate_elements((self.environment.land_binary_mask == 1), reason='settled_in_habitat')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work better:

self.deactivate_elements((self.environment.land_binary_mask == 6), reason='settled_in_habitat')

Changed self.environment.land_binary_mask == 1 to self.environment.land_binary_mask == 6 when particles are within an habitat (land_binary_mask == 1 was conflicting with settlement at the coast).
Calvin found that the function seeded_on_land was flagging the particles that stopped moving long after being released. I changed the function with the original version of basemodel.py and it seems to work as intended.
Optimization of the habitat module. The use of the MultiPolygon object should speed up the function.
@simonweppe

Copy link
Copy Markdown
Owner

@RomainChaput - sorry I've missed this one ! I'll have a good look next week.

@RomainChaput

RomainChaput commented Jun 26, 2021 via email

Copy link
Copy Markdown
Author

… maximum depth, and Haliotis iris

I added a vertical swimming behavior correlated to the direction of the currents: when larvae are advected away from the coast they start a correlated random walk, swimming up and down until they find a current that bring them closer to shore. Because this code involves calling the habitat module at every timestep, I used a Ball Tree algorithm to classify the habitat centroids and improve the efficiency of the searching algorithm.
I also added a maximum dispersal depth that the user can specify.
Finally, I added an option to simulate the vertical migration of Haliotis iris during the first 12 hours of dispersal (sink, then rise to the surface).
simonweppe pushed a commit that referenced this pull request Feb 22, 2024
…ce-for-physics-presentation

Add files via upload
simonweppe pushed a commit that referenced this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants