SARA
- class drama.sara.Model(objectxml)
class for storing all the objects in the sara model
- class drama.sara.ModelObject(obj)
class for single object of the sara model
- build_obj()
update the element with the new setting, in case changes have been made
- class drama.sara.Inclusion(obj)
class for inclusion elements of the sara model
- build_in()
update the inclusion with the new setting, in case changes have been made
- class drama.sara.Connection(obj)
class for connection of the sara model
- build_in()
update the connection with the new setting, in case changes have been made
- drama.sara.get_model(framework='DRAMA', project=None)
Returns the base model read from the provided project or the default if no project is specified.
- Parameters:
framework (str) – defines whether DRAMA or DMF is using the wrapper
project (str) – Path to DRAMA project to use as baseline (directory or exported project). If
None
the default project is used.
- Returns:
The config dict as specified in parameter
config
inrun()
.
- drama.sara.get_basic_config(framework='DRAMA', project=None)
Returns the base config read from the provided project or the default if no project is specified.
- Parameters:
framework (str) – defines whether DRAMA or DMF is using the wrapper
project (str) – Path to DRAMA project to use as baseline (directory or exported project). If
None
the default project is used.
- Returns:
The config dict as specified in parameter
config
inrun()
.
- drama.sara.run_lazy(config=None, dependent_variables=[], project=None, fap_day_content=None, fap_mon_content=None, save_output_dirs=None, parallel=True, ncpus=None, model=None, timeout=None, logging_queue=None, log_level='DEBUG', log_group_id=None, framework='DRAMA', keep_output_files='summary', spell_check=True, create_fig=False, **kwargs)
Runs (parametric) SARA analysis and returns a dictionary with config and iterable results.
- Parameters:
config (dict or list) –
The (parametric) SARA run configuration. If a dictionary is provided it must be of the following format (lists are used for parametric analyses):
{ "runID": str or list, "comment1": str or list, "comment2": str or list, "beginDate": datetime or list, "runMode": str or list, "monteCarlo": bool or list, "reentryType": str or list, "uncontrolledMethod": str or list, "growthScenario": str or list, "casualtyThreshold": float or list, "inclinationAngle": float or list, "dataPath": str or Path or list, "coordinateSystem": str or list, "initialDate": datetime or list, "element1": float or list, "element2": float or list, "element3": float or list, "element4": float or list, "element5": float or list, "element6": float or list, "assumedCrossSection": float or list, "dragCoefficient": float or list, "reflectivityCoefficient": float or list, "attitude": str or list, "attack": float or list, "sideSlip": float or list, "bank": float or list, "fragmentsAttitudeAfterBreakup": str or list, "globalSpacecraftTemperature": float or list, "atmosphericModel": str or Path or list, "voxelatorMode": int or list, "voxelatorResolutionLength": float or list, "densityScalingFactor": float or list, "dynamicEnvironment": bool or list, "useWind": bool or list, "solarActivityFromFile": bool or list, "ap": float or list, "f107a": float or list, "useEnvironmentCSV": bool or list, "energyThreshold": float or list, "plotVisibilityMaps": bool or list, "plotObjectTrajectories": bool or list, "propagationWithOscar": bool or list, }
Alternatively,
config
can also be a list of config dictionaries, or any iterable. Each config dictionary in this case describes one run and thus can not contain any list to expand.dependent_variables (list of lists of strs) – Describe which parameters depend on each other in a parametric analysis. Each list of parameters defines one dependency. See the example below for details.
project (str) – Path to DRAMA project to use as baseline (directory or exported project). If
None
the default project is used.fap_day_content (list) – Array of lines from fap_day.dat, available at https://static.sdo.esoc.esa.int/SOLMAG/
fap_mon_content (list) – Array of lines from fap_mon.dat
save_output_dirs – Save the output directories of all runs to this directory. Each run will have its own numbered directory. The path to it is stored in
output_dir
in each run’s config. IfNone
the output directories will be deleted.parallel (bool) – Define if simulations shall be run in parallel.
ncpus (int) – Number of CPUs to use if parallel is True. If not specified, the maximum available will be used.
timeout (int) – Timeout in seconds for each run.
logging_queue (manager.Queue) – Thread safe queue, which aggregates log messages for the caller.
log_level (str) – The log level for the logger, can be DEBUG, INFO, WARNING, ERROR and CRITICAL.
log_group_id (str) – Additional argument that is added to a log record.
framework (str) – Define whether DRAMA or DMF is using the wrapper.
keep_output_files (str or list) – If list, it contains the filenames of the output files that will be saved into the output_dir (shared list for reentry and risk analysis). If ‘all’ the whole output folder will be saved into the output_dir, if ‘summary’ (Default), only a default list of output files will be saved into the output_dir (valid only if output_dir is provided as input parameter).
spell_check (bool) – Specify if the case to run should contain only keywords that are present in the configuration file.
create_fig (bool) – if True, generates the png files into the output_dir.
**kwargs – If
config
isNone
, the SARA run configuration values can be passed on as kwargs.
- Returns:
{ 'config': provided config of all runs, 'results': <generator object generic_run_lazy>, }
Examples
Direct call with one run:
from drama import sara results_lazy = sara.run_lazy(element1=6878, element2=0.001, element3=98, initialDate=datetime(2024, 3, 27, 00, 00, 00))
Multiple parametric runs passing a configuration dictionary (four runs with all possible combinations):
from drama import sara config = { 'element1': [6378 + 480, 6378 + 500], 'element2': [0.001, 0.005], 'element3': 98, 'initialDate': datetime(2024, 3, 27, 00, 00, 00), } results_lazy = sara.run_lazy(config) #store the total casualty risk of each single run: total_casualty_risks=[] for res in results_lazy['results']: for single_run_res in res: total_casualty_risks.append(single_run_res['total_casualty_risk'])
Two runs with dependent variables (
element1 = 6858, element2 = 0.001
andelement1 = 6878, element2 = 0.005
):from drama import sara config = { 'element1': [6378 + 480, 6378 + 500], 'element2': [0.001, 0.005], } dependent_variables = [['element1', 'element2']] results_lazy = sara.run_lazy(config, dependent_variables)
Single run with modified model
from drama import sara #load default model: mymodel = sara.get_model() #or load model from a project: mymodel = sara.get_model(project='path-to-the-project') #list the elements, connections and inclusions of the model: mymodel.ls() #select one element for el in mymodel.el: #using ID: if el.ID =='desired-ID': #or using the name: if el.name=='desired-name' #modify the element: el.mass = value #mass of the element [kg] el.h = value #height of the element [m], only for box and cylinder el.w = value #width of the element [m], only for box el.l = value #lenght of the element [m], only for box el.r = value #radius of the element [m], only for sphere and cylinder el.hf = value #average heat flux aerodynamic scaling factor for the element [-] el.drag = value #drag aerodynamic scaling factor for the element [-] el.lift = value #lift aerodynamic scaling factor for the element [-] el.sf = value #side force aerodynamic scaling factor for the element [-] #custom delta velocity: el.dv_m = value #magnetude [km/sec] el.dv_fp = value #Flight Path Angle [deg] el.dv_ha = value #Heading Angle [deg] #select one inclusion for inc in mymodel.inc: #select the inclusion which using the ID of the parent element: if inc.ID =='desired-ID': #or select the inclusion which contains the ID of a children element: if 'desired-ID' in inc.ch: #or select the inclusion searching parent and childrens IDs: if 'desired-ID' in inc.all: #modify the inclusion: inc.h = value #break up altitude of the compound [m] (if it exists in the sara.xml) #select one connection (modify the break up altitude/temperature/dynamic pressure or heat flux): for cn in mymodel.cn: #select the connection which contains the ID of a parent element: if cn.ID =='desired-ID': cn.area = value #break up connection area [m^2] cn.h = value #break up altitude of the connection [m] cn.t = value #break up temperature of the connection [K] cn.p = value #break up dynamic pressure of the connection [Pa] cn.hf = value #break up heat flux of the connection [W/m^2] results_lazy = sara.run_lazy(model=mymodel) #print the status of each single run: for res in results_lazy['results']: for single_run_res in res: print(single_run_res['status'])
- drama.sara.run(config=None, dependent_variables=[], json=None, project=None, fap_day_content=None, fap_mon_content=None, save_output_dirs=None, parallel=True, ncpus=None, model=None, timeout=None, logging_queue=None, log_level='DEBUG', log_group_id=None, framework='DRAMA', keep_output_files='summary', tmprun_path=None, spell_check=True, create_fig=False, **kwargs)
Runs (parametric) SARA analysis and return the results.
- Parameters:
config (dict or list) –
The (parametric) SARA run configuration. If a dictionary is provided it must be of the following format (lists are used for parametric analyses):
{ "runID": str or list, "comment1": str or list, "comment2": str or list, "beginDate": datetime or list, "runMode": str or list, "monteCarlo": bool or list, "reentryType": str or list, "uncontrolledMethod": str or list, "growthScenario": str or list, "casualtyThreshold": float or list, "inclinationAngle": float or list, "dataPath": str or Path or list, "coordinateSystem": str or list, "initialDate": datetime or list, "element1": float or list, "element2": float or list, "element3": float or list, "element4": float or list, "element5": float or list, "element6": float or list, "assumedCrossSection": float or list, "dragCoefficient": float or list, "reflectivityCoefficient": float or list, "attitude": str or list, "attack": float or list, "sideSlip": float or list, "bank": float or list, "fragmentsAttitudeAfterBreakup": str or list, "globalSpacecraftTemperature": float or list, "atmosphericModel": str or Path or list, "voxelatorMode": int or list, "voxelatorResolutionLength": float or list, "densityScalingFactor": float or list, "dynamicEnvironment": bool or list, "useWind": bool or list, "solarActivityFromFile": bool or list, "ap": float or list, "f107a": float or list, "useEnvironmentCSV": bool or list, "energyThreshold": float or list, "plotVisibilityMaps": bool or list, "plotObjectTrajectories": bool or list, "propagationWithOscar": bool or list, }
Alternatively,
config
can also be a list of config dictionaries, or any iterable. Each config dictionary in this case describes one run and thus can not contain any list to expand.dependent_variables (list of lists of strs) – Describe which parameters depend on each other in a parametric analysis. Each list of parameters defines one dependency. See the example below for details.
json (dict) – Python object holding the resemblance of the JSON file containing all required fields needed for a run. It should conform with the sara_input.schema.json.
project (str) – Path to DRAMA project to use as baseline (directory or exported project). If
None
the default project is used.fap_day_content (list) – Holds an array of fap_day lines
fap_mon_content (list) – Holds an array of fap_mon lines
save_output_dirs – Save the output directories of all runs to this directory. Each run will have its own numbered directory. The path to it is stored in
output_dir
in each run’s config. IfNone
the output directories will be deleted.parallel (bool) – Define if simulations shall be run in parallel.
ncpus (int) – Number of CPUs to use if parallel is True. If not specified, the maximum available will be used.
timeout (int) – Timeout in seconds for each run.
logging_queue (manager.Queue) – thread safe queue, which aggregates log messages for the caller.
log_level (str) – the log level for the logger, can be DEBUG, INFO, WARNING, ERROR and CRITICAL.
log_group_id (str) – additional argument that is added to a log record.
framework (str) – defines whether DRAMA or DMF is using the wrapper.
keep_output_files (str or list) – If list, it contains the filenames of the output files that will be saved into the output_dir (shared list for reentry and risk analysis). If ‘all’ the whole output folder will be saved into the output_dir, if ‘summary’ (Default), only a default list of output files will be saved into the output_dir (valid only if output_dir is provided as input parameter).
tmprun_path (ValueProxy) – hands back the path to the temporary working directroy used by the analysis module so that it can be accessed from the outside, e.g. to parse the tmp files, which can be checked continuously in a separate thread.
spell_check (bool) – Specify if the case to run should contain only keywords that are present in the configuration file
create_fig (bool) – if True, generates the png files into the output_dir.
**kwargs – If
config
isNone
, the SARA run configuration values can be passed on as kwargs.
- Returns:
{ 'config': provided config of all runs, 'errors': [ # info on erroneous runs { 'config': {}, # config of single erroneous run, 'status': 'error <details>', 'reentry_output': stdout and stderr of reentry process, 'risk_output': stdout and stderr of risk process, 'reentry_logfile': reentry logfile content, 'risk_logfile': risk logfile content, }, ... ], 'results': [ { 'config': {}, # config of single successful run, 'status': 'success', 'reentry_output': stdout and stderr of reentry process, 'risk_output': stdout and stderr of risk process, 'reentry_logfile': reentry logfile content, 'risk_logfile': risk logfile content, 'total_casualty_x_section': total casualty for the x section, 'total_casualty_risk': total casualty risk, 'total_casualty_risk2D': total casualty risk 2D, }, ... ], }
Examples
Direct call with one run:
from drama import sara results = sara.run(element1=6878, element2=0.001, element3=98, initialDate=datetime(2024, 3, 27, 00, 00, 00))
Multiple parametric runs passing a configuration dictionary (four runs with all possible combinations):
from drama import sara config = { 'element1': [6378 + 480, 6378 + 500], 'element2': [0.001, 0.005], 'element3': 98, 'initialDate': datetime(2019, 5, 10, 00, 00, 00), } results = sara.run(config)
Two runs with dependent variables (
element1 = 6858, element2 = 0.001
andelement1 = 6878, element2 = 0.005
):from drama import sara config = { 'element1': [6378 + 480, 6378 + 500], 'element2': [0.001, 0.005], } dependent_variables = [['element1', 'element2']] results = sara.run(config, dependent_variables)
Single run with modified model
from drama import sara #load default model: mymodel = sara.get_model() #or load model from a project: mymodel = sara.get_model(project='path-to-the-project') #list the elements, connections and inclusions of the model: mymodel.ls() #select one element for el in mymodel.el: #using ID: if el.ID =='desired-ID': #or using the name: if el.name=='desired-name' #modify the element: el.mass = 10 #mass of the element [kg] el.h = 3 #height of the element [m], only for box and cylinder el.w = 5 #width of the element [m], only for box el.l = 2 #lenght of the element [m], only for box el.r = 4 #radius of the element [m], only for sphere and cylinder el.hf = value #average heat flux aerodynamic scaling factor for the element [-] el.drag = value #drag aerodynamic scaling factor for the element [-] el.lift = value #lift aerodynamic scaling factor for the element [-] el.sf = value #side force aerodynamic scaling factor for the element [-] #custom delta velocity: el.dv_m = value #magnetude [km/sec] el.dv_fp = value #Flight Path Angle [deg] el.dv_ha = value #Heading Angle [deg] #select one inclusion for inc in mymodel.inc: #select the inclusion which using the ID of the parent element: if inc.ID =='desired-ID': #or select the inclusion which contains the ID of a children element: if 'desired-ID' in inc.ch: #or select the inclusion searching parent and childrens IDs: if 'desired-ID' in inc.all: #modify the inclusion: inc.h = value #break up altitude of the compound [m] (if it exists in the sara.xml) #select one connection (modify the break up altitude/temperature/dynamic pressure or heat flux): for cn in mymodel.cn: #select the connection which contains the ID of a parent element: if cn.ID =='desired-ID': cn.area = value #break up connection area [m^2] cn.h = value #break up altitude of the connection [m] cn.t = value #break up temperature of the connection [K] cn.p = value #break up dynamic pressure of the connection [Pa] cn.hf = value #break up heat flux of the connection [W/m^2] results = sara.run(model=mymodel)
- drama.sara.run_monte_carlo_lazy(config=None, n=10000, project=None, parallel=True, ncpus=None, timeout=None, model=None, keep_output_files='summary', spell_check=True, create_fig=False, framework='DRAMA', **kwargs)
Lazy version of the SARA Monte Carlo runner.
- Parameters:
config (dict) – The config as specified in parameter
config
inrun()
, containing at least onemonte_carlo.Distribution
.n (int) – The number of runs.
project (str) – Path to DRAMA project to use as baseline (directory or exported project). If
None
the default project is used.parallel (bool) – Define if simulations shall be run in parallel.
ncpus (int) – Number of CPUs to use if parallel is True. If not specified, the maximum available will be used.
timeout (int) – Timeout in seconds for each run.
model (SaraObj) – sara model, could be explicity provided and used insted of the default model
keep_output_files (str or list) – If list, it contains the filenames of the output files that will be saved into the output_dir (shared list for reentry and risk analysis). If ‘all’ the whole output folder will be saved into the output_dir, if ‘summary’ (Default), only a default list of output files will be saved into the output_dir (valid only if output_dir is provided as input parameter).
spell_check (bool) – Specify if the case to run should contain only keywords that are present in the configuration file
create_fig (bool) – if True, generates the png files into the output_dir.
framework (str) – defines whether DRAMA or DMF is using the wrapper
**kwargs – If
config
isNone
, the SARA run configuration values can be passed on as kwargs.
- Returns:
{ 'config': provided config of all runs, 'results': <iterable>, 'stopping reason', }
The stopping reason should be always
n_max reached
.
Example
from drama import sara from drama.monte_carlo import Gaussian config = {'el1': Gaussian(mu=6700, sigma=2.5)} results_lazy = sara.run_monte_carlo_lazy(config) #print the status of each single run: for res in results_lazy['results']: for single_run_res in res: print(single_run_res['status'])
- drama.sara.run_monte_carlo(config=None, n=10000, project=None, parallel=True, ncpus=None, timeout=None, model=None, keep_output_files='summary', spell_check=True, create_fig=False, framework='DRAMA', **kwargs)
SARA Monte Carlo runner.
- Parameters:
config (dict) – The config as specified in parameter
config
inrun()
, containing at least onemonte_carlo.Distribution
.n (int) – The number of runs.
project (str) – Path to DRAMA project to use as baseline (directory or exported project). If
None
the default project is used.parallel (bool) – Define if simulations shall be run in parallel.
ncpus (int) – Number of CPUs to use if parallel is True. If not specified, the maximum available will be used.
timeout (int) – Timeout in seconds for each run.
model (SaraObj) – sara model, could be explicity provided and used insted of the default model
keep_output_files (str or list) – If list, it contains the filenames of the output files that will be saved into the output_dir (shared list for reentry and risk analysis). If ‘all’ the whole output folder will be saved into the output_dir, if ‘summary’ (Default), only a default list of output files will be saved into the output_dir (valid only if output_dir is provided as input parameter).
spell_check (bool) – Specify if the case to run should contain only keywords that are present in the configuration file
create_fig (bool) – if True, generates the png files into the output_dir.
framework (str) – defines whether DRAMA or DMF is using the wrapper
**kwargs – If
config
isNone
, the SARA run configuration values can be passed on as kwargs.
- Returns:
{ 'config': provided config of all runs, 'errors': [ # info on erroneous runs { 'config': {}, # config of single erroneous run, 'status': 'error <details>', 'reentry_output': stdout and stderr of reentry process, 'risk_output': stdout and stderr of risk process, 'reentry_logfile': reentry logfile content, 'risk_logfile': risk logfile content, }, ... ], 'results': [ { 'config': {}, # config of single successful run, 'status': 'success', 'reentry_output': stdout and stderr of reentry process, 'risk_output': stdout and stderr of risk process, 'reentry_logfile': reentry logfile content, 'risk_logfile': risk logfile content, 'total_casualty_x_section': total casualty for the x section, 'total_casualty_risk': total casualty risk, 'total_casualty_risk2D': total casualty risk 2D, }, ... ], 'stopping reason', }
The stopping reason should be always
n_max reached
.
Example
from drama import sara from drama.monte_carlo import Gaussian config = {'el1': Gaussian(mu=6700, sigma=2.5)} results = sara.run_monte_carlo(config)
- drama.sara.run_monte_carlo_with_wilson_confidence(config=None, n_max=10000, target_variable='total_casualty_risk', binary_criteria=0.0001, confidence_level=99.0, project=None, quantile=0.9, parallel=True, ncpus=None, timeout=None, model=None, keep_output_files='summary', spell_check=True, create_fig=False, framework='DRAMA', **kwargs)
SARA Monte Carlo runner checking for Wilson confidence interval with correction for continuity.
- Parameters:
config (dict) – The config as specified in parameter
config
inrun()
, containing at least onemonte_carlo.Distribution
.n_max (int) – The maximum number of runs.
target_variable (str) – The key in the result dictionaries to be checked.
binary_criteria (float) – The threshold value for the binary check.
confidence_level (float) – The confidence level to be reached. Supported confidence levels: 95.0, 99.0, 99.8.
project (str) – Path to DRAMA project to use as baseline (directory or exported project). If
None
the default project is used.quantile – Probability that the target variable is compliance with the binary criteria. Default value is 0.9 (90% probability).
parallel (bool) – Define if simulations shall be run in parallel.
ncpus (int) – Number of CPUs to use if parallel is True. If not specified, the maximum available will be used.
timeout (int) – Timeout in seconds for each run.
keep_output_files (str or list) – If list, it contains the filenames of the output files that will be saved into the output_dir (shared list for reentry and risk analysis). If ‘all’ the whole output folder will be saved into the output_dir, if ‘summary’ (Default), only a default list of output files will be saved into the output_dir (valid only if output_dir is provided as input parameter).
spell_check (bool) – Specify if the case to run should contain only keywords that are present in the configuration file
create_fig (bool) – if True, generates the png files into the output_dir.
model (SaraObj) – sara model, could be explicity provided and used insted of the default model
framework (str) – defines whether DRAMA or DMF is using the wrapper
**kwargs – If
config
isNone
, the SARA run configuration values can be passed on as kwargs.
- Returns:
{ 'config': provided config of all runs, 'errors': [ # info on erroneous runs { 'config': {}, # config of single erroneous run, 'status': 'error <details>', 'reentry_output': stdout and stderr of reentry process, 'risk_output': stdout and stderr of risk process, 'reentry_logfile': reentry logfile content, 'risk_logfile': risk logfile content, }, ... ], 'results': [ { 'config': {}, # config of single successful run, 'status': 'success', 'reentry_output': stdout and stderr of reentry process, 'risk_output': stdout and stderr of risk process, 'reentry_logfile': reentry logfile content, 'risk_logfile': risk logfile content, 'total_casualty_x_section': total casualty for the x section, 'total_casualty_risk': total casualty risk, 'total_casualty_risk2D': total casualty risk 2D, }, ... ], 'stopping reason', }
The stopping reason can be:
n_max reached
if the confidence level was not reached.confidence reached with status OK
if the confidence was reached and the hypothesis was fulfilled.confidence reached with status NOK
if the confidence level was reached and the hypothesis was not fulfilled.
Example
from drama import sara from drama.monte_carlo import Gaussian config = {'el1': Gaussian(mu=6700, sigma=2.5)} results = sara.run_monte_carlo_with_wilson_confidence(config=config, confidence_level=95.)
- drama.sara.get_progress(run_mode, rundir_path)
Retrieves the current progress of SARA, when the reentry_tmp_path already exists
- drama.plot_sara.plot_histogram(results, target='total_casualty_x_section', plotfile_name='histogram', x_label=None, framework='DRAMA')
Generates the histogram of the ‘target’ variable from the provided ‘results’ from SARA.
- Parameters:
results (list) – List of dict of SARA results. Each dictionary must contain the ‘target’ key.
target (str) – The target variable
plotfile_name (str) – file name (without extension) for the output file.
x_label (str) – label for the x axis
framework (str) – defines whether DRAMA or DMF is using the wrapper.
Note
Creates a
{plotfile_name}.png
file containing the histogram plot for the ‘target’ variable.
- drama.plot_sara.plot_cdf(results, target='total_casualty_x_section', plotfile_name='cdf', x_label=None, framework='DRAMA')
Generates the cumulative distribution function of the ‘target’ variable from the provided ‘results’ from SARA.
- Parameters:
results (list) – List of dict of SARA results. Each dictionary must contain the ‘target’ key.
target (str) – The target variable
plotfile_name (str) – file name (without extension) for the output file.
x_label (str) – label for the x axis
framework (str) – defines whether DRAMA or DMF is using the wrapper.
Note
Creates a
{plotfile_name}.png
file containing the cumulative distribution function plot for the ‘target’ variable.
- drama.plot_sara.plot_heatmap(results, variables, target='total_casualty_x_section', plotfile_name='heatmap', x_label=None, y_label=None, framework='DRAMA')
Generates the Heatmap of the ‘target’ variable from the provided ‘results’ from SARA.
- Parameters:
results (list) – List of dict of SARA results. Each dictionary must contain the ‘target’ key.
target (str) – The target variable
plotfile_name (str) – file name (without extension) for the output file.
x_label (str) – label for the x axis
y_label (str) – label for the y axis
framework (str) – defines whether DRAMA or DMF is using the wrapper.
Note
Creates a
{plotfile_name}.png
file containing the heatmap plot for the ‘target’ variable.