COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
sysParams.py
1 import json
2 import numpy as np
3 from shesha.util.writers import common
4 
5 def write_json_sys_param(sup, *, wfss_indices=None, ts=False, dms_indices=None, file_name="./sys-params.json"):
6  """Return a json representation of the AO system
7 
8  Args:
9  sup : (CompassSupervisor) : supervisor to get the json representation from
10 
11  Kargs:
12  wfss_indices : (list(int)) : list of wfs indices added into the json
13 
14  dms_indices : (list(int)) : list of dm indices added into the json
15 
16  file_name : (str) : output file name
17  """
18 
19  if(wfss_indices is None):
20  wfss_indices = list(range(len(sup.config.p_wfss)))
21  elif(isinstance(wfss_indices,int)):
22  wfss_indices = list(range(wfss_indices))
23 
24  if(dms_indices is None):
25  dms_indices = list(range(len(sup.config.p_dms)))
26  elif(isinstance(dms_indices,int)):
27  dms_indices = list(range(dms_indices))
28 
29  # general
30  sys_json={
31  "diam" : {
32  "comment": " meter : telescope diameter",
33  "value" : sup.config.p_tel.get_diam()
34  },
35  "cobs" : {
36  "comment": " percent : central obscuration",
37  "value" : sup.config.p_tel.get_cobs()
38  },
39  "tFrame": {
40  "comment": " second : frame rate",
41  "value": sup.config.p_loop.ittime
42  },
43  "fracsub": {
44  "comment": "Minimal illumination fraction for valid subap",
45  "value": sup.config.p_wfss[0].get_fracsub()
46  },
47  "throughAtm": {
48  "comment": "percent : atmosphere transmission",
49  "value": 1.0
50  },
51  "tracking": {
52  "comment": "arcsec^2 : telescope tracking error parameters (x^2, y^2 and xy)",
53  "value": [
54  1.0,
55  1.0,
56  1.0
57  ]
58  }
59  }
60 
61  diam = sup.config.p_tel.get_diam()
62  geom = sup.config.p_geom
63  #WFSs
64  lgs_json = []
65  ngs_json = []
66  target_json = None
67  ts_json = None
68  for i in wfss_indices:
69  w = sup.config.p_wfss[i]
70  if w in sup.config.p_wfs_lgs:
71  lgs_json.append(common.wfs_to_json(w,geom,"lgs"))
72  elif w in sup.config.p_wfs_ngs:
73  if( i == (len(sup.config.p_wfss) - 1) ):
74  target_json = common.wfs_to_json(w,geom,"target",
75  x_pos = [t.xpos for t in sup.config.p_targets],
76  y_pos = [t.ypos for t in sup.config.p_targets] )
77  else:
78  ngs_json.append(common.wfs_to_json(w,geom,"ngs"))
79  if ts :
80  w = sup.config.p_wfs_ts
81  if(w[0].nxsub == 0):
82  argmax = np.array([sup.config.p_wfss[i].nxsub for i in wfss_indices]).argmax()
83  w[0].set_nxsub(sup.config.p_wfss[argmax].nxsub)
84  w[0].set_pdiam(sup.config.p_wfss[argmax]._pdiam)
85  ts_json = common.wfs_to_json(w,geom,"ts")
86 
87  wfs_json = {
88  "notice_lgs" : common.wfs_json_notice("lgs"),
89  "notice_ngs" : common.wfs_json_notice("ngs"),
90  "lgs" : lgs_json,
91  "ngs" : ngs_json,
92  "ts" : ts_json,
93  "target":target_json}
94 
95  sys_json["wfs"] = wfs_json
96 
97  #DMs
98  dm_json = []
99  for i in dms_indices:
100  d = sup.config.p_dms[i]
101  dm_json.append(common.dm_to_json(d, geom))
102  sys_json["dm"] = dm_json
103 
104  f = open(file_name, "w")
105  f.write(json.dumps({"instrument":sys_json},indent=4))
106  f.close()
def write_json_sys_param(sup, *wfss_indices=None, ts=False, dms_indices=None, file_name="./sys-params.json")
Return a json representation of the AO system.
Definition: sysParams.py:17