-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsimmer.py
More file actions
432 lines (375 loc) · 14.7 KB
/
simmer.py
File metadata and controls
432 lines (375 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#!/usr/bin/env python
"""simmer.py: Create a dash/plotly GUI for an interferometric imaging simulator."""
__author__ = "Urvashi R.V."
__email__ = "rurvashi@nrao.edu"
import dash
from dash import dcc
from dash import html
from dash.dependencies import Input, Output
#import dash_daq as daq
#import pandas as pd
import plotly.graph_objs as go
import numpy as np
import copy
import time
from calcsim import CalcSim
tel = CalcSim()
#prevconfig='YConfig'
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
#### Set up the Layout
app.layout = html.Div([
html.Div(
children=[
html.Div( [
html.H6(children='Array configuration'),
dcc.Dropdown(
id='config-dropdown',
options=[
{'label': 'Y', 'value': 'YConfig'},
{'label': 'Spiral', 'value': 'SpiralConfig'},
{'label': 'Circle', 'value': 'CircleConfig'},
{'label': 'T', 'value': 'TConfig'},
{'label': 'Random', 'value': 'RandomConfig'},
{'label': 'Random with Compact Core', 'value': 'RandomCoreConfig'}
],
value='YConfig'
),
dcc.Dropdown(
id='nant-dropdown',
options=[
# {'label': '1 antenna', 'value': '1'},
{'label': '12 antennas', 'value': '12'},
{'label': '32 antennas', 'value': '32'},
{'label': '60 antennas', 'value': '60'}
],
value='12'
),
] , style={'width': '30%', 'display': 'inline-block','vertical-align':'top','padding':'20px'}),
html.Div( [
#html.H6(children='Set up the observatory and sky geometry'),
# html.H6(children='Source Declination'),
# dcc.Input(
# id = 'declination-picker',
# placeholder='Enter a declination value...',
# value='+60.0'
# ),
# html.H6(children='Observatory Latitude'),
# dcc.Input(
# id = 'latitude-picker',
# placeholder='Enter a latitude value...',
# value='34.0'
# )
html.H6(children='Source Declination'), #,style={'fontSize': 14}),
dcc.Slider(
id='declination-picker',
min=-90,
max=+90,
value=60,
marks={str(dec):str(dec) for dec in np.arange(-90,+91, 30)},
step=1,
included=False,
updatemode='mouseup'
) ,
html.Br(),
html.H6(children='Observatory Latitude'),
dcc.Slider(
id='latitude-picker',
min=-90,
max=+90,
value=34,
marks={str(lat):str(lat) for lat in np.arange(-90,+91, 30)},
step=1,
included=False,
updatemode='mouseup'
)
], style={'width': '30%', 'display': 'inline-block','vertical-align':'top','padding':'20px'}) ,
html.Div( [
html.H6(children='Observation Hour-Angle Range'),
dcc.RangeSlider(
id='timerange-slider',
count=1,
min=-6.0,
max=+6.0,
value=[-1.0,+1.0],
marks={str(ha): str(ha) for ha in range(-6,7,1)},
step=0.5
) ,
html.Br(),
html.H6(children='Observation Bandwidth'),
dcc.RangeSlider(
id='freqrange-slider',
count=1,
min=1.0,
max=2.0,
value=[1.5,+1.5],
marks={str(ha): "%2.1f"%(ha) for ha in np.arange(1.0,2.1,0.1)},
step=0.1
)
] , style={'width': '30%', 'display': 'inline-block','vertical-align':'top','padding':'20px'})
],
),
html.Div(
children=[
html.Div( [ dcc.Graph(id='antenna-layout') ],
style={'width': '33%', 'display': 'inline-block','vertical-align':'top'}),
html.Div( [ dcc.Graph(id='uvcov-image') ],
style={'width': '33%', 'display': 'inline-block','vertical-align':'top'}),
html.Div( [ dcc.Graph(id='observed-image') ],
style={'width': '33%', 'display': 'inline-block','vertical-align':'top'})
],
),
html.Div(
children=[
html.Div( [
html.H6(children='Expand or shrink the array layout'),
dcc.Slider(
id='zoom-slider',
min=-1,
max=1,
value=0.0,
marks={
-0.5: { 'label': 'More Compact', 'style': {'color': 'black'}},
0.0: {'label': 'Normal', 'style': {'color': 'black'}},
0.5: {'label': 'More Extended' , 'style': {'color': 'black'}}
},
step=0.1,
included=False,
updatemode='mouseup'
)
], style={'width': '30%', 'display': 'inline-block','vertical-align':'top','padding':'20px'}),
html.Div( [
# html.H6(children='Pick data weighting scheme'),
# dcc.RadioItems(
# id='weighting-picker',
# options=[
# {'label': 'Natural', 'value': 'natural'},
# {'label': 'Robust', 'value': 'robust'},
# {'label': 'Uniform', 'value': 'uniform'}
# ],
# value='natural',
# labelStyle={'display': 'inline-block'}
# )
html.H6(children='Density Weighting'),
dcc.Slider(
id='weighting-picker',
min=0.5,
max=+3.7,
value=+3.5,
marks={
+0.7: { 'label': 'Uniform', 'style': {'color': 'black'}},
+3.5: {'label': 'Natural', 'style': {'color': 'black'}},
},
# marks={str(lat):str(lat) for lat in np.arange(+0.0,+3.0, 0.5)},
step=0.05,
included=False,
updatemode='mouseup'
)
], style={'width': '30%', 'display': 'inline-block','vertical-align':'top','padding':'20px'}),
html.Div( [
html.H6(children='Object to observe'),
dcc.RadioItems(
id='source-dropdown',
options=[
{'label': 'One Point Source', 'value': 'im2'},
{'label': 'Few Points', 'value': 'im1'},
{'label': 'Multi-Scale', 'value': 'im3'}
],
value='im1',
labelStyle={'display': 'inline-block'}
)
# html.H6(children='Object to observe'),
# dcc.Dropdown(
# id='source-dropdown',
# options=[
# {'label': 'Few Compact Sources', 'value': 'im1'},
# {'label': 'One Point Source', 'value': 'im2'},
# {'label': 'Multi-scale Structure', 'value': 'im3'}
# ],
# value='im1'
# )
], style={'width': '30%', 'display': 'inline-block','vertical-align':'top','padding':'20px'}),
],
)
]) #, style={'columnCount': 2})
#### Define all the callbacks here.
### Update the Antenna Layout plot
@app.callback(
[Output('antenna-layout', 'figure'),
Output('uvcov-image', 'figure'),
Output('observed-image', 'figure')],
[Input('config-dropdown', 'value'),
Input('timerange-slider', 'value'),
Input('freqrange-slider', 'value'),
Input('source-dropdown', 'value'),
Input('nant-dropdown', 'value'),
Input('zoom-slider', 'value'),
Input('declination-picker', 'value'),
Input('latitude-picker', 'value'),
Input('weighting-picker','value')
])
def update_figure(selected_config,
selected_has,
selected_fas,
selected_im,
selected_nant,
selected_zoom,
selected_declination,
selected_latitude,
selected_weighting):
ctx = dash.callback_context
# print 'Trig : ', ctx.triggered
# print 'States : ', ctx.states
# print 'Inputs : ', ctx.inputs
#Trig : [{'prop_id': u'config-dropdown.value', 'value': u'RandomConfig'}]
thischanged=None
if ctx.triggered[0]['prop_id'].count('config-dropdown'):
thischanged = 'config'
if ctx.triggered[0]['prop_id'].count('source-dropdown'):
thischanged = 'source'
if ctx.triggered[0]['prop_id'].count('timerange-slider'):
thischanged = 'timerange'
if ctx.triggered[0]['prop_id'].count('freqrange-slider'):
thischanged = 'freqrange'
if ctx.triggered[0]['prop_id'].count('zoom-slider'):
thischanged = 'antzoom'
if ctx.triggered[0]['prop_id'].count('nant-dropdown'):
thischanged = 'nant'
if ctx.triggered[0]['prop_id'].count('declination-picker'):
thischanged = 'declination'
if ctx.triggered[0]['prop_id'].count('latitude-picker'):
thischanged = 'latitude'
if ctx.triggered[0]['prop_id'].count('weighting-picker'):
thischanged = 'weighting'
#print 'This changed : ', thischanged
tim1 = time.time()
if thischanged=='config' or thischanged=='antzoom' or thischanged=='nant':
changeseed=True
if thischanged=='antzoom' or thischanged=='nant':
changeseed=False
if eval(selected_nant)==2:
selected_config='RandomConfig'
print("Using random locations for 2 antennas")
tel.calcAntList(configtype = selected_config,
zoom=2**selected_zoom,
changeseed=changeseed,
nant=eval(selected_nant))
# if thischanged=='antzoom':
# tel.scaleAntList(zoom=selected_zoom)
antlist = tel.getAntList()
antlocsX = antlist['EastLoc']
antlocsY = antlist['NorthLoc']
tim2 = time.time()
# print antlocsX, antlocsY
### Prepare contents of antenna layout plot
traces1=[]
traces1.append( go.Scatter(
x=antlocsX,
y=antlocsY,
text=selected_config,
mode='markers',
opacity=0.7,
marker={
'size': 15,
'line': {'width': 0.5, 'color': 'white'}
},
))
tim3 = time.time()
### Prepare contents of observed image.
### Slider callback too
if thischanged=='config' or thischanged=='timerange' or thischanged=='freqrange' or thischanged=='antzoom' or thischanged=='nant' or thischanged=='declination' or thischanged=='latitude' or thischanged=='weighting':
tel.makeUVcov(has=selected_has,
dec=selected_declination,
obslatitude=selected_latitude,
weighting=selected_weighting,
bwr=selected_fas)
tim4 = time.time()
traces3=[]
traces3.append( go.Heatmap(
z=tel.getUVcov() ))
## sky callback
if thischanged=='source':
tel.setsky(imtype=selected_im)
tim5 = time.time()
## Sim
tel.makeImage()
tim6 = time.time()
traces2=[]
traces2.append( go.Heatmap(
z=tel.getImage() ))
tim7=time.time()
# print 'Ant read time : ', tim2-tim1
# print 'Ant plot time : ', tim3-tim2
# print 'UVcov time : ', tim4-tim3
# print 'Source time : ', tim5-tim4
# print 'Observe time :', tim6-tim5
# print 'Make raster : ', tim7-tim6
# print 'Total time in callback : ', tim7-tim1, ' sec'
### Return list of outputs, sync'd with specification above
dispsize = 400
return [{
'data': traces1,
'layout': go.Layout(
xaxis={'title': 'X Position (m)','range':[-1000,1000]},
yaxis={'title': 'Y Position (m)','range':[-1000,1000]},
title="ARRAY CONFIGURATION",
width = dispsize, height = dispsize,
autosize = True
)
},
{
'data': traces3,
'layout': go.Layout(
xaxis={'title': 'Spatial frequency : U (pixels)'},
yaxis={'title': 'Spatial frequency : V (pixels)'},
title="SPATIAL FREQUENCY COVERAGE",
width = dispsize, height = dispsize,
autosize = True
)
},
{
'data': traces2,
'layout': go.Layout(
xaxis={'title': 'Right Ascension (pixels)'},
yaxis={'title': 'Declination (pixels)'},
title="OBSERVED IMAGE",
width = dispsize, height = dispsize,
autosize = True
)
}
]
#
#### Update the Observed Image
#@app.callback(
# Output('observed-image', 'figure'),
# [Input('timerange-slider', 'value')])
#def update_figure(timran):
#
# ### Slider callback too
# tel.makeUVcov(has=timran, dec=+50.0,obslatitude=34.0)
# ## sky callback
# tel.setsky()
# ## Sim
# tel.makeImage()
#
#
# traces=[]
# traces.append( go.Heatmap(
# z=tel.getImage() ))
#
# return {
# 'data': traces,
# 'layout': go.Layout(
# xaxis={'title': 'Right Ascension'},
# yaxis={'title': 'Declination'},
# width = 500, height = 500,
# autosize = False,
#
# # margin={'l': 10, 'b': 20, 't': 0, 'r': 0},
## legend={'x': 0, 'y': 1},
# hovermode='closest'
# )
# }
#### Start the App
if __name__ == '__main__':
app.run_server(debug=True, port=8000, host='127.0.0.1')