imagine.simulators package

Submodules

imagine.simulators.hammurabi module

class imagine.simulators.hammurabi.Hammurabi(measurements, xml_path=None, exe_path=None)[source]

Bases: imagine.simulators.simulator.Simulator

This is an interface to hammurabi X Python wrapper.

Upon initialization, a Hampyx object is initialized and its XML tree should be modified according to measurements without changing its base file.

If a xml_path is provided, it will be used as the base XML tree, otherwise, hammurabiX’s default ‘params_template.xml’ will be used.

Dummy fields can be used to change the parameters of hammurabiX. Other fields are temporarily saved to disk (using imagine.rc ‘temp_dir’ directory) and loaded into hammurabi.

Parameters:
  • measurements (Measurements object) – IMAGINE defined dictionary of measured data.
  • exe_path (string) – Absolute hammurabi executable path.
  • xml_path (string) – Absolute hammurabi xml parameter file path.
initialize_ham_xml()[source]

Modify hammurabi XML tree according to the requested measurements.

simulate(key, coords_dict, realization_id, output_units)[source]

Must be overriden with a function that returns the observable described by key using the fields in self.fields, in units output_units.

Parameters:
  • key (tuple) – Observable key in the standard form (data-name,str(data-freq),str(data-Nside)/"tab",str(ext))
  • coords_dict (dictionary) – Dictionary containing coordinates associated with the observable (or None for HEALPix datasets).
  • Nside (int) – HEALPix Nside parameter for HEALPix datasets (or None for tabular datasets).
  • output_units (astropy.units.Unit) – The physical units that should be used for this mock observable
Returns:

1D pure numpy array of length compatible with Nside or coords_dict containing the mock observable in the output_units.

Return type:

numpy.ndarray

ALLOWED_GRID_TYPES = ['cartesian']
OPTIONAL_FIELD_TYPES = ['dummy', 'magnetic_field', 'thermal_electron_density', 'cosmic_ray_electron_density']
REQUIRED_FIELD_TYPES = []
SIMULATED_QUANTITIES = ['fd', 'dm', 'sync']

imagine.simulators.simulator module

class imagine.simulators.simulator.Simulator(measurements)[source]

Bases: imagine.tools.class_tools.BaseClass

Simulator base class

New Simulators must be introduced by sub-classing the present class. Overriding the method simulate() to convert a list of fields into simulated observables. For more details see Simulators section of the documentation.

Parameters:measurements (imagine.Measurements) – An observables dictionary containing the set of measurements that will be used to prepare the mock observables
grid

Grid object where the fields were evaluated (NB if a common grid is not being used, this is set to None

Type:imagine.Basegrid
grids

Grid objects for each individual field None if common grid is being used)

Type:imagine.Basegrid
fields

Dictionary containing field types as keys and the sum of evaluated fields as values

Type:dict
observables

List of Observable keys

Type:list
output_units

Output units used in the simulator

Type:astropy.units.Unit
__call__(field_list)[source]

Runs the simulator over a Fields list

Parameters:field_list (list) – List of imagine.Field object which must include all the required_field_types
Returns:sims – A Simulations object containing all the specified mock data
Return type:imagine.Simulations
prepare_fields(field_list, i)[source]

Registers the available fields checking whether all requirements are satisfied. all data is saved on a dictionary, simulator.fields, where field_types are keys.

The fields dictionary is reconstructed for each realisation of the ensemble. It relies on caching within the Field objects to avoid computing the same quantities multiple times.

If there is more than one field of the same type, they are summed together.

Parameters:
  • field_list (list) – List containing Field objects
  • i (int) – Index of the realisation of the fields that is being registred
register_ensemble_size(field_list)[source]

Checks whether fields have consistent ensemble size and stores this information

register_observables(measurements)[source]

Called during initalization to store the relevant information in the measurements dictionary

Parameters:measurements (imagine.Measurements) – An observables dictionary containing the set of measurements that will be used to prepare the mock observables
simulate(key, coords_dict, realization_id, output_units)[source]

Must be overriden with a function that returns the observable described by key using the fields in self.fields, in units output_units.

Parameters:
  • key (tuple) – Observable key in the standard form (data-name,str(data-freq),str(data-Nside)/"tab",str(ext))
  • coords_dict (dictionary) – Dictionary containing coordinates associated with the observable (or None for HEALPix datasets).
  • Nside (int) – HEALPix Nside parameter for HEALPix datasets (or None for tabular datasets).
  • output_units (astropy.units.Unit) – The physical units that should be used for this mock observable
