pygcam.mcs.gcamdata¶
The gcamdata module allows the GCAM data system to be run for each Monte
Carlo trial to generate XML files that correspond to some stochastic alteration
to data system input (CSV) files. See Running the GCAM data system for more information.
API¶
- class pygcam.mcs.gcamdata.GcamDataSystem(mapper: SimFileMapper, renv_dir=None, xml_modifier=None)¶
Class to run the GCAM data system within a Monte Carlo simulation
- activate_renv()¶
Activate the “renv” at directory
self.renv_dir.- Returns
none
- load_gcamdata()¶
Call devtools::load_all(self.ref_gcamdata_dir).
- Returns
none
- move_modified_xml_files(src_dir, dst_dir)¶
Move modified XML files from the temporary source directory
src_dirto the destination directorydst_dir.- Parameters
src_dir – (str) the source directory
dst_dir – (str) the destination directory
- Returns
(list of str) the paths to the modified XML files in the destination directory
- run_data_system(trials, user_modifications, delete=True)¶
Run the GCAM data system using “driver_drake” to generate XML files with
user_modifications.- Parameters
trials – (“PATH” or a comma-delimited list of ints or hyphen-separated numbers indicating the trials to run. (Example: “1,4,7-11,2,21-50”)
user_modifications – (str or list of str) names of “user modification” R functions to insert into the GCAM data system for use with drake. If None, just run the data system in the reference workspace, without any modifications to create the baesline.
delete – (bool) whether to delete the temporary directory in which the data system is run. Can be helpful to set to False for debugging.
- Returns
none
- run_drake(gcamdata_dir)¶
Run the gcamdata (R) function “driver_drake” in the given workspace. This is used to create the baseline drake information before running it with user modifications, and thus before copying the reference workspace to temporary trial sandboxes.
- Parameters
gcamdata_dir – (str) the pathname of the gcamdata dir in which to run “driver_drake”.
- Returns
none
- run_drake_with_mods(func_names)¶
Run the gcamdata (R) function “driver_drake”, passing in the user modification functions in
func_names- Parameters
func_names – (str or list(str)) the function name or list of function names to pass as the “user_modifications” to “driver_drake”.
- Returns
none
- trial_func(trial_num)¶
A function to call for each Monte Carlo trial. Does nothing in
GcamDataSystem; subclass can define this if needed.- Parameters
trial_num – (int) the trial being run
- Returns
none
- trial_sandbox(trial_num, delete=True)¶
Return the path to a temporary sandbox directory in which to build dependent XML files. A cache of these is maintained so on subsequent calls with the same
trial_num, the cached path is returned and no other action is taken.- Parameters
trial_num – (int) the number of the trial being run
delete – (bool) whether to delete the temporary directory created by this function at program exit.
- Returns
(str) the trial’s sandbox dir
- update_scenario_config(rel_dir: Path, abs_paths)¶
Update the configuration XML file for the
simIdandscenariofound in the savedmapper, substituting the path to the modified XML for the file ending with the same basename. This assumes basenames within the config file are unique.- Parameters
rel_dir – (Path) the directory that holds the modified XML files, relative to the “exe” directory for the given scenario, suitable for insertion into the configuration XML file.)
abs_paths – (list of Path) the absolute paths of the modified XML files.
- Returns
none
- pygcam.mcs.gcamdata.load_R_code(code_str)¶
Loads a string containing R code into the R interpreter running within Python.
- Parameters
code_str – (str) R code string
- Returns
none