Skip to content

Commit ec70ca6

Browse files
committed
Update Data.py
1 parent 39ec818 commit ec70ca6

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

xpsi/Data.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,11 @@ def from_pha( cls, path,
692692
TLMIN= _np.int32(Header['TLMIN1'])
693693

694694
if checkqual:
695-
if 'QUALITY' not in spectrum.columns.names :
696-
if checkdatasrc is not None:
697-
if hasattr(checkdatasrc, '_quality'):
698-
quality = checkdatasrc._quality
699-
else:
700-
raise IOError('QUALITY information are not found in the PHA file.')
695+
if checkdatasrc is not None:
696+
assert hasattr(checkdatasrc, '_quality')
697+
quality=checkdatasrc._quality
698+
elif 'QUALITY' not in spectrum.columns.names :
699+
raise IOError('QUALITY information are not found in the PHA file.')
701700
else:
702701
quality=spectrum['QUALITY']
703702
print('Bad bins detected...')
@@ -714,19 +713,23 @@ def from_pha( cls, path,
714713

715714
origpha = None
716715
if checkgrp:
717-
if 'GROUPING' not in spectrum.columns.names :
718-
if checkdatasrc is not None:
719-
if hasattr(checkdatasrc, '_grouping'):
720-
groupcha = checkdatasrc._grouping
721-
else:
722-
raise IOError('GROUPING information are not found in the PHA file')
716+
if checkdatasrc is not None:
717+
assert hasattr(checkdatasrc, '_grouping')
718+
groupcha=checkdatasrc._grouping
719+
elif 'GROUPING' not in spectrum.columns.names :
720+
raise IOError('GROUPING information are not found in the PHA file')
723721
else:
724722
groupcha=spectrum['GROUPING']
725723
grpdata = True
726724
origpha=spectrum
727725
print('Counts will be grouped into larger channels')
728726
min_binchannel = _np.where(groupcha == 1)[0]
729727
max_binchannel = _np.hstack((min_binchannel[1:], len(channels)))
728+
if checkdatasrc is not None:
729+
if type(checkdatasrc._origdata)==_np.ndarray: ##Few changes if the source data was loaded from an EVT file.
730+
mskch = [groupcha[i]==1 and checkdatasrc._quality[i]==0 for i in range(len(groupcha))]
731+
min_binchannel = _np.where(mskch)[0] - _np.where(checkdatasrc._quality==0)[0][0]
732+
max_binchannel = _np.hstack((min_binchannel[1:], len(_np.where(checkdatasrc._quality==0)[0])))
730733
groupcounts=_np.zeros(len(min_binchannel))
731734
if withuncs:
732735
grouperrors=_np.zeros(len(min_binchannel))

0 commit comments

Comments
 (0)