def doSuccessProcessOneFile(self, _edPlugin=None): self.DEBUG("EDPluginBioSaxsHPLCv1_5.doSuccessProcessOneFile") self.retrieveSuccessMessages(_edPlugin, "EDPluginBioSaxsHPLCv1_5.doSuccessProcessOneFile") if _edPlugin and _edPlugin.dataOutput and _edPlugin.dataOutput.status and _edPlugin.dataOutput.status.executiveSummary: self.lstExecutiveSummary.append(_edPlugin.dataOutput.status.executiveSummary.value) output = _edPlugin.dataOutput if not output.integratedCurve: strErr = "Edna plugin ProcessOneFile did not produce integrated curve" self.ERROR(strErr) self.lstExecutiveSummary.append(strErr) self.setFailure() return self.curve = output.integratedCurve.path.value if not os.path.exists(self.curve): strErr = "Edna plugin ProcessOneFile: integrated curve not on disk !!" self.ERROR(strErr) self.lstExecutiveSummary.append(strErr) self.setFailure() return self.xsDataResult.integratedCurve = output.integratedCurve self.xsDataResult.normalizedImage = output.normalizedImage self.xsDataResult.dataI = output.dataI self.xsDataResult.dataQ = output.dataQ self.xsDataResult.dataStdErr = output.dataStdErr self.intensity = EDUtilsArray.xsDataToArray(output.dataI) self.stdError = EDUtilsArray.xsDataToArray(output.dataStdErr) if output.experimentSetup and output.experimentSetup.timeOfFrame: startTime = output.experimentSetup.timeOfFrame.value else: try: startTime = float(fabio.openheader(self.dataInput.rawImage.path.value).header["time_of_day"]) except Exception: self.ERROR("Unable to read time_of_day in header of %s" % self.dataInput.rawImage.path.value) startTime = 0 if not self.hplc_run.first_curve: with self._sem: if True: #not self.hplc_run.first_curve: # Populate the buffer with the first curve if needed self.hplc_run.first_curve = self.curve self.hplc_run.start_time = startTime self.hplc_run.q = EDUtilsArray.xsDataToArray(output.dataQ) self.hplc_run.size = self.hplc_run.q.size self.hplc_run.buffer_I = self.intensity self.hplc_run.buffer_Stdev = self.stdError self.hplc_run.firstCurveIntensity = self.intensity self.hplc_run.for_buffer_sum_I = self.intensity self.hplc_run.for_buffer_sum_sigma2 = self.stdError ** 2 self.hplc_run.for_buffer.append(self.frameId) self.frame.curve = self.curve self.frame.time = startTime self.xsDataResult.timeStamp = XSDataTime(value=(startTime - self.hplc_run.start_time)) # self.calcIntensity() self.frame.sum_I = float(self.intensity.sum()) self.xsDataResult.summedIntensity = XSDataDouble(value=self.frame.sum_I)
def doSuccessProcessOneFile(self, _edPlugin=None): self.DEBUG("EDPluginBioSaxsHPLCv1_2.doSuccessProcessOneFile") self.retrieveSuccessMessages( _edPlugin, "EDPluginBioSaxsHPLCv1_2.doSuccessProcessOneFile") if _edPlugin and _edPlugin.dataOutput and _edPlugin.dataOutput.status and _edPlugin.dataOutput.status.executiveSummary: self.lstExecutiveSummary.append( _edPlugin.dataOutput.status.executiveSummary.value) output = _edPlugin.dataOutput if not output.integratedCurve: strErr = "Edna plugin ProcessOneFile did not produce integrated curve" self.ERROR(strErr) self.lstExecutiveSummary.append(strErr) self.setFailure() return self.curve = output.integratedCurve.path.value if not os.path.exists(self.curve): strErr = "Edna plugin ProcessOneFile: integrated curve not on disk !!" self.ERROR(strErr) self.lstExecutiveSummary.append(strErr) self.setFailure() return self.xsDataResult.integratedCurve = output.integratedCurve self.xsDataResult.normalizedImage = output.normalizedImage self.xsDataResult.dataI = output.dataI self.xsDataResult.dataQ = output.dataQ self.xsDataResult.dataStdErr = output.dataStdErr if output.experimentSetup and output.experimentSetup.timeOfFrame: startTime = output.experimentSetup.timeOfFrame.value else: try: startTime = float( fabio.openheader(self.dataInput.rawImage.path.value). header["time_of_day"]) except Exception: self.ERROR("Unable to read time_of_day in header of %s" % self.dataInput.rawImage.path.value) startTime = 0 with self._sem: if not self.hplc_run.first_curve: self.hplc_run.first_curve = self.curve self.hplc_run.start_time = startTime self.frame.curve = self.curve self.frame.time = startTime self.xsDataResult.timeStamp = XSDataTime( value=(startTime - self.hplc_run.start_time)) self.calcIntensity()
def doSuccessProcessOneFile(self, _edPlugin=None): self.DEBUG("EDPluginBioSaxsHPLCv1_2.doSuccessProcessOneFile") self.retrieveSuccessMessages(_edPlugin, "EDPluginBioSaxsHPLCv1_2.doSuccessProcessOneFile") if ( _edPlugin and _edPlugin.dataOutput and _edPlugin.dataOutput.status and _edPlugin.dataOutput.status.executiveSummary ): self.lstExecutiveSummary.append(_edPlugin.dataOutput.status.executiveSummary.value) output = _edPlugin.dataOutput if not output.integratedCurve: strErr = "Edna plugin ProcessOneFile did not produce integrated curve" self.ERROR(strErr) self.lstExecutiveSummary.append(strErr) self.setFailure() return self.curve = output.integratedCurve.path.value if not os.path.exists(self.curve): strErr = "Edna plugin ProcessOneFile: integrated curve not on disk !!" self.ERROR(strErr) self.lstExecutiveSummary.append(strErr) self.setFailure() return self.xsDataResult.integratedCurve = output.integratedCurve self.xsDataResult.normalizedImage = output.normalizedImage self.xsDataResult.dataI = output.dataI self.xsDataResult.dataQ = output.dataQ self.xsDataResult.dataStdErr = output.dataStdErr if output.experimentSetup and output.experimentSetup.timeOfFrame: startTime = output.experimentSetup.timeOfFrame.value else: try: startTime = float(fabio.openheader(self.dataInput.rawImage.path.value).header["time_of_day"]) except Exception: self.ERROR("Unable to read time_of_day in header of %s" % self.dataInput.rawImage.path.value) startTime = 0 with self._sem: if not self.hplc_run.first_curve: self.hplc_run.first_curve = self.curve self.hplc_run.start_time = startTime self.frame.curve = self.curve self.frame.time = startTime self.xsDataResult.timeStamp = XSDataTime(value=(startTime - self.hplc_run.start_time)) self.calcIntensity()
def normalizeFolderEDF(self): ''' Performs correction on all EDF images in the folder ''' listFlats = [] listDarks = [] listData = [] dirname = self.frames_folder for oneFile in os.listdir(dirname): if oneFile.startswith(self.flatprefix) and oneFile.endswith(self.suffix): oneCompleteFile = os.path.abspath(os.path.join(dirname, oneFile)) listFlats.append(oneCompleteFile) if oneFile.startswith(self.darkprefix) and oneFile.endswith(self.suffix): oneCompleteFile = os.path.abspath(os.path.join(dirname, oneFile)) listDarks.append(oneCompleteFile) if oneFile.startswith(self.dataprefix) and oneFile.endswith(self.suffix): oneCompleteFile = os.path.abspath(os.path.join(dirname, oneFile)) listData.append(oneCompleteFile) #makes an associative array from listDarks arrayDarks = {} for dark in listDarks: ex = fabio.open(dark).header["exposure_time"] arrayDarks[ex] = dark #performs correction on each data frame for data_fullname in listData: data = os.path.basename(data_fullname) if self.verbose: print("processing frame %s..." % data) #get the ID of the data data_id = data[len(self.dataprefix):-len(self.suffix)] #get the corresponding flats exp_ref, ex2 = -1.0, -1.0 for ref_fullname in listFlats: ref = os.path.basename(ref_fullname) ref_id = ref[len(self.flatprefix):-len(self.suffix)] if self.dark_data is None: exp_data = fabio.openheader(ref_fullname).header["exposure_time"] dark_data = arrayDarks[exp_data] self.dark_data = fabio.open(dark_data).data if ref_id == data_id: flat1 = ref_fullname[:] #get the exposure time of flat 1 exp_ref = fabio.openheader(ref_fullname).header["exposure_time"] #get the corresponding Dark ("dark data") if self.dark_ref is None: dark_ref = arrayDarks[exp_ref] self.dark_ref = fabio.open(dark_ref).data if int(ref_id[-4:]) == (int(data_id[-4:]) + 1): #FIXME: hard-coded ! flat2 = ref_fullname[:] #get the exposure time of flat 2 ex2 = fabio.open(ref_fullname).header["exposure_time"] #get the corresponding Dark ("dark ref") if exp_ref == -1.0 or ex2 == -1.0: print("Failed to get flats for %s, using the same flat" % (data)) flat2 = flat1 ex2 = exp_ref cor = self.normalize(fabio.open(data_fullname).data, fabio.open(flat1).data, fabio.open(flat2).data) fabio.edfimage.edfimage(data=cor).write(os.path.join(self.corrected_folder , "frame_%s.edf" % data_id)) # scipy.misc.imsave(os.path.join(self.corrected_folder , "frame_%s.png" % data_id), cor) if self.verbose: print("Done")
def normalizeFolderEDF(self): ''' Performs correction on all EDF images in the folder ''' listFlats = [] listDarks = [] listData = [] dirname = self.frames_folder for oneFile in os.listdir(dirname): if oneFile.startswith(self.flatprefix) and oneFile.endswith( self.suffix): oneCompleteFile = os.path.abspath( os.path.join(dirname, oneFile)) listFlats.append(oneCompleteFile) if oneFile.startswith(self.darkprefix) and oneFile.endswith( self.suffix): oneCompleteFile = os.path.abspath( os.path.join(dirname, oneFile)) listDarks.append(oneCompleteFile) if oneFile.startswith(self.dataprefix) and oneFile.endswith( self.suffix): oneCompleteFile = os.path.abspath( os.path.join(dirname, oneFile)) listData.append(oneCompleteFile) #makes an associative array from listDarks arrayDarks = {} for dark in listDarks: ex = fabio.open(dark).header["exposure_time"] arrayDarks[ex] = dark #performs correction on each data frame for data_fullname in listData: data = os.path.basename(data_fullname) if self.verbose: print("processing frame %s..." % data) #get the ID of the data data_id = data[len(self.dataprefix):-len(self.suffix)] #get the corresponding flats ex1, ex2 = -1.0, -1.0 for ref_fullname in listFlats: ref = os.path.basename(ref_fullname) ref_id = ref[len(self.flatprefix):-len(self.suffix)] if self.dark_data is None: exp_data = fabio.openheader( ref_fullname).header["exposure_time"] dark_data = arrayDarks[exp_data] self.dark_data = fabio.open(dark_data).data if ref_id == data_id: flat1 = ref_fullname[:] #get the exposure time of flat 1 exp_ref = fabio.openheader( ref_fullname).header["exposure_time"] #get the corresponding Dark ("dark data") if self.dark_ref is None: dark_ref = arrayDarks[exp_ref] self.dark_ref = fabio.open(dark_ref).data if int(ref_id[-4:]) == (int(data_id[-4:]) + 1): #FIXME: hard-coded ! flat2 = ref_fullname[:] #get the exposure time of flat 2 ex2 = fabio.open(ref_fullname).header["exposure_time"] #get the corresponding Dark ("dark ref") if ex1 == -1.0 or ex2 == -1.0: print("Error: failed to get flats for %s" % (data)) flat2 = flat1 ex2 = ex1 cor = self.normalize( fabio.open(data_fullname).data, fabio.open(flat1).data, fabio.open(flat2).data) fabio.edfimage.edfimage(data=cor).write( os.path.join(self.corrected_folder, "frame_%s.edf" % data_id)) # scipy.misc.imsave(os.path.join(self.corrected_folder , "frame_%s.png" % data_id), cor) if self.verbose: print("Done")