Skip to content

Commit

Permalink
Added some startup checks for existence of settings files and useful …
Browse files Browse the repository at this point in the history
…error messages to user about what to do. The idea is to enable users to get going by trial and error. The build_template_workspace utility mentioned in the error message does not exist yet. Coming soon.
  • Loading branch information
Jonathan Bloedow committed Jun 20, 2024
1 parent 7b97db0 commit 8d71f4e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jb/src/idmlaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def main():
idmlaser - A description of your package.
Usage:
python -m idmlaser
idmlaser
This module provides the following functionality:
- Feature 1: Description of feature 1
Expand Down
5 changes: 5 additions & 0 deletions jb/src/idmlaser/measles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
sys.path.insert(0, os.getcwd())
import numpy as np

if not os.path.exists( "settings.py" ):
raise ValueError( f"You will need to provide a settings.py file. If running for first time, use: python3 -m idmlaser.utils.build_template_workspace" )
if not os.path.exists( "demographics_settings.py" ):
raise ValueError( f"You will need to provide a demographics_settings.py file. If running for first time, use: python3 -m idmlaser.utils.build_template_workspace" )

# Import a model
from . import sir_numpy_c as model

Expand Down
5 changes: 5 additions & 0 deletions jb/src/idmlaser/model_numpy/eula.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
from collections import defaultdict
import os
import settings
import demographics_settings

Expand All @@ -11,6 +12,10 @@
age_bins = np.arange(demographics_settings.eula_age, 102)
probability_of_dying = 2.74e-6 * ( makeham_parameter + np.exp(gompertz_parameter * (age_bins - age_bins[0])) )
#print( f"probability_of_dying = {probability_of_dying}" )

if not os.path.exists( demographics_settings.eula_pop_fits ):
raise ValueError( f"File not found: {demographics_settings.eula_pop_fits}. Have you run the workflow to create the input model files?" )

fits = np.load(demographics_settings.eula_pop_fits, allow_pickle=True).item()
def calculate_y(x, m, b):
return int(m * x + b)
Expand Down
3 changes: 3 additions & 0 deletions jb/src/idmlaser/sir_numpy_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def load_attraction_probs():
return data

def initialize_database():
if not os.path.exists( demographics_settings.pop_file ):
raise ValueError( f"File not found: {demographics_settings.pop_file}. Have you run the workflow to create the input model files?" )

print( f"Attempting to load {demographics_settings.pop_file} from {os.getcwd()}." )
return load( demographics_settings.pop_file )

Expand Down

0 comments on commit 8d71f4e

Please sign in to comment.