def intensity_export(): path = selectSaveFolder() if path == None: return dss = __DATASOURCE__.getSelectedDatasets() if len(dss) == 0: print 'Error: please select at least one data file.' prog_bar.max = len(dss) + 1 prog_bar.selection = 0 if len(dss) == 0: return fi = File(path) if not fi.exists(): if not fi.mkdir(): print 'Error: failed to make directory: ' + path return if eff_corr_enabled.value and eff_map.value != None \ and len(eff_map.value.strip()) > 0: map = lib.make_eff_map(df, str(eff_map.value)) else: map = None dss_idx = 0 for dinfo in dss: dss_idx += 1 prog_bar.selection = dss_idx df.datasets.clear() log('exporting ' + dinfo.location) ds = df[str(dinfo.location)] rds = silent_reduce(ds, map) masks = [] if reg_enabled.value : try: masks = Plot1.get_masks() except: pass if len(masks) == 0: if reg_list.value != None and reg_list.value.strip() != '': masks = str2mask(reg_list.value) vi = lib.v_intg(rds, masks) ir = lib.i_intg(vi) ir.copy_metadata_shallow(vi) ir.location = ds.location lib.i_export(ir, path) prog_bar.selection = dss_idx + 1 prog_bar.selection = 0 set_prof_value(SAVED_MASK_PRFN , str(reg_list.value)) set_prof_value(SAVED_EFFICIENCY_FILENAME_PRFN , str(eff_map.value)) save_pref() print 'Done'
def intensity_export(): path = selectSaveFolder() if path == None: return dss = __get_selected_files__() if len(dss) == 0: print 'Error: please select at least one data file.' prog_bar.max = len(dss) + 1 prog_bar.selection = 0 if len(dss) == 0: return fi = File(path) if not fi.exists(): if not fi.mkdir(): print 'Error: failed to make directory: ' + path return if eff_corr_enabled.value and eff_map.value != None \ and len(eff_map.value.strip()) > 0: map = lib.make_eff_map(df, get_calibration_path() + '/' + str(eff_map.value)) else: map = None dss_idx = 0 rfs = [] for dinfo in dss: dss_idx += 1 prog_bar.selection = dss_idx df.datasets.clear() log('exporting ' + dinfo) ds = df[str(dinfo)] rds = silent_reduce(ds, map) masks = [] if reg_enabled.value : try: masks = Plot1.get_masks() except: pass if len(masks) == 0: # if reg_list.value != None and reg_list.value.strip() != '': # masks = str2mask(reg_list.value) masks = get_mask_str() vi = lib.v_intg(rds, masks) ir = lib.i_intg(vi) ir.copy_metadata_shallow(vi) ir.location = ds.location rf = lib.i_export(ir, path) rfs.append(rf) prog_bar.selection = dss_idx + 1 prog_bar.selection = 0 set_pref_value(SAVED_MASK_PRFN , get_mask_str()) set_pref_value(SAVED_EFFICIENCY_FILENAME_PRFN , str(eff_map.value)) save_pref() # sname = 'Kowari_intensity_' + str(int(time.time() * 1000))[2:] + '.zip' # print 'compressing result in ' + sname # f_out = zipfile.ZipFile(path + '/' + sname, mode='w') # for rfn in rfs: # try: # f_out.write(rfn, arcname = rfn[rfn.rindex('/') + 1 :]) # except: # print 'failed to zip' # f_out.close() # f_out.close() # report_file(sname) zip_files(rfs, '/Kowari_int_' + str(int(time.time()))[2:] + '.zip') print 'Done'
def integration_export(): global INT_EXP_OPTIONS path = selectSaveFolder() if path == None: return dss = __get_selected_files__() if len(dss) == 0: print 'Error: please select at least one data file.' prog_bar.max = len(dss) + 1 prog_bar.selection = 0 if len(dss) == 0: return fi = File(path) if not fi.exists(): if not fi.mkdir(): print 'Error: failed to make directory: ' + path return if eff_corr_enabled.value and eff_map.value != None \ and len(eff_map.value.strip()) > 0: map = lib.make_eff_map(df, get_calibration_path() + '/' + str(eff_map.value)) else: map = None dss_idx = 0 rfs = [] for dinfo in dss: dss_idx += 1 prog_bar.selection = dss_idx df.datasets.clear() log('exporting ' + dinfo) ds = df[str(dinfo)] rds = silent_reduce(ds, map) masks = [] if exp_mask.value == INT_EXP_OPTIONS[0]: if reg_enabled.value : try: masks = Plot1.get_masks() except: pass if len(masks) == 0: # if reg_list.value != None and reg_list.value.strip() != '': # masks = str2mask(reg_list.value) masks = str2mask(get_mask_str()) c_masks = [] for m in masks: c_m = RectangleMask(True, -180, m.minY, 360, m.maxY - m.minY) c_masks.append(c_m) vi = lib.v_intg(rds, c_masks) vi.location = ds.location rf = lib.v_export(vi, path) rfs.append(rf) elif exp_mask.value == INT_EXP_OPTIONS[1]: vi = lib.v_intg(rds, masks) vi.location = ds.location rf = lib.v_export(vi, path) rfs.append(rf) else : idx = INT_EXP_OPTIONS.index(exp_mask.value) mask_group = make_mask_group(rds, idx) for mask in mask_group : vi = lib.v_intg(rds, [mask]) vi.location = ds.location rf = lib.v_export(vi, path) rfs.append(rf) prog_bar.selection = dss_idx + 1 prog_bar.selection = 0 # set_pref_value(SAVED_MASK_PRFN , str(reg_list.value)) set_pref_value(SAVED_MASK_PRFN , get_mask_str()) set_pref_value(SAVED_EFFICIENCY_FILENAME_PRFN , str(eff_map.value)) save_pref() # sname = 'Kowari_reduced_' + str(int(time.time() * 1000))[2:] + '.zip' # print 'compressing result in ' + sname # f_out = zipfile.ZipFile(path + '/' + sname, mode='w') # for rfn in rfs: # try: # f_out.write(rfn, arcname = rfn[rfn.rindex('/') + 1 :]) # except: # print 'failed to zip' # f_out.close() # f_out.close() # report_file(sname) zip_files(rfs, '/Kowari_rd_' + str(int(time.time()))[2:] + '.zip') print 'Done'
def reduce(): global DS global VI global IR old_id = -1 if not DS is None: old_id = DS.id li = __get_selected_files__() if len(li) == 0: open_error('Please select a file from the file source view.') return if Plot1.ndim is 0: Plot1.set_dataset(instance([2,2])) prog_bar.max = 5 prog_bar.selection = 1 df.datasets.clear() DS = df[str(li[0])] curr_idx = -1 if old_id == DS.id: curr_idx = ind_jump.value location = DS.location id = DS.id title = DS.title DS = DS.get_reduced(1) prog_bar.selection = 2 if eff_corr_enabled.value and eff_map.value != None \ and len(eff_map.value.strip()) > 0: log('running efficiency correction') map = lib.make_eff_map(df, get_calibration_path() + '/' + str(eff_map.value)) DS = lib.eff_corr(DS, map) prog_bar.selection = 3 if geo_corr_enabled.value : log('running geometry correction') DS = lib.geo_corr(DS, geo_corr_enabled.value) DS.location = location DS.id = id DS.title = title # Plot1.set_dataset(DS[0]) # Plot1.title = str(DS.id) + '_0' # Plot1.set_mask_listener(regionListener) masks = [] if reg_enabled.value : if len(Plot1.get_masks()) > 0: masks = Plot1.get_masks() else : # if reg_list.value != None and reg_list.value.strip() != '': # if reg_minX.value != None and reg_minX.value.strip() != '' and reg_maxX.value != None and reg_maxX.value.strip() != '' \ # reg_minY.value != None and reg_minY.value.strip() != '' reg_maxY.value != None and reg_maxY.value.strip() != '' # mask_str = 'I-1[' + reg_minX.value + ',' + reg_maxX.value + ',' + reg_minY.value + ',' + reg_maxY.value + ']' mask_str = get_mask_str() masks = str2maskstr(mask_str) for mask in masks: Plot1.add_mask_2d(float(mask[0]), float(mask[1]), \ float(mask[2]), float(mask[3]), mask[4]) masks = Plot1.get_masks() prog_bar.selection = 4 log('running vertical integration') VI = lib.v_intg(DS, masks) # Plot2.set_dataset(VI[0]) # Plot2.title = str(DS.id) + "_integration_0" ind_jump.options = range(DS.shape[0]) var_jump.options = DS.axes[0].tolist() if curr_idx == -1: ind_jump.value = 0 else: ind_jump.value = curr_idx update_plots(curr_idx) prog_bar.selection = 5 log('running intensity integration') IR = lib.i_intg(VI) prog_bar.selection = 5 Plot3.set_dataset(IR) Plot3.title = str(DS.id) + "_intensity" Plot3.set_mouse_listener(NavMouseListener()) Plot1.set_awt_mouse_listener(mouse_press_listener) Plot1.set_mask_listener(regionListener) prog_bar.selection = 0 # set_pref_value(SAVED_MASK_PRFN , str(reg_list.value)) set_pref_value(SAVED_MASK_PRFN , str(get_mask_str())) set_pref_value(SAVED_EFFICIENCY_FILENAME_PRFN, str(eff_map.value)) save_pref()
def export_images(): path = selectSaveFolder() if path == None: return dss = __DATASOURCE__.getSelectedDatasets() if len(dss) == 0: print 'Error: please select at least one data file.' fi = File(path) if not fi.exists(): if not fi.mkdir(): print 'Error: failed to make directory: ' + path return dss_idx = 0 prog_bar.max = len(dss) + 1 try: for dinfo in dss: dss_idx += 1 prog_bar.selection = dss_idx ds = df[str(dinfo.location)] if ds.ndim < 3: log('dimension of ' + str(ds.id) + ' is not supported') dname = ds.name if ds.ndim == 4: ds = ds.get_reduced(1) if par_eff.value and eff_map.value != None \ and len(eff_map.value.strip()) > 0: log('running efficiency correction') map = lib.make_eff_map(df, str(eff_map.value)) ds = lib.eff_corr(ds, map) if par_geo.value : log('running geometry correction') ds = lib.geo_corr(ds, par_geo.value) log('process ' + dname) idx = dname.find('.') if idx > 0: fn = dname[0:idx] fn = path + '/' + fn wt = int(math.log10(len(ds))) + 1 for i in xrange(len(ds)): log('\t frame ' + str(i)) if ds.ndim == 4: sl = ds[i, 0] elif ds.ndim == 3: sl = ds[i] elif ds.ndim == 2: sl = ds else: log('dimensions are not allowed for ' + dname) break if str(par_type.value) == 'ASCII' : ext = ('%0' + str(wt) + 'd.xyz') % i f = open(fn + '_' + ext, 'w') try: header = '#' header += get_line(sl.axes[1], 3) f.write(header) for line in sl: f.write(get_line(line, 3)) finally: f.close() else: pds = NXFactory.createHist2DDataset(sl.__iNXDataset__) HPLOT.setDataset(pds) HPLOT.getChart().setTitle(str(dname) + '_' + str(i)) ext = (('%0' + str(wt) + 'd.' + str(par_type.value)) % i) try: HPLOT.getXYPlot().getRenderer().getPaintScale().setColorScale(color_scale.Rainbow) except: pass HPLOT.saveImage(fn + '_' + ext, str(par_type.value)) finally: prog_bar.selection = 0 prog_bar.max = 0 log('Done')
def intensity_export(): path = selectSaveFolder() if path == None: return dss = __get_selected_files__() if len(dss) == 0: print 'Error: please select at least one data file.' prog_bar.max = len(dss) + 1 prog_bar.selection = 0 if len(dss) == 0: return fi = File(path) if not fi.exists(): if not fi.mkdir(): print 'Error: failed to make directory: ' + path return if eff_corr_enabled.value and eff_map.value != None \ and len(eff_map.value.strip()) > 0: map = lib.make_eff_map( df, get_calibration_path() + '/' + str(eff_map.value)) else: map = None dss_idx = 0 rfs = [] for dinfo in dss: dss_idx += 1 prog_bar.selection = dss_idx df.datasets.clear() log('exporting ' + dinfo) ds = df[str(dinfo)] rds = silent_reduce(ds, map) masks = [] if reg_enabled.value: try: masks = Plot1.get_masks() except: pass if len(masks) == 0: # if reg_list.value != None and reg_list.value.strip() != '': # masks = str2mask(reg_list.value) masks = get_mask_str() vi = lib.v_intg(rds, masks) ir = lib.i_intg(vi) ir.copy_metadata_shallow(vi) ir.location = ds.location rf = lib.i_export(ir, path) rfs.append(rf) prog_bar.selection = dss_idx + 1 prog_bar.selection = 0 set_pref_value(SAVED_MASK_PRFN, get_mask_str()) set_pref_value(SAVED_EFFICIENCY_FILENAME_PRFN, str(eff_map.value)) save_pref() # sname = 'Kowari_intensity_' + str(int(time.time() * 1000))[2:] + '.zip' # print 'compressing result in ' + sname # f_out = zipfile.ZipFile(path + '/' + sname, mode='w') # for rfn in rfs: # try: # f_out.write(rfn, arcname = rfn[rfn.rindex('/') + 1 :]) # except: # print 'failed to zip' # f_out.close() # f_out.close() # report_file(sname) zip_files(rfs, '/Kowari_int_' + str(int(time.time()))[2:] + '.zip') print 'Done'
def integration_export(): global INT_EXP_OPTIONS path = selectSaveFolder() if path == None: return dss = __get_selected_files__() if len(dss) == 0: print 'Error: please select at least one data file.' prog_bar.max = len(dss) + 1 prog_bar.selection = 0 if len(dss) == 0: return fi = File(path) if not fi.exists(): if not fi.mkdir(): print 'Error: failed to make directory: ' + path return if eff_corr_enabled.value and eff_map.value != None \ and len(eff_map.value.strip()) > 0: map = lib.make_eff_map( df, get_calibration_path() + '/' + str(eff_map.value)) else: map = None dss_idx = 0 rfs = [] for dinfo in dss: dss_idx += 1 prog_bar.selection = dss_idx df.datasets.clear() log('exporting ' + dinfo) ds = df[str(dinfo)] rds = silent_reduce(ds, map) masks = [] if exp_mask.value == INT_EXP_OPTIONS[0]: if reg_enabled.value: try: masks = Plot1.get_masks() except: pass if len(masks) == 0: # if reg_list.value != None and reg_list.value.strip() != '': # masks = str2mask(reg_list.value) masks = str2mask(get_mask_str()) c_masks = [] for m in masks: c_m = RectangleMask(True, -180, m.minY, 360, m.maxY - m.minY) c_masks.append(c_m) vi = lib.v_intg(rds, c_masks) vi.location = ds.location rf = lib.v_export(vi, path) rfs.append(rf) elif exp_mask.value == INT_EXP_OPTIONS[1]: vi = lib.v_intg(rds, masks) vi.location = ds.location rf = lib.v_export(vi, path) rfs.append(rf) else: idx = INT_EXP_OPTIONS.index(exp_mask.value) mask_group = make_mask_group(rds, idx) for mask in mask_group: vi = lib.v_intg(rds, [mask]) vi.location = ds.location rf = lib.v_export(vi, path) rfs.append(rf) prog_bar.selection = dss_idx + 1 prog_bar.selection = 0 # set_pref_value(SAVED_MASK_PRFN , str(reg_list.value)) set_pref_value(SAVED_MASK_PRFN, get_mask_str()) set_pref_value(SAVED_EFFICIENCY_FILENAME_PRFN, str(eff_map.value)) save_pref() # sname = 'Kowari_reduced_' + str(int(time.time() * 1000))[2:] + '.zip' # print 'compressing result in ' + sname # f_out = zipfile.ZipFile(path + '/' + sname, mode='w') # for rfn in rfs: # try: # f_out.write(rfn, arcname = rfn[rfn.rindex('/') + 1 :]) # except: # print 'failed to zip' # f_out.close() # f_out.close() # report_file(sname) zip_files(rfs, '/Kowari_rd_' + str(int(time.time()))[2:] + '.zip') print 'Done'
def reduce(): global DS global VI global IR old_id = -1 if not DS is None: old_id = DS.id li = __get_selected_files__() if len(li) == 0: open_error('Please select a file from the file source view.') return if Plot1.ndim is 0: Plot1.set_dataset(instance([2, 2])) prog_bar.max = 5 prog_bar.selection = 1 df.datasets.clear() DS = df[str(li[0])] curr_idx = -1 if old_id == DS.id: curr_idx = ind_jump.value location = DS.location id = DS.id title = DS.title DS = DS.get_reduced(1) prog_bar.selection = 2 if eff_corr_enabled.value and eff_map.value != None \ and len(eff_map.value.strip()) > 0: log('running efficiency correction') map = lib.make_eff_map( df, get_calibration_path() + '/' + str(eff_map.value)) DS = lib.eff_corr(DS, map) prog_bar.selection = 3 if geo_corr_enabled.value: log('running geometry correction') DS = lib.geo_corr(DS, geo_corr_enabled.value) DS.location = location DS.id = id DS.title = title # Plot1.set_dataset(DS[0]) # Plot1.title = str(DS.id) + '_0' # Plot1.set_mask_listener(regionListener) masks = [] if reg_enabled.value: if len(Plot1.get_masks()) > 0: masks = Plot1.get_masks() else: # if reg_list.value != None and reg_list.value.strip() != '': # if reg_minX.value != None and reg_minX.value.strip() != '' and reg_maxX.value != None and reg_maxX.value.strip() != '' \ # reg_minY.value != None and reg_minY.value.strip() != '' reg_maxY.value != None and reg_maxY.value.strip() != '' # mask_str = 'I-1[' + reg_minX.value + ',' + reg_maxX.value + ',' + reg_minY.value + ',' + reg_maxY.value + ']' mask_str = get_mask_str() masks = str2maskstr(mask_str) for mask in masks: Plot1.add_mask_2d(float(mask[0]), float(mask[1]), \ float(mask[2]), float(mask[3]), mask[4]) masks = Plot1.get_masks() prog_bar.selection = 4 log('running vertical integration') VI = lib.v_intg(DS, masks) # Plot2.set_dataset(VI[0]) # Plot2.title = str(DS.id) + "_integration_0" ind_jump.options = range(DS.shape[0]) var_jump.options = DS.axes[0].tolist() if curr_idx == -1: ind_jump.value = 0 else: ind_jump.value = curr_idx update_plots(curr_idx) prog_bar.selection = 5 log('running intensity integration') IR = lib.i_intg(VI) prog_bar.selection = 5 Plot3.set_dataset(IR) Plot3.title = str(DS.id) + "_intensity" Plot3.set_mouse_listener(NavMouseListener()) Plot1.set_awt_mouse_listener(mouse_press_listener) Plot1.set_mask_listener(regionListener) prog_bar.selection = 0 # set_pref_value(SAVED_MASK_PRFN , str(reg_list.value)) set_pref_value(SAVED_MASK_PRFN, str(get_mask_str())) set_pref_value(SAVED_EFFICIENCY_FILENAME_PRFN, str(eff_map.value)) save_pref()
def integration_export(): global INT_EXP_OPTIONS path = selectSaveFolder() if path == None: return dss = __DATASOURCE__.getSelectedDatasets() if len(dss) == 0: print 'Error: please select at least one data file.' prog_bar.max = len(dss) + 1 prog_bar.selection = 0 if len(dss) == 0: return fi = File(path) if not fi.exists(): if not fi.mkdir(): print 'Error: failed to make directory: ' + path return if eff_corr_enabled.value and eff_map.value != None \ and len(eff_map.value.strip()) > 0: map = lib.make_eff_map(df, str(eff_map.value)) else: map = None dss_idx = 0 for dinfo in dss: dss_idx += 1 prog_bar.selection = dss_idx df.datasets.clear() log('exporting ' + dinfo.location) ds = df[str(dinfo.location)] rds = silent_reduce(ds, map) masks = [] if exp_mask.value == INT_EXP_OPTIONS[0]: if reg_enabled.value : try: masks = Plot1.get_masks() except: pass if len(masks) == 0: if reg_list.value != None and reg_list.value.strip() != '': masks = str2mask(reg_list.value) c_masks = [] for m in masks: c_m = RectangleMask(True, -180, m.minY, 360, m.maxY - m.minY) c_masks.append(c_m) vi = lib.v_intg(rds, c_masks) vi.location = ds.location lib.v_export(vi, path) elif exp_mask.value == INT_EXP_OPTIONS[1]: vi = lib.v_intg(rds, masks) vi.location = ds.location lib.v_export(vi, path) else : idx = INT_EXP_OPTIONS.index(exp_mask.value) mask_group = make_mask_group(rds, idx) for mask in mask_group : vi = lib.v_intg(rds, [mask]) vi.location = ds.location lib.v_export(vi, path) prog_bar.selection = dss_idx + 1 prog_bar.selection = 0 set_prof_value(SAVED_MASK_PRFN , str(reg_list.value)) set_prof_value(SAVED_EFFICIENCY_FILENAME_PRFN , str(eff_map.value)) save_pref() print 'Done'