-
Notifications
You must be signed in to change notification settings - Fork 0
/
instrument_setup.py
166 lines (132 loc) · 6.57 KB
/
instrument_setup.py
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
import numpy as np
import healpy as hp
import ionRIME_funcs as irf
import os
import sys
import errno
import hera_NicCST_instrument_setup as hnis
import hera_CTP_instrument_setup as hcis
import hera_vivaldi_instrument_setup as hvis
import hera_nicsinuous_instrument_setup as hnsis
import hera_hfss_instrument_setup as hhis
import paper_hfss_instrument_setup as phis
import legacy_cst_instrument_setup as lcis
import sim_group_test0_instrument_setup as sgtest0
class InstrumentConstructor(object):
def __init__(self, parameters, antenna='a'):
for key in parameters:
setattr(self, key, parameters[key])
self.npix = hp.nside2npix(self.nside)
self.lmax = 3 * self.nside -1
self.nu_axis = np.linspace(self.nu_0, self.nu_f, num=self.nfreq, endpoint=True)
self.hpxidx = np.arange(self.npix)
self.l, self.m = hp.Alm.getlm(self.lmax)
attribute_test = getattr(self, 'z0_cza',None)
if attribute_test is None:
self.z0_cza = np.radians(120.7215) # latitude of HERA/PAPER
parameters.update({
'npix':self.npix,
'lmax':self.lmax,
'nu_axis': self.nu_axis,
'hpxidx': self.hpxidx,
'l': self.l,
'm': self.m,
'z0_cza': self.z0_cza})
if antenna == 'b':
if self.instrument_b != 'same':
self.antenna_model = self.instrument_b
else:
self.antenna_model = self.instrument
else:
self.antenna_model = self.instrument
nu0 = str(int(self.nu_axis[0] / 1e6))
nuf = str(int(self.nu_axis[-1] / 1e6))
self.fname = "ijones" + "band_" + nu0 + "-" + nuf + "mhz_nfreq" + str(self.nfreq)+ "_nside" + str(self.nside) + ".npy"
self.InstrumentDirectories = {
'hera_NicCST': 'jones_save/HERA_NicCST/',
'hera_ctp': 'jones_save/HERA_CTP/',
'hera_vivaldi': 'jones_save/HERA_Vivaldi/',
'hera_nicsinuous': 'jones_save/HERA_NicSinuous/',
'hera_hfss': 'jones_save/HERA_HFSS/',
'paper_hfss': 'jones_save/PAPER_HFSS/',
'paper_feko': 'jones_save/PAPER/',
'hera_legacy': 'jones_save/',
'analytic_dipole': 'analytic_dipole/',
'airy_dipole': 'jones_save/airy_dipole/',
'sim_group_test0': 'jones_save/sim_group_test0/'
}
self.relative_path = self.InstrumentDirectories[self.antenna_model] + self.fname
self.InstrumentGenerators = {
'hera_NicCST': self.hera_NicCST,
'hera_ctp': self.hera_ctp,
'hera_vivaldi': self.hera_vivaldi,
'hera_nicsinuous': self.hera_nicsinuous,
'hera_hfss': self.hera_hfss,
'paper_hfss': self.paper_hfss,
'paper_feko': self.paper_feko,
'hera_legacy': self.hera_legacy,
'analytic_dipole': self.analytic_dipole,
'airy_dipole': self.airy_dipole,
'sim_group_test0': self.sim_group_test0,
}
try:
os.makedirs(self.InstrumentDirectories[self.antenna_model])
except OSError as e:
if e.errno != errno.EEXIST:
raise
if os.path.exists(self.relative_path) is True:
self.iJonesModel = np.load(self.relative_path)
print "Restored Jones model"
else:
self.iJonesModel = self.InstrumentGenerators[self.antenna_model](parameters)
if self.antenna_model != 'analytic_dipole':
np.save(self.relative_path, self.iJonesModel)
def hera_NicCST(self, parameters):
ijones, solid_angle, peak_norms = hnis.make_ijones_spectrum(parameters, verbose=True)
nu0 = str(int(self.nu_axis[0] / 1e6))
nuf = str(int(self.nu_axis[-1] / 1e6))
fname = "norms_ijones" + "band_" + nu0 + "-" + nuf + "mhz_nfreq" + str(self.nfreq)+ "_nside" + str(self.nside) + '.npz'
save_path = self.InstrumentDirectories[self.antenna_model] + fname
np.savez(save_path, solid_angle=solid_angle, peak_norms=peak_norms)
return ijones
def hera_ctp(self, parameters):
ijones, solid_angle, peak_norms = hcis.make_ijones_spectrum(parameters, verbose=True)
nu0 = str(int(self.nu_axis[0] / 1e6))
nuf = str(int(self.nu_axis[-1] / 1e6))
fname = "norms_ijones" + "band_" + nu0 + "-" + nuf + "mhz_nfreq" + str(self.nfreq)+ "_nside" + str(self.nside) + '.npz'
save_path = self.InstrumentDirectories[self.antenna_model] + fname
np.savez(save_path, solid_angle=solid_angle, peak_norms=peak_norms)
return ijones
def hera_vivaldi(self, parameters):
ijones, solid_angle, peak_norms = hvis.make_ijones_spectrum(parameters, verbose=True)
nu0 = str(int(self.nu_axis[0] / 1e6))
nuf = str(int(self.nu_axis[-1] / 1e6))
fname = "norms_ijones" + "band_" + nu0 + "-" + nuf + "mhz_nfreq" + str(self.nfreq)+ "_nside" + str(self.nside) + '.npz'
save_path = self.InstrumentDirectories[self.antenna_model] + fname
np.savez(save_path, solid_angle=solid_angle, peak_norms=peak_norms)
return ijones
def hera_nicsinuous(self, parameters):
ijones, solid_angle, peak_norms = hnsis.make_ijones_spectrum(parameters, verbose=True)
nu0 = str(int(self.nu_axis[0] / 1e6))
nuf = str(int(self.nu_axis[-1] / 1e6))
fname = "norms_ijones" + "band_" + nu0 + "-" + nuf + "mhz_nfreq" + str(self.nfreq)+ "_nside" + str(self.nside) + '.npz'
save_path = self.InstrumentDirectories[self.antenna_model] + fname
np.savez(save_path, solid_angle=solid_angle, peak_norms=peak_norms)
return ijones
def hera_hfss(self, parameters):
return hhis.make_ijones_spectrum(parameters, verbose=False)
def paper_hfss(self, parameters):
return phis.make_ijones_spectrum(parameters, verbose=True)
def paper_feko(self, parameters):
return irf.PAPER_instrument_setup(parameters, self.z0_cza)
def hera_legacy(self, parameters):
freqs = [x * 1e6 for x in range(140,171)] # Hz
Jdata = lcis.instrument_setup(self.z0_cza, freqs)
return lcis.interpolate_jones_freq(Jdata, freqs, interp_type=self.interp_type)
def analytic_dipole(self, parameters):
return irf.analytic_dipole_setup(self.nside, self.nfreq,sigma=self.dipole_hpbw, z0_cza=self.z0_cza)
def airy_dipole(self, parameters):
a = 14.6/2. # HERA dish radius ...or was it 14.0?
return irf.airy_dipole_setup(self.nside, self.nu_axis, a, z0_cza=self.z0_cza)
def sim_group_test0(self, parameters):
return sgtest0.make_ijones_spectrum(parameters)