def uti_data_file_plot(self, _fname, _read_labels=1, _e=0, _x=0, _y=0, _graphs_joined=1): #data, mode, allrange = srw_ascii_load(fname) #data, mode, allrange, arLabels, arUnits = _file_load(_fname, _read_labels) data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load( _fname, _read_labels) #print(allrange) m = self._enum('T', 'V', 'H', 'E', 'HV', 'EV', 'EH', 'EHV') if mode == m.T: fig = self.__mode_T(data, allrange, arLabels, arUnits, _e, _x, _y) elif mode == m.V: fig = self.__mode_V(data, allrange) elif mode == m.H: fig = self.__mode_H(data, allrange) elif mode == m.E: fig = self.__mode_E(data, allrange, arLabels, arUnits) elif mode == m.HV: fig = self.__mode_HV(data, allrange, arLabels, arUnits, _x, _y, _graphs_joined) #elif mode==m.EV: # fig = __mode_EV(data,allrange) #elif mode==m.EH: # fig = __mode_EH(data,allrange) elif mode == m.EHV: fig = self.__mode_EHV(data, allrange, arLabels, arUnits, _e, _x, _y, _graphs_joined) return self._maybe_savefig(fig)
def read_srw_file(filename): data, mode, ranges, labels, units = srw_io.file_load(filename) data = np.array(data).reshape((ranges[8], ranges[5]), order='C') return {'data': data, 'shape': data.shape, 'mean': np.mean(data), 'total': np.sum(data), 'photon_energy': ranges[0], 'horizontal_extent': ranges[3:5], 'vertical_extent': ranges[6:8], # 'mode': mode, 'labels': labels, 'units': units}
def read_srw_file(filename): """ This function takes in an srw file and returns the beam data. This was adapted from srwl_uti_dataProcess.py file""" data, mode, ranges, labels, units = srw_io.file_load(filename) data = np.array(data).reshape((ranges[8], ranges[5]), order='C') ''' return {'data': data, 'shape': data.shape, 'mean': np.mean(data), 'photon_energy': ranges[0], 'horizontal_extent': ranges[3:5], 'vertical_extent': ranges[6:8], # 'mode': mode, 'labels': labels, 'units': units} ''' return data
def extract_simulation_data(filename): # usage: # data = extract_simulation_data('filename.txt') data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load(filename) # data, allrange, arLabels, arUnits are list return { 'initial_photon_energy': allrange[0], 'final_photon_energy': allrange[1], 'x_range': allrange[3:5], 'y_range': allrange[6:8], 'data_shape': (allrange[8], allrange[5]), 'mean_intensity': np.mean(data), 'photon_energy_unit': arUnits[0], 'position_unit': arUnits[1], 'photon_intensity_unit': arUnits[3], 'data': np.array(data).reshape((allrange[8], allrange[5]), order='C') }
def extract_report_data(filename, model_data): sValShort = 'Flux'; sValType = 'Flux through Finite Aperture'; sValUnit = 'ph/s/.1%bw' if 'models' in model_data and model_data['models']['fluxReport']['fluxType'] == 2: sValShort = 'Intensity' sValUnit = 'ph/s/.1%bw/mm^2' is_gaussian = False if 'models' in model_data and model_data['models']['simulation']['sourceType'] == 'g': is_gaussian = True files_3d = ['res_pow.dat', 'res_int_se.dat', 'res_int_pr_se.dat', 'res_mirror.dat', _MULTI_ELECTRON_FILENAME] file_info = { 'res_spec_se.dat': [['Photon Energy', 'Intensity', 'On-Axis Spectrum from Filament Electron Beam'], ['eV', _intensity_units(is_gaussian, model_data)]], 'res_spec_me.dat': [['Photon Energy', sValShort, sValType], ['eV', sValUnit]], 'res_pow.dat': [['Horizontal Position', 'Vertical Position', 'Power Density', 'Power Density'], ['m', 'm', 'W/mm^2']], 'res_int_se.dat': [['Horizontal Position', 'Vertical Position', '{photonEnergy} eV Before Propagation', 'Intensity'], ['m', 'm', _intensity_units(is_gaussian, model_data)]], #TODO(pjm): improve multi-electron label _MULTI_ELECTRON_FILENAME: [['Horizontal Position', 'Vertical Position', 'After Propagation', 'Intensity'], ['m', 'm', _intensity_units(is_gaussian, model_data)]], 'res_int_pr_se.dat': [['Horizontal Position', 'Vertical Position', '{photonEnergy} eV After Propagation', 'Intensity'], ['m', 'm', _intensity_units(is_gaussian, model_data)]], 'res_mirror.dat': [['Horizontal Position', 'Vertical Position', 'Optical Path Difference', 'Optical Path Difference'], ['m', 'm', 'm']], } data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load(filename) filename = os.path.basename(filename) title = file_info[filename][0][2] if '{photonEnergy}' in title: title = title.format(photonEnergy=model_data['models']['simulation']['photonEnergy']) info = { 'title': title, 'x_range': [allrange[0], allrange[1]], 'y_label': _superscript(file_info[filename][0][1] + ' [' + file_info[filename][1][1] + ']'), 'x_label': file_info[filename][0][0] + ' [' + file_info[filename][1][0] + ']', 'x_units': file_info[filename][1][0], 'y_units': file_info[filename][1][1], 'points': data, } if filename in files_3d: info = _remap_3d(info, allrange, file_info[filename][0][3], file_info[filename][1][2]) return info
def uti_data_file_plot(self, _fname, _read_labels=1, _e=0, _x=0, _y=0, _graphs_joined=1): #data, mode, allrange = srw_ascii_load(fname) #data, mode, allrange, arLabels, arUnits = _file_load(_fname, _read_labels) data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load(_fname, _read_labels) #print(allrange) m = self._enum('T','V','H','E','HV','EV','EH','EHV') if mode==m.T: fig = self.__mode_T(data, allrange, arLabels, arUnits, _e, _x, _y) elif mode==m.V: fig = self.__mode_V(data, allrange) elif mode==m.H: fig = self.__mode_H(data, allrange) elif mode==m.E: fig = self.__mode_E(data, allrange, arLabels, arUnits) elif mode==m.HV: fig = self.__mode_HV(data, allrange, arLabels, arUnits, _x, _y, _graphs_joined) #elif mode==m.EV: # fig = __mode_EV(data,allrange) #elif mode==m.EH: # fig = __mode_EH(data,allrange) elif mode==m.EHV: fig = self.__mode_EHV(data, allrange, arLabels, arUnits, _e, _x, _y, _graphs_joined) return self._maybe_savefig(fig)
def uti_plot_data_file( self, _fname, _read_labels=1, _e=0, _x=0, _y=0, _graphs_joined=1, #OC16112017 (renamed: uti_plot_data_file -> uti_plot_data_file) _multicolumn_data=False, _column_x=None, _column_y=None, #MR31102017 _scale='linear', _width_pixels=None): #data, mode, allrange = srw_ascii_load(fname) #data, mode, allrange, arLabels, arUnits = _file_load(_fname, _read_labels) #data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load(_fname, _read_labels) #data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load(_fname, _read_labels, _traj_report, _traj_axis) #MR20160729 #data = np.array(data) #MR27012017 (lines added until "pass") #if _scale != 'linear': # available_scales = ['log', 'log2', 'log10'] # if _scale not in available_scales: # raise ValueError('Scale "{}" is not supported. Available scales: {}.'.format(_scale, ', '.join(available_scales))) # data[np.where(data <= 0.)] = 1.e-23 # data = getattr(np, _scale)(data) #if _width_pixels: # try: # from scipy.ndimage import zoom # data = np.reshape(data, (allrange[5], allrange[8]), order='f') # resize_factor = float(_width_pixels) / float(allrange[5]) # print('Size before: {} Dimensions: {}'.format(data.size, data.shape)) # data = zoom(data, resize_factor) # if _scale == 'linear': # data[np.where(data < 0.)] = 0.0 # print('Size after : {} Dimensions: {}'.format(data.size, data.shape)) # allrange = list(allrange) # allrange[5] = data.shape[0] # allrange[8] = data.shape[1] # allrange = tuple(allrange) # data = np.reshape(data, (data.shape[0] * data.shape[1]), order='f') # except: # print('Cannot resize the image - scipy.ndimage.zoom() cannot be imported.') # pass data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load( _fname, _read_labels, _multicolumn_data) #MR31102017 if not _multicolumn_data: data = np.array(data) #if mode == 3: #OC17112017 (commented-out) # try: # fwhm_dict = uti_math.fwhm(np.linspace(allrange[0], allrange[1], allrange[2]), data, return_as_dict=True) # except: # fwhm_dict = {'fwhm': -1} # print('FWHM: {:.5f} [{}]'.format(fwhm_dict['fwhm'], arUnits[0])) if _scale != 'linear': available_scales = ['log', 'log2', 'log10'] if _scale not in available_scales: raise ValueError( 'Scale "{}" is not supported. Available scales: {}.'. format(_scale, ', '.join(available_scales))) data[np.where(data <= 0.)] = 1.e-23 data = getattr(np, _scale)(data) if _width_pixels: try: from scipy.ndimage import zoom data = np.reshape(data, (allrange[5], allrange[8]), order='C') resize_factor = float(_width_pixels) / float(allrange[5]) print('Size before: {} Dimensions: {}'.format( data.size, data.shape)) data = zoom(data, resize_factor) if _scale == 'linear': data[np.where(data < 0.)] = 0.0 print('Size after : {} Dimensions: {}'.format( data.size, data.shape)) allrange = list(allrange) allrange[5] = data.shape[0] allrange[8] = data.shape[1] allrange = tuple(allrange) data = np.reshape(data, (data.shape[0] * data.shape[1]), order='C') except: print( 'Cannot resize the image - scipy.ndimage.zoom() cannot be imported.' ) pass #print(allrange) m = self._enum('T', 'V', 'H', 'E', 'HV', 'EV', 'EH', 'EHV') if mode == m.T: fig = self.__mode_T(data, allrange, arLabels, arUnits, _e, _x, _y) elif mode == m.V: fig = self.__mode_V(data, allrange) elif mode == m.H: fig = self.__mode_H(data, allrange) elif mode == m.E: fig = self.__mode_E(data, allrange, arLabels, arUnits) elif mode == m.HV: fig = self.__mode_HV(data, allrange, arLabels, arUnits, _x, _y, _graphs_joined) #elif mode==m.EV: # fig = __mode_EV(data,allrange) #elif mode==m.EH: # fig = __mode_EH(data,allrange) elif mode == m.EHV: fig = self.__mode_EHV(data, allrange, arLabels, arUnits, _e, _x, _y, _graphs_joined) if _multicolumn_data: #MR31102017 available_cols = list(data.keys()) for c in [_column_x, _column_y]: if c not in available_cols: raise ValueError( 'Incorrect column specified: {}.\nAvailable columns: {}' .format(c, available_cols)) fig = self._plot_1D_XvsY(data, _column_x, _column_y) return self._maybe_savefig(fig)
def extract_report_data(filename, model_data): sValShort = 'Flux' sValType = 'Flux through Finite Aperture' sValUnit = 'ph/s/.1%bw' if 'models' in model_data and model_data['models']['fluxReport'][ 'fluxType'] == 2: sValShort = 'Intensity' sValUnit = 'ph/s/.1%bw/mm^2' is_gaussian = False if 'models' in model_data and model_data['models']['simulation'][ 'sourceType'] == 'g': is_gaussian = True files_3d = [ 'res_pow.dat', 'res_int_se.dat', 'res_int_pr_se.dat', 'res_mirror.dat', _MULTI_ELECTRON_FILENAME ] file_info = { 'res_spec_se.dat': [[ 'Photon Energy', 'Intensity', 'On-Axis Spectrum from Filament Electron Beam' ], ['eV', _intensity_units(is_gaussian, model_data)]], 'res_spec_me.dat': [['Photon Energy', sValShort, sValType], ['eV', sValUnit]], 'res_pow.dat': [[ 'Horizontal Position', 'Vertical Position', 'Power Density', 'Power Density' ], ['m', 'm', 'W/mm^2']], 'res_int_se.dat': [[ 'Horizontal Position', 'Vertical Position', '{photonEnergy} eV Before Propagation', 'Intensity' ], ['m', 'm', _intensity_units(is_gaussian, model_data)]], #TODO(pjm): improve multi-electron label _MULTI_ELECTRON_FILENAME: [[ 'Horizontal Position', 'Vertical Position', 'After Propagation', 'Intensity' ], ['m', 'm', _intensity_units(is_gaussian, model_data)]], 'res_int_pr_se.dat': [[ 'Horizontal Position', 'Vertical Position', '{photonEnergy} eV After Propagation', 'Intensity' ], ['m', 'm', _intensity_units(is_gaussian, model_data)]], 'res_mirror.dat': [[ 'Horizontal Position', 'Vertical Position', 'Optical Path Difference', 'Optical Path Difference' ], ['m', 'm', 'm']], } data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load(filename) filename = os.path.basename(filename) title = file_info[filename][0][2] if '{photonEnergy}' in title: title = title.format( photonEnergy=model_data['models']['simulation']['photonEnergy']) info = { 'title': title, 'x_range': [allrange[0], allrange[1]], 'y_label': _superscript(file_info[filename][0][1] + ' [' + file_info[filename][1][1] + ']'), 'x_label': file_info[filename][0][0] + ' [' + file_info[filename][1][0] + ']', 'x_units': file_info[filename][1][0], 'y_units': file_info[filename][1][1], 'points': data, } if filename in files_3d: info = _remap_3d(info, allrange, file_info[filename][0][3], file_info[filename][1][2]) return info
def uti_plot_data_file(self, _fname, _read_labels=1, _e=0, _x=0, _y=0, _graphs_joined=1, #OC16112017 (renamed: uti_plot_data_file -> uti_plot_data_file) _multicolumn_data=False, _column_x=None, _column_y=None, #MR31102017 _scale='linear', _width_pixels=None): #data, mode, allrange = srw_ascii_load(fname) #data, mode, allrange, arLabels, arUnits = _file_load(_fname, _read_labels) #data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load(_fname, _read_labels) #data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load(_fname, _read_labels, _traj_report, _traj_axis) #MR20160729 #data = np.array(data) #MR27012017 (lines added until "pass") #if _scale != 'linear': # available_scales = ['log', 'log2', 'log10'] # if _scale not in available_scales: # raise ValueError('Scale "{}" is not supported. Available scales: {}.'.format(_scale, ', '.join(available_scales))) # data[np.where(data <= 0.)] = 1.e-23 # data = getattr(np, _scale)(data) #if _width_pixels: # try: # from scipy.ndimage import zoom # data = np.reshape(data, (allrange[5], allrange[8]), order='f') # resize_factor = float(_width_pixels) / float(allrange[5]) # print('Size before: {} Dimensions: {}'.format(data.size, data.shape)) # data = zoom(data, resize_factor) # if _scale == 'linear': # data[np.where(data < 0.)] = 0.0 # print('Size after : {} Dimensions: {}'.format(data.size, data.shape)) # allrange = list(allrange) # allrange[5] = data.shape[0] # allrange[8] = data.shape[1] # allrange = tuple(allrange) # data = np.reshape(data, (data.shape[0] * data.shape[1]), order='f') # except: # print('Cannot resize the image - scipy.ndimage.zoom() cannot be imported.') # pass data, mode, allrange, arLabels, arUnits = uti_plot_com.file_load(_fname, _read_labels, _multicolumn_data) #MR31102017 if not _multicolumn_data: data = np.array(data) #if mode == 3: #OC17112017 (commented-out) # try: # fwhm_dict = uti_math.fwhm(np.linspace(allrange[0], allrange[1], allrange[2]), data, return_as_dict=True) # except: # fwhm_dict = {'fwhm': -1} # print('FWHM: {:.5f} [{}]'.format(fwhm_dict['fwhm'], arUnits[0])) if _scale != 'linear': available_scales = ['log', 'log2', 'log10'] if _scale not in available_scales: raise ValueError('Scale "{}" is not supported. Available scales: {}.'.format(_scale, ', '.join(available_scales))) data[np.where(data <= 0.)] = 1.e-23 data = getattr(np, _scale)(data) if _width_pixels: try: from scipy.ndimage import zoom data = np.reshape(data, (allrange[5], allrange[8]), order='C') resize_factor = float(_width_pixels) / float(allrange[5]) print('Size before: {} Dimensions: {}'.format(data.size, data.shape)) data = zoom(data, resize_factor) if _scale == 'linear': data[np.where(data < 0.)] = 0.0 print('Size after : {} Dimensions: {}'.format(data.size, data.shape)) allrange = list(allrange) allrange[5] = data.shape[0] allrange[8] = data.shape[1] allrange = tuple(allrange) data = np.reshape(data, (data.shape[0] * data.shape[1]), order='C') except: print('Cannot resize the image - scipy.ndimage.zoom() cannot be imported.') pass #print(allrange) m = self._enum('T','V','H','E','HV','EV','EH','EHV') if mode==m.T: fig = self.__mode_T(data, allrange, arLabels, arUnits, _e, _x, _y) elif mode==m.V: fig = self.__mode_V(data, allrange) elif mode==m.H: fig = self.__mode_H(data, allrange) elif mode==m.E: fig = self.__mode_E(data, allrange, arLabels, arUnits) elif mode==m.HV: fig = self.__mode_HV(data, allrange, arLabels, arUnits, _x, _y, _graphs_joined) #elif mode==m.EV: # fig = __mode_EV(data,allrange) #elif mode==m.EH: # fig = __mode_EH(data,allrange) elif mode==m.EHV: fig = self.__mode_EHV(data, allrange, arLabels, arUnits, _e, _x, _y, _graphs_joined) if _multicolumn_data: #MR31102017 available_cols = list(data.keys()) for c in [_column_x, _column_y]: if c not in available_cols: raise ValueError('Incorrect column specified: {}.\nAvailable columns: {}'.format(c, available_cols)) fig = self._plot_1D_XvsY(data, _column_x, _column_y) return self._maybe_savefig(fig)