drtsans.files package

Submodules

drtsans.files.event_nexus_nodes module

class drtsans.files.event_nexus_nodes.BankNode(name, bank_name)[source]

Bases: GroupNode

Node for bank entry such as /entry/bank12

set_events(event_id_array, event_index_array, event_time_offset_array, run_start_time, event_time_zero_array)[source]
Parameters:
  • event_id_array (numpy.ndarray) – pixel IDs for each event. Size is equal to number of events

  • event_time_offset_array (numpy.ndarray) – TOF of each neutron event. Size is equal to number of events

  • event_time_zero_array (numpy.ndarray) – Staring time, as seconds offset to run start time, of each pulse

  • run_start_time (str) – Run start time in ISO standard

  • event_index_array (numpy.ndarray) – Index of staring event in each pulse. Size is equal to number of pulses

class drtsans.files.event_nexus_nodes.DasLogsCollectionNode[source]

Bases: GroupNode

Node for ‘/entry/DASlogs’

class drtsans.files.event_nexus_nodes.DataSetNode(name=None)[source]

Bases: HDFNode

Node for data set

match(other_node)[source]

Match this node with other

Parameters:

other_node (DataSetNode) – another node to match against

parse_h5_entry(h5_entry)[source]

Parse HDF5 entry

Parameters:

h5_entry (Group) – hdf5 entry

Return type:

None

set_string_value(str_value)[source]

Set value from a single string (object)

Parameters:

str_value (str) – string to be written to an entry’s only value

set_value(data_array)[source]

Set data value (as numpy array)

Parameters:

data_array (np.ndarray) – data value

property value
write(parent_entry)[source]

Write buffer node to an HDF entry

Parameters:

parent_entry (Group, File) – parent HDF node

class drtsans.files.event_nexus_nodes.InstrumentNode[source]

Bases: GroupNode

Node for instrument entry (i.e., /entry/instrument)

set_idf(idf_str, idf_type, description)[source]

Set instrument xml

Parameters:
  • idf_str (Bytes) – IDF XML string

  • idf_type (Bytes) – IDF type

  • description (Bytes) – Description

set_instrument_info(target_station_number, beam_line, name, short_name)[source]

Set instrument information

Parameters:
  • target_station_number (int) – target station number. 1 is used for HFIR

  • beam_line (Bytes) – CG2, CG3

  • name (Bytes) – CG2, CG3

  • short_name (Bytes) – CG2, CG3

Return type:

None

class drtsans.files.event_nexus_nodes.MonitorNode(name, monitor_name)[source]

Bases: GroupNode

Node to record monitor counts

set_monitor_events(event_index_array, event_time_offset_array, run_start_time, event_time_zero_array)[source]

Monitor counts are recorded as events

Parameters:
  • event_time_offset_array (numpy.ndarray) – TOF of each neutron event. Size is equal to number of events

  • event_time_zero_array (numpy.ndarray) – Staring time, as seconds offset to run start time, of each pulse

  • run_start_time (str) – Run start time in ISO standard

  • event_index_array (numpy.ndarray) – Index of staring event in each pulse. Size is equal to number of pulses

drtsans.files.event_nexus_rw module

class drtsans.files.event_nexus_rw.DasDevice(id, name, target)

Bases: tuple

id

Alias for field number 0

name

Alias for field number 1

target

Alias for field number 2

class drtsans.files.event_nexus_rw.DasLog(name, times, values, unit, device)

Bases: tuple

device

Alias for field number 4

name

Alias for field number 0

times

Alias for field number 1

unit

Alias for field number 3

values

Alias for field number 2

class drtsans.files.event_nexus_rw.EventNeXusWriter(beam_line, instrument_name)[source]

Bases: object

Write an Event NeXus file

generate_event_nexus(nexus_name, start_time, stop_time, monitor_counts)[source]

Generate an event Nexus file from scratch :param nexus_name: Output NeXus file name :type nexus_name: str :param start_time: :param stop_time: :param monitor_counts:

set_bank_histogram(bank_id, bank_histogram)[source]

Set a single bank’s counts

Parameters:
  • bank_id

  • bank_histogram (TofHistogram) – Histogram for simulating TOF

set_instrument_info(num_banks, instrument_xml)[source]

Set information related to SANS instrument including IDF in plain XML string and number of banks

Parameters:
  • num_banks (int) – number of banks

  • instrument_xml (str) – instrument definition in plain XML string

set_meta_data(meta_data)[source]
Parameters:

meta_data (DasLog) – Das log object

set_run_number(run_number)[source]

Set run number if required

Parameters:

run_number (int) – run number

class drtsans.files.event_nexus_rw.NexusEvents(event_id, event_index, event_time_offset, event_time_zero)

Bases: tuple

event_id

Alias for field number 0

event_index

Alias for field number 1

event_time_offset

Alias for field number 2

event_time_zero

