Skip to content

Commit

Permalink
refs #86 update the FlyScan demo, next docs
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jan 27, 2017
1 parent 2c9b541 commit e808bea
Showing 1 changed file with 25 additions and 49 deletions.
74 changes: 25 additions & 49 deletions demo/usaxs_flyscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import numpy
import os

import spec2nexus.converters
import spec2nexus.specplot
import spec2nexus.specplot_gallery

Expand Down Expand Up @@ -73,58 +72,19 @@ def retrieve_flyScanData(scan):
hdf_file_name = comment[index:-1]
abs_file = os.path.abspath(os.path.join(path, hdf_file_name))

plotData = []
plotData = {}
if os.path.exists(abs_file):
reduced = read_reduced_fly_scan_file(abs_file)
s_num_bins = str(REDUCED_FLY_SCAN_BINS)

if s_num_bins in reduced:
choice = reduced[s_num_bins]
elif 'full' in reduced:
choice = reduced['full']
else:
choice = None
choice = reduced.get(s_num_bins) or reduced.get('full')

if choice is not None:
plotData = [choice[axis] for axis in 'Q R'.split()]
plotData = {axis: choice[axis] for axis in 'Q R'.split()}

return plotData


class USAXS_FlyScan_Structure(spec2nexus.converters.PlotDataStructure):
'''
describe plottable data from 1-D scans such as `ascan`
:param obj scan: instance of :class:`spec2nexus.spec.SpecDataFileScan`
Attributes:
:x: array of horizontal axis values
:y: array of vertical axis values
'''

def __init__(self, scan, fly_scan_data):
spec2nexus.converters.PlotDataStructure.__init__(self, scan)

if len(fly_scan_data) != 2:
raise spec2nexus.converters.NoDataToPlot(str(scan))

self.signal = 'R'
self.axes = ['Q',]
self.data = dict(Q=fly_scan_data[0], R=fly_scan_data[1])

def plottable(self):
'''
can this data be plotted as expected?
'''
if self.signal in self.data:
signal = self.data[self.signal]
if signal is not None and len(signal) > 0 and len(self.axes) == 1:
if len(signal) == len(self.data[self.axes[0]]):
return True
return False


class USAXS_FlyScan_Plotter(spec2nexus.specplot.LinePlotter):
'''
customize `FlyScan` handling, plot :math:`log(I)` *vs.* :math:`log(Q)`
Expand All @@ -139,25 +99,41 @@ def get_plot_data(self):
# get the data from the HDF5 file
fly_data = retrieve_flyScanData(self.scan)

# place the data in specplot's plotting structure
structure = USAXS_FlyScan_Structure(self.scan, fly_data)
if len(fly_data) != 2:
raise spec2nexus.specplot.NoDataToPlot(str(scan))

self.signal = 'R'
self.axes = ['Q',]
self.data = fly_data

# customize the plot just a bit
# TODO: sample name as given by the user?
subtitle = '#%s FlyScan: %s' % (str(self.scan.scanNum), self.scan.comments[0])
# sample name as given by the user?
subtitle = '#' + str(self.scan.scanNum)
subtitle += ' FlyScan: ' + self.scan.comments[0]
self.configure(
x_log = True,
y_log = True,
x_title = r'$|\vec{Q}|, 1/\AA$',
y_title = r'USAXS $R(|\vec{Q}|)$, a.u.',
subtitle = subtitle,
)
return structure

def plottable(self):
'''
can this data be plotted as expected?
'''
if self.signal in self.data:
signal = self.data[self.signal]
if signal is not None and len(signal) > 0 and len(self.axes) == 1:
if len(signal) == len(self.data[self.axes[0]]):
return True
return False


def debugging_setup():
import os, sys
import shutil
sys.path.insert(0, os.path.join('..', 'src'))
path = '__usaxs__'
shutil.rmtree(path, ignore_errors=True)
os.mkdir(path)
Expand All @@ -173,5 +149,5 @@ def main():


if __name__ == '__main__':
# debugging_setup()
debugging_setup()
main()

0 comments on commit e808bea

Please sign in to comment.