Skip to content

Commit

Permalink
Merge pull request #127 from slaclab/fix_analyze_h5_test
Browse files Browse the repository at this point in the history
Fix analyze h5 test
  • Loading branch information
nstelter-slac authored Aug 28, 2024
2 parents 3ff082a + 5c4ccc2 commit 1effbdc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
53 changes: 35 additions & 18 deletions suite_scripts/AnalyzeH5.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# log to file named <curr script name>.log
currFileName = os.path.basename(__file__)
ls.setupScriptLogging(currFileName[:-3] + ".log", logging.ERROR) # change to logging.INFO for full logging output
ls.setupScriptLogging(currFileName[:-3] + ".log", logging.INFO) # change to logging.INFO for full logging output
# for logging from current file
logger = logging.getLogger(__name__)

Expand All @@ -47,28 +47,45 @@ def getFiles(self):
fileNames = self.files.split(",")
self.h5Files = []
for f in fileNames:
print(f)
print("using file: ", f)
self.h5Files.append(h5py.File(f))

def identifyAnalysis(self):

for key in ["analysis", "sliceCoordinates", "modules", "rows", "cols"]:
if key not in self.h5Files[0]:
print("h5 file missing metadata for key: '" + key + "'\nexiting...")
exit(1) # eventually try get this data from cmdline args?? or maybe have default vals to try with?

encoding = 'utf-8'

# note: [()] is h5py way to access key's data

# handle how some different machines create h5 differently
try:
##print("in identifyAnalysis")
encoding = 'utf-8'
self.analysis = self.h5Files[0]["analysis"][()][0].decode(encoding)
self.sliceCoordinates = self.h5Files[0]["sliceCoordinates"][()][0]
self.detModules = self.h5Files[0]["modules"][()][0]
self.detRows = self.h5Files[0]["rows"][()][0]
self.detCols = self.h5Files[0]["cols"][()][0]
##print("slice coordinates:", self.sliceCoordinates)
except Exception:
print("imposing old hr info, something went wrong")
## do something useful here, maybe
self.analysisType = None
## but for now
self.analysisType = "cluster"
self.sliceCoordinates = [[270, 288], [59, 107]]
self.sliceEdges = [288 - 270, 107 - 59]

except:
try:
self.analysis = self.h5Files[0]["analysis"][()].decode(encoding)
except Exception as e:
print(f"failed to decode metadata value for key 'analysis': {e}")
print("exiting...")
exit(1)

self.analysis = self.h5Files[0]["analysis"][()].decode(encoding)
self.sliceCoordinates = self.h5Files[0]["sliceCoordinates"][()]
self.detModules = self.h5Files[0]["modules"][()]
self.detRows = self.h5Files[0]["rows"][()]
self.detCols = self.h5Files[0]["cols"][()]

print("the following metadata was read from h5:")
print("analysis: ", self.analysis)
print("sliceCoordinates: ", self.sliceCoordinates)
print("detModules: ", self.detModules)
print("detRows: ", self.detRows)
print("detCols: ", self.detCols)


def sliceToDetector(self, sliceRow, sliceCol):
return sliceRow + self.sliceCoordinates[0][0], sliceCol + self.sliceCoordinates[1][0]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_data

0 comments on commit 1effbdc

Please sign in to comment.