Alias for field number 3

class drtsans.files.event_nexus_rw.RunTime(start, stop)

Bases: tuple

start

Alias for field number 0

stop

Alias for field number 1

class drtsans.files.event_nexus_rw.TofHistogram(pixel_ids, counts, pulse_duration, tof_min, tof_max)

Bases: tuple

counts

Alias for field number 1

pixel_ids

Alias for field number 0

pulse_duration

Alias for field number 2

tof_max

Alias for field number 4

tof_min

Alias for field number 3

drtsans.files.event_nexus_rw.convert_events_to_histogram(bank_entry)[source]

Convert events information in bank to histogram

Parameters:

bank_entry

Returns:

Histogram converted from TOF bank information

Return type:

TofHistogram

drtsans.files.event_nexus_rw.generate_events_from_histogram(bank_histogram, tof_resolution=0.1, verbose=False)[source]

Convert histogram (counts on detector pixels) to ‘fake’ events

Parameters:
  • bank_histogram (TofHistogram) – Histogram for a single bank

  • tof_resolution (float) – resolution of TOF

  • verbose (bool) – flag to print out events information

Returns:

Generated TOF events in NeXus format

Return type:

NexusEvents

drtsans.files.event_nexus_rw.init_event_nexus()[source]

Initialize an event Nexus file buffer including - entry

Returns:

root event NeXus node

Return type:

FileNode

drtsans.files.event_nexus_rw.parse_event_nexus(source_nexus_name, num_banks, logs_white_list=None)[source]

Parse an event Nexus file for minimal required information

Parameters:
  • source_nexus_name

  • num_banks (int) – number of banks. assuming bank numbers are consecutive

drtsans.files.hdf5_rw module

class drtsans.files.hdf5_rw.DataSetNode(name=None)[source]

Bases: HDFNode

Node for data set

match(other_node)[source]

Match this node with other

Parameters:

other_node (DataSetNode) – another node to match against

parse_h5_entry(h5_entry)[source]

Parse HDF5 entry

Parameters:

h5_entry (Group) – hdf5 entry

Return type:

None

set_string_value(str_value)[source]

Set value from a single string (object)

Parameters:

str_value (str) – string to be written to an entry’s only value

set_value(data_array)[source]

Set data value (as numpy array)

Parameters:

data_array (np.ndarray) – data value

property value
write(parent_entry)[source]

Write buffer node to an HDF entry

Parameters:

parent_entry (Group, File) – parent HDF node

class drtsans.files.hdf5_rw.FileNode[source]

Bases: GroupNode

Node for an HDF file

write(file_name)[source]

Write to a file

Parameters:

file_name (str) – Name of file to write to

class drtsans.files.hdf5_rw.GroupNode(name=None)[source]

Bases: HDFNode

Node for an HDF Group

property children
get_child(child_name, is_short_name=False)[source]

Get a child

Parameters:
  • child_name (str)

  • is_short_name (bool) – If True, concatenate the child name with current self._name

Returns:

Child HDFNode

Return type:

GroupNode, DataSetNode

match(other_node)[source]

Compare this node with another node

Parameters:

other_node

parse_h5_entry(h5_entry)[source]

Parse HDF5 entry

Parameters:

h5_entry (Group) – hdf5 entry

Return type:

None

remove_child(child_node_name)[source]
set_child(child_node)[source]
Parameters:

child_node (GroupNode, DataSetNode) – child node to append

write(parent_entry)[source]

Write buffer node to an HDF entry

Parameters:

parent_entry (Dataset, Group, File) – parent HDF node

write_content(curr_entry)[source]
class drtsans.files.hdf5_rw.HDFNode(name=None)[source]

Bases: object

an HDF node with more information

add_attributes(attributes)[source]

Add a list of attributes to the HDF5 node

Parameters:

attributes (~dict) – Attributes to add. key = attribute name, value = attribute value

property attributes
match(other_node)[source]

Compare 2 HDFNode to see whether they are same

If mismatch, an exception will be raised including - TypeError: for nodes are nto same type - ValueError: attribute or node name value mismatch - KeyError: some attribute does not exist in both node

Parameters:

other_node (HDFNode) – other node to compare

property name
parse_h5_entry(h5_entry)[source]

Parse an HDF5 entry

Parameters:

h5_entry

write(inputs)[source]
Parameters:

inputs (str, Group, File) – Node to input

write_attributes(curr_entry)[source]

drtsans.files.log_h5_reader module

drtsans.files.log_h5_reader.verify_cg2_reduction_results(sample_names, output_dir, gold_path, title, prefix)[source]

Verify reduction result for GPSANS

Parameters:
  • sample_names (list) – list of names of samples

  • output_dir (str) – output directory

  • gold_path (str) – path to the gold file

  • title (str) – title of output figure

  • prefix (str) – prefix for output png file in order not to confusing various error outputs

Module contents