Returns:

1D pure numpy array of length compatible with Nside or coords_dict containing the mock observable in the output_units.

Return type:

numpy.ndarray

REQ_ATTRS = ['SIMULATED_QUANTITIES', 'REQUIRED_FIELD_TYPES', 'ALLOWED_GRID_TYPES']
allowed_grid_types

Must be overriden with a list or set of allowed grid types that work with this Simulator. Example: [‘cartesian’]

ensemble_size
optional_field_types

Can be overriden with a list or set of field types that Simulator can use if available. Example: [‘magnetic_field’, ‘cosmic_ray_electron_density’]

required_field_types

Must be overriden with a list or set of required field types that the Simulator needs. Example: [‘magnetic_field’, ‘cosmic_ray_electron_density’]

simulated_quantities

Must be overriden with a list or set of simulated quantities this Simulator produces. Example: [‘fd’, ‘sync’]

use_common_grid

Must be overriden with a list or set of allowed grid types that work with this Simulator. Example: [‘cartesian’]

imagine.simulators.test_simulator module

For testing purposes only

class imagine.simulators.test_simulator.TestSimulator(measurements, LoS_axis='y')[source]

Bases: imagine.simulators.simulator.Simulator

Example simulator for illustration and testing

Computes a Faraday-depth-like property at a given point without performing the integration, i.e. computes:

\[$t(x,y,z) = B_y\,n_e\,$\]
simulate(key, coords_dict, realization_id, output_units)[source]

Must be overriden with a function that returns the observable described by key using the fields in self.fields, in units output_units.

Parameters:
  • key (tuple) – Observable key in the standard form (data-name,str(data-freq),str(data-Nside)/"tab",str(ext))
  • coords_dict (dictionary) – Dictionary containing coordinates associated with the observable (or None for HEALPix datasets).
  • Nside (int) – HEALPix Nside parameter for HEALPix datasets (or None for tabular datasets).
  • output_units (astropy.units.Unit) – The physical units that should be used for this mock observable
Returns:

1D pure numpy array of length compatible with Nside or coords_dict containing the mock observable in the output_units.

Return type:

numpy.ndarray

ALLOWED_GRID_TYPES = ['cartesian']
REQUIRED_FIELD_TYPES = ['magnetic_field', 'thermal_electron_density']
SIMULATED_QUANTITIES = ['test']

Module contents

class imagine.simulators.Hammurabi(measurements, xml_path=None, exe_path=None)[source]

Bases: imagine.simulators.simulator.Simulator

This is an interface to hammurabi X Python wrapper.

Upon initialization, a Hampyx object is initialized and its XML tree should be modified according to measurements without changing its base file.

If a xml_path is provided, it will be used as the base XML tree, otherwise, hammurabiX’s default ‘params_template.xml’ will be used.

Dummy fields can be used to change the parameters of hammurabiX. Other fields are temporarily saved to disk (using imagine.rc ‘temp_dir’ directory) and loaded into hammurabi.

Parameters:
  • measurements (Measurements object) – IMAGINE defined dictionary of measured data.
  • exe_path (string) – Absolute hammurabi executable path.
  • xml_path (string) – Absolute hammurabi xml parameter file path.
initialize_ham_xml()[source]

Modify hammurabi XML tree according to the requested measurements.

simulate(key, coords_dict, realization_id, output_units)[source]

Must be overriden with a function that returns the observable described by key using the fields in self.fields, in units output_units.

Parameters:
  • key (tuple) – Observable key in the standard form (data-name,str(data-freq),str(data-Nside)/"tab",str(ext))
  • coords_dict (dictionary) – Dictionary containing coordinates associated with the observable (or None for HEALPix datasets).
  • Nside (int) – HEALPix Nside parameter for HEALPix datasets (or None for tabular datasets).
  • output_units (astropy.units.Unit) – The physical units that should be used for this mock observable
Returns:

1D pure numpy array of length compatible with Nside or coords_dict containing the mock observable in the output_units.

Return type:

numpy.ndarray

ALLOWED_GRID_TYPES = ['cartesian']
OPTIONAL_FIELD_TYPES = ['dummy', 'magnetic_field', 'thermal_electron_density', 'cosmic_ray_electron_density']
REQUIRED_FIELD_TYPES = []
SIMULATED_QUANTITIES = ['fd', 'dm', 'sync']
class imagine.simulators.Simulator(measurements)[source]

Bases: imagine.tools.class_tools.BaseClass

Simulator base class

