COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
coronagraphCompass.py
1 
37 import numpy as np
38 import shesha.config as conf
39 import shesha.constants as scons
40 from carmaWrap import context
41 from shesha.supervisor.components.targetCompass import TargetCompass
42 from abc import ABC, abstractmethod
43 from shesha.util.coronagraph_utils import compute_contrast
44 
45 class CoronagraphCompass():
46  """ Class for Compass Coronagraph modules
47 
48  Attributes:
49  _spupil: (np.ndarray[ndim=2, dtype=np.float32]): Telescope pupil mask
50 
51  _pupdiam : (int): Number of pixels along the pupil diameter
52 
53  _dim_image :(int): Coronagraphic image dimension
54 
55  _p_corono: (Param_corono): Coronagraph parameters
56 
57  _target: (TargetCompass): Compass Target used as input for the coronagraph
58 
59  _norm_img : (float): Normalization factor for coronagraphic image
60 
61  _norm_psf : (float): Normalization factor for PSF
62 
63  _coronos: (Coronagraph): Coronagraph instances
64  """
65  def __init__(self):
66  """ Initialize a coronagraph instance with generic attributes
67 
68  Args:
69  p_corono: (Param_corono): Compass coronagraph parameters
70 
71  p_geom: (Param_geom): Compass geometry parameters
72 
73  targetCompass: (TargetCompass): Compass Target used as input for the coronagraph
74 
75  coroType: (CoronoType): type of coronagraph
76  """
77 
78  self._coronos_coronos = []
79 
80  def add_corono(self, context:context, p_corono: conf.Param_corono, p_geom: conf.Param_geom,
81  targetCompass: TargetCompass):
82  """ Add a coronagraph
83 
84  Args:
85  p_corono: (Param_corono): Compass coronagraph parameters
86 
87  p_geom: (Param_geom): Compass geometry parameters
88 
89  targetCompass: (TargetCompass): Compass Target used as input for the coronagraph
90  """
91  if(p_corono._type == scons.CoronoType.CUSTOM) or (p_corono._type == scons.CoronoType.SPHERE_APLC):
92  from shesha.supervisor.components.coronagraph.stellarCoronagraph import StellarCoronagraphCompass
93  self._coronos_coronos.append(StellarCoronagraphCompass(context, targetCompass, p_corono, p_geom))
94 
95  elif(p_corono._type == scons.CoronoType.PERFECT):
96  from shesha.supervisor.components.coronagraph.perfectCoronagraph import PerfectCoronagraphCompass
97  self._coronos_coronos.append(PerfectCoronagraphCompass(context, targetCompass, p_corono, p_geom))
98 
99  def compute_image(self, coro_index: int, *, comp_psf: bool = True, accumulate: bool = True):
100  """ Compute the SE coronagraphic image, and accumulate it in the LE image
101 
102  Args:
103  coro_index: (int): Index of the coronagraph
104 
105  comp_psf: (bool, optionnal): If True (default), also compute the PSF SE & LE
106 
107  accumulate: (bool, optional): If True (default), the computed SE image is accumulated in
108  long exposure
109  """
110  self._coronos_coronos[coro_index].compute_image(comp_psf=comp_psf, accumulate=accumulate)
111 
112  def compute_psf(self, coro_index: int, *, accumulate: bool = True):
113  """ Compute the SE psf, and accumulate it in the LE image
114 
115  Args:
116  coro_index: (int): Index of the coronagraph
117 
118  accumulate: (bool, optional): If True (default), the computed SE psf is accumulated in
119  long exposure
120  """
121  self._coronos_coronos[coro_index].compute_psf(accumulate=accumulate)
122 
123  def get_image(self, coro_index: int, *, expo_type:str=scons.ExposureType.LE):
124  """ Return the coronagraphic image
125 
126  Args:
127  coro_index: (int): Index of the coronagraph
128 
129  expo_type: (str, optional): If "le" (default), returns the long exposure image.
130  If "se", returns short exposure one.
131 
132  Return:
133  img: (np.ndarra[ndim=2,dtype=np.float32]): coronagraphic image
134  """
135  return self._coronos_coronos[coro_index].get_image(expo_type=expo_type)
136 
137  def get_psf(self, coro_index: int, *, expo_type:str=scons.ExposureType.LE):
138  """ Return the psf
139 
140  Args:
141  coro_index: (int): Index of the coronagraph
142 
143  expo_type: (str, optional): If "le" (default), returns the long exposure psf.
144  If "se", returns short exposure one.
145 
146  Return:
147  img: (np.ndarra[ndim=2,dtype=np.float32]): psf
148  """
149  return self._coronos_coronos[coro_index].get_psf(expo_type=expo_type)
150 
151  def reset(self, *, coro_index: int=None):
152  """ Reset long exposure image and PSF
153 
154  Args:
155  coro_index: (int): Index of the coronagraph to reset. If not provided, reset all coronagraphs
156  """
157  if coro_index is None:
158  for corono in self._coronos_coronos:
159  corono.reset()
160  else:
161  self._coronos_coronos[coro_index].reset()
162 
163  def get_contrast(self, coro_index, *, expo_type=scons.ExposureType.LE, d_min=None, d_max=None, width=None, normalized_by_psf=True):
164  """ Computes average, standard deviation, minimum and maximum of coronagraphic
165  image intensity, over rings at several angular distances from the optical axis.
166 
167  A ring includes the pixels between the following angular distances :
168  d_min + k * width - width / 2 and d_min + k * width + width / 2 (in lambda/D units)
169  with k = 0, 1, 2... until d_min + k * width > d_max (excluded).
170 
171  Args:
172  coro_index: (int): Index of the coronagraph
173 
174  expo_type: (str, optional): If "le" (default), computes contrast on the long exposure image.
175  If "se", it uses the short exposure one.
176 
177  d_min: (float, optional): Angular radius of the first ring in lambda/D unit.
178  Default = width
179 
180  d_max: (float, optional): Maximum angular distances in lambda/D unit.
181  Default includes the whole image.
182 
183  width: (float, optional): Width of one ring in lambda/D unit.
184  Default = 1 [lambda/D]
185 
186  normalized_by_psf: (bool, optional): If True (default), the coronagraphic image
187  is normalized by the maximum of the PSF
188 
189  Returns:
190  distances: (1D array): angular distances to the optical axis in lambda/D unit
191 
192  mean: (1D array): corresponding average intensities
193 
194  std: (1D array): corresponding standard deviations
195 
196  mini: (1D array): corresponding minimums
197 
198  maxi: (1D array): corresponding maximums
199  """
200  return self._coronos_coronos[coro_index].get_contrast(expo_type=expo_type, d_min=d_min, d_max=d_max,
201  width=width,
202  normalized_by_psf=normalized_by_psf)
203 
204  def set_electric_field_amplitude(self, coro_index, amplitude:np.ndarray):
205  """ Set the amplitude of the electric field
206 
207  Args:
208  coro_index: (int): Index of the coronagraph
209 
210  amplitude: (np.ndarray[ndim=3, dtype=np.float32]): amplitude for each wavelength
211  """
212  self._coronos_coronos[coro_index].set_electric_field_amplitude(amplitude)
def get_psf(self, int coro_index, *str expo_type=scons.ExposureType.LE)
Return the psf.
def compute_psf(self, int coro_index, *bool accumulate=True)
Compute the SE psf, and accumulate it in the LE image.
def add_corono(self, context context, conf.Param_corono p_corono, conf.Param_geom p_geom, TargetCompass targetCompass)
Add a coronagraph.
def get_contrast(self, coro_index, *expo_type=scons.ExposureType.LE, d_min=None, d_max=None, width=None, normalized_by_psf=True)
Computes average, standard deviation, minimum and maximum of coronagraphic image intensity,...
def set_electric_field_amplitude(self, coro_index, np.ndarray amplitude)
Set the amplitude of the electric field.
def compute_image(self, int coro_index, *bool comp_psf=True, bool accumulate=True)
Compute the SE coronagraphic image, and accumulate it in the LE image.
def reset(self, *int coro_index=None)
Reset long exposure image and PSF.
def get_image(self, int coro_index, *str expo_type=scons.ExposureType.LE)
Return the coronagraphic image.
Parameter classes for COMPASS.
Numerical constants for shesha and config enumerations for safe-typing.
Definition: constants.py:1