Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bivalvelarvae.py with habitat settlement #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

RomainChaput
Copy link

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
in_habitat = pt.within(poly)
if in_habitat == True:
#import pdb; pdb.set_trace()
self.environment.land_binary_mask[old_enough[i]] = 1
Copy link
Author

@RomainChaput RomainChaput Apr 29, 2021

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


# 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
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
Owner

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

@RomainChaput
Copy link
Author

RomainChaput commented Jun 26, 2021 via email

… 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
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