New Simulators must be introduced by sub-classing the present class. Overriding the method simulate() to convert a list of fields into simulated observables. For more details see Simulators section of the documentation.

Parameters:measurements (imagine.Measurements) – An observables dictionary containing the set of measurements that will be used to prepare the mock observables
grid

Grid object where the fields were evaluated (NB if a common grid is not being used, this is set to None

Type:imagine.Basegrid
grids

Grid objects for each individual field None if common grid is being used)

Type:imagine.Basegrid
fields

Dictionary containing field types as keys and the sum of evaluated fields as values

Type:dict
observables

List of Observable keys

Type:list
output_units

Output units used in the simulator

Type:astropy.units.Unit
__call__(field_list)[source]

Runs the simulator over a Fields list

Parameters:field_list (list) – List of imagine.Field object which must include all the required_field_types
Returns:sims – A Simulations object containing all the specified mock data
Return type:imagine.Simulations
prepare_fields(field_list, i)[source]

Registers the available fields checking whether all requirements are satisfied. all data is saved on a dictionary, simulator.fields, where field_types are keys.

The fields dictionary is reconstructed for each realisation of the ensemble. It relies on caching within the Field objects to avoid computing the same quantities multiple times.

If there is more than one field of the same type, they are summed together.

Parameters:
  • field_list (list) – List containing Field objects
  • i (int) – Index of the realisation of the fields that is being registred
register_ensemble_size(field_list)[source]

Checks whether fields have consistent ensemble size and stores this information

register_observables(measurements)[source]

Called during initalization to store the relevant information in the measurements dictionary

Parameters:measurements (imagine.Measurements) – An observables dictionary containing the set of measurements that will be used to prepare the mock observables
simulate(key, coords_dict, realization_id, output_units)[source]

Must be overriden with a function that returns the observable described by key using the fields in self.fields, in units output_units.

Parameters:
  • key (tuple) – Observable key in the standard form (data-name,str(data-freq),str(data-Nside)/"tab",str(ext))
  • coords_dict (dictionary) – Dictionary containing coordinates associated with the observable (or None for HEALPix datasets).
  • Nside (int) – HEALPix Nside parameter for HEALPix datasets (or None for tabular datasets).
  • output_units (astropy.units.Unit) – The physical units that should be used for this mock observable
Returns:

1D pure numpy array of length compatible with Nside or coords_dict containing the mock observable in the output_units.

Return type:

numpy.ndarray

REQ_ATTRS = ['SIMULATED_QUANTITIES', 'REQUIRED_FIELD_TYPES', 'ALLOWED_GRID_TYPES']
allowed_grid_types

Must be overriden with a list or set of allowed grid types that work with this Simulator. Example: [‘cartesian’]

ensemble_size
optional_field_types

Can be overriden with a list or set of field types that Simulator can use if available. Example: [‘magnetic_field’, ‘cosmic_ray_electron_density’]

required_field_types

Must be overriden with a list or set of required field types that the Simulator needs. Example: [‘magnetic_field’, ‘cosmic_ray_electron_density’]

simulated_quantities

Must be overriden with a list or set of simulated quantities this Simulator produces. Example: [‘fd’, ‘sync’]

use_common_grid

Must be overriden with a list or set of allowed grid types that work with this Simulator. Example: [‘cartesian’]

class imagine.simulators.TestSimulator(measurements, LoS_axis='y')[source]

Bases: imagine.simulators.simulator.Simulator

Example simulator for illustration and testing

Computes a Faraday-depth-like property at a given point without performing the integration, i.e. computes:

\[$t(x,y,z) = B_y\,n_e\,$\]
simulate(key, coords_dict, realization_id, output_units)[source]

Must be overriden with a function that returns the observable described by key using the fields in self.fields, in units output_units.

Parameters:
  • key (tuple) – Observable key in the standard form (data-name,str(data-freq),str(data-Nside)/"tab",str(ext))
  • coords_dict (dictionary) – Dictionary containing coordinates associated with the observable (or None for HEALPix datasets).
  • Nside (int) – HEALPix Nside parameter for HEALPix datasets (or None for tabular datasets).
  • output_units (astropy.units.Unit) – The physical units that should be used for this mock observable
Returns:

1D pure numpy array of length compatible with Nside or coords_dict containing the mock observable in the output_units.

Return type:

numpy.ndarray

ALLOWED_GRID_TYPES = ['cartesian']
REQUIRED_FIELD_TYPES = ['magnetic_field', 'thermal_electron_density']
SIMULATED_QUANTITIES = ['test']