helper.py
as_list(x)
Converts the input x to a list if it is not already a list.
Source code in utility\helper.py
485 486 487 488 489 |
|
check_exp_inputs(exp, attribute_check=False)
Helper function to validate experiment inputs.
Parameters: |
|
---|
Raises: |
|
---|
Source code in utility\helper.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
configure_calib_scenarios(exp)
Configures experiment-specific attributes based on the run mode.
Source code in utility\helper.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
create_scenarios_csv(exp, col_list)
Generate a scenarios DataFrame based on the provided experiment object and column list.
This function constructs a DataFrame of all possible combinations of attributes specified
in col_list
and maps additional experiment-specific parameters, including entomology mode,
number of seeds, and calibration target inputs. It also processes specific interventions
such as cc_step
if present.
Parameters: |
|
---|
Returns: |
|
---|
Source code in utility\helper.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
|
create_simsetup_csv(exp)
Creates a CSV file containing simulation setup parameters. Args: exp (Experiment): Experiment object containing experiment specifications.
Source code in utility\helper.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
exec(command)
Executes the specified command in a subprocess.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Notes
- This function runs the command in a new shell and captures both standard output and standard error.
- The output can be accessed through the Popen object returned by this function.
Source code in utility\helper_slurm.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
get_intervention_params(exp)
Retrieve intervention parameters for a specific experiment.
Parameters: - exp: Experiment object.
Returns: Intervention parameters based on the specified experiment.
Source code in utility\helper_simulation.py
16 17 18 19 20 21 22 23 24 25 26 27 |
|
get_param_from_dataframe(df, name)
Retrieves a parameter value from a DataFrame and returns it in the correct format for storage in an experiment object (exp).
Example
exp.seasonality = get_param(exp_scen_df, ‘seasonality’, listparam=True)
Parameters: |
|
---|
Returns: |
|
---|
Source code in utility\helper.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
get_seasonal_eir(exp=None)
Generates seasonal EIR (Entomological Inoculation Rate) values.
Examples:
season_daily, season_month, seasonal, perennial = get_seasonal_eir() exp = get_seasonal_eir(exp)
Parameters: |
|
---|
Returns: |
|
---|
Source code in utility\helper_simulation.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
get_simulation_time_params(exp)
Calculates simulation time parameters for EMOD, malariasimulation and OpenMalaria based on the provided arguments.
Parameters: |
|
---|
Returns: |
|
---|
Source code in utility\helper_simulation.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
make_dirs(exp, overwrite=False)
Creates necessary directories for a simulation experiment.
Args: exp (Experiment): The experiment object containing project directory information. overwrite (bool, optional): If True, existing directories will be overwritten. Defaults to False.
Returns: exp (Experiment): The experiment object with updated directory paths.
Source code in utility\helper.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
map_model_calib_inputs(exp, df)
Maps model inputs based on output targets.
Parameters: |
|
---|
Returns: pandas.DataFrame: Updated DataFrame.
Source code in utility\helper.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
|
monthly_to_daily_EIR(monthly_EIR)
Convert monthly EIR values to daily using cubic spline interpolation.
Parameters: |
|
---|
Returns: |
|
---|
Source code in utility\helper_simulation.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
param_variation(df, exp)
Perform parameter variation for malariasimulation simulations.
Parameters: - df: DataFrame containing data from scenarios.csv. - exp: Experiment object.
Returns: DataFrame with added column ‘malariasimulation_pv’ representing malariasimulation parameter variation values.
Source code in utility\helper_simulation.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
parse_args()
Parses command-line arguments for simulation specifications.
Returns: argparse.Namespace: Parsed command-line arguments.
Source code in utility\helper.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
process_case_management(df)
Processes and splits the case management column.
Handles cases where case_management
contains either a list of two values
or a single value in a list.
Parameters: |
|
---|
Returns: |
|
---|
Source code in utility\helper.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
rep_scen_df(df)
Repeats scenario data in a DataFrame based on the number of seeds.
Parameters: |
|
---|
Returns: |
|
---|
Source code in utility\helper.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
save_exp_scen(exp, scen_df, save_dirs)
Saves the experiment and scenario data to the specified save directories. Args: exp (Experiment): Experiment object containing experiment specifications. scen_df (pandas.DataFrame): The scenario data to be saved. save_dirs (list): List of directories to save the data.
Source code in utility\helper.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
save_scen(scen_df, fname, save_dirs=None)
Saves a scenario DataFrame to a CSV file in the specified directories. Args: scen_df (pandas.DataFrame): The DataFrame containing the scenario data. fname (str): The name of the CSV file to be saved. save_dirs (list of str, optional): List of directories to save the CSV file. Defaults to None.
Source code in utility\helper.py
266 267 268 269 270 271 272 273 274 275 |
|
shell_header_quest(sh_account, time_str='6:00:00', memG=3, job_name='myjob', arrayJob=None, mem_scl=1)
Generates the SLURM shell script header for submitting jobs to a high-performance computing cluster.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Notes
- The function checks if the ‘log’ directory exists and creates it if it does not.
- The partition is selected based on the job time limit if the account is not a buy-in account.
- The generated header includes job error and output log file paths based on whether the job is an array job or a single job.
Source code in utility\helper_slurm.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
str_to_digit(x)
Converts a string to a float if possible, otherwise returns the original string. Args: x (str): The input string. Returns: float or str: The converted float if conversion is successful, otherwise the original string.
Source code in utility\helper.py
506 507 508 509 510 511 512 513 514 515 516 517 518 |
|
submit_run_plotters(exp)
Submits and manages the creation of shell scripts to run standardized plots based on the models specified in the experiment.
Parameters: |
|
---|
Returns: |
|
---|
Notes
- The function checks which models (EMOD, malariasimulation, OpenMalaria) are
specified in
exp.models_to_run
and sets corresponding job IDs. - It prepares a submission script for a set of default plots (
relationship
,timeseries
,agecurves
) and also handles custom plots if specified inexp.plots_to_run
. - Memory requirements for each plot are defined and passed to the submission
script. The default is 20 GB, but this can be adjusted based on specific
plot needs (e.g.,
ccstep
requires 80 GB). - If
exp.plots_to_run
is set to'all'
, all available plots will be processed.
Source code in utility\helper_slurm.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
submit_run_pyscript(exp, pyscript='plotter/plot_relationship.py', shname='run_relationship_plots.sh', custom_args='--modelname EMOD malariasimulation OpenMalaria', t='05:00:00', memG=20, job_id_EMOD=False, job_id_malariasimulation=False, job_id_OpenMalaria=False, job='pyjob', wdir=None, write_only=False)
Submits a job to run a specified Python script using SLURM.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Notes
- The function generates a shell script that includes the SLURM header and the command to run the specified Python script.
- It handles job dependencies based on the provided job IDs for EMOD, malariasimulation, and OpenMalaria.
- The script is written to the job directory and submitted to the SLURM workload manager.
- The submitted job ID is printed to the console for tracking purposes.
Source code in utility\helper_slurm.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
write_txt(txtobj, path, fname)
Writes a text object to a file. Args: txtobj (str): The text object to write. path (str): The path to the directory where the file will be saved. fname (str): The filename to use for the file.
Source code in utility\helper.py
492 493 494 495 496 497 498 499 500 501 502 503 |
|