Skip to content

Commit

Permalink
add missing pages (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzanka authored May 19, 2021
1 parent c40e8d9 commit b4c203a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pymchelper/readers/shieldhit/reader_bdo2016.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
14 changes: 11 additions & 3 deletions pymchelper/readers/shieldhit/reader_bdo2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,25 @@ 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)))
estimator.add_page(Page())
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)))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b4c203a

Please sign in to comment.