Skip to content

Commit

Permalink
1) Added tool to generate synthetic suitability data. 2) Added code t…
Browse files Browse the repository at this point in the history
…o load and use that data. 3) Added code to run script to generate code if not found. 4) Added manifest.py file to be central store of paths to input and output datafiles.
  • Loading branch information
Jonathan Bloedow committed Sep 21, 2024
1 parent 59a804c commit ed93d2e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include idmlaser_cholera/USA-pyramid-2023.csv
include src/idmlaser_cholera/mods/libtx.so
include src/idmlaser_cholera/mods/libages.so
include src/idmlaser_cholera/tools/make_suitability_random_data.py

16 changes: 12 additions & 4 deletions src/idmlaser_cholera/cholera.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
from datetime import datetime
from tqdm import tqdm
from . import manifest

# Very simple!
class Model:
Expand Down Expand Up @@ -119,11 +120,18 @@ def save_pops_in_nodes( model, nn_nodes, initial_populations):
model.nodes.add_vector_property("network", model.nodes.count, dtype=np.float32)
# The climatically driven environmental suitability of V. cholerae by node and time
model.nodes.add_vector_property("psi", model.params.ticks, dtype=np.float32)
model.nodes.psi[:] = 0.001 # placeholder, probably load from csv
#model.nodes.psi[:] = 0.001 # placeholder, probably load from csv
def init_psi_from_data():
suitability_filename = "suitability_data_random_419_5yr.csv"
suitability_filename = manifest.psi_data
import pandas as pd
data = pd.read_csv(suitability_filename)
try:
data = pd.read_csv(suitability_filename)
except Exception as ex:
print( str( ex ) )
print( "Running 'python -m idmlaser_cholera.tools.make_synthetic_suitability_data' and continuing." )
import idmlaser_cholera.tools.make_suitability_random_data
data = pd.read_csv(suitability_filename)


# Convert the DataFrame into a NumPy array
suitability_data = data.values
Expand All @@ -133,7 +141,7 @@ def init_psi_from_data():

# Assign the data to the "psi" vector in the model
model.nodes.psi[:] = suitability_data
#init_psi_from_data()
init_psi_from_data()
# theta: The proportion of the population that have adequate Water, Sanitation and Hygiene (WASH).
model.nodes.add_scalar_property("WASH_fraction", dtype=np.float32) # leave at 0 for now, not used yet

Expand Down
1 change: 1 addition & 0 deletions src/idmlaser_cholera/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
psi_data="synthetic_psi_data.csv"
Empty file.
34 changes: 34 additions & 0 deletions src/idmlaser_cholera/tools/make_suitability_random_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import numpy as np
import pandas as pd

# Define the dimensions of the CSV
rows = 419 # Number of nodes
columns = 365 * 5 # Time steps (5 years with 365 steps per year)

# Generate random amplitude (between 0.1 and 0.9) for each row
amplitudes = np.random.uniform(0.1, 0.9, size=(rows, 1))

# Generate random phase offsets (between 0 and 2*pi for a full cycle) for each row
phase_offsets = np.random.uniform(0, 2 * np.pi, size=(rows, 1))

# Create a time vector representing the time steps for the sin wave (columns represent days)
time_vector = np.arange(columns)

# Generate sinusoidal data for each row
# Formula: value = amplitude * sin(2 * pi * time / period + phase) + 0.5 (to shift range to 0 to 1)
sin_data = amplitudes * np.sin(2 * np.pi * time_vector / 365 + phase_offsets) + 0.5

# Clip the data to ensure it stays between 0 and 1
sin_data_clipped = np.clip(sin_data, 0, 1)

# Create a DataFrame from the sinusoidal values
df = pd.DataFrame(sin_data_clipped)

# Define the filename for the CSV
csv_filename = "synthetic_psi_data.csv"

# Save the DataFrame to a CSV file
df.to_csv(csv_filename, index=False)

csv_filename

0 comments on commit ed93d2e

Please sign in to comment.