Common Methods: spec2nexus.utils

source code documentation

(internal library) common methods used in spec2nexus modules

clean_name(key) create a name that is allowed by both HDF5 and NeXus rules
iso8601(date) convert SPEC time (example: Wed Nov 03 13:39:34 2010) into ISO8601 string
strip_first_word(line) return everything after the first space on the line from the spec data file
sanitize_name(group, key) make name that is allowed by HDF5 and NeXus rules
reshape_data(scan_data, scan_shape) Shape scan data from raw to different dimensionality
spec2nexus.utils.clean_name(key)[source]

create a name that is allowed by both HDF5 and NeXus rules

Parameters:key (str) – identifying string from SPEC data file
See:http://download.nexusformat.org/doc/html/datarules.html

The “sanitized” name fits this regexp:

[A-Za-z_][\w_]*

An easier expression might be: [\w_]* but this will not pass the rule that valid NeXus group or field names cannot start with a digit.

spec2nexus.utils.iso8601(date)[source]

convert SPEC time (example: Wed Nov 03 13:39:34 2010) into ISO8601 string

Parameters:date (str) – time string from SPEC data file

Example

SPEC:Wed Nov 03 13:39:34 2010
ISO8601:2010-11-03T13:39:34
SPOCK:09/15/17 04:39:10
ISO8601:2017-09-15T04:39:10
spec2nexus.utils.reshape_data(scan_data, scan_shape)[source]

Shape scan data from raw to different dimensionality

Some SPEC macros collect data in a mesh or grid yet report the data as a 1-D sequence of observations. For further processing (such as plotting), the scan data needs to be reshaped according to its intended dimensionality.

modified from nexpy.readers.readspec.reshape_data

spec2nexus.utils.sanitize_name(group, key)[source]

make name that is allowed by HDF5 and NeXus rules

Note:

deprecated use clean_name() instead (group is never used)

Parameters:
  • group (str) – unused
  • key (str) – identifying string from SPEC data file
See:

http://download.nexusformat.org/doc/html/datarules.html

sanitized name fits this regexp:

[A-Za-z_][\w_]*

An easier expression might be: [\w_]* but this will not pass the rule that valid names cannot start with a digit.

spec2nexus.utils.split_column_labels(text)[source]

SPEC labels may contain one space

spec2nexus.utils.strip_first_word(line)[source]

return everything after the first space on the line from the spec data file