def get_petlink32_stats(): """Get information about the current petlink32 listmode data. """ descriptor = [ { 'name': 'n_packets', 'type': 'long', 'value': None }, { 'name': 'n_unknown', 'type': 'uint', 'value': None }, { 'name': 'n_prompt', 'type': 'uint', 'value': None }, { 'name': 'n_delayed', 'type': 'uint', 'value': None }, { 'name': 'n_elapsedtime', 'type': 'uint', 'value': None }, { 'name': 'n_deadtime', 'type': 'uint', 'value': None }, { 'name': 'n_motion', 'type': 'uint', 'value': None }, { 'name': 'n_gating', 'type': 'uint', 'value': None }, { 'name': 'n_tracking', 'type': 'uint', 'value': None }, { 'name': 'n_control', 'type': 'uint', 'value': None }, ] r = call_c_function(petlink32_c.get_petlink32_stats, descriptor) if not r.status == status_success(): raise ErrorInCFunction( "The execution of 'get_petlink32_stats' was unsuccesful.", r.status, 'petlink32_c.get_petlink32_stats') return r.dictionary
def get_info(): """Extract information from Siemens binary physiological data file: get information from global memory structure. """ descriptor = [ { 'name': 'n_samples_breathing', 'type': 'uint', 'value': None }, { 'name': 'n_samples_ecg_I', 'type': 'uint', 'value': None }, { 'name': 'n_samples_ecg_aVF', 'type': 'uint', 'value': None }, { 'name': 'n_samples_pulse_ox', 'type': 'uint', 'value': None }, { 'name': 'n_samples_external', 'type': 'uint', 'value': None }, ] r = call_c_function(physiological_c.get_info, descriptor) if not r.status == status_success(): raise ErrorInCFunction("The execution of get_info was unsuccesful.", r.status, 'get_info') return r.dictionary
def uncompress_static_projection(offsets, counts, locations, N_u, N_v): """Get the static projection corresponding to a given time bin of the current dynamic projection data. """ N_counts = counts.size N_axial = offsets.shape[0] N_azimuthal = offsets.shape[1] descriptor = [ { 'name': 'N_counts', 'type': 'uint', 'value': N_counts }, { 'name': 'N_axial', 'type': 'uint', 'value': N_axial }, { 'name': 'N_azimuthal', 'type': 'uint', 'value': N_azimuthal }, { 'name': 'N_u', 'type': 'uint', 'value': N_u }, { 'name': 'N_v', 'type': 'uint', 'value': N_v }, { 'name': 'offsets', 'type': 'array', 'value': offsets }, { 'name': 'counts', 'type': 'array', 'value': counts }, { 'name': 'locations', 'type': 'array', 'value': locations }, { 'name': 'projection', 'type': 'array', 'value': None, 'dtype': np.uint32, 'size': (N_axial, N_azimuthal, N_u, N_v) }, ] r = call_c_function(petlink32_c.uncompress_static_projection, descriptor) if not r.status == status_success(): raise ErrorInCFunction( "The execution of 'uncompress_static_projection' was unsuccesful.", r.status, 'petlink32_c.uncompress_static_projection') return r.dictionary
def status_parameter_error(): """Returns the value returned by the function calls to the library in case of parameter error. """ r = call_c_function(petlink32_c.status_parameter_error, [{ 'name': 'return_value', 'type': 'int', 'value': None }]) return r.return_value
def status_success(): """Returns the value returned by the function calls to the library in case of success. """ r = call_c_function(physiological_c.status_success, [{ 'name': 'return_value', 'type': 'int', 'value': None }]) return r.return_value
def status_decode_error(): """Returns the value returned by the function calls to the library in case of error decoding a file. """ r = call_c_function(physiological_c.status_decode_error, [{ 'name': 'return_value', 'type': 'int', 'value': None }]) return r.return_value
def status_unhandled_error(): """Returns the value returned by the function calls to the library in case of unhandled error. """ r = call_c_function(physiological_c.status_unhandled_error, [{ 'name': 'return_value', 'type': 'int', 'value': None }]) return r.return_value
def free_memory(): """Free memory""" r = call_c_function(petlink32_c.free_memory, []) if not r.status == status_success(): raise ErrorInCFunction( "The execution of 'free_memory' was unsuccesful.", r.status, 'petlink32_c.free_memory') return r.dictionary
def petlink32_info(filename, n_packets): """Extracts summary information from a listmode binary file. """ descriptor = [ { 'name': 'filename', 'type': 'string', 'value': filename, 'size': len(filename) }, { 'name': 'n_packets', 'type': 'int', 'value': n_packets }, { 'name': 'n_prompts', 'type': 'int', 'value': None }, { 'name': 'n_delayed', 'type': 'int', 'value': None }, { 'name': 'n_tags', 'type': 'int', 'value': None }, { 'name': 'n_time', 'type': 'int', 'value': None }, { 'name': 'n_motion', 'type': 'int', 'value': None }, { 'name': 'n_monitoring', 'type': 'int', 'value': None }, { 'name': 'n_control', 'type': 'int', 'value': None }, ] r = call_c_function(petlink32_c.petlink32_info, descriptor) if not r.status == status_success(): raise ErrorInCFunction( "The execution of petlink32_info was unsuccesful.", r.status, 'petlink32_c.petlink32_info') return r.dictionary
def load_data(filename): """Extract information from Siemens binary physiological data file: load_interfile data to global memory structure """ descriptor = [ { 'name': 'filename', 'type': 'string', 'value': filename, 'size': len(filename) }, ] r = call_c_function(physiological_c.load_data, descriptor) if not r.status == status_success(): raise ErrorInCFunction("The execution of load_data was unsuccesful.", r.status, 'load_data') return r.dictionary
def test_library(): """Test whether the C library responds. Used in the package testing. """ number = 134 # a (lucky) number descriptor = [ { 'name': 'input', 'type': 'int', 'value': number }, { 'name': 'output', 'type': 'int', 'value': None }, ] r = call_c_function(physiological_c.echo, descriptor) return r.output == number
def test_library_petlink32_c(): """Test whether the C library petlink32_c responds. """ number = 101 # just a number descriptor = [ { 'name': 'input', 'type': 'int', 'value': number }, { 'name': 'output', 'type': 'int', 'value': None }, ] r = call_c_function(petlink32_c.echo, descriptor) return r.output == number
def get_dynamic_projection_info(): """Get information about the current dynamic projection data. """ descriptor = [ { 'name': 'N_time_bins', 'type': 'uint', 'value': None }, { 'name': 'N_counts', 'type': 'long', 'value': None }, ] r = call_c_function(petlink32_c.get_dynamic_projection_info, descriptor) if not r.status == status_success(): raise ErrorInCFunction( "The execution of 'get_dynamic_projection_info' was unsuccesful.", r.status, 'petlink32_c.get_dynamic_projection_info') return r.dictionary
def petlink32_bin_addresses(filename, n_packets): """Extract list of bin indexes from listmode data. """ descriptor = [ { 'name': 'filename', 'type': 'string', 'value': filename, 'size': len(filename) }, { 'name': 'n_packets', 'type': 'int', 'value': n_packets }, { 'name': 'bin_addresses', 'type': 'array', 'value': None, 'dtype': np.int32, 'size': (1, n_packets) }, { 'name': 'n_prompts', 'type': 'int', 'value': None }, { 'name': 'n_delayed', 'type': 'int', 'value': None }, { 'name': 'n_tags', 'type': 'int', 'value': None }, { 'name': 'n_time', 'type': 'int', 'value': None }, { 'name': 'n_motion', 'type': 'int', 'value': None }, { 'name': 'n_monitoring', 'type': 'int', 'value': None }, { 'name': 'n_control', 'type': 'int', 'value': None }, ] r = call_c_function(petlink32_c.petlink32_bin_addresses, descriptor) if not r.status == status_success(): raise ErrorInCFunction( "The execution of petlink32_bin_addresses was unsuccesful.", r.status, 'petlink32_c.petlink32_bin_addresses') return r.dictionary
def petlink32_to_static_sinogram(filename, n_packets, n_radial_bins, n_angles, n_sinograms): """Make static sinogram from listmode data. """ descriptor = [ { 'name': 'filename', 'type': 'string', 'value': filename, 'size': len(filename) }, { 'name': 'n_packets', 'type': 'long', 'value': n_packets }, { 'name': 'n_radial_bins', 'type': 'int', 'value': n_radial_bins }, { 'name': 'n_angles', 'type': 'int', 'value': n_angles }, { 'name': 'n_sinograms', 'type': 'int', 'value': n_sinograms }, { 'name': 'sinogram', 'type': 'array', 'value': None, 'dtype': np.int32, 'size': (n_radial_bins, n_angles, n_sinograms) }, { 'name': 'packets_unknown', 'type': 'int', 'value': None }, { 'name': 'packets_prompt', 'type': 'int', 'value': None }, { 'name': 'packets_delayed', 'type': 'int', 'value': None }, { 'name': 'packets_elapsedtime', 'type': 'int', 'value': None }, { 'name': 'packets_deadtime', 'type': 'int', 'value': None }, { 'name': 'packets_motion', 'type': 'int', 'value': None }, { 'name': 'packets_gating', 'type': 'int', 'value': None }, { 'name': 'packets_tracking', 'type': 'int', 'value': None }, { 'name': 'packets_control', 'type': 'int', 'value': None }, ] r = call_c_function(petlink32_c.petlink32_to_static_sinogram, descriptor) if not r.status == status_success(): raise ErrorInCFunction( "The execution of 'petlink32_to_static_sinogram' was unsuccesful.", r.status, 'petlink32_c.petlink32_to_static_sinogram') return r.dictionary
def petlink32_to_dynamic_projection(filename, n_packets, n_radial_bins, n_angles, n_sinograms, time_bins, n_axial, n_azimuthal, angular_step_axial, angular_step_azimuthal, size_u, size_v, n_u, n_v): """Make dynamic compressed projection from list-mode data. """ descriptor = [ { 'name': 'filename', 'type': 'string', 'value': filename, 'size': len(filename) }, { 'name': 'n_packets', 'type': 'long', 'value': n_packets }, { 'name': 'n_radial_bins', 'type': 'uint', 'value': n_radial_bins }, { 'name': 'n_angles', 'type': 'uint', 'value': n_angles }, { 'name': 'n_sinograms', 'type': 'uint', 'value': n_sinograms }, { 'name': 'n_time_bins', 'type': 'uint', 'value': len(time_bins) }, { 'name': 'time_bins', 'type': 'array', 'value': np.int32(time_bins) }, { 'name': 'n_axial', 'type': 'uint', 'value': n_axial }, { 'name': 'n_azimuthal', 'type': 'uint', 'value': n_azimuthal }, { 'name': 'angular_step_axial', 'type': 'float', 'value': angular_step_axial }, { 'name': 'angular_step_azimuthal', 'type': 'float', 'value': angular_step_azimuthal }, { 'name': 'size_u', 'type': 'float', 'value': size_u }, { 'name': 'size_v', 'type': 'float', 'value': size_v }, { 'name': 'n_u', 'type': 'uint', 'value': n_u }, { 'name': 'n_v', 'type': 'uint', 'value': n_v }, ] r = call_c_function(petlink32_c.petlink32_to_dynamic_projection, descriptor) if not r.status == status_success(): raise ErrorInCFunction( "The execution of 'petlink32_to_dynamic_compressed_sinogram' was unsuccesful.", r.status, 'petlink32_c.petlink32_to_dynamic_compressed_sinogram') return r.dictionary
def get_data(n_samples_breathing, n_samples_ecg_I, n_samples_ecg_aVF, n_samples_pulse_ox, n_samples_external): """Extract information from Siemens binary physiological data file: get data from global memory strucutre. """ descriptor = [ { 'name': 'n_samples_breathing', 'type': 'uint', 'value': n_samples_breathing }, { 'name': 'n_samples_ecg_I', 'type': 'uint', 'value': n_samples_ecg_I }, { 'name': 'n_samples_ecg_aVF', 'type': 'uint', 'value': n_samples_ecg_aVF }, { 'name': 'n_samples_pulse_ox', 'type': 'uint', 'value': n_samples_pulse_ox }, { 'name': 'n_samples_external', 'type': 'uint', 'value': n_samples_external }, { 'name': 'samples_breathing', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_breathing) }, { 'name': 'samples_ecg_I', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_ecg_I) }, { 'name': 'samples_ecg_aVF', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_ecg_aVF) }, { 'name': 'samples_pulse_ox', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_pulse_ox) }, { 'name': 'samples_external', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_external) }, { 'name': 'triggers_breathing', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_breathing) }, { 'name': 'triggers_ecg_I', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_ecg_I) }, { 'name': 'triggers_ecg_aVF', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_ecg_aVF) }, { 'name': 'triggers_pulse_ox', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_pulse_ox) }, { 'name': 'triggers_external', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (n_samples_external) }, ] r = call_c_function(physiological_c.get_data, descriptor) if not r.status == status_success(): raise ErrorInCFunction("The execution of get_data was unsuccesful.", r.status, 'get_data') return r.dictionary
def get_static_projection_info(time_bin): """Get information about a time bin of the current dynamic projection data. """ descriptor = [ { 'name': 'time_bin', 'type': 'uint', 'value': time_bin }, { 'name': 'time_start', 'type': 'uint', 'value': None }, { 'name': 'time_end', 'type': 'uint', 'value': None }, { 'name': 'N_counts', 'type': 'uint', 'value': None }, { 'name': 'N_axial', 'type': 'uint', 'value': None }, { 'name': 'N_azimuthal', 'type': 'uint', 'value': None }, { 'name': 'angular_step_axial', 'type': 'float', 'value': None }, { 'name': 'angular_step_azimuthal', 'type': 'float', 'value': None }, { 'name': 'size_u', 'type': 'float', 'value': None }, { 'name': 'size_v', 'type': 'float', 'value': None }, { 'name': 'N_u', 'type': 'uint', 'value': None }, { 'name': 'N_v', 'type': 'uint', 'value': None }, ] r = call_c_function(petlink32_c.get_static_projection_info, descriptor) if not r.status == status_success(): raise ErrorInCFunction( "The execution of 'get_static_projection_info' was unsuccesful.", r.status, 'petlink32_c.get_static_projection_info') return r.dictionary
def get_static_projection(time_bin): """Get the static projection corresponding to a given time bin of the current dynamic projection data. """ info = get_static_projection_info(time_bin) N_counts = info['N_counts'] N_axial = info['N_axial'] N_azimuthal = info['N_azimuthal'] descriptor = [ { 'name': 'time_bin', 'type': 'uint', 'value': time_bin }, { 'name': 'time_start', 'type': 'uint', 'value': None }, { 'name': 'time_end', 'type': 'uint', 'value': None }, { 'name': 'N_counts', 'type': 'uint', 'value': None }, { 'name': 'N_axial', 'type': 'uint', 'value': None }, { 'name': 'N_azimuthal', 'type': 'uint', 'value': None }, { 'name': 'angular_step_axial', 'type': 'float', 'value': None }, { 'name': 'angular_step_azimuthal', 'type': 'float', 'value': None }, { 'name': 'size_u', 'type': 'float', 'value': None }, { 'name': 'size_v', 'type': 'float', 'value': None }, { 'name': 'N_u', 'type': 'uint', 'value': None }, { 'name': 'N_v', 'type': 'uint', 'value': None }, { 'name': 'offsets', 'type': 'array', 'value': None, 'dtype': np.uint32, 'size': (N_axial, N_azimuthal) }, { 'name': 'counts', 'type': 'array', 'value': None, 'dtype': np.float32, 'size': N_counts }, { 'name': 'locations', 'type': 'array', 'value': None, 'dtype': np.uint16, 'size': (N_counts, 3) }, ] r = call_c_function(petlink32_c.get_static_projection, descriptor) if not r.status == status_success(): raise ErrorInCFunction( "The execution of 'get_static_projection' was unsuccesful.", r.status, 'petlink32_c.get_static_projection') return r.dictionary