Last active
August 29, 2015 14:22
-
-
Save ars096/973e20db71518a4827a3 to your computer and use it in GitHub Desktop.
zobs_tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zobs_tools | |
g1 = zobs_tools.forest_co_3line(1024, 3072, 64, 64) | |
print(g1.generate()) | |
g2 = zobs_tools.forest_co_3line(2048, 2048, 128, 64) | |
print(g2.generate()) | |
g3 = zobs_tools.forest_co_3line(1024, 3072, 64, 64) | |
print(g3.generate()) | |
g4 = zobs_tools.forest_co_3line_subarray(1024, 2048, 128, 128, 64, 64) | |
print(g4.generate()) | |
# ----- | |
# old ver | |
numch12 = 2048 | |
numch13 = 2048 | |
bin12 = 8 | |
bin13 = 8 | |
# -- | |
import zobs_tools | |
f12 = 115271202000.0 | |
f13 = 110201354000.0 | |
f18 = 109782173000.0 | |
forest = zobs_tools.receiver(105131482500, 15e9, 8e9) | |
f_if12a = forest.get_if(f12) | |
f_if13a = forest.get_if(f13) | |
f_if18a = forest.get_if(f18) | |
# -- | |
lo2_1 = f_if13a.if_freq | |
lo2_2 = f_if12a.if_freq | |
# -- | |
if_usb1 = zobs_tools.new_if_system(lo2_1) | |
if_usb2 = zobs_tools.new_if_system(lo2_2) | |
f_if12b = if_usb2.get_if(f_if12a) | |
f_if13b = if_usb1.get_if(f_if13a) | |
f_if18b = if_usb1.get_if(f_if18a) | |
spw1 = zobs_tools.sp_window(f_if12b.if_freq, numch12, bin12) | |
spw2 = zobs_tools.sp_window(f_if18b.if_freq, numch13, bin13) | |
a01 = zobs_tools.array(f12, forest, if_usb2, spw1) | |
# ----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from zobs import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f_12co = 115271202000.0 | |
f_13co = 110201354000.0 | |
f_c18o = 109782173000.0 | |
class forest_co_3line(object): | |
numch1 = 0 | |
numch2 = 0 | |
bin1 = 0 | |
bin2 = 0 | |
rx = None | |
newif = None | |
def __init__(self, numch1213=2048, numch18=2048, bin1213=64, bin18=64): | |
self.numch1 = numch1213 | |
self.numch2 = numch18 | |
self.bin1 = bin1213 | |
self.bin2 = bin18 | |
self.prepare() | |
pass | |
def prepare(self): | |
rx = receiver(105131482500, 15e9, 8e9) | |
f12 = rx.get_if(f_12co) | |
f13 = rx.get_if(f_13co) | |
f18 = rx.get_if(f_c18o) | |
lo2_12 = f12.if_freq | |
lo2_13 = f13.if_freq | |
if12 = new_if_system(lo2_12) | |
if13 = new_if_system(lo2_13) | |
f12 = if12.get_if(f12) | |
f13 = if13.get_if(f13) | |
f18 = if13.get_if(f18) | |
spw1 = sp_window(f12.if_freq, self.numch1, self.bin1) | |
spw2 = sp_window(f18.if_freq, self.numch2, self.bin2) | |
a = [None for i in range(32)] | |
for i in range(0, 16, 2): a[i] = array(f12, rx, if12, spw1) | |
for i in range(16, 32, 2): a[i] = array(f12, rx, if12, spw2) | |
for i in range(1, 16, 2): a[i] = array(f13, rx, if13, spw1) | |
for i in range(17, 32, 2): a[i] = array(f18, rx, if13, spw2) | |
self.array = a | |
self.spw1 = spw1 | |
self.spw2 = spw2 | |
self.if12 = if12 | |
self.if13 = if13 | |
return | |
def generate(self): | |
script = "\n" | |
script += "SET SAM45 REST_FREQ (%s)\n"%(','.join([a.rest_freq() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 OBS_BAND (%s)\n"%(','.join([a.obs_band() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 FQDAT_F0 (%s)\n"%(','.join([a.fqdat_f0() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 FQDAT_FQ (%s)\n"%(','.join([a.fqdat_fq() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 FQDAT_CH (%s)\n"%(','.join([a.fqdat_ch() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 CH_RANGE (%s)\n"%(','.join([a.ch_range() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 N_SPEC_WINDOW_SUB1 2\n" | |
script += "\n" | |
script += "SET SAM45 START_CHAN_SUB1 (%d,%d)\n"%(self.spw1.ch_start, self.spw2.ch_start) | |
script += "SET SAM45 END_CHAN_SUB1 (%d,%d)\n"%(self.spw1.ch_end, self.spw2.ch_end) | |
script += "SET SAM45 CHAN_AVG_SUB1 (%d,%d)\n"%(self.spw1.num_bin, self.spw2.num_bin) | |
script += "\n" | |
script += "2ndLO12: %.5f\n"%(self.if12.lo / 1e6) | |
script += "2ndLO13: %.5f\n"%(self.if13.lo / 1e6) | |
script += "\n" | |
return script | |
class forest_co_3line_subarray(object): | |
numch1 = 0 | |
numch2 = 0 | |
bin11 = 0 | |
bin12 = 0 | |
bin21 = 0 | |
bin22 = 0 | |
rx = None | |
newif = None | |
def __init__(self, nch1=2048, nch2=2048, bin11=64, bin12=64, bin21=64, bin22=64): | |
self.numch1 = nch1 | |
self.numch2 = nch2 | |
self.bin11 = bin11 | |
self.bin12 = bin12 | |
self.bin21 = bin21 | |
self.bin22 = bin22 | |
self.prepare() | |
pass | |
def prepare(self): | |
rx = receiver(105131482500, 15e9, 8e9) | |
f12 = rx.get_if(f_12co) | |
f13 = rx.get_if(f_13co) | |
f18 = rx.get_if(f_c18o) | |
lo2_12 = f12.if_freq | |
lo2_13 = f13.if_freq | |
if12 = new_if_system(lo2_12) | |
if13 = new_if_system(lo2_13) | |
f12 = if12.get_if(f12) | |
f13 = if13.get_if(f13) | |
f18 = if13.get_if(f18) | |
spw11 = sp_window(f12.if_freq, self.numch1, self.bin11) | |
spw12 = sp_window(f18.if_freq, self.numch1, self.bin12) | |
spw21 = sp_window(f12.if_freq, self.numch2, self.bin21) | |
spw22 = sp_window(f18.if_freq, self.numch2, self.bin22) | |
a = [None for i in range(32)] | |
for i in range(0, 8, 2): a[i] = array(f12, rx, if12, spw11) # sub 1, window 1 | |
for i in range(8, 16, 2): a[i] = array(f12, rx, if12, spw21) # sub 2, window 1 | |
for i in range(16, 24, 2): a[i] = array(f12, rx, if12, spw12) # sub 1, window 2 | |
for i in range(24, 32, 2): a[i] = array(f12, rx, if12, spw22) # sub 2, window 2 | |
for i in range(1, 9, 2): a[i] = array(f13, rx, if13, spw11) # sub 1, window 1 | |
for i in range(9, 17, 2): a[i] = array(f13, rx, if13, spw21) # sub 2, window 1 | |
for i in range(17, 25, 2): a[i] = array(f18, rx, if13, spw12) # sub 1, window 2 | |
for i in range(25, 33, 2): a[i] = array(f18, rx, if13, spw22) # sub 2, window 2 | |
self.array = a | |
self.spw11 = spw11 | |
self.spw12 = spw12 | |
self.spw21 = spw21 | |
self.spw22 = spw22 | |
self.if12 = if12 | |
self.if13 = if13 | |
return | |
def generate(self): | |
script = "\n" | |
script += "SET SAM45 REST_FREQ (%s)\n"%(','.join([a.rest_freq() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 OBS_BAND (%s)\n"%(','.join([a.obs_band() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 FQDAT_F0 (%s)\n"%(','.join([a.fqdat_f0() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 FQDAT_FQ (%s)\n"%(','.join([a.fqdat_fq() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 FQDAT_CH (%s)\n"%(','.join([a.fqdat_ch() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 CH_RANGE (%s)\n"%(','.join([a.ch_range() for a in self.array])) | |
script += "\n" | |
script += "SET SAM45 N_SPEC_WINDOW_SUB1 2\n" | |
script += "SET SAM45 N_SPEC_WINDOW_SUB2 2\n" | |
script += "\n" | |
script += "SET SAM45 START_CHAN_SUB1 (%d,%d)\n"%(self.spw11.ch_start, self.spw12.ch_start) | |
script += "SET SAM45 END_CHAN_SUB1 (%d,%d)\n"%(self.spw11.ch_end, self.spw12.ch_end) | |
script += "SET SAM45 CHAN_AVG_SUB1 (%d,%d)\n"%(self.spw11.num_bin, self.spw12.num_bin) | |
script += "\n" | |
script += "SET SAM45 START_CHAN_SUB2 (%d,%d)\n"%(self.spw21.ch_start, self.spw22.ch_start) | |
script += "SET SAM45 END_CHAN_SUB2 (%d,%d)\n"%(self.spw21.ch_end, self.spw22.ch_end) | |
script += "SET SAM45 CHAN_AVG_SUB2 (%d,%d)\n"%(self.spw21.num_bin, self.spw22.num_bin) | |
script += "\n" | |
script += "2ndLO12: %.5f\n"%(self.if12.lo / 1e6) | |
script += "2ndLO13: %.5f\n"%(self.if13.lo / 1e6) | |
script += "\n" | |
return script | |
class if_params(object): | |
rf_freq = 0.0 | |
if_freq = 0.0 | |
if_freq_list = list() | |
if_direction = 1 | |
lo_freq = list() | |
sideband = list() | |
def __init__(self, rf_freq): | |
self.rf_freq = rf_freq | |
self.if_freq = rf_freq | |
self.if_freq_list = [rf_freq] | |
self.lo_freq = [] | |
self.sideband = [] | |
pass | |
def add_transform(self, lo_freq): | |
self.lo_freq.append(lo_freq) | |
if lo_freq > self.if_freq: | |
self.sideband.append('LSB') | |
self.if_direction *= -1 | |
else: | |
self.sideband.append('USB') | |
pass | |
self.if_freq = abs(lo_freq - self.if_freq) | |
self.if_freq_list.append(self.if_freq) | |
return | |
def copy(self): | |
ifp = if_params(0) | |
ifp.rf_freq = self.rf_freq | |
ifp.if_freq = self.if_freq | |
ifp.if_direction = self.if_direction | |
ifp.if_freq_list = self.if_freq_list[:] | |
ifp.lo_freq = self.lo_freq[:] | |
ifp.sideband = self.sideband[:] | |
return ifp | |
class receiver(object): | |
lo1 = 0.0 | |
lo2 = 0.0 | |
lo2_thres = 0.0 | |
def __init__(self, lo1=None, lo2=None, lo2_thres=1e11): | |
self.lo1 = lo1 | |
self.lo2 = lo2 | |
self.lo2_thres = lo2_thres | |
pass | |
def get_if(self, rf_freq): | |
ifp = if_params(rf_freq) | |
ifp.add_transform(self.lo1) | |
if ifp.if_freq > self.lo2_thres: ifp.add_transform(self.lo2) | |
return ifp | |
class new_if_system(object): | |
lo = 0.0 | |
center_freq = 0.0 | |
def __init__(self, center_freq): | |
self.center_freq = center_freq | |
self.lo = center_freq + 3e9 | |
pass | |
def get_if(self, rf_output): | |
ifp = rf_output.copy() | |
ifp.add_transform(self.lo) | |
return ifp | |
class sp_window(object): | |
center_freq = 0.0 | |
num_ch = 0 | |
sp_res = 0 | |
num_bin = 0 | |
bandwidth = 0 | |
table_bin_res = {1: 3.81, 2: 7.63, 4: 15.26, 8: 30.52, 16: 61.04, | |
32: 122.07, 64: 244.14, 128: 488.24} | |
ch_start = 0 | |
ch_end = 0 | |
def __init__(self, center_freq, num_ch, spres_numbin): | |
self.center_freq = center_freq | |
self.num_ch = num_ch | |
num_bin, sp_res = self.check_bin_res(spres_numbin) | |
self.num_bin = num_bin | |
self.sp_res = sp_res | |
self.bandwidth = sp_res * 1e3 * num_ch | |
self.calc_ch() | |
pass | |
def check_bin_res(self, spres_numbin): | |
if type(spres_numbin)==int: | |
num_bin = spres_numbin | |
sp_res = self.table_bin_res[num_bin] | |
else: | |
num_bin = 0 | |
sp_res = 0 | |
pass | |
return num_bin, sp_res | |
def calc_ch(self): | |
if_offset = 2e9 | |
if_fullwidth = 2e9 | |
num_fullch = 2**19 | |
ch_unit = 8 * self.num_bin | |
cch = int(round((self.center_freq - if_offset) / if_fullwidth * num_fullch)) | |
sch = int(round((cch - (self.num_ch/2*self.num_bin)) / (ch_unit)) * ch_unit) | |
ech = sch + (self.num_ch * self.num_bin) - 1 | |
self.ch_start = sch | |
self.ch_end = ech | |
return | |
class array(object): | |
radio = if_params | |
rf = 0.0 | |
rx = receiver | |
newif = new_if_system | |
spw = sp_window | |
def __init__(self, radio, rx, newif, spw): | |
self.radio = radio | |
self.rf = radio.rf_freq | |
self.rx = rx | |
self.newif = newif | |
self.spw = spw | |
pass | |
def rest_freq(self): | |
return '%12.8E'%(self.rf) | |
def obs_freq(self): | |
return '' | |
def obs_band(self): | |
return '%7.2E'%(self.spw.bandwidth) | |
def fqdat_f0(self): | |
return '%12.8E'%(self.rf) | |
def fqdat_fq(self): | |
if self.radio.if_direction == 1: | |
start = self.rf - (self.spw.bandwidth/2.) | |
end = self.rf + (self.spw.bandwidth/2.) | |
else: | |
end = self.rf - (self.spw.bandwidth/2.) | |
start = self.rf + (self.spw.bandwidth/2.) | |
return '%12.8E,%12.8E'%(start, end) | |
def fqdat_ch(self): | |
start = 1 | |
end = self.spw.num_ch | |
return '%d,%d'%(start, end) | |
def ch_range(self): | |
start = 1 | |
end = self.spw.num_ch | |
return '%d,%d'%(start, end) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment