usnistgov / mass

Microcalorimeter pulse-analysis software
MIT License
6 stars 0 forks source link

resfreshFromFiles fails for this experiment state file and off file #271

Closed joefowler closed 5 months ago

joefowler commented 6 months ago

Original report by Galen O'Neil (Bitbucket: oneilg, GitHub: oneilg).


# unix time in nanoseconds, state label
1697484378937217074, START
1697484745299889963, A
1697485399208931183, B
1697485926167354421, C
1697486056988285912, IGNORE
1697486140155652332, C
1697486494707281352, STOP

files = mass.off.getOffFileListFromOneFile(r'/home/pcuser/data/20231016/0000/20231016_run0000', 3)      
In [12]: files                                       
Out[12]: 
['/home/pcuser/data/20231016/0000/20231016_run0000_chan1.off',
 '/home/pcuser/data/20231016/0000/20231016_run0000_chan2.off',
 '/home/pcuser/data/20231016/0000/20231016_run0000_chan3.off']
data=mass.off.ChannelGroup(files)   
In [14]: data.refreshFromFiles()                                                                                                                                                                           
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [14], in <cell line: 1>()
----> 1 data.refreshFromFiles()

File ~/qsp/src/mass/mass/off/channels.py:1169, in ChannelGroup.refreshFromFiles(self)
   1167     i0_unixnanos = len(ds)
   1168     ds.offFile._updateMmap()  # will update nRecords by mmapping more data in the offFile if available
-> 1169     ds._statesDict = self.experimentStateFile.calcStatesDict(
   1170         ds.unixnano[i0_unixnanos:], ds.statesDict, i0_allLabels, i0_unixnanos)
   1171     n_new_pulses_dict[ds.channum] = len(ds)-i0_unixnanos
   1172 return n_new_labels, n_new_pulses_dict

File ~/qsp/src/mass/mass/off/experiment_state.py:117, in ExperimentStateFile.calcStatesDict(self, unixnanos, statesDict, i0_allLabels, i0_unixnanos)
    115     last_key = k
    116 s = statesDict[last_key]
--> 117 s2 = slice(s.start, i0_unixnanos+len(unixnanos))  # set the slice from the start of the state to the last new record
    118 statesDict[k] = s2
    119 return statesDict

AttributeError: 'list' object has no attribute 'start'  

joefowler commented 6 months ago

Original comment by Galen O'Neil (Bitbucket: oneilg, GitHub: oneilg).


diff --git a/mass/off/experiment_state.py b/mass/off/experiment_state.py
index 1fb3cea33..de6626934 100644
--- a/mass/off/experiment_state.py
+++ b/mass/off/experiment_state.py
@@ -113,8 +113,13 @@ class ExperimentStateFile:
             assert i0_allLabels > 0
             for k in statesDict.keys():
                 last_key = k
-            s = statesDict[last_key]
-            s2 = slice(s.start, i0_unixnanos+len(unixnanos))  # set the slice from the start of the state to the last new record
+                s = statesDict[last_key]
+            if isinstance(s, slice):
+                s2 = slice(s.start, i0_unixnanos+len(unixnanos))  # set the slice from the start of the state to the last new record
+            if isinstance(s, list):
+                s_ = s[-1] # get last instance of same state
+                s[-1] = slice(s_.start, i0_unixnanos+len(unixnanos))  # set the slice from the start of the state to the last new record
+                s2 = s    
             statesDict[k] = s2
             return statesDict

appears to fix it, but since massgui only works with an older version of mass I can’t easily make a PR from the ebit computer