-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Exposure #87
Conversation
There was a problem hiding this 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
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) |
There was a problem hiding this comment.
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) | ||
|
There was a problem hiding this comment.
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)) # ??
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}}( |
There was a problem hiding this comment.
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) `. |
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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,...)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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!)
03494a8
to
fcfbd24
Compare
Description
Add two rules of exposure to treatment:
ThresholdExposure
: Exposure to a single treatment depending on a threshold layerRotationExposure
: Exposure by several treatments in rotation depending on a threshold layerChanges (choose one only, with x or click after creating PR):
Checklist:
For bugfixes
For new
Rule
s/test/newrulename.jl