Commit 6fa2ad68 authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

infer the phase step

parent 93ba1454
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ from pysen.inout import EchoWriter, make_echofilename
def main():
    "the main"
    parser = argparse.ArgumentParser()
    parser.set_defaults(ntof=42, npix=32, step=45.0, outdir='.', loglevel=logging.INFO)
    parser.set_defaults(ntof=42, npix=32, step=None, outdir='.', loglevel=logging.INFO)
    parser.add_argument('filename', metavar='file', nargs='+', help='filename to convert')
    parser.add_argument('--outdir', '-o', metavar='out', dest='outdir',
                        help='set output directory (default %(default)s)')
@@ -21,7 +21,7 @@ def main():
    parser.add_argument('--ntof', '-T', type=int, dest='ntof',
                        help='set number of tof channels (default %(default)s)')
    parser.add_argument('--step', '-S', type=float, dest='step',
                        help='set precession phase step (default %(default)s)')
                        help='set precession phase step (default: find it from the NeXus file)')
    #
    parser.add_argument('--verbose', '-v', dest='loglevel', action='store_const',
                        const=logging.DEBUG,   help='increase verbosity level')
+28 −6
Original line number Diff line number Diff line
@@ -11,8 +11,6 @@ from ..config import NXCHAN as NPIX, NTCHAN as NTOF
from .nexus   import process_nexus, print_nexus_info, X0_PIX, Y0_PIX, XWID2, YWID2

# BUNCH OF HARD CODED CONSTANTS
# TO DO: some of this is repeated in nexus.py file (merge!)
DEFAULT_PHASE_STEP = 45.0 # degrees

TAU_IDX   = 1000
DN_IDX    =  100
@@ -119,16 +117,40 @@ class EchoScan(BaseScan):
                    self.info['base'], t, len(p), nphases)
        return ntaus, nphases

    def get_phase_step(self, phase_step, max_delta=1.0):
        "get average phase step and round it to a degree"
        phasesens   = self.info.get('phasesens')
        nphases     = self.info.get('nphases')
        act_phase_step  = []
        for tau in self.data.values():
            phases = np.asarray([ _pha['phase'] for _pha in tau ])
            phases = phases[:nphases]
            dpha = phases[1:]-phases[:-1]
            act_phase_step.append(list(dpha*phasesens))
        act_phase_step = np.asarray(act_phase_step)
        avg_phase_step = np.average(act_phase_step)
        avg_phase_step = round(avg_phase_step,0)

        if phase_step is None:
            return avg_phase_step

        if abs(avg_phase_step-phase_step)>max_delta:
            self.log.warning("%s: used phase step %g (deg), but actual is %g (deg)",
                            self.info['base'], phase_step, avg_phase_step)
        return phase_step

    def read_nexus(self, nxsfile, **kwargs):
        """read nexus file"""
        kwargs.setdefault('phase_step', DEFAULT_PHASE_STEP)
        phase_step = kwargs.pop('phase_step')
        if not super().read_nexus(nxsfile, scan_type='echo', **kwargs):
            return False
        ntaus, nphases = self.get_taus_and_phases()
        self.info['nphases']    = nphases
        self.log.info('%s: found %s taus, with %d phases in each tau',
            self.info['base'], ntaus, nphases)
        self.info['phase_step'] = self.get_phase_step(phase_step)
        # post processing
        self.log.info('%s: found %s tau(s), %d phases/tau, phase_step=%g (deg)',
            self.info['base'], ntaus, nphases, self.info['phase_step'])

        return True

class XYZScan(BaseScan):
+2 −2
Original line number Diff line number Diff line
@@ -147,9 +147,8 @@ class EchoWriter(EchoScan):
        out.write( "\n")
        return out.getvalue()


    def to_echo(self, outdir='.'):
        "phase point callback"
        "convert read nexus file to .echo file"
        with open(os.path.join(outdir, self.echofile), 'wt', encoding='ascii') as fd:
            #
            self.log.info("%s: creating echo file", self.echofile)
@@ -164,6 +163,7 @@ class EchoWriter(EchoScan):
            qmin = self.info.get('qmin')
            sample_temp = self.info.get('sample_temp')
            phasesens   = self.info.get('phasesens')

            for it,tau in enumerate(self.data):
                self.log.info("%s: writing tau=%2d", self.echofile, tau)
                #res1   = self.data[tau][ 0] # first phase
+2 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ PySEN revision module
"""
import sys
__version__  = "2.0"
__release__  = "b4"
__date__     = "Feb 4, 2025"
__release__  = "b5"
__date__     = "Feb 11, 2025"

def version(full=False):
    "get pysen version number"