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

Add exception when emergence is negative in SimpleMPD model #379

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

acavelan
Copy link
Collaborator

@acavelan acavelan commented Jan 3, 2024

When the seasonality increases too fast and when the annual EIR is low, the following quantity can become negative:

invLarvalResources[t] = (probPreadultSurvival * yt - mosqEmergeRate[t]) / (mosqEmergeRate[t] * yt);
which causes the emergence rate to be negative and crash the simulation.

This pull request does not fix the error, but the code will now throw a helpful exception and stop the simulation when this happens. This error is rare and can usually be fixed by adjusting the seasonal monthly values or the fourier coefficients and by making sure that the lowest EIR is within 1% of the peak EIR.

@acavelan acavelan changed the title add exception when emergence is negative in SimpleMPD model Add exception when emergence is negative in SimpleMPD model Jan 3, 2024
@ThomasASmith
Copy link
Collaborator

why not replace the emergence rate with zero and send a warning, without stopping the simulation

@acavelan
Copy link
Collaborator Author

acavelan commented Jan 3, 2024

@ThomasASmith This is exactly what I did initially. However setting the emergence to 0 will affect the simulation and because it is quite rare, users running thousands of scenarios will not see it unless they manually check all the logs.

By throwing an exception, the user will see that an output is missing and can decide how to handle the situation.

In most cases I would argue this error is caused by a bad or unrealistic seasonality. In addition, the Fourier transform that we use to smooth the input EIR values struggles with small values. It seems that just setting the lowest EIR values to 1% of the peak will solve all the problems.

I actually have another open pull request that will automatically set the minimum EIR to 1% of the max EIR in all scenarios but this is not always needed so it has been pending for a while. Maybe it's time to merge this one too?

Many users probably have this problem without realizing their smoothed input EIR in OpenMalaria doesn't actually match their initial monthly values.

To illustrate this, you can copy-paste the following monthly EIR values into this tool: https://swisstph.github.io/openmalaria/fourier The following values will crash the simulation when using the SimpleMPD model. You can see with the tool that the Fourier series does not match the input very well.

1.0
0.950484
0.850176
0.998646
0.592984
0.090076
0.002824
0.001974
0.019501
0.115986
0.440608
0.866085

image

However, setting the two smallest values to 0.01 or moving the decimal place solves the problem:

1.0
0.950484
0.850176
0.998646
0.592984
0.090076
0.02824
0.01974
0.019501
0.115986
0.440608
0.866085

image

Not only the smoothed EIR matches the monthly values, but the simulation no longer crashes with the SimpleMPD model.

@ThomasASmith
Copy link
Collaborator

ThomasASmith commented Jan 3, 2024 via email

Copy link
Collaborator

@nakul7 nakul7 left a comment

Choose a reason for hiding this comment

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

As discussed on call

@acavelan acavelan merged commit 505fc6c into SwissTPH:main Jan 17, 2024
7 checks passed
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