def test_calculateLowResPixel_max_value_hard(self): ''''Step4 - assert the max value of low res for an hard data set ''' [xdata, ydata, edata] = loadCsvFile(self.top_folder + '/hard_data_set.csv') peakfinder = LowResFinder(xdata, ydata, edata) low_res_range = peakfinder.get_low_res() self.assertEqual(low_res_range[1], 197)
def test_calculateLowResPixel_min_value_medium(self): ''''Step4 - assert the min value of low res for an medium data set ''' [xdata, ydata, edata] = loadCsvFile(self.top_folder + '/medium_data_set.csv') peakfinder = LowResFinder(xdata, ydata, edata) low_res_range = peakfinder.get_low_res() self.assertEqual(low_res_range[0], 89)
def __init__(self, workspace, lconfig=None, is_data=True, parent=None): #TODO: there appears to be duplicate instances of this class being # created when loading a file. self.parent = parent self._tof_axis = [] self.Ixyt = [] self.Exyt = [] self.data = [] self.xydata = [] self.ytofdata = [] self.countstofdata = [] self.countxdata = [] self.ycountsdata = [] self.workspace = mtd[workspace] self.workspace_name = workspace mt_run = self.workspace.getRun() self.ipts = mt_run.getProperty('experiment_identifier').value self.run_number = mt_run.getProperty('run_number').value if float(self.run_number) < RUN_NUMBER_0_BETTER_CHOPPER_COVERAGE: self.is_better_chopper_coverage = False self.lambda_requested = float( mt_run.getProperty('LambdaRequest').value[0]) self.lambda_requested_units = mt_run.getProperty('LambdaRequest').units self.thi = mt_run.getProperty('thi').value[0] self.thi_units = mt_run.getProperty('thi').units self.ths = mt_run.getProperty('ths').value[0] self.ths_units = mt_run.getProperty('ths').units self.tthd = mt_run.getProperty('tthd').value[0] self.tthd_units = mt_run.getProperty('tthd').units self.S1W = mt_run.getProperty('S1HWidth').value[0] self.S1H = mt_run.getProperty('S1VHeight').value[0] self.parent.current_ipts = mt_run.getProperty( 'experiment_identifier').value self.total_counts = self.workspace.getNumberEvents() try: self.SiW = mt_run.getProperty('SiHWidth').value[0] self.SiH = mt_run.getProperty('SiVHeight').value[0] self.isSiThere = True except: self.S2W = mt_run.getProperty('S2HWidth').value[0] self.S2H = mt_run.getProperty('S2VHeight').value[0] self.isSiThere = False self.attenuatorNbr = mt_run.getProperty('vATT').value[0] - 1 self.date = mt_run.getProperty('run_start').value sample = self.workspace.getInstrument().getSample() source = self.workspace.getInstrument().getSource() self.dMS = sample.getDistance(source) # create array of distances pixel->sample self.number_x_pixels = int( self.workspace.getInstrument().getNumberParameter( "number-of-x-pixels")[0]) # 256 self.number_y_pixels = int( self.workspace.getInstrument().getNumberParameter( "number-of-y-pixels")[0]) dPS_array = np.zeros((self.number_x_pixels, self.number_y_pixels)) for x in range(self.number_y_pixels): for y in range(self.number_x_pixels): _index = self.number_x_pixels * x + y detector = self.workspace.getDetector(_index) dPS_array[y, x] = sample.getDistance(detector) # distance sample->center of detector self.dSD = dPS_array[self.number_x_pixels / 2, self.number_y_pixels / 2] # distance source->center of detector self.dMD = self.dSD + self.dMS # calculate theta self.theta = self.calculate_theta() self.frequency = float(mt_run.getProperty('Speed1').value[0]) tof_coeff_narrow = 1.7 * 60 / self.frequency tof_coeff_large = 2.5 * 60 / self.frequency tof_coeff = 0.5 * 60 / self.frequency if lconfig is not None: autotmin = np.float(lconfig.tof_range[0]) autotmax = np.float(lconfig.tof_range[1]) else: if self.is_better_chopper_coverage: autotmin = self.dMD / H_OVER_M_NEUTRON * ( self.lambda_requested - tof_coeff_narrow) * 1e-4 autotmax = self.dMD / H_OVER_M_NEUTRON * ( self.lambda_requested + tof_coeff_narrow) * 1e-4 else: autotmin = self.dMD / H_OVER_M_NEUTRON * ( self.lambda_requested + tof_coeff - tof_coeff_narrow) * 1e-4 autotmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + tof_coeff + \ tof_coeff_narrow) * 1e-4 # automatically calcualte the TOF range for display if self.is_better_chopper_coverage: tmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested - tof_coeff_large) * 1e-4 tmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + tof_coeff_large) * 1e-4 else: tmin = self.dMD / H_OVER_M_NEUTRON * ( self.lambda_requested + tof_coeff - tof_coeff_large) * 1e-4 tmax = self.dMD / H_OVER_M_NEUTRON * ( self.lambda_requested + tof_coeff + tof_coeff_large) * 1e-4 if tmin < 0: tmin = 0 self.tof_range_auto = [autotmin, autotmax] # microS self.tof_range_auto_with_margin = [tmin, tmax] # microS # manual tof range (if user wants to use a manual time range) self.tof_range = [ autotmin, autotmax ] # for the first time, initialize tof_range like auto (microS) self.tof_range_manual = [autotmin, autotmax] self.binning = [tmin, self.read_options['bins'], tmax] self.calculate_lambda_range() self.incident_angle = 2. * self.calculate_theta( with_offset=False) # 2.theta self.calculate_q_range() # self.lambda_range = self.calculate_lambda_range() # Proton charge _proton_charge = float(mt_run.getProperty('gd_prtn_chrg').value) _proton_charge_units = mt_run.getProperty('gd_prtn_chrg').units new_proton_charge_units = 'mC' self.proton_charge = _proton_charge * 3.6 # to go from microA/h to mC self.proton_charge_units = new_proton_charge_units self.peak = [0, 0] self.back = [0, 0] self.clocking = [0, 0] self.back_flag = True self.all_plot_axis = AllPlotAxis() self.tof_auto_flag = True self.new_detector_geometry_flag = self.is_nexus_taken_after_refDate() self.data_loaded = False self.read_data() if lconfig is None: pf = PeakFinderDerivation(range(len(self.ycountsdata)), self.ycountsdata) [peak1, peak2] = pf.getPeaks() self.peak = [str(peak1), str(peak2)] backOffsetFromPeak = self.read_options['back_offset_from_peak'] back1 = int(peak1 - backOffsetFromPeak) back2 = int(peak2 + backOffsetFromPeak) self.back = [str(back1), str(back2)] lw_pf = LowResFinder(range(len(self.countsxdata)), self.countsxdata) [lowres1, lowres2] = lw_pf.get_low_res() self.low_res = [str(lowres1), str(lowres2)] clocking_pf = ClockingFinder(parent=self.parent, xdata=range(len(self.ycountsdata)), ydata=self.ycountsdata) [clocking1, clocking2] = clocking_pf.clocking clock_array = [clocking1, clocking2] clock_array.sort() self.clocking = [str(clocking1), str(clocking2)] else: # if we loaded a config that does not have the clocking info, we will have to retrieve once # everything has been loaded (before display) if lconfig.data_clocking[0] != '': self.clocking = [ np.float(lconfig.data_clocking[0]), np.float(lconfig.data_clocking[1]) ] else: clocking_pf = LowResFinder(range(len(self.ycountsdata)), self.ycountsdata) [clocking1, clocking2] = clocking_pf.get_low_res() self.clocking = [str(clocking1), str(clocking2)] self.tof_auto_flag = np.bool(lconfig.tof_auto_flag) if is_data: self.peak = [ np.int(lconfig.data_peak[0]), np.int(lconfig.data_peak[1]) ] self.back = [ np.int(lconfig.data_back[0]), np.int(lconfig.data_back[1]) ] self.low_res = [ np.int(lconfig.data_low_res[0]), np.int(lconfig.data_low_res[1]) ] self.low_res_flag = np.bool(lconfig.data_low_res_flag) self.back_flag = np.bool(lconfig.data_back_flag) else: self.peak = [ np.int(lconfig.norm_peak[0]), np.int(lconfig.norm_peak[1]) ] self.back = [ np.int(lconfig.norm_back[0]), np.int(lconfig.norm_back[1]) ] self.low_res = [ np.int(lconfig.norm_low_res[0]), np.int(lconfig.norm_low_res[1]) ] self.low_res_flag = np.bool(lconfig.norm_low_res_flag) self.back_flag = np.bool(lconfig.norm_back_flag)
def __init__(self, workspace): self._tof_axis = [] self.Ixyt = [] self.Exyt= [] self.data = [] self.xydata = [] self.ytofdata = [] self.countstofdata = [] self.countxdata = [] self.ycountsdata = [] self.workspace = mtd[workspace] self.workspace_name = workspace mt_run = self.workspace.getRun() self.ipts = mt_run.getProperty('experiment_identifier').value self.run_number = mt_run.getProperty('run_number').value self.lambda_requested = float(mt_run.getProperty('LambdaRequest').value[0]) self.lambda_requested_units = mt_run.getProperty('LambdaRequest').units self.thi = mt_run.getProperty('thi').value[0] self.thi_units = mt_run.getProperty('thi').units self.tthd = mt_run.getProperty('tthd').value[0] self.tthd_units = mt_run.getProperty('tthd').units self.S1W = mt_run.getProperty('S1HWidth').value[0] self.S1H = mt_run.getProperty('S1VHeight').value[0] try: self.SiW = mt_run.getProperty('SiHWidth').value[0] self.SiH = mt_run.getProperty('SiVHeight').value[0] self.isSiThere = True except: self.S2W = mt_run.getProperty('S2HWidth').value[0] self.S2H = mt_run.getProperty('S2VHeight').value[0] self.isSiThere = False self.attenuatorNbr = mt_run.getProperty('vATT').value[0] - 1 self.date = mt_run.getProperty('run_start').value #self.full_file_name = mt_run.getProperty('Filename').value[0] #self.filename = ','.join([os.path.basename(_file) for _file in self.full_file_name]) sample = self.workspace.getInstrument().getSample() source = self.workspace.getInstrument().getSource() self.dMS = sample.getDistance(source) # create array of distances pixel->sample self.number_x_pixels = int(self.workspace.getInstrument().getNumberParameter("number-of-x-pixels")[0]) # 256 self.number_y_pixels = int(self.workspace.getInstrument().getNumberParameter("number-of-y-pixels")[0]) dPS_array = np.zeros((self.number_x_pixels, self.number_y_pixels)) for x in range(self.number_y_pixels): for y in range(self.number_x_pixels): _index = self.number_x_pixels * x + y detector = self.workspace.getDetector(_index) dPS_array[y, x] = sample.getDistance(detector) # distance sample->center of detector self.dSD = dPS_array[self.number_x_pixels / 2, self.number_y_pixels / 2] # distance source->center of detector self.dMD = self.dSD + self.dMS # calculate theta self.theta = self.calculate_theta() #if self.read_options['is_auto_tof_finder'] or self.tof_range == None: # automatically calculate the TOF range autotmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + 0.5 - 1.7) * 1e-4 autotmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + 0.5 + 1.7) * 1e-4 #else: #autotmin = np.float(self.tof_range[0]) #autotmax = np.float(self.tof_range[1]) # automatically calcualte the TOF range for display if mt_run.getProperty('Speed1').value[0] == 60: tmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + 0.5 + 2.5) * 1e-4 tmin = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + 0.5 - 2.5) * 1e-4 else: tmax = self.dMD / H_OVER_M_NEUTRON * (self.lambda_requested + 0.5 + 4.5) * 1e-4 tmin = 0 self.tof_range_auto = [autotmin, autotmax] # microS self.tof_range_auto_with_margin = [tmin, tmax] # microS # manual tof range (if user wants to use a manual time range) self.tof_range = [autotmin, autotmax] # for the first time, initialize tof_range like auto (microS) self.tof_range_manual = [autotmin, autotmax] self.binning = [tmin, self.read_options['bins'], tmax] self.calculate_lambda_range() self.incident_angle = 2.*self.calculate_theta(with_offset = False) # 2.theta self.calculate_q_range() # self.lambda_range = self.calculate_lambda_range() # Proton charge _proton_charge = float(mt_run.getProperty('gd_prtn_chrg').value) _proton_charge_units = mt_run.getProperty('gd_prtn_chrg').units new_proton_charge_units = 'mC' self.proton_charge = _proton_charge * 3.6 # to go from microA/h to mC self.proton_charge_units = new_proton_charge_units self.peak = [0, 0] self.back = [0, 0] self.clocking = [0, 0] self.back_flag = True self.all_plot_axis = AllPlotAxis() self.tof_auto_flag = True self.new_detector_geometry_flag = self.is_nexus_taken_after_refDate() self.data_loaded = False self.read_data() if self.read_options['is_auto_peak_finder']: pf = PeakFinderDerivation(range(len(self.ycountsdata)), self.ycountsdata) [peak1, peak2] = pf.getPeaks() self.peak = [str(peak1), str(peak2)] backOffsetFromPeak = self.read_options['back_offset_from_peak'] back1 = int(peak1 - backOffsetFromPeak) back2 = int(peak2 + backOffsetFromPeak) self.back = [str(back1), str(back2)] lw_pf = LowResFinder(range(len(self.countsxdata)), self.countsxdata) [lowres1, lowres2] = lw_pf.get_low_res() self.low_res = [str(lowres1), str(lowres2)] clocking_pf = LowResFinder(range(len(self.ycountsdata)), self.ycountsdata) [clocking1, clocking2] = clocking_pf.get_low_res() self.clocking = [str(clocking1), str(clocking2)]