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

Exposure #87

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

virgile-baudrot
Copy link
Contributor

Description

Add two rules of exposure to treatment:

  • ThresholdExposure: Exposure to a single treatment depending on a threshold layer
  • RotationExposure: Exposure by several treatments in rotation depending on a threshold layer

Changes (choose one only, with x or click after creating PR):

  • New formulation/rule
  • Documentation
  • Bug fix for existing rules (non-breaking syntax)
  • Major change to existing rules (breaking syntax, needs a breaking version bump)

Checklist:

  • My code follows the BlueStyle style guide
  • My code is commented with explanations of anything hard to understand
  • There are no unnecessary or unrelated code changes included in this PR
  • There are no depencecies added: if so, please consider if they are necessary and explain why they are required

For bugfixes

  • My PR addresses a single bug/connected group of bugs
  • I have included a test that will ensure the bug does not recur

For new Rules

  • My PR is limited to a clear theme/cenceptual unit. (Otherwise make multiple PRs that can be discussed separately)
  • New rules have tests in a file of the same name as the rule file, e.g. /test/newrulename.jl
  • I have cited the source of the new formulation/s, if applicable
  • I have added a documentation string to formulation struct/s, and added an entry in the docs

Copy link
Member

@rafaqz rafaqz left a comment

Choose a reason for hiding this comment

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

Thanks Virgile, this code and the test are solid and clean. Mostly my comments are just BlueStyle changes, and some questions about naming.

src/exposure.jl Outdated Show resolved Hide resolved
src/exposure.jl Outdated Show resolved Hide resolved
src/exposure.jl Outdated Show resolved Hide resolved
src/exposure.jl Outdated
Base.:+(x::Number, rs::RotationStruct) = RotationStruct(x + rs.rotationStep, rs.timeStep)
Base.:+(rs1::RotationStruct, rs2::RotationStruct) = RotationStruct(rs1.rotationStep + rs2.rotationStep, rs1.timeStep + rs2.timeStep)
Base.:-(rs::RotationStruct, x::Number) = RotationStruct(rs.rotationStep - x, rs.timeStep)
Base.:-(x::Number, rs::RotationStruct) = RotationStruct(x - rs.rotationStep, rs.timeStep)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need these methods for addition/subtraction of a scalar?

src/exposure.jl Outdated
Base.:-(rs::RotationStruct, x::Number) = RotationStruct(rs.rotationStep - x, rs.timeStep)
Base.:-(x::Number, rs::RotationStruct) = RotationStruct(x - rs.rotationStep, rs.timeStep)
Base.:-(rs1::RotationStruct, rs2::RotationStruct) = RotationStruct(rs1.rotationStep - rs2.rotationStep, rs1.timeStep - rs2.timeStep)

Copy link
Member

Choose a reason for hiding this comment

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

If you want you can make it convert to color for ImageOutput that would be good.

Add a method for oneunit - it's basically the same as zero - needed for normalising for RGB output.

Base.oneunit(::Type{<:RotationStruct{T1,T2}}) where {T1,T2} = RotationStruct(oneunit(T1), oneunit(T2))

And division by a scalar to normalise between 0 and 1 (limits for colors) using minval and maxval

Base.:/(rs::RotationStruct, x::Number) = RotationStruct(rs.rotationStep / x, rs.timeStep) 

And method for converting to color - rotationstep will be between 0 and 1 at this point. Edit this to suit:

DynamicGrids.to_rgb(scheme::ObjectScheme, obj::RotationStruct) = ARGB32(RGB(make it a color somehow))
# For use with ColorSchemes.jl etc - `get` needs a single `Real` number
DynamicGrids.to_rgb(scheme, obj::RotationStruct) = ARGB32(get(scheme, obj.rotationstep)) # ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rafaqz DynamicGrids.to_rgb is not avaible when doing in the instantiate of Dispersal.jl using JuliaHub release

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I messed up the registration of the new version, hopefully it will all be register in a few hours.

