From b4c203a78ad250b19d90bb508dbde9dc641b75b2 Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Wed, 19 May 2021 15:28:11 +0200 Subject: [PATCH] add missing pages (#396) --- pymchelper/readers/shieldhit/reader_bdo2016.py | 6 +++++- pymchelper/readers/shieldhit/reader_bdo2019.py | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pymchelper/readers/shieldhit/reader_bdo2016.py b/pymchelper/readers/shieldhit/reader_bdo2016.py index a66bebcb7..7df91a8e9 100644 --- a/pymchelper/readers/shieldhit/reader_bdo2016.py +++ b/pymchelper/readers/shieldhit/reader_bdo2016.py @@ -2,7 +2,7 @@ import numpy as np -from pymchelper.estimator import MeshAxis +from pymchelper.estimator import MeshAxis, Page from pymchelper.readers.shieldhit.reader_base import SHReader, _get_mesh_units, _bintyp, _get_detector_unit, \ read_next_token from pymchelper.readers.shieldhit.binary_spec import SHBDOTagID, detector_name_from_bdotag @@ -29,6 +29,10 @@ def read_data(self, estimator): logger.debug("Endian: " + _x['end'][0].decode('ASCII')) logger.debug("VerStr: " + _x['vstr'][0].decode('ASCII')) + # if no pages are present, add first one + if not estimator.pages: + estimator.add_page(Page()) + while f: token = read_next_token(f) if token is None: diff --git a/pymchelper/readers/shieldhit/reader_bdo2019.py b/pymchelper/readers/shieldhit/reader_bdo2019.py index 11c2e0996..7ee4fb8f3 100644 --- a/pymchelper/readers/shieldhit/reader_bdo2019.py +++ b/pymchelper/readers/shieldhit/reader_bdo2019.py @@ -89,8 +89,12 @@ def read_data(self, estimator): estimator.z = estimator.z._replace(unit=_units[2]) _has_geo_units_in_ascii = True - # detector type + # page(detector) type if token_id == SHBDOTagID.SHBDO_PAG_TYPE: + # if no pages present, add first one + if not estimator.pages: + logger.debug("SHBDO_PAG_TYPE Creating first page") + estimator.add_page(Page()) # check if detector type attribute present, if yes, then create new page if estimator.pages[-1].dettyp is not None: # the same tag appears again, looks like new page logger.debug("SHBDO_PAG_TYPE Creating new page no {}".format(len(estimator.pages))) @@ -98,8 +102,12 @@ def read_data(self, estimator): logger.debug("Setting page.dettyp = {} ({})".format(SHDetType(payload), SHDetType(payload).name)) estimator.pages[-1].dettyp = SHDetType(payload) - # detector data + # page(detector) data if token_id == SHBDOTagID.SHBDO_PAG_DATA: + # if no pages present, add first one + if not estimator.pages: + logger.debug("SHBDO_PAG_TYPE Creating first page") + estimator.add_page(Page()) # check if data attribute present, if yes, then create new page if estimator.pages[-1].data_raw.size > 1: logger.debug("SHBDO_PAG_DATA Creating new page no {}".format(len(estimator.pages))) @@ -137,7 +145,7 @@ def read_data(self, estimator): # Copy the SH12A specific units into the general placeholders: for page in estimator.pages: page.unit = page.data_unit - # in future, a user may optionially give a more specific name in SH12A detect.dat, which then + # in future, a user may optionally give a more specific name in SH12A detect.dat, which then # may be written to the .bdo file. If the name is not set, use the official detector name instead: if not page.name: page.name = str(page.dettyp)