Commit 2752a271 authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

fix nxs2taco - handle empty runs

catch and raise RuntimeError when
* no proton charge in NeXus file
* no neutron counts in NeXus file
* no neutron counts scan point
parent bd91b928
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -276,5 +276,5 @@ def convert_files(*filenames, **kwargs):
        except (OSError, RuntimeError) as exc:
            if not ignore_errors:
                raise
            logging.getLogger().warning("Ignoring file %s (%s)", fname, str(exc))
            logging.getLogger().warning("Skipping file %s: %s", fname, str(exc))
    return results
+4 −1
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ def get_run_info(nxsfile):
    res['title']    = nxsfile['/entry/title'][0].decode('ascii')
    res['notes']    = nxsfile['/entry/notes'][0].decode('ascii')
    res['duration'] = nxsfile['/entry/duration'][0]
    res['total_counts']  = nxsfile['/entry/total_counts'][0]
    res['proton_charge'] = nxsfile['/entry/proton_charge'][0]
    res['ipts'] = nxsfile['/entry/experiment_identifier'][0].decode('ascii')
    res['experiment'] = nxsfile['/entry/experiment_title'][0].decode('ascii')
@@ -186,8 +187,10 @@ def process_scan_point(events, pcharge, ltot, begin=None, end=None, values=None)
    # events selection
    ev_sel = np.logical_and(begin<ev_t0,ev_t0<end)
    evid     = ev_id[ev_sel]   # select event ids with correct scan time
    id1, id2 = evid[0], evid[-1] # first and last event
    if len(evid)<=0:
        raise RuntimeError(f"no neutron counts for times [{begin:g},{end:g}]")

    id1, id2 = evid[0], evid[-1] # first and last event
    # event_time_offset is in usec
    lam = tof2lambda(events['event_time_offset'][id1:id2]*MICRO, ltot)/ANGSTROM
    pix = pixel_decompose(events['event_id'][id1:id2])
+9 −0
Original line number Diff line number Diff line
@@ -59,6 +59,15 @@ class BaseScan:
        self.info['ybin'] = np.linspace(Y0_PIX-YWID2, Y0_PIX+YWID2, self.info['npix']+1)
        self.info['tbin'] = np.linspace(lmin, lmax, self.info['ntof']+1)
        #
        if self.info['proton_charge']<=0:
            #self.log.warning("file %s has no proton_charge", nxsfilename)
            #return False
            raise RuntimeError("zero total proton_charge")
        if self.info['total_counts']<=0:
            #self.log.warning("file %s has no neutron counts", nxsfilename)
            #return False
            raise RuntimeError("zero total neutron counts")
        #
        # debug
        self.log.debug("nexus info: %s", print_nexus_info(self.info))
        return True
+2 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ PySEN revision module
"""
import sys
__version__  = "2.0"
__release__  = ".5a"
__date__     = "Aug 18, 2025"
__release__  = ".5b"
__date__     = "Aug 20, 2025"

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