Copy link
Member

Choose a reason for hiding this comment

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

But you can checkout master of both DynamicGrids.jl and Dispersal.jl

test/exposure.jl Outdated
crop=Aux(:crop), rotationsize=3, rotationindex= 2,
pulselevel=20.0, popthreshold = 1000.0,degradationrate=0.5, timestep = 1
)
ruleTreatment3 = RotationExposure{Tuple{:pesticide3,:population,:rotation}, Tuple{:pesticide3,:rotation}}(
Copy link
Member

Choose a reason for hiding this comment

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

no space in type params

src/exposure.jl Outdated
# Keyword Arguments

- `crop`: Crop field. May be a `Number`, an [`Aux`](@ref) array or another [`Grid`](@ref).
Treatment is applied when `crop > zero(crop) || return zero(pesticide) `.
Copy link
Member

Choose a reason for hiding this comment

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

probably delete this bit || return zero(pesticide) and just say "when crop is above zero"

src/exposure.jl Outdated
)
Exposure by treatment depending on a threshold layer (population size) set with
`popthreshold`.
Treatment is applied only on `crop` fields (value of `crop` cell > 0).
Copy link
Member

Choose a reason for hiding this comment

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

Is crop always about crops? Or is it a more generic switch like active?

Copy link
Member

Choose a reason for hiding this comment

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

agree this may be more generic than crop (e.g. in biosecurity responses)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, ok

Abstract supertype of `CellRule` for rules of exposure dynamics
"""

abstract type Exposure{R,W} <: CellRule{R,W} end
Copy link
Member

@rafaqz rafaqz Feb 5, 2021

Choose a reason for hiding this comment

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

I'm not sure I understand this enough, but Exposure seems like it should be about insect populations being exposed and the effect of that on their population? But this is calculating the treatment application rates and decay time, in response to population. Is it really like:

abstract type Treatment end
struct ThreasholdTreatment <: Treatment end
struct RotatingTreatment <: Treatment end

and should the files be caled exposure.jl or something else?

@jamesmaino you might have some input here too

Copy link
Member

Choose a reason for hiding this comment

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

The types you have suggested might not work because the threshold concept and rotating concept are not mutually exclusive. But I would suggest rotation by default because no rotation is just a special case of rotation where the series is just (treatment1, treatment1, treatment1,...)

Copy link
Member

Choose a reason for hiding this comment

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

Ok. FYI these are just renames of the types already in this PR.

I'm also wondering if these actually just ExponentialGrowth with this rotation/threshold/rotation+threshol treatment regime as separate, very simple rules? Should the degradation be a separate rule from the means of applying the pesticide?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, very good point.
The assumption is that treatment always degradates. So we should consider the degradation rule as separate (which is the same as the exponential growth with a negative rate).

Then we would have the pulse rule which would be very simple based on theshold, And a rotation+pulsethreshold rule...

src/exposure.jl Outdated
`popthreshold`.
Treatment is applied only on `crop` fields (value of `crop` cell > 0).
The amount of treatment `pulselevel` is applied once this threshold is passed.
At every time step the pesticide is degradated at rate `degradationrate`
Copy link
Member

Choose a reason for hiding this comment

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

Should this say treatment instead of pesticide, as above?

Copy link
Member

Choose a reason for hiding this comment

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

or "chemical" as not all treatments will decay.

Copy link
Member

Choose a reason for hiding this comment

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

"not all treatments will decay" seems like decay should be in a separate rule to treatment application then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok for separating degradation rule.
I would prefere something like "exposon": a thing to which the population is exposed to... but maybe "exposure" works?
Their is the idea of "exposome" https://en.wikipedia.org/wiki/Environmental_factor#Exposome

Copy link
Member

Choose a reason for hiding this comment

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

Exposure doesn't work... exposon would be great but we can't really do that in english!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

arff ok. Science should be in a more playable language :-D (no worry, french is worst!)

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.

3 participants