Modules
CLOUDY sampling
The sampling module samples the CLOUDY input parameter space using LHS in order to produce combinations of inputs that map out the whole space efficiently.
- sampling.sampling_adjust_units(parameters)
Some parameter units have to be adjusted to be compatible with Cloudy’s input formats. For example, we sampled some parameters in log space which need to be changed to linear space. Others parameters might require linear transformations. All required changes can be performed in this function.
- Parameters:
parameters (object) – parameter object
- Returns:
parameter object
- Return type:
object
- sampling.sampling_create_parameters(path, N_sample, filter=False, save_to_file=True, plot=False)
This function creates a set of parameters for a sample.
- Parameters:
path (str) – output directory
N_sample (int) – Number of parameter samples to be generated
save_to_file (bool) – Boolean - Save parameters to file
filter (bool) – Boolean - Filter the sample for parameter combinations that are unphysical. This will results in a lower n_sample than specified.
plot (bool) – Boolean - create a visualisation of the parameter space
- Returns:
A 2D numpy array in which each row represents a parameter vector. It will also be saved as a numpy object.
- Return type:
numpy.array
- sampling.sampling_filter_redshift_stellar_age(parameters)
Remove all parameter vectors for which the stellar age exceeds the age of the universe (given by the redshift)
- Parameters:
parameters (numpy.array) – 2D array containing the parameters
- Returns:
The filtered 2D parameter array
- Return type:
numpy.array
CLOUDY inputs
The following class takes the sampled CLOUDY input parameter combinations and for every combination creates the model.in file that CLOUDY expects.
- class cloudy_input.CloudyInput(index: int, N_sample: int, target_dir: str, LineList_path: str)
Class used to create model.in file and the file structure given a sample, a combination of parameters that are to be run on CLOUDY.
- Parameters:
index (int) – index identifier of the sample within the whole array of samples.
N_sample (int) – number of total models.
target_dir (str) – path of directory where samples are to be saved.
LineList_path (str) – path to file where lines to be saved are written.
- create(log_gas_density: float, gas_phase_metallicity: float, redshift: float, cosmic_ray_ionization_factor: float, ionization_parameter: float, stellar_metallicity: float, stellar_age: float, DTM: float) str
Main method of the class, called to produce the model.in file using the parameters in the sample. Returns the path to the model.in file created so the location is known and it can be found and run with ease.
- Parameters:
log_gas_density (float) – value logarithm of the gas density
gas_phase_metallicity (float) – value log of the gas metallicity
redshift (float) – value of the redshift
cosmic_ray_ionization_factor (float) – value to use to scale the cosmic ray background
ionization_parameter (float) – value log of the ionization parameter
stellar_metallicity (float) – value log of the stellar metallicity
stellar_age (float) – value stellar age in years
DTM (float) – value dust-to-metal ratio
- Returns:
path to the model.in file created
- Return type:
str
- cloudy_input.create_inputs(N: int, target_dir: str, LineList_path: str, filter: bool = True, save_to_file: bool = True, plot: bool = False)
Creates the model.in inputs for CLOUDY and saves them creaing the folder structure. Calls the sampling.sampling_create_parameters() to obtain the combinations of parameters, then for every combination it creates the model.in file using the template.
- Parameters:
N (int) – number of original (before filtering) different combinations of input parameters.
target_dir (str) – string path to the directory where the samples are to be saved.
LineList_path (str) – string path to the file where the list of lines to be saved are listed.
filter (bool) – Filter out non-physical combinations.
save_to_file (bool) – Saves the resulting parameters as numpy array.
plot (bool) – Create a visual representation of the input space.
- Returns:
None
- Return type:
None
Running CLOUDY
Using the generated inputs (model.in files) this module can be used to set up a queue of inputs to be run in CLOUDY using multiple workers. The result of which are stored in a “done/” directory.
- class manager.QueueManager(sample_dir: str, N_CPUs: Optional[int] = None, N_batch: Optional[int] = None, verbose: bool = True)
Class used to manage a queue of Cloudy input models.
It uses the directory containing a sample of models, creates a queue of runs to be performed, and runs subprocesses on multiple CPU cores.
- Parameters:
sample_dir (str) – string path to the folder where the samples are to be saved
N_CPUs (int) – int Maximum number of CPUS to use, if not defined it will use all available CPUS in the system.
N_batch (int) – int Number of models to run. If not specified or larger than the total number of models, all models will be run.
verbose (bool) – bool flag used to activate/deactivate the verbosity. Defaults to True (verbose)
- manager_run() None
Main method of the class, it wraps the private methods to read the files and run the files.
Parsing CLOUDY
After running the models, given the directory where the outputs are stored we can then use the parser module to look for all outputs within the directory “done/” and parse some of the results for further processing.