COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
target_init.py
1 
37 
38 import shesha.config as conf
39 
40 import shesha.constants as scons
41 from shesha.constants import CONST
42 
43 import numpy as np
44 from shesha.sutra_wrap import carmaWrap_context, Target, Target_brahma, Telescope
45 
46 
47 def target_init(ctxt: carmaWrap_context, telescope: Telescope, p_targets: list,
48  p_atmos: conf.Param_atmos, p_tel: conf.Param_tel,
49  p_geom: conf.Param_geom, dm=None, brahma=False):
50  """Create a cython target from parametres structures
51 
52  :parameters:
53  ctxt: (carmaWrap_context) :
54  telescope: (Telescope): Telescope object
55  p_targets: (lis of Param_target) : target_settings
56  p_atmos: (Param_atmos) : atmos settings
57  p_tel: (Param_tel) : telescope settings
58  p_geom: (Param_geom) : geom settings
59  dm: (Param_dm) : (optional) dm settings
60  brahma: (bool): (optional) brahma flag
61  :return:
62  tar: (Target): Target object
63  """
64  type_target = "atmos"
65 
66  if (p_targets is not None):
67  for p_target in p_targets:
68  if (p_target.dms_seen is None and dm is not None):
69  p_target.dms_seen = np.arange(len(dm))
70 
71  sizes = np.ones(len(p_targets), dtype=np.int64) * p_geom.pupdiam
72 
73  ceiled_pupil = np.ceil(p_geom._spupil)
74 
75  ceiled_pupil[np.where(ceiled_pupil > 1)] = 1
76 
77  if (p_target.apod == 1):
78  Npts = 0
79  # TODO apodizer, Npts=nb element of apodizer>0
80  ceiled_apodizer = np.ceil(p_geom._apodizer * p_geom._spupil)
81  ceiled_apodizer[np.where(ceiled_apodizer > 1)] = 1
82  Npts = np.sum(ceiled_apodizer)
83  else:
84  Npts = np.sum(ceiled_pupil)
85 
86  xpos = np.array([p_target.xpos for p_target in p_targets], dtype=np.float32)
87  ypos = np.array([p_target.ypos for p_target in p_targets], dtype=np.float32)
88  Lambda = np.array([p_target.Lambda for p_target in p_targets], dtype=np.float32)
89  mag = np.array([p_target.mag for p_target in p_targets], dtype=np.float32)
90  zerop = p_targets[0].zerop
91 
92  if (brahma):
93  target = Target_brahma(ctxt, "target_brahma", telescope, 0, len(p_targets), xpos,
94  ypos, Lambda, mag, zerop, sizes, Npts, ctxt.active_device)
95  else:
96  target = Target(ctxt, telescope, len(p_targets), xpos, ypos, Lambda, mag, zerop,
97  sizes, Npts, ctxt.active_device)
98 
99  # cc=i
100  for i in range(len(p_targets)):
101  p_target = p_targets[i]
102  if (p_atmos.nscreens > 0):
103  for j in range(p_atmos.nscreens):
104  xoff = p_target.xpos * CONST.ARCSEC2RAD * \
105  p_atmos.alt[j] / p_atmos.pupixsize
106  yoff = p_target.ypos * CONST.ARCSEC2RAD * \
107  p_atmos.alt[j] / p_atmos.pupixsize
108  xoff += float((p_atmos.dim_screens[j] - p_geom._n) / 2)
109  yoff += float((p_atmos.dim_screens[j] - p_geom._n) / 2)
110  pupdiff = (p_geom._n - p_geom.pupdiam) / 2
111  xoff += pupdiff
112  yoff += pupdiff
113  target.d_targets[i].add_layer(type_target, j, xoff, yoff)
114 
115  # if (y_dm != []) {
116  if (dm is not None):
117  # j=ddd
118  # for (ddd=1;ddd<=numberof(*y_target(cc).dms_seen);ddd++) {
119  for j in range(p_target.dms_seen.size):
120  # k=dd
121  # dd = (*y_target(cc).dms_seen)(ddd)
122  k = p_target.dms_seen[j]
123  dims = dm[k]._n2 - dm[k]._n1 + 1
124  dim = p_geom._mpupil[2].size
125  dim_dm = max(dim, dims)
126  xoff = p_target.xpos * CONST.ARCSEC2RAD * \
127  dm[k].alt / p_tel.diam * p_geom.pupdiam
128  yoff = p_target.ypos * CONST.ARCSEC2RAD * \
129  dm[k].alt / p_tel.diam * p_geom.pupdiam
130 
131  xoff += float((dim_dm - p_geom._n) / 2)
132  yoff += float((dim_dm - p_geom._n) / 2)
133 
134  pupdiff = (p_geom._n - p_geom.pupdiam) / 2
135  xoff += pupdiff
136  yoff += pupdiff
137 
138  # if (dm[k].type == scons.DmType.KL):
139  # xoff -= 2
140  # yoff -= 2
141  target.d_targets[i].add_layer(dm[k].type, k, xoff, yoff)
142 
143  target.d_targets[i].init_strehlmeter()
144 
145  return target
shesha.sutra_wrap
Definition: sutra_wrap.py:1
shesha.init.target_init.target_init
def target_init(carmaWrap_context ctxt, Telescope telescope, list p_targets, conf.Param_atmos p_atmos, conf.Param_tel p_tel, conf.Param_geom p_geom, dm=None, brahma=False)
Create a cython target from parametres structures.
Definition: target_init.py:61
shesha.constants
Numerical constants for shesha and config enumerations for safe-typing.
Definition: constants.py:1
shesha.config
Parameter classes for COMPASS.
Definition: shesha/shesha/config/__init__.py:1