spec2nexus.utils#

Common methods used throughout the package.

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

reshape_data(scan_data, scan_shape)

Shape scan data from raw to different dimensionality

sanitize_name(group, key)

make name that is allowed by HDF5 and NeXus rules

split_column_labels(text)

SPEC labels may contain one space

split_scan_number_string(key)

Split a string scan number into its parts.

strip_first_word(line)

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

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

https://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

https://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.split_scan_number_string(key)[source]#

Split a string scan number into its parts.

key str:

A value from the list returned by getScanNumbers().

returns:

tuple of (#S number, repeat occurrence number)

EXAMPLES:

>>> split_scan_number_string("0")
(0, 0)
>>> split_scan_number_string("0.5")
(0, 5)
spec2nexus.utils.strip_first_word(line)[source]#

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