Skip to content

Commit

Permalink
Merge branch 'main' into feat/qualitative
Browse files Browse the repository at this point in the history
  • Loading branch information
fivegrant authored Aug 30, 2023
2 parents 027f22d + 6ae2382 commit 54e32af
Show file tree
Hide file tree
Showing 8 changed files with 7,745 additions and 15 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ Set environment variable `MOCK_TA1` to `False` and adding the correct endpoints
To add additional scenarios, create a new directory in `tests/scenarios`. The directory must contain a `config.yaml` where each tests you wish to be run
will be specified in `enabled`.

The `.env` will be used to specify the `MOCK_TA1` setting as well as the appropriate endpoints and can be passed into the test suite with:
```
poetry shell && export $(cat .env | xargs) && pytest -s
```

Run `poetry run poe report`, to generate `tests/output/report.json` which contains the status of each scenario and operation.


## License

[Apache License 2.0](LICENSE)
5 changes: 0 additions & 5 deletions tests/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
pdf_extraction:
- text.json
- paper.pdf
- extractions.json
pdf_to_text:
- text.json
- paper.pdf
code_to_amr:
- code.py
- amr.json
equations_to_amr:
- equations.txt
- amr.json
profile_dataset:
- text.json
- paper.pdf
- data.csv
- data_card.json
profile_model:
- text.json
- paper.pdf
Expand Down
76 changes: 76 additions & 0 deletions tests/scenarios/sidarthe/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from scipy.integrate import odeint
import numpy as np
import pandas as pd
import plotly.express as px
import matplotlib.pyplot as plt

def SIDARTHE_model(y, t, alpha, beta, gamma, delta, epsilon, mu, zeta, lamb, eta, rho, theta, kappa, nu, xi, sigma, tau):
S, I, D, A, R, T, H, E = y
dSdt = -S*(alpha(t)*I + beta(t)*D + gamma(t)*A + delta(t)*R)
dIdt = S*(alpha(t)*I + gamma(t)*D + beta(t)*A + delta(t)*R) - (zeta(t) + lamb(t))*I
dDdt = epsilon(t)/3*I - (eta(t))*D
dAdt = zeta(t)*I - (theta(t) + mu(t) + kappa(t))*A
dRdt = eta(t)*D + theta(t)*A - (nu(t) + xi(t))*R
dTdt = mu(t)*A + nu(t)*R - sigma(t)*T + tau(t)*T
dHdt = lamb(t)*I + sigma(t)*D + xi(t)*R + kappa(t)*T
dEdt = -tau(t)*T

return dSdt, dIdt, dDdt, dAdt, dRdt, dTdt, dHdt, dEdt

# Example Simulation and Plot

def alpha(t): return np.piecewise(t, [t>=0], [0.75])
def beta(t): return np.piecewise(t, [t>=0], [0.1])
def delta(t): return np.piecewise(t, [t>=0], [0.05])
def gamma(t): return np.piecewise(t, [t>=0], [0.2])

def epsilon(t): return np.piecewise(t, [t>=0], [0.1])
def theta(t): return np.piecewise(t, [t>=0], [0.1])

def zeta(t): return np.piecewise(t, [t>=0], [0.05])
def eta(t): return np.piecewise(t, [t>=0], [0.05])

def mu(t): return np.piecewise(t, [t>=0], [0.05])
def nu(t): return np.piecewise(t, [t>=0], [0.05])
def lamb(t): return np.piecewise(t, [t>=0], [0.05])
def rho(t): return np.piecewise(t, [t>=0], [0.05])

def kappa(t): return np.piecewise(t, [t>=0], [0.01])
def xi(t): return np.piecewise(t, [t>=0], [0.01])
def sigma(t): return np.piecewise(t, [t>=0], [0.01])

def tau(t): return np.piecewise(t, [t>=0], [0.05])

N0 = 1e6
I0, D0, A0, R0, T0, H0, E0 = 50/N0, 50/N0, 5/N0, 1/N0, 0, 0, 0
S0 = 1-I0-D0-A0-R0-T0-H0-E0
y0 = S0, I0, D0, A0, R0, T0, H0, E0 # Initial conditions vector

dt = 2
tstart = 0
tend = 40
tvect = np.arange(tstart, tend, dt)

sim = odeint(SIDARTHE_model, y0, tvect, args=(alpha, beta, gamma, delta, epsilon, mu, zeta, lamb, eta, rho, theta, kappa, nu, xi, sigma, tau))
S, I, D, A, R, T, H, E = sim.T

f, ax = plt.subplots(1,1,figsize=(10,4))
ax.plot(tvect, S, 'b', alpha=0.7, linewidth=2, label='Susceptible')
ax.plot(tvect, I, 'r', alpha=0.7, linewidth=2, label='Infected (Asymptomatic, Infected, Undetected)')
ax.plot(tvect, D, 'r.', alpha=0.7, linewidth=2, label='Diagnosed (Asymptomatic, Infected, Detected)')
ax.plot(tvect, A, 'r:', alpha=0.7, linewidth=2, label='Ailing (Symptomatic, Infected, Undetected)')
ax.plot(tvect, R, 'r--', alpha=0.7, linewidth=2, label='Recognized (Symptomatic, Infected, Detected)')
ax.plot(tvect, T, 'r-.', alpha=0.7, linewidth=2, label='Threatened (Acutely Symptomatic)')
ax.plot(tvect, H, 'g', alpha=0.7, linewidth=2, label='Healed')
ax.plot(tvect, E, 'k', alpha=0.7, linewidth=2, label='Extinct (Dead)')

ax.set_xlabel('Time (days)')
ax.set_ylabel('Fraction of population')

ax.yaxis.set_tick_params(length=0)
ax.xaxis.set_tick_params(length=0)
ax.grid(b=True, which='major', c='w', lw=2, ls='-')
legend = ax.legend()
legend.get_frame().set_alpha(0.5)

plt.show();
7 changes: 7 additions & 0 deletions tests/scenarios/sidarthe/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: "SIDARTHE"
description: "Scenario to process SIDARTHE paper and code"
enabled:
- pdf_extraction
- pdf_to_text
- code_to_amr
Binary file added tests/scenarios/sidarthe/paper.pdf
Binary file not shown.
Loading

0 comments on commit 54e32af

Please sign in to comment.