Loading pysen/inout/writer.py +20 −26 Original line number Diff line number Diff line Loading @@ -16,14 +16,16 @@ from ..constants import PICO, NANO, MICRO, ANGSTROM, GAUSS from .nexus import MOTORS, B_SENSORS, time_format from .scans import EchoScan, DiffractionScan, TransmissionScan # BUNCH OF HARD CODED CONSTANTS # TO DO: some of this is repeated in nexus.py file (merge!) # FIXME: BUNCH OF HARD CODED CONSTANTS PHASE_INDEX = 100 PHASE_UP = 2 # up phase padding PHASE_DN = 1 # down phase padding PHASES_NPOL = 2+3 # 2xPC for down and 3xPC for up # INV_NUMOR = -999999 # "invalid" numor # RE_TRAN = re.compile('transmission', re.IGNORECASE) # match transmission line RE_NUMOR = re.compile(r'\d+') def get_phase_index(scan_index, offset=0): "return phase index" Loading @@ -32,24 +34,22 @@ def get_phase_index(scan_index, offset=0): return updn + offset return scan_index%PHASE_INDEX - offset - 1 def make_filename(base, prefix='taco'): "make a TACO filename" match = re.search(RE_NUMOR, base) if match: numor = match.group(0) else: numor = INV_NUMOR return f"{prefix}{numor}.dat" RE_TRAN = re.compile('transmission', re.IGNORECASE) class TransmissionWriter(TransmissionScan): "Convert EPICS/ADARA/NeXus file to transmission .dat file" @staticmethod def make_filename(base): "make diffraction filename" root, _ = os.path.splitext(os.path.basename(base)) # remove h5 root, _ = os.path.splitext(root) # remove nxs numor = int(root.split('_')[-1]) return f"transmission_{numor}.dat" def save(self, outdir='.'): "convert read nexus file to diffrun .dat file" transmission_run = self.make_filename(self.info['base']) transmission_run = make_filename(self.info['base'], prefix='transmission_') with open(os.path.join(outdir, transmission_run), 'wt', encoding='ascii') as fd: # self.log.info("%s: creating transmission .dat file", transmission_run) Loading Loading @@ -94,20 +94,14 @@ class TransmissionWriter(TransmissionScan): class DiffractionWriter(DiffractionScan): "Convert EPICS/ADARA/NeXus file to diffrun .dat file" @staticmethod def make_filename(base): "make diffraction filename" root, _ = os.path.splitext(os.path.basename(base)) # remove h5 root, _ = os.path.splitext(root) # remove nxs numor = int(root.split('_')[-1]) return f"diffrun_{numor}.dat" def save(self, outdir='.'): "convert read nexus file to diffrun .dat file" #pylint: disable=too-many-statements #FIXME: refactor this diffrun = self.make_filename(self.info['base']) diffrun = make_filename(self.info['base'], prefix='diffrun_') print(self.info['base']) outdir='.' print(diffrun, outdir) with open(os.path.join(outdir, diffrun), 'wt', encoding='ascii') as fd: # fd.write( "\"############################\"\n") Loading Loading @@ -170,9 +164,9 @@ class DiffractionWriter(DiffractionScan): fd.write( "\n") if not spin_up: if detsum>0: try: fr = upcnt/detsum else: except TypeError: fr = np.nan fd.write(f"\"Q\" {qmin:g} ") fd.write(f"\"flip ratio\" {fr:g}\n") Loading test/test_inout_hdf.py +1 −1 Original line number Diff line number Diff line """ Python unit test cases for pysen.echo.fit module Python unit test cases for pysen.echo.converter module """ import unittest import os.path Loading Loading
pysen/inout/writer.py +20 −26 Original line number Diff line number Diff line Loading @@ -16,14 +16,16 @@ from ..constants import PICO, NANO, MICRO, ANGSTROM, GAUSS from .nexus import MOTORS, B_SENSORS, time_format from .scans import EchoScan, DiffractionScan, TransmissionScan # BUNCH OF HARD CODED CONSTANTS # TO DO: some of this is repeated in nexus.py file (merge!) # FIXME: BUNCH OF HARD CODED CONSTANTS PHASE_INDEX = 100 PHASE_UP = 2 # up phase padding PHASE_DN = 1 # down phase padding PHASES_NPOL = 2+3 # 2xPC for down and 3xPC for up # INV_NUMOR = -999999 # "invalid" numor # RE_TRAN = re.compile('transmission', re.IGNORECASE) # match transmission line RE_NUMOR = re.compile(r'\d+') def get_phase_index(scan_index, offset=0): "return phase index" Loading @@ -32,24 +34,22 @@ def get_phase_index(scan_index, offset=0): return updn + offset return scan_index%PHASE_INDEX - offset - 1 def make_filename(base, prefix='taco'): "make a TACO filename" match = re.search(RE_NUMOR, base) if match: numor = match.group(0) else: numor = INV_NUMOR return f"{prefix}{numor}.dat" RE_TRAN = re.compile('transmission', re.IGNORECASE) class TransmissionWriter(TransmissionScan): "Convert EPICS/ADARA/NeXus file to transmission .dat file" @staticmethod def make_filename(base): "make diffraction filename" root, _ = os.path.splitext(os.path.basename(base)) # remove h5 root, _ = os.path.splitext(root) # remove nxs numor = int(root.split('_')[-1]) return f"transmission_{numor}.dat" def save(self, outdir='.'): "convert read nexus file to diffrun .dat file" transmission_run = self.make_filename(self.info['base']) transmission_run = make_filename(self.info['base'], prefix='transmission_') with open(os.path.join(outdir, transmission_run), 'wt', encoding='ascii') as fd: # self.log.info("%s: creating transmission .dat file", transmission_run) Loading Loading @@ -94,20 +94,14 @@ class TransmissionWriter(TransmissionScan): class DiffractionWriter(DiffractionScan): "Convert EPICS/ADARA/NeXus file to diffrun .dat file" @staticmethod def make_filename(base): "make diffraction filename" root, _ = os.path.splitext(os.path.basename(base)) # remove h5 root, _ = os.path.splitext(root) # remove nxs numor = int(root.split('_')[-1]) return f"diffrun_{numor}.dat" def save(self, outdir='.'): "convert read nexus file to diffrun .dat file" #pylint: disable=too-many-statements #FIXME: refactor this diffrun = self.make_filename(self.info['base']) diffrun = make_filename(self.info['base'], prefix='diffrun_') print(self.info['base']) outdir='.' print(diffrun, outdir) with open(os.path.join(outdir, diffrun), 'wt', encoding='ascii') as fd: # fd.write( "\"############################\"\n") Loading Loading @@ -170,9 +164,9 @@ class DiffractionWriter(DiffractionScan): fd.write( "\n") if not spin_up: if detsum>0: try: fr = upcnt/detsum else: except TypeError: fr = np.nan fd.write(f"\"Q\" {qmin:g} ") fd.write(f"\"flip ratio\" {fr:g}\n") Loading
test/test_inout_hdf.py +1 −1 Original line number Diff line number Diff line """ Python unit test cases for pysen.echo.fit module Python unit test cases for pysen.echo.converter module """ import unittest import os.path Loading