bjet_mcmc.blazar_model module
file name: blazar_model.py Contains functions to interact with the C++ code to create the SED models. In separate functions, it creates the necessary parameter file, calls the C++ code, reads the data saved by the C++ code, and processes the model data into a usable format.
Then, the function make_model does all of this when called with parameters, which is
the function that is used by the rest of the code.
Note
All file paths are relative to blazars-mcmc
Parameters are always listed in the following order:
[delta, K, n1, n2, gamma_min, gamma_max, gamma_break, B, R]
The additional parameters for EIC are bb_temp, l_nuc, tau, blob_dist, in that order.
All parameters are the logarithm of the true value except for delta, n1, and n2.
Parameter |
Description |
Scale |
|---|---|---|
|
Doppler factor |
Linear |
|
Particle density [cm^-3] |
Log |
|
alpha_1 (first index) |
Linear |
|
alpha_2 (second index) |
Linear |
|
Low-energy cutoff |
Log |
|
High-energy cutoff |
Log |
|
Energy break |
Log |
|
Magnetic field strength [G] |
Log |
|
Blob radius [cm] |
Log |
Additional params for EIC
Parameter |
Description |
Scale |
|---|---|---|
|
Black body temp of disk [K] |
Log |
|
Nucleus luminosity [ergs/s] |
Log |
|
Fraction of luminosity scattered |
Log |
|
Distance of blob [cm] |
Log |
- bjet_mcmc.blazar_model.add_data(current_data, new_data=None, file_suffix=None, name_stem=None, data_folder=None, cols=(0, 2))
Add new data to the current data.
- Raises:
IOError – If the specified data file cannot be read.
ValueError – If neither new data nor file suffix is provided.
- Parameters:
current_data (tuple) – Tuple containing current data of the format (current_logv, current_logvFv, current_v, current_vFv).
new_data (tuple) – Optional. Tuple containing new data to be added of the format (model_logv, model_logvFv, model_v, model_vFv).
file_suffix (str) – Optional. String representing the file suffix for loading model data.
name_stem (str) – Optional. String representing the name stem for the model data file.
data_folder (str) – Optional. String representing the folder path for the model data file to load.
cols (tuple) – Optional. Tuple representing the column indices to extract from the loaded data. Defaults to (0, 2).
- Returns:
Tuple containing the interpolated data of the format (logv, logvFv, v, vFv).
- Return type:
- bjet_mcmc.blazar_model.command_line_sub_strings(name_stem=None, theta=None, redshift=None, min_freq=None, max_freq=None, data_folder=None, prev_files=False, eic=False)
- Parameters:
name_stem (str) – The prefix for the file name. If not provided, it defaults to NAME_STEM.
theta (float) – The angle value. If not provided, it defaults to 0.57.
redshift (float) – The redshift value.
min_freq (float) – The minimum frequency value. If not provided, it defaults to 1.0e08.
max_freq (float) – The maximum frequency value. If not provided, it defaults to 1.0e28.
data_folder (str) – The folder where the data files are located. If not provided, it defaults to DATA_FOLDER.
prev_files (bool) – Flag indicating whether to use previous files. If set to True, it uses “2” as the value of p, otherwise it uses “3”.
eic (bool) – Flag indicating the model type. If set to True, it uses “1” as the value of model_type, otherwise it uses “0”.
- Returns:
A tuple containing the settings and transformation values, and the constant and numerical values.
- Return type:
- bjet_mcmc.blazar_model.create_params_file(params, name_stem=None, parameter_file=None, theta=None, redshift=None, min_freq=None, max_freq=None, verbose=False)
Given parameters and a file, put the data in the file in the format understandable by the C++ code.
Note
Cannot be used with EIC
- Raises:
IOError – if parameter_files cannot be written to (likely, a folder in the path does not exist)
- Parameters:
params (list) – List of parameters Form: [delta (linear), K (log), n1 (linear), n2 (linear), gamma_min (log), gamma_max (log), gamma_break (log), B (log), R (log)]
name_stem (str) – Name stem of the output file. Data will be saved in files named <name_stem>_*.dat
parameter_file (str) – Output file name. String with the relative path of the parameter file; default is None; will be set to “<PARAMETER_FOLDER>/params.txt”
theta (float) – Angle to the line of sight
redshift (float) – Redshift
min_freq (float) – Minimal frequency. Specifies min frequency model SEDs should use; default is None; will be set to 5.0e+7
max_freq (float) – Maximal frequency. Specifies max frequency model SEDs should use; default is None; will be set to 1.0e+29
verbose (bool) – Verbose output flag
- Returns:
None parameter_files is over-written (and createed if necessary) with parameter information.
- Return type:
None
- bjet_mcmc.blazar_model.file_make_SED(parameter_file=None, data_folder=None, executable=None, prev_files=False, verbose=False)
Calls the C++ code to generate the SED. Compton model data is saved to <home directory>/DATA_FOLDER/<file prefix>_cs.dat Sync model data is saved to <home directory>/DATA_FOLDER/<file prefix>_ss.dat
- Parameters:
parameter_file (str) – Relative path to param file, will be overwritten with parameters; default is <PARAMETER_FOLDER>/params.txt.
data_folder (str) – The path to the data folder. Default is None.
executable (str) – The path to the executable file. Default is None.
prev_files (bool) – Flag indicating whether to create previous files. Default is False.
verbose (bool) – Flag indicating whether to display verbose output. Default is False.
- Returns:
None
- Return type:
None
This function generates a system energy dissipation (SED) file by calling a C++ code. The SED file is stored in the <home directory>/DATA_FOLDER with a given file name prefix. Data saved to <home directory>/DATA_FOLDER/<file prefix>_*.dat. Parameter file overwritten or created.
If the parameter_file is not provided, it will default to the “params.txt” file in the PARAMETER_FOLDER. If the data_folder is not provided, it will default to the DATA_FOLDER. If the executable is not provided, it will default to the EXECUTABLE file in the CPP_FOLDER.
If prev_files is True, the C++ code is called with a “2” input mode. If prev_files is False, the C++ code is called with a “3” input mode.
If verbose is True, the C++ code is called with verbose output. If verbose is False, the C++ code is called without displaying the output.
Note
This method uses older implementation and it is recommended to rewrite the method using bj_core methods, avoiding building a command string.
- bjet_mcmc.blazar_model.make_SED(params, name_stem=None, theta=None, redshift=None, min_freq=None, max_freq=None, torus_temp=None, torus_luminosity=None, torus_frac=None, data_folder=None, executable=None, command_params_full=None, command_params_1=None, command_params_2=None, prev_files=False, verbose=False, eic=False, folder=None)
- Parameters:
params (numpy.ndarray) – 1D numpy array of NUM_DIM floats
name_stem (str, optional) – Name stem for make_model. Default is None; will then be set to default.
theta (float, optional) – Angle from the line of sight. Default is None, and it will be set to the default value of 0.57.
redshift (float, optional) – Redshift value; default is None, so the log_prior function will use the default, which is 0.143 (the value for J1010).
min_freq (float, optional) – Minimum frequency for the SED model. Default is None, where it will be set to the default value of 5.0e+7 in blazar_model.process_model.
max_freq (float, optional) – Maximum frequency for the SED model. Default is None, where it will be set to the default value of 1.0e+29 in blazar_model.process_model.
torus_temp (float, optional) – Value for the torus temperature. Default is None, and it will be set to the default of 2.0e+4.
torus_luminosity (float, optional) – Value for the torus luminosity. Default is None, and it will be set to the default of 5.5e+20.
torus_frac (float, optional) – Value for the fraction of the torus luminosity reprocessed isotropically. Default is None, and it will be set to the default of 9.0e-5.
data_folder (str, optional) – Relative path to the folder where data will be saved to.
executable (str, optional) – Where the bjet executable is located.
command_params_full (numpy.ndarray, optional) – Full set of parameters to pass to the bjet exec–see the README for information. Should be length 22, 23, 28, or 29.
command_params_1 (numpy.ndarray, optional) – The settings and transformation parameters: [prev files flag, data folder, model type, redshift, hubble constant, theta].
command_params_2 (numpy.ndarray, optional) – The constant and numerical parameters: [length of the emitting region, absorption by EBL, blob distance, # of spectral points, min freq, max freq, file name prefix].
prev_files (bool, optional) – Whether bjet should create _prev files after each run; default is False.
verbose (bool, optional) – Whether information on the model should be displayed; default is False.
eic (bool) – States whether the run is eic or std; default is False (std).
folder (str, optional) – Additional folder information; default is None.
- bjet_mcmc.blazar_model.make_model(params, name_stem=None, theta=None, redshift=None, min_freq=None, max_freq=None, torus_temp=None, torus_luminosity=None, torus_frac=None, data_folder=None, executable=None, command_params_full=None, command_params_1=None, command_params_2=None, parameter_file=None, prev_files=False, use_param_file=False, verbose=False, eic=False, fixed_params=None, folder=None)
Given parameters, returns v and vFv for the corresponding model.
- Args:
params (list of floats): a list of NUM_DIM floats which are the parameters name_stem (str): data will be saved in files of the form <name_stem>_*.dat parameter_file (str): optional; relative path of the parameter file theta: optional; params is fixed for modeling redshift: optional; redshift is fixed for modeling min_freq (float): optional; specifies min frequency model SEDs should use; default value used if none provided, which is 5.0e+7. max_freq (float): optional; specifies max frequency model SEDs should use; default value used if none provided, which is 1.0e+29. executable (str): optional; where the bjet executable is located data_folder (str): relative path to the folder where data will be saved to use_param_file (bool): specifies if bjet should be called with parameter file or with command line args verbose (bool): specifies if parameters and output of bjet should be shown
After function call: parameter_files is over-written with parameter information. Files of the form <name_stem>_*.dat are created inside <path>
- Returns:
a tuple of 4 1D numpy arrays
all arrays have the same length. logv_all, logvFv_all, v_all, vFv_all
logv_all: a 1D numpy array of the log of all frequencies logvFv_all: a 1D numpy array of the log of all the energy flux v_all: a 1D numpy array of all frequencies in the data vFv_all: a 1D numpy array of corresponding energy fluxes for the frequencies
- Raises:
IOError – if parameter_files cannot be written to (likely, a folder in the path does not exist)
- Parameters:
params (numpy.ndarray) – The parameters for the model computation. A list of NUM_DIM floats which are the parameters
name_stem (str) – The stem name for the model files.
theta (float) – The angle parameter for the model computation.
redshift (float) – The redshift parameter for the model computation.
min_freq (float) – The minimum frequency parameter for the model computation.
max_freq (float) – The maximum frequency parameter for the model computation.
torus_temp (float) – The temperature parameter for the torus component in the model computation.
torus_luminosity (float) – The luminosity parameter for the torus component in the model computation.
torus_frac (float) – The fraction parameter for the torus component in the model computation.
data_folder (str) – The folder containing the data files.
executable (str) – The path to the executable file.
command_params_full (str) – Additional command line parameters for the model computation.
command_params_1 (str) – Additional command line parameters for the model computation.
command_params_2 (str) – Additional command line parameters for the model computation.
parameter_file (str) – The path to the parameter file.
prev_files (bool) – Flag indicating whether to use previous files.
use_param_file (bool) – Flag indicating whether to use the parameter file.
verbose (bool) – Flag indicating whether to display verbose output.
eic (bool) – Flag indicating whether to use EIC mode.
fixed_params (numpy.ndarray) – The fixed parameters for the model computation.
folder (str) – The folder for the model files.
- Returns:
The computed model.
- Return type:
numpy.ndarray
- bjet_mcmc.blazar_model.params_linear_to_log(params, param_is_log=None, eic=False)
Converts linear scale parameters to logarithmic scale.
Note
If param_is_log is not provided, it will be inferred from the model properties based on eic.
The conversion to log scale is performed using the base 10 logarithm (np.log10).
- Parameters:
params (List or numpy array) – The linear scale parameters to be converted.
param_is_log (List or numpy array, default None) – Optional. A list indicating whether each parameter should be converted to log scale. If not provided, it will be determined based on the model properties.
eic (bool, default False) – Optional. A flag indicating whether the model properties are based on EIC. Defaults to False. If True, the model properties will be used to determine param_is_log. If False, param_is_log will be used as is.
- Returns:
The parameters converted to logarithmic scale.
- Return type:
List or numpy array
- bjet_mcmc.blazar_model.params_log_to_linear(params, param_is_log=None, eic=False)
Converts parameters from logarithmic to linear scale.
- Parameters:
- Returns:
A new list of parameters converted from log scale to linear scale if necessary.
- Return type:
- bjet_mcmc.blazar_model.process_model(name_stem=None, data_folder=None, verbose=False, eic=False, additional_suffixes=None)
Read a model from data files and returns arrays of frequencies and energy flux. This model only uses data from the compton model and the synchrotron model. The data we want are an array of frequencies (v) and an array of corresponding flux energies (vFv). Flux energy is the sum of the flux energy from the synchrotron model and that from the compton model when there are data points for both of them.
Warning
- Requirements:
The SED model must have already been created (using make_SED above) with the given name_stem.
By default, data is read from DATA_FOLDER/<name_stem>_*.dat, the location that make_SED writes to.
- Returns:
a tuple of 4 1D numpy arrays
all arrays have the same length.
logv_all, logvFv_all, v_all, vFv_all
logv_all: a 1D numpy array of the log of all frequencies
logvFv_all: a 1D numpy array of the log of all the energy flux
v_all: a 1D numpy array of all frequencies in the data
vFv_all: a 1D numpy array of corresponding energy fluxes for the frequencies
- Raises:
IOError – when data cannot be read
Note
The frequency values used are the ones used in the synchrotron spectrum and the ones in the compton model greater than the max in the synchrotron. The frequency values present in the Compton model in the overlap are not used.
- Parameters:
name_stem (str, optional) – The stem name that will be used to construct the file names of the models. If not provided, it will use the default value NAME_STEM. Model data is saved in files named in the form <name_stem>_*.dat, specify file name
data_folder (str, optional) – The folder where the model files are located. If not provided, it will use the default value DATA_FOLDER.
verbose (bool, optional) – Determines whether to print additional information during the process. Default is False.
eic (bool, optional) – Determines whether to enable Extended Inverse Compton (EIC) mode. Default is False.
additional_suffixes (list, optional) – A list of additional suffixes to be used for reading data in EIC mode. Default is None.
- Returns:
Four numpy arrays representing the logarithm of frequency, logarithm of energy flux, frequency, and energy flux respectively.
- Return type:
tuple of numpy arrays