COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
util/writers/common/wfs.py
1 import numpy as np
2 import json
3 
4 def get_subap_pos_pixel(wfs):
5  """Return the coordinates of the valid subapertures of a given WFS
6 
7  these coordinates are given in pixels
8 
9  Args:
10  wfs : Param_wfs : wfs to get the subapertures position from
11 
12  Return:
13  valid_X : (np.ndarray[ndim=1, dtype=np.float64]) : subapertures positions along axis x
14 
15  valid_Y : (np.ndarray[ndim=1, dtype=np.float64]) : subapertures positions along axis y
16  """
17 
18  return wfs._validpuppixx-2 , wfs._validpuppixy-2
19 
20 
21 def get_subap_pos_meter(sup, wfs_id):
22  """Return the coordinates of the valid subapertures of a given WFS
23 
24  these coordinates are given in meters and centered
25 
26  Args:
27  sup : (compassSupervisor) : supervisor
28 
29  wfs_id : (int) : index of the WFS
30 
31  Return :
32  valid_X : (np.ndarray[ndim=1, dtype=np.float64]) : subapertures positions along axis x
33 
34  valid_Y : (np.ndarray[ndim=1, dtype=np.float64]) : subapertures positions along axis y
35  """
36 
37  config = sup.config
38  wfs = config.p_wfss[wfs_id]
39  geom = config.p_geom
40  valid_X, valid_Y = get_subap_pos_pixel(wfs)
41  total = geom.pupdiam/wfs.nxsub*(wfs.nxsub-1)
42  valid_X = (valid_X-total/2)*geom.get_pixsize()
43  valid_Y = (valid_Y-total/2)*geom.get_pixsize()
44  return valid_X, valid_Y
45 
46 
47 def wfs_to_json(wfs, geom, type, *, x_pos=None, y_pos=None):
48  """return a json description of a wfs
49 
50  Args:
51  wfs : (Param_wfs) : wfs to represent as json
52 
53  geom : (Param_geom) : geom settings
54 
55  type : (string) : wfs type ("lgs", "ngs" "target" or "ts")
56 
57  Kargs:
58  x_pos : (list(float)) : x coordinates of the targets ()
59 
60  y_pos : (list(float)) : y coordinates of the targets ()
61  """
62  types = ["lgs", "ngs", "target", "ts"]
63  if(type not in types):
64  ValueError("type must be one of "+str(types))
65 
66  wfs_json={}
67 
68  if(type == "ts"):
69  wfs_json = {
70  "nssp" : wfs[0].get_nxsub(),
71  "alphaX_as" : [w.get_xpos() for w in wfs],
72  "alphaY_as" : [w.get_ypos() for w in wfs]
73  }
74 
75  elif(type == "target"):
76  if(x_pos is None or len(x_pos) != len(y_pos)):
77  ValueError("pointing direction of WFS target must be provided (x_pos, y_pos)")
78  wfs_json = {
79  "nssp" : wfs.get_nxsub(),
80  "alphaX_as" : x_pos,
81  "alphaY_as" : y_pos
82  }
83 
84  else :
85  bdw = 3.3e-7
86  lgs_depth = 5000.
87  lgs_cst = 0.1
88  wfs_json = {
89  "nssp" : wfs.get_nxsub(),
90  "alphaX_as" : wfs.get_xpos(),
91  "alphaY_as" : wfs.get_ypos(),
92  "XPup" : wfs.get_dx() * geom.get_pixsize(),
93  "YPup" : wfs.get_dy() * geom.get_pixsize(),
94  "thetaML" : wfs.get_thetaML() ,
95  "thetaCam" : 0 ,
96  "sensitivity" : 0 ,
97  "pixSize" : wfs.get_pixsize(),
98  "lambdaWFS" : wfs.get_Lambda() ,
99  "bandwidth" : bdw ,
100  "throughput" : wfs.get_optthroughput() ,
101  "RON" : wfs.get_noise()
102  }
103 
104  if(wfs.get_gsalt()>0):
105  if(type == "ngs"):
106  ValueError("wfs is not a NGS (gsalt > 0)")
107 
108  wfs_json["lgsAlt"] = wfs.get_gsalt()
109  wfs_json["lgsDepth"] = lgs_depth
110  wfs_json["lgsFlux"] = wfs.lgsreturnperwatt * wfs.laserpower * \
111  wfs.optthroughput * 10**4
112  wfs_json["spotWidth"] = wfs.get_beamsize()
113  wfs_json["lgsCst"] = lgs_cst
114 
115  else:
116  if(type == "lgs"):
117  ValueError("wfs is not a LGS (gsalt == 0) ")
118  wfs_json["magnitude"] = wfs.get_gsmag()
119 
120  return wfs_json
121 
122 def wfs_json_notice(type):
123  """Return the notice of the wfs json representation
124 
125  Args:
126  type : (string) : wfs type ("lgs", "ngs" or "target")
127  """
128  if(type != "lgs" and type != "ngs" and type != "target"):
129  ValueError("type must be either \"lgs\", \"ngs\" or \"target\"")
130  if(type == "target"):
131  notice = {
132  "nssp" : " : number of subapertures along the diameter",
133  "alphaX_as" : " arcsec : list of pointing direction of the wfs (on x axis)",
134  "alphaY_as" : " arcsec : list of pointing direction of the wfs (on y axis)",
135  }
136  else :
137  notice = {
138  "nssp" : " : number of subapertures along the diameter",
139  "alphaX_as" : " arcsec : pointing direction of the wfs (on x axis)",
140  "alphaY_as" : " arcsec : pointing direction of the wfs (on y axis)",
141  "XPup" : " meter : pupil shift of the WFS (on axis x)",
142  "YPup" : " meter : pupil shift of the WFS (on axis y)",
143  "thetaML" : " radian : rotation of the camera",
144  "thetaCam" : " radian : rotation of the microlenses",
145  "sensitivity" : " : sensitivity coeff of this WFS",
146  "pixSize" : " arcsec : WFS pixel size",
147  "lambdaWFS" : " meter : WFS wavelength",
148  "bandwidth" : " meter : WFS bandwidth",
149  "throughput" : " percent : transmission for the GS",
150  "RON" : " nb of e- : Read Out Noise",
151  }
152  if(type == "lgs"):
153  notice["lgsAlt"] = " meter : laser guide star altitude"
154  notice["lgsDepth"] = " meter : laser guide star depth"
155  notice["lgsFlux"] = " (ph/m2/s) : LGS photon return at M1"
156  notice["spotWidth"] = " arcsec : lazer width"
157  notice["lgsCst"] = " : constant on lgs (simulate that LGS cannot measure tip-tilt and focus, for Linear Algebra purpose)"
158  if(type == "ngs"):
159  notice["magnitude"] = " : guide stars magnitude"
160 
161  return notice
def wfs_json_notice(type)
Return the notice of the wfs json representation.
def get_subap_pos_pixel(wfs)
Return the coordinates of the valid subapertures of a given WFS.
def wfs_to_json(wfs, geom, type, *x_pos=None, y_pos=None)
return a json description of a wfs
def get_subap_pos_meter(sup, wfs_id)
Return the coordinates of the valid subapertures of a given WFS.