19/11/20
Paul Hockett, https://github.com/phockett/tmo-dev
Pretty rough so far, with the aim of developing some routine methods & visualisation/data exploration routines. Inital work based on examples in /reg/data/ana15/tmo/tmolw0618/results/tmo_ana/templates/.
Implemented:
read_preproc.ipynb).To do:
This doc shows some examples so far. You'll just need the file tmoDataBase.py (available at https://github.com/phockett/tmo-dev), and to have Holoviews installed. (For getting setup with an installable env, see the SLAC notes on Anaconda and installing packages.)
import numpy as np
from h5py import File
from pathlib import Path
# HV imports
import holoviews as hv
from holoviews import opts
hv.extension('bokeh', 'matplotlib')
# Memory profiler - OPTIONAL for testing
# https://timothymonteath.com/articles/monitoring_memory_usage/
# %load_ext memory_profiler
# %memit
# Import class - this requires pointing to the `tmoDataBase.py` file.
# See https://github.com/phockett/tmo-dev
# Import class from file
import sys
sys.path.append(r'/cds/home/p/phockett/dev/tmo-dev')
import tmoDataBase as tb
tb.setPlotDefaults() # Set plot defaults (optional)
# Set main data path
baseDir = Path('/reg/data/ana15/tmo/tmolw0618/scratch/preproc/v2')
# Setup class object and which runs to read.
data = tb.tmoDataBase(fileBase = baseDir, runList = range(89,97+1), fileSchema='_preproc_elecv2')
# The class has a bunch of dictionaries holding info on the data
data.runs['files']
# Read in the files with h5py
# There is very basic checking implemented currently, just to see if 'energies' is present.
data.readFiles()
# Once read in, data is stored in a new dictionary, keyed by run #
print(data.data.keys())
print(data.data[89].keys())
for key in data.data[89].keys():
print(f'\n{key}: {data.data[89][key]}')
# The method .hist(dim) sets (1D) histograms for the given dimension
dim = 'intensities'
data.hist(dim)
# To display for a single run, call the relevant dictionary item for a specific run
run = 89
pType = 'curve'
data.data[run][pType][dim]
Note the plot above is interactive via the tools at the edge, and will also display values on rollover. Clicking the legend will turn data series on/off. The interactivity will remain upon HTML export.
# For more output, try the histOverlay method
data.histOverlay(dim)
# The ndoverlay plot shows all the data
data.ndoverlay
# This is a bit busy, so use the layout instead
# Note that these plots are linked, so zooming + panning is consistent over all plots.
data.layout
These currently build and display 2D histograms using hv.HexTiles. The code needs some work, but for now use the holomap object generated to throw out some plots.
# Pass two dimensions here, note the 1st must be 1D
data.hist2d(dim=['energies','intensities'])
# This is currently set as a dict of HexTiles plots per run, and these are stacked as a HoloMap object.
data.data[89]['hist2d']
# Display HoloMap - this currently messes up with autoranges, not sure why!
data.data[89]['hist2d']['hmap']
# Display as a layout (needs some work!)
data.data[89]['hist2d']['hmap'].layout().cols(1)
This is currently set for single-valued or inclusive ranges (passed as lists), and will set self.data[key]['mask'] for each dataset. This will be automatically applied to subsequent plots.
data.filterData(filterOptions={'gas':[True], 'energies':[0.02, 0.06]})
# Recalc correlation plots with filtered data
data.hist2d(dim=['energies','intensities'])
# Display as a layout (needs some work!)
data.data[89]['hist2d']['hmap'].layout().cols(1)
# Display as a layout (needs some work!)
# With smaller tiled plots
data.data[89]['hist2d']['hmap'].opts(width=300, height=300).layout().cols(3)