spec2nexus.charts

source code documentation

charting for spec2nexus

make_png(image, image_file[, axes, title, …]) read the image from the named HDF5 file and make a PNG file
xy_plot(x, y, plot_file[, title, subtitle, …]) with MatPlotLib, generate a plot of a scan (as if data from a scan in a SPEC file)
spec2nexus.charts.make_png(image, image_file, axes=None, title='2-D data', subtitle='', log_image=False, hsize=9, vsize=5, cmap='cubehelix', xtitle=None, ytitle=None, timestamp_str=None)[source]

read the image from the named HDF5 file and make a PNG file

Test that the HDF5 file exists and that the path to the data exists in that file. Read the data from the named dataset, mask off some bad values, convert to log(image) and use Matplotlib to make the PNG file.

Parameters:
  • image (obj) – array of data to be rendered
  • image_file (str) – name of image file to be written (path is optional)
  • log_image (bool) – plot log(image)
  • hsize (int) – horizontal size of the PNG image (default: 7)
  • hsize – vertical size of the PNG image (default: 3)
  • cmap (str) – colormap for the image (default: ‘cubehelix’), ‘jet’ is another good one
Return str:

image_file

The HDF5 file could be a NeXus file, or some other layout.

spec2nexus.charts.xy_plot(x, y, plot_file, title=None, subtitle=None, xtitle=None, ytitle=None, xlog=False, ylog=False, hsize=9, vsize=5, timestamp_str=None)[source]

with MatPlotLib, generate a plot of a scan (as if data from a scan in a SPEC file)

Parameters:
  • x ([float]) – horizontal axis data
  • y ([float]) – vertical axis data
  • plot_file (str) – file name to write plot image
  • xtitle (str) – horizontal axis label (default: not shown)
  • ytitle (str) – vertical axis label (default: not shown)
  • title (str) – title for plot (default: date time)
  • subtitle (str) – subtitle for plot (default: not shown)
  • xlog (bool) – should X axis be log (default: False=linear)
  • ylog (bool) – should Y axis be log (default: False=linear)
  • timestamp_str (str) – date to use on plot (default: now)

Tip

when using this module as a background task …

MatPlotLib has several interfaces for plotting. Since this module runs as part of a background job generating lots of plots, MatPlotLib’s standard plt code is not the right model. It warns after 20 plots and will eventually run out of memory.

Here’s the fix used in this module: http://stackoverflow.com/questions/16334588/create-a-figure-that-is-reference-counted/16337909#16337909