def tab1_update_CleanStrID(): global dftmp global ports if tab1_selected_StrID_entry: StrIDList = pd.read_json(event_dir + 'StrID_list_tmp.json') StrIDList = StrIDList.sort_values(by='timeran', ascending=1) StrID = StrIDList.iloc[tab1_selected_StrID_entry[0]] out_json = event_dir + StrID['str_id'][0] + '.json' StrID.to_json(out_json) struct_id = StrID['str_id'][0] + '/' FS_config = dumpCurrFS(StrID, {'cleanid': Text_CleanID.value, 'imfitid': ''}) FS_specfile = FS_config['datadir']['FS_specfile'] CleanIDdir = event_dir + struct_id + Text_CleanID.value + '/' print CleanIDdir if not os.path.exists(CleanIDdir): os.makedirs(CleanIDdir) FS_dspecDF = CleanIDdir + 'dspecDF-base' if not os.path.exists(FS_specfile): time0, time1 = StrID['time'][0], StrID['time'][1] freq0, freq1 = StrID['freq'][0], StrID['freq'][-1] bl = tab1_specdata['bl'] spec = tab1_specdata['spec'] npol = tab1_specdata['npol'] nbl = tab1_specdata['nbl'] ntim = tab1_specdata['ntim'] nfreq = tab1_specdata['nfreq'] tim = tab1_specdata['tim'][:] freq = tab1_specdata['freq'] / 1e9 timeidx0 = next(i for i in xrange(ntim) if tim[i] >= time0) timeidx1 = next(i for i in xrange(ntim - 1, -1, -1) if tim[i] <= time1) + 1 freqidx0 = next(i for i in xrange(nfreq) if freq[i] >= freq0) freqidx1 = next(i for i in xrange(nfreq - 1, -1, -1) if freq[i] <= freq1) + 1 spec = spec[:, :, freqidx0:(freqidx1 + 1), timeidx0:(timeidx1 + 1)] tim = tim[timeidx0:(timeidx1 + 1)] freq = freq[freqidx0:(freqidx1 + 1)] * 1.0e9 ntim = len(tim) nfreq = len(freq) np.savez(FS_specfile, spec=spec, tim=tim, freq=freq, bl=bl, npol=npol, nbl=nbl, nfreq=nfreq, ntim=ntim) if os.path.exists(FS_dspecDF): Text_CleanID.value = DButil.getcurtimstr() tab1_Div_Tb.text = """<p>CleanID existed. Click <b>FSview</b> to see the results or use the <b>new CleanID</b> to continue.</p>""" else: port = DButil.getfreeport() print 'bokeh serve {}DataBrowser/ToClean --show --port {} &'.format(suncasa_dir, port) os.system('bokeh serve {}DataBrowser/ToClean --show --port {} &'.format(suncasa_dir, port)) ports.append(port) tab1_Div_Tb.text = """<p>Check the <b>ToClean </b> in the <b>new tab</b></p>""" else: tab1_Div_Tb.text = """<p><b>Warning: No StrID selected. Select one StrID first!!!</b></p>"""
def tab1_selection_StrID_entry(attrname, old, new): global tab1_selected_StrID_entry global CleanIDdir, CleanIDdirdict tab1_selected_StrID_entry = tab1_SRC_StrIDPatch.selected['1d']['indices'] StrID = StrIDList.iloc[tab1_selected_StrID_entry[0]] struct_id = StrID['str_id'][0] + '/' in_path = event_dir + struct_id CleanIDdirdict = DButil.getlatestfile(directory=in_path) if CleanIDdirdict: tab1_Select_CleanID.options = [os.path.basename(ll) for ll in CleanIDdirdict['items']] tab1_Select_CleanID.value = os.path.basename(CleanIDdirdict['latest']) CleanIDdir = CleanIDdirdict['latest'] else: tab1_Select_CleanID.options = [] tab1_Select_CleanID.value = '' CleanIDdir = '' tab1_Div_FSview.text = """<p>Click <b>ToClean </b> to make synthesis images first!!</p>""" Text_CleanID.value = DButil.getcurtimstr()
height=config_main['plot_config']['tab_QLook']['StrID_DataTb_hght']) # , editable=True) tab1_Div_Tb = Div(text=""" """, width=config_main['plot_config']['tab_QLook']['StrID_DataTb_wdth']) tab1_Div_FSview = Div(text=""" """, width=config_main['plot_config']['tab_QLook']['StrID_DataTb_BUT_wdth']) tab1_Div_exit = Div(text=""" <p><b>Warning</b>: 1. Click the <b>Exit QLook</b> first before closing the tab</p> <p><b>Warning</b>: 2. <b>FSview</b> or <b>ToClean</b> tabs will disconnect if <b>Exit QLook is clicked</b></p>""", width=150) tab1_selected_dspec_square = None tab1_SRC_dspec_square.on_change('selected', tab1_SRC_dspec_square_select) tab1_input_StrID = TextInput(value="Type in here", title="New StrID:", **tab1_BUT_OPT2) Text_sdodir = TextInput(value=SDOdir, title="SDO Directory:", **tab1_BUT_OPT2) Text_CleanID = TextInput(value=DButil.getcurtimstr(), title="CleanID:", **tab1_BUT_OPT2) timestart = xx[0] tab1_selected_StrID_entry = None tab1_SRC_StrIDPatch.on_change('selected', tab1_selection_StrID_entry) But_sdodir = Button(label='Directory', **tab1_BUT_OPT2) But_sdodir.on_click(Buttonasksdodir_handler) tab1_BUT_addStrID = Button(label='Add', button_type='success', **tab1_BUT_OPT1) tab1_BUT_addStrID.on_click(tab1_update_addStrID) tab1_BUT_deleteStrID = Button(label='Delete', button_type='danger', **tab1_BUT_OPT1) tab1_BUT_deleteStrID.on_click(tab1_update_deleteStrID) tab1_BUT_saveStrID = Button(label='Save', button_type='primary', **tab1_BUT_OPT1) tab1_BUT_saveStrID.on_click(tab1_update_saveStrID)
text=""" """, width=config_main['plot_config']['tab_QLook']['StrID_DataTb_BUT_wdth']) tab1_Div_exit = Div(text=""" <p><b>Warning</b>: 1. Click the <b>Exit QLook</b> first before closing the tab</p> <p><b>Warning</b>: 2. <b>FSview</b> or <b>ToClean</b> tabs will disconnect if <b>Exit QLook is clicked</b></p>""", width=150) tab1_selected_dspec_square = None tab1_SRC_dspec_square.on_change('selected', tab1_SRC_dspec_square_select) tab1_input_StrID = TextInput(value="Type in here", title="New StrID:", **tab1_BUT_OPT2) Text_sdodir = TextInput(value=SDOdir, title="SDO Directory:", **tab1_BUT_OPT2) Text_CleanID = TextInput(value=DButil.getcurtimstr(), title="CleanID:", **tab1_BUT_OPT2) timestart = xx[0] tab1_selected_StrID_entry = None tab1_SRC_StrIDPatch.on_change('selected', tab1_selection_StrID_entry) But_sdodir = Button(label='Directory', **tab1_BUT_OPT2) But_sdodir.on_click(Buttonasksdodir_handler) tab1_BUT_addStrID = Button(label='Add', button_type='success', **tab1_BUT_OPT1) tab1_BUT_addStrID.on_click(tab1_update_addStrID) tab1_BUT_deleteStrID = Button(label='Delete', button_type='danger',