API Documentation for ghosts

Stuff

camera interface

ghosts.camera

camera module

This module provides functions to display a dummy camera, with rafts, CCDs and amplifiers.

ghosts.camera.make_amp(x, y)[source]

Build an amplifier rectangle

Parameters:
  • x (float) – x position of the lower left angle of the amplifier rectangle

  • y (float) – y position of the lower left angle of the amplifier rectangle

Returns:

- – a Rectangle object

Return type:

matplotlib.patches.Rectangle

ghosts.camera.make_ccd(x, y)[source]

Build a CCD rectangle

Parameters:
  • x (float) – x position of the lower left angle of the CCD rectangle

  • y (float) – y position of the lower left angle of the CCD rectangle

Returns:

- – a Rectangle object

Return type:

matplotlib.patches.Rectangle

ghosts.camera.make_raft(x, y)[source]

Build a raft rectangle

Parameters:
  • x (float) – x position of the lower left angle of the raft rectangle

  • y (float) – y position of the lower left angle of the raft rectangle

Returns:

- – a Rectangle object

Return type:

matplotlib.patches.Rectangle

ghosts.camera.make_ccd_with_amp(x, y)[source]

Build a CCD rectangle filled with Amplifiers :param x: x position of the lower left angle of the raft rectangle :type x: float :param y: y position of the lower left angle of the raft rectangle :type y: float

Returns:

ccd – a list of CCDs with amplifiers

Return type:

list of matplotlib.patches.Rectangle

ghosts.camera.make_raft_with_ccd(x, y)[source]

Build a raft filled with CCDs

Parameters:
  • x (float) – x position of the lower left angle of the raft rectangle

  • y (float) – y position of the lower left angle of the raft rectangle

Returns:

raft – a list of rafts with CCDs

Return type:

list of matplotlib.patches.Rectangle

ghosts.camera.make_raft_with_ccd_with_amp(x, y)[source]

Build a raft filled with CCDs filled with amps

Parameters:
  • x (float) – x position of the lower left angle of the raft rectangle

  • y (float) – y position of the lower left angle of the raft rectangle

Returns:

raft – a list of CCDs with amplifiers

Return type:

list of matplotlib.patches.Rectangle

ghosts.camera.make_raft_with_one_ccd_with_amp(x, y, i_ccd)[source]

Build a raft with one CCD filled with amps

Parameters:
  • x (float) – x position of the lower left angle of the raft rectangle

  • y (float) – y position of the lower left angle of the raft rectangle

  • i_ccd (int) – number of the CCD that you wish to fill with amplifiers

Returns:

raft – a list of CCDs and some amplifiers

Return type:

list of matplotlib.patches.Rectangle

ghosts.camera.build_camera()[source]

Build a camera as a collection of Rectangles

Returns:

  • rafts (matplotlib.collections.PatchCollection) – a collection of rectangles that looks like the rafts of the Rubin LSST Camera

  • ccds (matplotlib.collections.PatchCollection) – a collection of rectangles that looks like the CCDs of the Rubin LSST Camera

  • amps (matplotlib.collections.PatchCollection) – a collection of rectangles that looks like the Amplifiers of the Rubin LSST Camera

ghosts.camera.show_camera(axis, camera)[source]

Add camera to an axis

Parameters:
  • axis (matplotlib.axes.Axes) – the matplotlib figure axis on which to add the camera

  • camera (tuple) – a tuple of collections containing the camera rectangles

beam configuration interface

ghosts.beam_configs

Beam configurations are defined as simple dictionaries with minimal information.

BEAM_CONFIG_0 = {'beam_id': 0, 'wl': 500e-9, 'n_photons': 1000, 'radius': 0.00125,
                 'x_offset': 0., 'y_offset': 0, 'z_offset': 2.2,
                 'z_euler': 0., 'y_euler': 0., 'x_euler': 0.}

beam interface

ghosts.beam

beam module

This module provides tools to manipulate beam geometries, and generate light rays as batoid.RayVector

ghosts.beam.to_panda(beam_config)[source]

Convert a beam configuration dictionary to a panda data frame

Indexing is done using the beam configuration beam_id.

Parameters:

beam_config (dict) – a dictionary with beam characteristics

Returns:

data_frame – a pandas data frame with beam information

Return type:

pandas.DataFrame

ghosts.beam.to_dict(beam_frame)[source]

Convert a beam panda data frame to a dictionary of use with simulator

The beam data frame is expected to have only one beam configuration.

Parameters:

beam_frame (pandas.DataFrame) – a pandas data frame with one beam configuration

Returns:

beam_config – a dictionary with a beam configuration

Return type:

dict

ghosts.beam.concat_frames(beam_frame_list)[source]

Concatenates beam configuration data frames within one table

Parameters:

beam_frame_list (list of pandas.DataFrame) – a list of beam configuration data frames

Returns:

beam_concat – a pandas data frame with several configurations of beams

Return type:

pandas.DataFrame

ghosts.beam.concat_dicts(beam_dict_list)[source]

Concatenates geometry configuration dictionaries into a data frame

Parameters:

beam_dict_list (list of dict) – a list of beam configuration dictionaries

Returns:

beam_concat – a pandas data frame with several configurations of beams

Return type:

pandas.DataFrame

ghosts.beam.to_beam_set(beam_frame)[source]

Convert a data frame of many beam configurations to a beam set (list of dicts)

Parameters:

beam_frame (pandas.DataFrame) – a pandas data frame with several configurations of beams

Returns:

beam_set – a beam set as a list of beam configuration dictionaries

Return type:

list of dict

ghosts.beam.get_photon_energy(beam_nu)[source]

Compute the energy of a photon at a given frequency

Parameters:

beam_nu (float) – light frequency in Hz

Returns:

photon_energy – the photon energy in Joules

Return type:

float

ghosts.beam.get_n_phot_for_power(beam_power, beam_nu)[source]

Compute the number of photons in a beam of light of a given power for a given frequency

Parameters:
  • beam_power (float) – light beam power in nanowatt

  • beam_nu (float) – light frequency in Hz

Returns:

n_photon – a number of photons

Return type:

int

ghosts.beam.get_n_phot_for_power_nw_wl_nm(beam_power, wl)[source]

Compute the number of photons in a beam of light of a given power for a given wavelength

Parameters:
  • beam_power (float) – light beam power in nanowatt

  • wl (int) – light wavelength

Returns:

n_photon – a number of photons

Return type:

int

ghosts.beam.point_beam_to_target(beam_config, target_x=0.0, target_y=0.0)[source]

Compute the Euler angles to point the beam at the camera center given a beam position

Parameters:
  • beam_config (dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

  • target_x (float) – target position on the X-axis of the camera plane

  • target_y (float) – target position on the Y-axis of the camera plane

Returns:

new_beam – a dictionary with the light beam configuration (see ghosts.beam_configs) that points toward the requested position on the camera plane

Return type:

dict

ghosts.beam.beam_on(beam_config)[source]

Generates a beam of light rays to be used for a simulation

Parameters:

beam_config (dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

Returns:

rays – a light beam as many photons of the requested wave length

Return type:

batoid.RayVectors

ghosts.beam.simple_beam(x_offset=0.1, y_offset=0, wl=5e-07, n_photons=1000)[source]

Proxy to generate a simple beam of light rays to be used for a simulation

Offsets are with respect to the default beam configuration, see BEAM_CONFIG_0 at ghosts.beam_configs.

Parameters:
  • x_offset (float) – the beam offset along x in meters

  • y_offset (float) – the beam offset along y in meters

  • wl (int) – the light wavelength in nanometers

  • n_photons (int) – the number of light rays to generate

Returns:

rays – a light beam as many photons of the requested wave length

Return type:

batoid.RayVectors

ghosts.beam.rotate_config_to_ub(beam_config, u, b)[source]

Rotate a beam configuration to given b and u CCOB motor angles

Email from Andy: - Check that U=0, B rotates around the Y axis, B>0 -> +X, B<0 -> -X - Check that U>0 rotates around -Z in the right-handed sense.

Euler angles in extrinsic rotations https://en.wikipedia.org/wiki/Euler_angles#Conventions_by_extrinsic_rotations

Parameters:
  • beam_config (ghost.beam_config) – a beam configuration as a dictionary

  • u (float) – the value of the rotation angle in degrees around “-Z” (when b=0)

  • b (float) – the value of the rotation angle in degrees around “Y” (when u=0)

Returns:

new_beam – a new beam configuration corresponding to CCOB motor set as (u, b) angles

Return type:

ghost.beam_config

ghosts.beam.build_translation_set(base_beam_config, axis, shifts_list, base_id=0)[source]

Build a set of beams for the given list of translations

Parameters:
  • base_beam_config (dict) – the base beam configuration dictionary to start from

  • axis (string) – the name of the translation axis, usually x or y

  • shifts_list (list of float) – the list of distances to scan in meters

  • base_id (int) – the id of the first beam configuration created, following ids will be id+1

Returns:

beams – a list of beam configuration dictionaries

Return type:

list of geom_config

ghosts.beam.build_rotation_set(base_beam_config, axis, angles_list, base_id=0)[source]

Build a set of beam configurations for the given list of rotations starting from the given beam configuration

Parameters:
  • base_beam_config (dict) – the base beam configuration dictionary to start from

  • axis (string) – axis around which to rotate as Euler rotations: “x_euler” or “y_euler”

  • angles_list (list of float) – the list of angles to scan in degrees

  • base_id (int) – the id of the first beam configuration created, following ids will be id+1

Returns:

beams – a list of geometry configuration dictionaries

Return type:

list of geom_config

ghosts.beam.build_square_set(distances, base_id=0)[source]

Build a square set of beams for a given list of distances

Parameters:
  • distances (list of float) – list of distances from -x/-y to +x/+Y

  • base_id (int) – the id of the first beam configuration created, following ids will be id+1

Returns:

beams – a list of beam configuration dictionaries

Return type:

list of geom_config

ghosts.beam.build_first_quadrant_square_set(delta=0.02, d_max=0.26, base_id=0)[source]

Build a set of beams to cover the first quadrant with a square grid

Parameters:
  • delta (float) – distance between 2 points in x or y, usually 2 cm = 0.02 m

  • d_max (float) – maximum distance to go from center, up to ~0.26 m is fine, then beam does not converge on camera

  • base_id (int) – the id of the first beam configuration created, following ids will be id+1

Returns:

beams – a list of beam configuration dictionaries

Return type:

list of geom_config

ghosts.beam.build_full_frame_square_set(delta=0.02, d_max=0.26, base_id=0)[source]

Build a full square set of beams on the full camera frame

Parameters:
  • delta (float) – distance between 2 points in x or y, usually 2 cm = 0.02 m

  • d_max (float) – maximum distance to go from center, up to ~0.26 m is fine, then beam does not converge on camera

  • base_id (int) – the id of the first beam configuration created, following ids will be id+1

Returns:

beams – a list of beam configuration dictionaries

Return type:

list of geom_config

ghosts.beam.build_square_set_on_target(base_beam_config, distances, target_x=0, target_y=0, base_id=0)[source]

Build a set of beams for the given list of distances from target

Parameters:
  • base_beam_config (dict) – the base beam configuration dictionary to start from

  • distances (list of float) – list of distances from -x/-y to +x/+Y

  • target_x (float) – target position on the X-axis of the camera plane

  • target_y (float) – target position on the Y-axis of the camera plane

  • base_id (int) – the id of the first beam configuration created, following ids will be id+1

Returns:

beams – a list of beam configuration dictionaries

Return type:

list of geom_config

ghosts.beam.build_polar_set(distances, angles, base_id=0)[source]

Build a set of beams for the given list of distances to center and a list of angles

Parameters:
  • distances (list of float) – list of distances to center to sample lenses

  • angles (list of float) – list of polar angles to sample lenses

  • base_id (int) – the id of the first beam configuration created, following ids will be id+1

Returns:

beams – a list of beam configuration dictionaries

Return type:

list of geom_config

ghosts.beam.build_first_quadrant_polar_set(delta=0.02, d_max=0.36, base_id=0)[source]

Build a set of beams for the given list of distances, and rotate on the first quadrant

Parameters:
  • delta (float) – distance between 2 points in x or y, usually 2 cm = 0.02 m

  • d_max (float) – maximum distance to go from center, up to ~0.26 m is fine, then beam does not converge on camera

  • base_id (int) – the id of the first beam configuration created, following ids will be id+1

Returns:

beams – a list of beam configuration dictionaries

Return type:

list of geom_config

ghosts.beam.build_full_frame_polar_set(base_id=0, set_size='large')[source]

Build a set of beams for the given list of translations

Parameters:
  • base_id (int) – the id of the first beam configuration created, following ids will be id+1

  • set_size ('string') – small, medium, large are the 3 default configurations

Returns:

beams – a list of beam configuration dictionaries

Return type:

list of geom_config

ghosts.beam.set_n_photons_on_beam_set(beam_set, n_photons=1000)[source]

Build a beam configuration matching the reference one, but with fewer photons so that the simulations called by the fit are faster

Parameters:
  • beam_set (list of dict) – the list of beam configurations to adjust

  • n_photons (int) – the number of rays to simulate for the new configuration

Returns:

fix_beam_set – the list of beam configuration with the adjusted number of photons

Return type:

list of dict

geom configuration interface

ghosts.geom_configs

Geometry configurations are defined as dictionaries with translations and rotations for each of the optical element

GEOM_CONFIG_0 = {'geom_id': 0,
                 'L1_dx': 0.0, 'L1_dy': 0.0, 'L1_dz': 0.0, 'L1_rx': 0.0, 'L1_ry': 0.0, 'L1_rz': 0.0,
                 'L2_dx': 0.0, 'L2_dy': 0.0, 'L2_dz': 0.0, 'L2_rx': 0.0, 'L2_ry': 0.0, 'L2_rz': 0.0,
                 'L3_dx': 0.0, 'L3_dy': 0.0, 'L3_dz': 0.0, 'L3_rx': 0.0, 'L3_ry': 0.0, 'L3_rz': 0.0,
                 'Filter_dx': 0.0, 'Filter_dy': 0.0, 'Filter_dz': 0.0,
                 'Filter_rx': 0.0, 'Filter_ry': 0.0, 'Filter_rz': 0.0,
                 'Detector_dx': 0.0, 'Detector_dy': 0.0, 'Detector_dz': 0.0,
                 'Detector_rx': 0.0, 'Detector_ry': 0.0, 'Detector_rz': 0.0}

geom interface

ghosts.geom

geom module

This module provides tools to manipulate telescope geometries, i.e. shifts and rotations

ghosts.geom.get_optics_translation(optics, geom_config)[source]

Return a vector with the translations of the given optics

Parameters:
  • optics (string) – the name of an optical element in L1, L2, L3, Filter, Detector

  • geom_config (dict) – a dictionary with shifts and rotations for each optical element

Returns:

translation_vector – a vector of translations for the optical element

Return type:

list of float

ghosts.geom.get_optics_rotation(optics, geom_config)[source]

Return a vector with the rotations of the given optics

Parameters:
  • optics (string) – the name of an optical element in L1, L2, L3, Filter, Detector

  • geom_config (dict) – a dictionary with shifts and rotations for each optical element

Returns:

rotation_vector – a vector of rotations for the optical element

Return type:

list of float

ghosts.geom.to_panda(geom_config)[source]

Convert a geometry configuration dictionary to a panda data frame

Indexing is done using the beam configuration geom_id.

Parameters:

geom_config (dict) – a dictionary with shifts and rotations for each optical element

Returns:

data_frame – a pandas data frame with shifts and rotations information

Return type:

pandas.DataFrame

ghosts.geom.to_dict(geom_frame)[source]

Convert a geometry panda data frame to a dictionary of use with tweak_optics

The geom data frame is expected to have only one geometry configuration.

Parameters:

geom_frame (pandas.DataFrame) – a pandas data frame with shifts and rotations information

Returns:

geom_config – a dictionary with shifts and rotations for each optical element

Return type:

dict

ghosts.geom.concat_frames(geom_frame_list)[source]

Concatenates geometry configuration data frames within one table

Parameters:

geom_frame_list (list of pandas.DataFrame) – a list of geometry configuration data frames

Returns:

geom_concat – a pandas data frame with several configurations of shifts and rotations information

Return type:

pandas.DataFrame

ghosts.geom.concat_dicts(geom_dict_list)[source]

Concatenates geometry configuration dictionaries into a data frame

Parameters:

geom_dict_list (list of dict) – a list of geometry configuration dictionaries

Returns:

geom_concat – a pandas data frame with several configurations of shifts and rotations information

Return type:

pandas.DataFrame

ghosts.geom.translate_optic(optic_name, axis, distance, geom_id=1000000)[source]

Create a dictionary to translate a piece of optic along an axis

Parameters:
  • optic_name (string) – the name of an optical element

  • axis (string) – the name of the translation axis, in [x, y , z]

  • distance (float) – the value of the shift in meters

  • geom_id (int) – the id of the new geometry configuration

Returns:

geom – a geom_config dictionary for the application of the translation

Return type:

dict

ghosts.geom.rotate_optic(optic_name, axis, angle, geom_id=1000000)[source]

Rotate one optical element of a telescope given a list of Euler angles

Parameters:
  • optic_name (string) – the name of an optical element

  • axis (string) – the name of the rotation axis, usually y

  • angle (float) – the values of angle in degrees

  • geom_id (int) – the id of the new geometry configuration

Returns:

geom – a geom_config dictionary for the application of the rotation

Return type:

dict

ghosts.geom.build_translation_set(optic_name, axis, shifts_list, base_id=0)[source]

Build a set of geometries for the given list of translations

Parameters:
  • optic_name (string) – the name of an optical element

  • axis (string) – the name of the rotation axis, usually y

  • shifts_list (list of float) – the list of distances to scan in meters

  • base_id (int) – the id of the first geometry configuration created, following ids will be id+1

Returns:

geoms – a list of geometry configuration dictionaries

Return type:

list of geom_config

ghosts.geom.build_rotation_set(optic_name, axis, angles_list, base_id=0)[source]

Build a set of geometries for the given list of rotations

Parameters:
  • optic_name (string) – the name of an optical element

  • axis (string) – the name of the rotation axis, usually y

  • angles_list (list of float) – the list of angles to scan in degrees

  • base_id (int) – the id of the first geometry configuration created, following ids will be id+1

Returns:

geoms – a list of geometry configuration dictionaries

Return type:

list of geom_config

ghosts.geom.build_random_geom(max_angle=0.1, max_shift=0.001)[source]

Build a random geometry from a base geometry configuration

Parameters:
  • max_angle (float) – the maximum value of the rotation angle in degree

  • max_shift (floats) – the maximum value of the shift in meters

Returns:

rnd_geom – a random geometry

Return type:

geom.geom_configs

tweak optics interface

ghosts.tweak_optics

tweak_optics module

This module is used to build new telescope with a modified geometry from the default telescope read in the yaml file.

ghosts.tweak_optics.get_list_of_optics(telescope, debug=False)[source]

Get a simple list of optical elements from a batoid telescope

Todo

get_list_of_optics needs to better handle optics which are not of interest, e.g. fake baffle

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • debug (bool) – print debug information or not

Returns:

optics – a simple list of optical element names

Return type:

list of string objects

ghosts.tweak_optics.make_optics_reflective(telescope, coating='simple', r_frac=[0.02, 0.02, 0.15], debug=False)[source]

Applies a simple coating as a unique refraction index for each optical element surface

Todo

make_optics_reflective should implement wavelength dependent coating for each optical surface

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • coating (string) – use “simple” for simple coating, just one reflection fraction for all surfaces, or “smart” to set one coefficient per element type

  • r_frac (list of float) – the fraction of light that you wish surfaces to reflect, usually of the order of 0.02 use a list of 3 elements, for simple coating only the first one is used for smart coating all 3 are used for lens, filter and detector

  • debug (bool) – print debug information or not

ghosts.tweak_optics.get_optics_position(telescope, name, axis_i)[source]

Internal interface to get the position of an optical element given its name

Todo

get_optics_position should be a hidden internal interface

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • name (string) – the name of an optical element

  • axis_i (int) – the axis index in [0, 1, 2]

Returns:

position_i – the position along the axis index i

Return type:

float

ghosts.tweak_optics.get_optics_position_x(telescope, name)[source]

Proxy to get the position of an optical element along the x-axis

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • name (string) – the name of an optical element

Returns:

pos_x – the position along the axis x

Return type:

float

ghosts.tweak_optics.get_optics_position_y(telescope, name)[source]

Proxy to get the position of an optical element along the y-axis

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • name (string) – the name of an optical element

Returns:

pos_y – the position along the axis y

Return type:

float

ghosts.tweak_optics.get_optics_position_z(telescope, name)[source]

Proxy to get the position of an optical element along the z axis

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • name (string) – the name of an optical element

Returns:

pos_z – the position along the axis z

Return type:

float

ghosts.tweak_optics.rotate_optic(telescope, name, axis='y', angle=1, debug=False)[source]

Rotate one optical element of a telescope around a given axis and for a given rotation angle

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • name (string) – the name of an optical element

  • axis (string) – the name of the rotation axis, usually y

  • angle (float) – the value of the rotation angle in degrees

  • debug (bool) – print debug information if True

Returns:

rotated_telescope – a new telescope with a rotated optical element

Return type:

batoid.telescope

ghosts.tweak_optics.translate_optic(telescope, name, axis='x', distance=0.01)[source]

Translate one optical element of a telescope along a given axis and for a given length

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • name (string) – the name of an optical element

  • axis (string) – the name of the rotation axis, usually y

  • distance (float) – the value of the shift in meters

Returns:

rotated_telescope – a new telescope with a rotated optical element

Return type:

batoid.telescope

ghosts.tweak_optics.rotate_optic_vector(telescope, name, angles, verbose=False)[source]

Rotate one optical element of a telescope given a list of Euler angles

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • name (string) – the name of an optical element

  • angles (list of floats) – the values of Euler angles in degrees as a list,e.g. [0.1, 0.1, 0.1]

  • verbose (bool) – the verbose mode, true or false

Returns:

rotated_telescope – a new telescope with a rotated optical element

Return type:

batoid.telescope

ghosts.tweak_optics.translate_optic_vector(telescope, name, shifts)[source]

Translate an optical element of a telescope given a list of shifts along x, y and z axis

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • name (string) – the name of an optical element

  • shifts (list of floats) – the values of shifts in meters as a list for x, y and z axis, e.g. [0.001, 0.001, 0.001]

Returns:

rotated_telescope – a new telescope with a rotated optical element

Return type:

batoid.telescope

ghosts.tweak_optics.randomized_telescope(telescope, max_angle=0.1, max_shift=0.001, verbose=False)[source]

Randomly translates and rotates all optical elements of a telescope according to uniform distributions drown from the given a maximum rotation angle and shift.

Rotation angles are drawn from a uniform distribution in [-max_angle; +max_angle]

Translation values are drawn from a uniform distribution in [-max_shift; +max_shift]

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • max_angle (float) – the maximum value of the rotation angle in degree

  • max_shift (floats) – the maximum value of the shift in meters

  • verbose (bool) – the verbose mode, true or false

Returns:

rnd_telescope – a new telescope with randomized optics position and rotation

Return type:

batoid.telescope

ghosts.tweak_optics.tweak_telescope(telescope, geom_config)[source]

Tweak a telescope using rotations and shifts from a dictionary

Todo

tweak_telescope should preserve coating

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • geom_config (dict) – a dictionary with shifts and rotations for each optical element

Returns:

tweaked_telescope – a new telescope with tweaked optical elements

Return type:

batoid.telescope

ghosts.tweak_optics.build_telescope(yaml_geometry='../data/LSST_CCOB_r.yaml')[source]

Build a telescope from a geometry description

Parameters:

yaml_geometry (string) – a yaml telescope geometry

Returns:

telescope – a telescope with the given geometry

Return type:

batoid.telescope

ghosts.tweak_optics.build_telescope_at_600nm(yaml_geometry)[source]

Build the reference telescope from a yaml geometry.

Parameters:

yaml_geometry (string) – path to the yaml file with the reference geometry to be used.

Returns:

ref_telescope – the reference optical setup as defined in batoid with reflectivity at 600 nm

Return type:

batoid.telescope

ghosts.tweak_optics.build_telescope_from_geom(geom_config)[source]

Build the default telescope and tweak its optics given shifts and rotations from a geometry configuration

Parameters:

geom_config (dict) – a dictionary with shifts and rotations for each optical element

Returns:

tw_telescope – a telescope with the given geometry tweaks

Return type:

batoid.telescope

reflectivity interface

ghosts.reflectivity

reflectivity module

This module is used to read and handcraft wave length dependent reflectivity of the different optical element

ghosts.reflectivity.read_sensor_reflectivity(file_path='../data/sensor_reflectivity_qe_r+qe.xlsx')[source]

Reads sensor reflectivity from a spreadsheet and get back data formatted into a panda data frame

Parameters:

file_path (string) – the path to the spreadsheet containing sensor reflectivity data

Returns:

data_frame – a panda data frame with wavelength, reflectivity, Q.E. and Q.E. error

Return type:

pandas.DataFrame

ghosts.reflectivity.make_simple_coating(telescope, r_frac=[0.02, 0.02, 0.15], debug=False)[source]

Applies a simple coating as a unique refraction index for each optical element surface

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • r_frac (list of float) – a refraction index, usually of the order of 0.02

  • debug (bool) – print debug information or not

Returns:

coef – the reflexion coefficient applied

Return type:

float

ghosts.reflectivity.make_smart_coating(telescope, r_frac=[0.02, 0.02, 0.15], debug=False)[source]

Applies a different reflexion index for each element type lens, filter, detector

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • r_frac (list of float) – the fraction of light that you wish surfaces to reflect, usually of the order of 0.02 use a list of a unique element for simple coating, or of 3 elements for smart coating (lens, filter, detector)

  • debug (bool) – print debug information or not

simulator interface

ghosts.simulator

simulator module

This module provides tools to run full simulations from telescope geometries and beam configurations, some functions also run the full workflow to the beam spots data analysis.

ghosts.simulator.run_simulation(telescope, beam_config)[source]

Runs a ray tracing simulation of a light beam into the CCOB.

Takes a telescope optical object and a beam configuration as a dictionary, simulates the light beam through the optics and returns the full ray tracing, including ghosts and the beam as a vector of light ays

Parameters:
  • telescope (batoid.telescope) – the optical setup

  • beam_config (dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

Returns:

  • trace_full (OrderedDict of dict) – an ordered dictionary of dictionaries for incoming and outgoing rays for each optics interface, see batoid.optic.traceFull

  • forward_rays (list of batoid.RayVector) – a list of forward rays, as each item in list comes from one distinct path through the optic exiting in the forward direction. see batoid.optic.traceSplit

  • reverse_rays (list of batoid.RayVector) – the list of reverse rays, as each item in list comes from one distinct path through the optic exiting in the reverse direction., see batoid.optic.traceSplit

  • rays (batoid.RayVector) – the input light beam, generated by the beam functions see ghosts.beam.beam().

ghosts.simulator.run_and_analyze_simulation(telescope, geom_id, beam_config)[source]

Runs a ray tracing simulation of a light beam into the CCOB and analyze beam spots data.

Parameters:
  • telescope (batoid.telescope) – the optical setup

  • geom_id (int) – an integer corresponding to the id of the geometry of the telescope

  • beam_config (dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

Returns:

spots_data_frame – a pandas data frame with ghost spot data information, including beam and geometry configurations, see ghosts.analysis.make_data_frame()

Return type:

pandas.DataFrame

ghosts.simulator.run_simulation_from_configs(geom_config, beam_config)[source]

Runs a ray tracing simulation of a light beam into the CCOB.

Takes a telescope optical object and a beam configuration as a dictionary, simulates the light beam through the optics and returns the full ray tracing, including ghosts and the beam as a vector of light ays

Parameters:
  • geom_config (dict) – a dictionary with the geometry configuration, see ghosts.geom_configs.

  • beam_config (dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

Returns:

  • trace_full (OrderedDict of dict) – an ordered dictionary of dictionaries for incoming and outgoing rays for each optics interface, see batoid.optic.traceFull

  • forward_rays (list of batoid.RayVector) – a list of forward rays, as each item in list comes from one distinct path through the optic exiting in the forward direction. see batoid.optic.traceSplit

  • reverse_rays (list of batoid.RayVector) – the list of reverse rays, as each item in list comes from one distinct path through the optic exiting in the reverse direction., see batoid.optic.traceSplit

  • rays (batoid.RayVector) – the input light beam, generated by the beam functions see ghosts.beam.beam().

ghosts.simulator.run_full_simulation_from_configs(geom_config, beam_config)[source]

Runs and analyse a ray tracing simulation of a light beam into the CCOB.

Parameters:
  • geom_config (dict) – a dictionary with the geometry configuration, see ghosts.geom_configs.

  • beam_config (dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

Returns:

spots_data_frame – a pandas data frame with ghost spot data information, including beam and geometry configurations, see ghosts.analysis.make_data_frame()

Return type:

pandas.DataFrame

ghosts.simulator.run_and_analyze_simulation_for_configs_sets(geom_set, beam_set)[source]

Runs and analyze a ray tracing simulation of a light beam into the CCOB for a set of beam configurations and geometry configurations

Note that we first build a reference telescope and then tweak it at will, as building a telescope from yaml file is slow.

Parameters:
  • geom_set (list of dict) – a dictionary with the geometry configuration, see ghosts.geom_configs.

  • beam_set (list of dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

Returns:

spots_df_list – a list of pandas data frame with ghost spot data information, including beam configuration, see ghosts.analysis.make_data_frame()

Return type:

pandas.DataFrame

ghosts.simulator.run_and_analyze_simulation_for_configs_sets_parallel(geom_set, beam_set)[source]

Runs and analyze a ray tracing simulation of a light beam into the CCOB for a set of beam configurations and geometry configurations, multithread version.

Note that we first build a reference telescope and then tweak it at will, as building a telescope from yaml file is slow. Threading is done with a pool on beam configuration for each geometry.

Parameters:
  • geom_set (list of dict) – a dictionary with the geometry configuration, see ghosts.geom_configs.

  • beam_set (list of dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

Returns:

spots_df_list – a list of pandas data frame with ghost spot data information, including beam configuration, see ghosts.analysis.make_data_frame()

Return type:

pandas.DataFrame

ghosts.simulator.run_and_analyze_simulation_for_telescope_and_beam_set(telescope, geom_id, beam_set)[source]

Runs and analyze a ray tracing simulation of a light beam into the CCOB for a set of beam configurations given a telescope.

Note that we first build a reference telescope and then tweak it at will, as building a telescope from yaml file is slow. Threading is done with a pool on beam configuration for each geometry.

Parameters:
  • telescope (batoid.telescope) – the optical setup

  • geom_id (int) – an integer corresponding to the id of the geometry of the telescope

  • beam_set (list of dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

Returns:

spots_df_list – a list of pandas data frame with ghost spot data information, including beam configuration, see ghosts.analysis.make_data_frame()

Return type:

pandas.DataFrame

ghosts.simulator.full_rotation(telescope, optic_name='L2', axis='y', angle=0.1, beam_config={'beam_id': 1, 'n_photons': 1000, 'radius': 0.00125, 'wl': 5e-07, 'x_euler': 0.0, 'x_offset': 0.1, 'y_euler': 0.0, 'y_offset': 0, 'z_euler': 0.0, 'z_offset': 2.7974726}, debug=False)[source]

Runs a ray tracing simulation of a light beam into the CCOB with one of the optical element rotated.

Takes a telescope optical object, the name of an optical element and a rotation angle, and simulates the light beam through the optics and returns the full ray tracing, including ghosts and the beam as a vector of light ays

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • optic_name (string) – the name of the optical element to rotate

  • axis (string) – x, y, z as the rotation axis you wish

  • angle (float) – the rotation angle in degrees

  • beam_config (dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

  • debug (bool) – debug mode or not

Returns:

ghosts.simulator.full_rotation_L2(telescope, angle=0.1)[source]

Simple proxy to run a simulation with a rotation of L2, see ghosts.simulator.full_rotation()

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • angle (float) – the rotation angle in degrees

Returns:

ghosts.simulator.sim_scan_rotated_optic(telescope, optic_name, min_angle, max_angle, step_angle, ref_data_frame)[source]

Helper to run and plot a scan in one optical element rotation

Todo

sim_scan_rotated_optic should handle better reference data frame

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • optic_name (string) – the name of the optical element to rotate

  • min_angle (float) – the first rotation angle in degrees

  • max_angle (float) – the last rotation angle in degrees

  • step_angle (float) – the angle step size for the rotation in degrees

  • ref_data_frame (pandas.DataFrame) –

Returns:

  • merged_data_frame (pandas.DataFrame) – a`pandas` data frame with all the ghosts spot data information, for each telescope optics configuration, including beam configuration, see ghosts.analysis.make_data_frame()

  • scan_angles (list of floats) – the list of the rotation angles used for the scan

ghosts.simulator.full_translation(telescope, optic_name, axis, distance, beam_config={'beam_id': 1, 'n_photons': 1000, 'radius': 0.00125, 'wl': 5e-07, 'x_euler': 0.0, 'x_offset': 0.1, 'y_euler': 0.0, 'y_offset': 0, 'z_euler': 0.0, 'z_offset': 2.7974726})[source]

Runs a ray tracing simulation of a light beam into the CCOB, with one optical element translated.

Takes a telescope optical object, the name of an optical element, and a translation distance, simulates the light beam through the optics and returns the full ray tracing, including ghosts and the beam as a vector of light ays

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • optic_name (string) – the name of the optical element to rotate

  • axis (string) – x, y, z as the translation axis you wish

  • distance (float) – the distance in meters

  • beam_config (dict) – a dictionary with the light beam configuration, see ghosts.beam_configs.

Returns:

ghosts.simulator.sim_scan_translated_optic(telescope, optic_name, min_dist, max_dist, step_dist, ref_data_frame)[source]
Helper to run a set of ray tracing simulation of a light beam into the CCOB,

with one optical element translated along one axis of a set of difference distance

Takes a telescope optical object, the name of an optical element, and a range for the translation distances, simulates the light beam through the optics and returns the full ray tracing, including ghosts and the beam as a vector of light ays

Todo

sim_scan_translated_optic needs to better handle the reference data frame

Todo

sim_scan_translated_optic should take a list of distances rather than min, max, step

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • optic_name (string) – the name of the optical element to rotate

  • min_dist (float) – the start distance in meters

  • max_dist (float) – the stop distance in meters

  • step_dist (float) – the step size as a distance in meters

  • ref_data_frame (pandas.dataFrame) – a data frame with your ghosts spots reference data

Returns:

  • merged_data_frame (pandas.DataFrame) – a`pandas` data frame with all the ghosts spot data information, for each telescope optics configuration, including beam configuration, see ghosts.analysis.make_data_frame()

  • scan_values (list of floats) – the list of distance of translation used for the scan

ghosts.simulator.full_random_telescope_sim(telescope, max_angle, max_shift, beam_config)[source]
Runs a ray tracing simulation of a light beam into the CCOB, with optics with randomized positions

and rotation angles.

Takes a telescope optical object, the maximum value of the rotation angle and translation distance, and the beam configuration dictionary. Random distributions for the angle and distance are uniform.

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • max_angle (float) – the maximum value of the rotation angle, a value will be taken out of a uniform distribution in [-max_angle ; +max_angle]

  • max_shift (float) – the maximum value of the translation distance, a value will be taken out of a uniform distribution in [-max_shift ; +max_shift]

  • beam_config (dict) – a beam configuration dictionary

Returns:

ghosts.simulator.scan_dist_rotation(telescope, ref_data_frame, optic_name, axis, angles_list, r_scale=10)[source]

Run simulation to scan a given list of angles on one optic around an axis, and computes the reduced distance in 2D and 3D.

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • ref_data_frame (pandas.DataFrame) – the reference set of beam spots to compute distances to

  • optic_name (string) – the name of the optical element to rotate

  • axis (string) – x, y, z as the translation axis you wish

  • angles_list (list of float) – a list of angles to scan

  • r_scale (float) – the 3D distance scale factor to take into account the spots sizes

Returns:

  • angles_list (list of float) – the list of angles scanned

  • distances_2d (list of float) – the list of 2D reduced distance computed for each angle

  • distances_3d (list of float) – the list of 3D reduced distance computed for each angle

ghosts.simulator.scan_dist_translation(telescope, ref_data_frame, optic_name, axis, shifts_list, r_scale=10)[source]

Run simulation to scan a given list of shifts on one optic along an axis, and computes the reduced distance in 2D and 3D.

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • ref_data_frame (pandas.DataFrame) – the reference set of beam spots to compute distances to

  • optic_name (string) – the name of the optical element to translate

  • axis (string) – x, y, z as the translation axis you wish

  • shifts_list (list of float) – a list of shifts to scan

  • r_scale (float) – the 3D distance scale factor to take into account the spots sizes

Returns:

  • shifts_list (list of float) – a list of shifts to scan

  • distances_2d (list of float) – the list of 2D reduced distance computed for each angle

  • distances_3d (list of float) – the list of 3D reduced distance computed for each angle

ghosts.simulator.simulate_impact_points_for_beam_set(telescope, beam_set)[source]

Runs a ray tracing simulation of a light beam into the CCOB for a list of beam configurations

Parameters:
  • telescope (batoid.telescope) – the optical setup

  • beam_set (list of dict) – a list of dictionaries with the light beam configuration, see ghosts.beam_configs.

Returns:

  • data_frame (pandas.DataFrame) – a panda data frame with information on beam positions and main impact points

  • ——-

analysis interface

ghosts.analysis

analysis module

This module provides functions to analyze ghosts spots on the full focal plane, like getting ghosts positions and features, computing separations between ghosts spots, associating ghosts spots and computing distances between to sets of ghosts spots.

ghosts.analysis.get_full_light_on_camera(r_forward)[source]

Convert list of forward batoid ray vectors to list of impact points on camera

Parameters:

r_forward (list of batoid.RayVector) – a list of batoid RayVector with a bunch of rays propagated through the system.

Returns:

  • all_x (list) – list of x coordinates of all light rays impact points on the detector

  • all_y (list) – list of y coordinates of all light rays impact points on the detector

  • all_f (list) – list of fluxes coordinates of all light rays impact points on the detector

ghosts.analysis.get_ghost_name(ghost, debug=False)[source]

Just the name of a ghost spot as a tuple containing the names of the surface on which the first and second light reflection occured.

Parameters:
  • ghost (batoid.RayVector) – a batoid RayVector with a bunch of rays propagated through the system.

  • debug (bool) – debug mode or not

Returns:

ghost_name_tuple – name of the ghost as a tuple of strings, e.g. (‘Filter_entrance’, ‘L2_exit’) or (‘L2_entrance’, ‘L1_entrance’)

Return type:

tuple of strings

ghosts.analysis.get_ghost_stats(ghost)[source]

Compute some basic stats for a simulated ghost spot image

Todo

get_ghost_stats is only working on simulated images for now

Parameters:

ghost (batoid.RayVector) – A batoid RayVector with a bunch of rays propagated through the system.

Returns:

  • mean_x, std_x, mean_y, std_y (floats) – spot position with uncertainty as standard deviation in x and y

  • x_width, y_width (floats) – spot width in x and y

  • radius, radius_err (float) – beam spot radius from x and y widths, and an estimator of the uncertainty

  • weights_sum (float) – total flux as computed by batoid flux.sum()

  • mean_intensity (float) – average flux of all rays

  • spot_surface_mm2 (float) – spot surface, using x_width as the diameter

  • density_phot_mm2 (float) – density of photons per \(mm^2\), for one simulated photon, as the mean_intensity/spot_surface_mm2

ghosts.analysis.get_ghost_spot_data(i, ghost, p=100, wl=600)[source]

Get some basic information for a simulated ghost spot image

Todo

get_ghost_spot_data should be made wavelength dependent

Parameters:
  • i (int) – the ghost index, useful really only on simulated data

  • ghost (batoid.RayVector) – a batoid RayVector with a bunch of rays propagated through the system.

  • p (float) – beam power in nW to compute the photon density

  • wl (int) – the beam wavelength in nm

Returns:

ghost_spot_data – a dictionary with ghost spot information : index, name, pos_x, width_x, pos_x, width_y, surface, n_pixels, pixel_signal and photon_density

Return type:

dict

ghosts.analysis.map_ghost(ghost, ax, n_bins=100, dr=0.01)[source]

Builds a binned image, as a matplotlib.hexbin of a ghost

Parameters:
  • ghost (batoid.RayVector) – a batoid RayVector with a bunch of rays propagated through the system.

  • ax (matplotlib.axis) – an axis object to draw the histogram

  • n_bins (int) – the number of bins of the histogram, that is also the number of “pixel” of the “image”

  • dr (float) – the extra space around the ghost spot image, to get nice axis ranges

Returns:

ghost_map – a binned image (2D histogram) of the ghost on the detector plane

Return type:

matplotlib.axis.hexbin

ghosts.analysis.reduce_ghosts(r_forward)[source]

Builds a binned image, as a matplotlib.hexbin of a ghost

Parameters:

r_forward (batoid.RayVector) – a batoid RayVector with a bunch of rays propagated through the system.

Returns:

  • spots_data (list of dict) – a list of dictionaries of ghost spot data (position, radius, brightness)

  • ghost_maps (list of matplotlib.axis.hexbin) – a list of images of ghosts as 2D histograms

ghosts.analysis.make_data_frame(spots_data, beam_id=0, geom_id=0)[source]

Create a pandas data frame from the ghost spots data dictionary and a beam configuration.

Parameters:
  • spots_data (dict) – a dictionary with ghost spots data

  • beam_id (int) – a beam configuration id

  • geom_id (int) – a geometry configuration id

Returns:

data_frame – a panda data frame with ghost spot data information, including beam and geometry configuration ids

Return type:

pandas.DataFrame

ghosts.analysis.compute_ghost_separations(data_frame)[source]

Compute ghosts images separations and various ratios from a ghosts spot data frame

Todo

compute_ghost_separations remove main image from the distance since it’s saturated in data.

Parameters:

data_frame (pandas.DataFrame) – a ghost spots data frame

Returns:

data_frame – a pandas data frame with information on ghost spots data separations and ratios

Return type:

pandas.DataFrame

ghosts.analysis.compute_distance_spot_to_spot(df_slice_1, df_slice_2, radius_scale_factor=100)[source]

Compute a 3D geometric distance between 2 ghosts spots centers, considering the spot radius as the 3rd dimension.

Parameters:
  • df_slice_1 (pandas.DataFrame) – a ghost spots data frame slice, with one line corresponding to one ghost

  • df_slice_2 (pandas.DataFrame) – a ghost spots data frame slice, with one line corresponding to one ghost

  • radius_scale_factor (float) – as the radius is considered a 3rd dimension, we scale it to the same range as the x and y axis, e.g. the spot radius is 2.5 mm to scale to the 60 cm of the focal plane ~ 100

Returns:

  • dist_2d (float) – the distance between 2 spots for the 2D distance

  • dist_2d_err (float) – the error on that distance from the std error on the position centers and radius for the 2D distance

  • dist_3d (float) – the distance between 2 spots for the 3D distance

  • dist_3d_err (float) – the error on that distance from the std error on the position centers and radius for the 3D distance

ghosts.analysis.find_nearest_ghost(ghost_slice, ghosts_df, radius_scale_factor=100)[source]

Find the nearest ghost spot to a given ghost spot and report its distance with its error

This is done using both the 2D and 3D distances.

Parameters:
  • ghost_slice (pandas.DataFrame) – a ghost spots data frame slice, with one line corresponding to one ghost

  • ghosts_df (pandas.DataFrame) – a pandas data frame with information on ghost spots data separations and ratios

  • radius_scale_factor (float) – a kind of weight for the spot radius to be used in the distance computation

Returns:

  • index_of_min_2d (int) – the index in the data frame of the nearest ghost for the 2D distance

  • min_distance_2d (float) – distance of the given ghost spot to the nearest ghost spot for the 2D distance

  • min_distance_2d_err (float) – the uncertainty on the distance with the nearest ghost spot for the 2D distance

  • index_of_min_3d (int) – the index in the data frame of the nearest ghost for the 3D distance

  • min_distance_3d (float) – distance of the given ghost spot to the nearest ghost spot for the 3D distance

  • min_distance_3d_err (float) – the uncertainty on the distance with the nearest ghost spot for the 3D distance

ghosts.analysis.match_ghosts(ghosts_df_1, ghosts_df_2, radius_scale_factor=100)[source]

Match ghosts positions from two ghosts data frames

Parameters:
  • ghosts_df_1 (pandas.DataFrame) – a pandas data frame with information on ghost spots data separations and ratios

  • ghosts_df_2 (pandas.DataFrame) – a pandas data frame with information on ghost spots data separations and ratios

  • radius_scale_factor (float) – a kind of weight for the spot radius to be used in the distance computation

Returns:

ghosts_match – a pandas data frame with the indices of each ghost and nearest ghost, and the distance between the two

Return type:

pandas.DataFrame

ghosts.analysis.compute_reduced_distance(ghosts_match)[source]

Compute a kind of reduced distance between two lists of ghosts

\[L = \frac{\sqrt{\sum_{i=1}^{n} \frac{d(g_{s,i}, g_{r,k_i})^2}{\sigma_d(g_{s,i}, g_{r,k_i})^2}}}{n}\]
Parameters:

ghosts_match (pandas.DataFrame) – a data frame with information about matching ghosts spots, see match_ghosts

Returns:

reduced_distance – a reduced distance computed as the average of the square root of the sum of squared input distances divided by the square of the errors on the distance.

Return type:

float

ghosts.analysis.compute_2d_reduced_distance(ghosts_match)[source]

Compute a simple 2D reduced distance between two lists of ghosts

Parameters:

ghosts_match (pandas.DataFrame) – a data frame with information about matching ghosts spots, see match_ghosts

Returns:

reduced_distance – a reduced distance computed as the average of the square root of the sum of squared input distances divided

Return type:

float

ghosts.analysis.match_and_dist_2d(ref_df, fit_df)[source]

Match ghosts catalogs and compute 2D distance

Parameters:
  • ref_df (pandas.DataFrame) – reference ghost catalog

  • fit_df (pandas.DataFrame) – ghost catalog from the fit

Returns:

dist_2d – 2D distance between the two ghosts catalogs

Return type:

double

ghosts.analysis.compute_uber_distance_2d(spots_df_list, ordered_fit_df)[source]

Compute a simple 2D reduced distance between two lists of ghosts

Parameters:
  • spots_df_list (list[pandas.DataFrame]) – list of data frame of ghosts spots

  • ordered_fit_df (list[pandas.DataFrame]) – list of data frame of ghosts spots

Returns:

uber_dist – Uber distance between 2 list of ghosts matches

Return type:

float

plotter interface

ghosts.plotter

plotter module

This module provides functions to plot every single thing that the ghosts module produces.

ghosts.plotter.plot_setup(telescope, simulation)[source]

Plots a standard CCOB optical setup, including wide and close views on the beam and the image obtained on the full focal plane through the simulation

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • simulation (list of rays from the simulation) – a list with like this [trace_full, forward_rays, rReverse, rays], r_reverse is not used. This list is provided by the output of ghosts.simulator.run_simulation()

Returns:

0 – 0 if all is well

Return type:

0

ghosts.plotter.plot_setup_3d(telescope, simulation)[source]

Plots a CCOB optical setup for standard projection XZ and a 3D view

Parameters:
  • telescope (batoid.telescope) – the optical setup as defined in batoid

  • simulation (list of rays from the simulation) – a list with like this [trace_full, forward_rays, rReverse, rays], r_reverse is not used. This list is provided by the output of ghosts.simulator.run_simulation()

Returns:

0 – 0 if all is well

Return type:

0

ghosts.plotter.plot_zoom_on_ghosts(forward_rays)[source]

Plots the 2D image of the focal plane, and its projection along the x-axis

Parameters:
  • forward_rays (list of batoid.RayVector) – a list of forward rays, as each item in list comes from one distinct path through the optic exiting in the forward direction. see batoid.optic.traceSplit

  • todo:: (..) – plot_zoom_on_ghosts should automatically zoom on the ghosts, if possible

Returns:

0 – 0 if all is well

Return type:

0

ghosts.plotter.plot_full_camera(forward_rays, log_scale=False)[source]

Plots the 2D image of the full focal plane

Parameters:
  • forward_rays (list of batoid.RayVector) – a list of forward rays, as each item in list comes from one distinct path through the optic exiting in the forward direction. see batoid.optic.traceSplit

  • log_scale (bool) – set to True to have a log color scale on the z-axis

Returns:

0 – 0 if all is well

Return type:

0

ghosts.plotter.plot_ghosts_map(forward_rays)[source]

Plots a canvas with thumbnails of each one of the 37 possible images of the input beam on the focal plane, a.k.a. ghosts map.

Parameters:

forward_rays (list of batoid.RayVector) – a list of forward rays, as each item in list comes from one distinct path through the optic exiting in the forward direction. see batoid.optic.traceSplit

Returns:

spots_data – a list of dictionaries of ghost spot data (position, radius, brightness)

Return type:

list of dict

ghosts.plotter.plot_spots_stats(data_frame)[source]

Plots overall ghosts image spots statistics

Parameters:

data_frame (pandas.DataFrame) – a pandas data frame with ghost spots data information, including beam configuration

Returns:

  • fig (matplotlib.Figure) – the matplotlib figure object

  • axs (matplotlib.Axis) – the list of matplotlib axis

ghosts.plotter.plot_ghosts_spots_distances(ghosts_separations)[source]

Plots distances, ghost to ghost centers and borders

Parameters:

ghosts_separations (pandas.DataFrame) – a pandas data frame with information on ghost spots data separations and ratios

Returns:

ax – the list of matplotlib axis

Return type:

matplotlib.Axis

ghosts.plotter.plot_ghosts_displacements(merged_data_frame)[source]

Plots a histogram of the displacement of all the ghosts along the x axis

Parameters:

merged_data_frame (pandas.DataFrame) – a pandas data frame with all the ghosts spot data information, for each telescope optics configuration, including beam configuration, see ghosts.analysis.make_data_frame() and ghosts.sim_scan_translated_optic()

Returns:

ax – the matplotlib axis

Return type:

matplotlib.Axis

ghosts.plotter.plot_max_displacement_for_sim_scan(merged_data_frame, scan_values, trans_type='rotation')[source]

Plots the value of the maximum displacement among all the ghosts for a series of translated or rotated telescope simulations, see ghosts.sim_scan_translated_optic().

A linear fit is also done and plotted with its residuals.

Parameters:
  • merged_data_frame (pandas.DataFrame) – a pandas data frame with all the ghosts spot data information, for each telescope optics configuration, including beam configuration, see ghosts.analysis.make_data_frame() and ghosts.sim_scan_translated_optic()

  • scan_values (list of floats) – the list of angles or shifts of the simulation scan

  • trans_type (string) – the transformation type is either ‘rotation’ or ‘translation’

Returns:

0 – 0 if all is well

Return type:

0

ghosts.plotter.plot_spots(data_frame_list, spot_size_scaling=10, range_x=(- 0.35, 0.35), range_y=(- 0.35, 0.35))[source]

Plot spots positions and size from a list of data frames

Each data frame has a different marker color.

Parameters:
  • data_frame_list (list of pandas.dataframe) – a list of data frame with spots positions and radius, e.g. from make_data_frame

  • spot_size_scaling (int) – a scaling factor to see large or small circles

  • range_x (tuple of floats) – min and max of the x-axis in meters, default is full camera

  • range_y (tuple of floats) – min and max of the y-axis in meters, default is full camera

Returns:

  • fig (matplotlib.Figure) – the figure object

  • ax (matplotlib.Axis) – the axis object

ghosts.plotter.plot_full_camera_and_spots(forward_rays, data_frame, log_scale=False, spot_size_scaling=10)[source]

Plots the 2D image of the full focal plane

Parameters:
  • forward_rays (list of batoid.RayVector) – a list of forward rays, as each item in list comes from one distinct path through the optic exiting in the forward direction. see batoid.optic.traceSplit

  • data_frame (pandas.dataframe) – a data frame with spots positions and radius, e.g. from make_data_frame

  • log_scale (bool) – set to True to have a log color scale on the z-axis

  • spot_size_scaling (int) – a scaling factor to see large or small circles

Returns:

0 – 0 if all is well

Return type:

0

ghosts.plotter.plot_distances_for_scan(scan_values, distances_2d, distances_3d, scan_type='rotation')[source]

Plot likelihood value and profile

Parameters:
  • scan_values (list of floats) – a list of angles or shifts in degrees

  • distances_2d (list of floats) – a list of reduced distances computed in 2D

  • distances_3d (list of floats) – a list of reduced distances computed in 3D

  • scan_type (string) – either rotation or translation

Returns:

  • fig (matplotlib.Figure) – the figure object

  • ax (matplotlib.Axis) – the axis object

ghosts.plotter.plot_impact_point_vs_beam_offset(data_frame)[source]

Plot likelihood value and profile

Parameters:

data_frame (pandas.DataFrame) – a panda data frame with information on beam positions and main impact points typically created with simulator.simulate_impact_points_for_beam_set

Returns:

  • fig (matplotlib.Figure) – the figure object

  • ax (matplotlib.Axis) – the axis object

ghosts.plotter.plot_beam_pointing_precision(data_frame, target_x, target_y)[source]

Plot beam pointing precision as histograms of the differences in position of the beam and the target

Parameters:
  • data_frame (pandas.DataFrame) – a panda data frame with information on beam positions and main impact points typically created with simulator.simulate_impact_points_for_beam_set

  • target_x (float) – the beam target position along x on the camera focal plane

  • target_y (float) – the beam target position along y on the camera focal plane

Returns:

  • fig (matplotlib.Figure) – the figure object

  • ax (matplotlib.Axis) – the axis object

ghosts.plotter.plot_impact_points_full_frame(data_frame)[source]

Plot impact point of a beam set on the full camera focal plane

Parameters:

data_frame (pandas.DataFrame) – a panda data frame with information on beam positions and main impact points typically created with simulator.simulate_impact_points_for_beam_set

Return type:

0

tools interface

ghosts.tools

Tools moduls

This module provides a number of generic tools.

ghosts.tools.get_default_yaml_path()[source]

Hack to find where the default yaml is, to be fixed properly

ghosts.tools.get_vector(axis, value)[source]

Returns a vector containing the given value at the right spot for the given axis

Parameters:
  • axis (string) – the name of the rotation axis, x, y or z

  • value (float) – the value of the rotation angle in degrees or of the shift in meters

Returns:

vector – a list containing value at the corresponding spot of the given axis

Return type:

list of floats

ghosts.tools.get_ranges(x, y, dr=0.01)[source]

Get x and y ranges around their mean values with a delta of dr

This is useful to center plots around a region of interest

Parameters:
  • x (numpy.array) – The input array along the x-axis

  • y (numpy.array) – The input array along the y-axis

  • dr (float) – The delta around the mean value, or the box size if you wish

Returns:

x_min, x_max, y_min, y_max – The min and max values for x- and y-axis, i.e. the box boundaries.

Return type:

a tuple of 4 floats

ghosts.tools.get_main_impact_point(r_forward)[source]

Return main image light rays

Direct path will be r_forward with fewest number of things in “path”

Todo

get_main_impact_point should compute a real barycentre?

Parameters:

r_forward (list of batoid.RayVector) – a list of batoid RayVector with a bunch of rays propagated through the system.

Returns:

  • i_straight (int) – the index of the main image

  • direct_x, direct_y (float, float) – the x and y coordinate of the center of the main image

  • direct_f (float) – the main image flux, relative to 1

ghosts.tools.unpack_geom_params(geom_params, geom_labels)[source]

Convert a list of geometry parameters into a dictionary as a telescope geometry configuration

Parameters:
  • geom_params (list) – an ordered list of parameters corresponding to a geometry configuration

  • geom_labels (list) – a list of the geometry parameter labels (names) matching the list above

Returns:

fitted_geom_config – a dictionary with the geometry of the telescope to fit

Return type:

dict