Helper functions and variables, especially for handling CTSimU JSON objects via the rl_json
extension, as well as unit conversions and other types of conversions. These functions and variables are available directly under the ::ctsimu
namespace.
pi
—3.1415926535897931
ctsimu_module_namespace
— Namespace of the CTSimU module in aRTist. Should be set from aRTist when loading the module using::ctsimu::set_module_namespace
.module_directory
— The script directory (to access files inside the module package).json_path
— Absolute path to the currently loaded JSON file. Usually set by a::ctsimu::scenario
when a JSON scenario is loaded.
aRTist_available
— To check whether theaRTist
namespace is available.set_module_namespace { ns }
— Store reference to aRTist module namespace inctsimu
namespace, so that themodulemain.tcl
can be accessed. Used to show GUI status messages.set_module_directory { dir }
— Set the absolute directory path of the CTSimU module (in aRTist).set_json_path { jsonpath }
— Set the absolute path to the currently loaded JSON file, so thatget_absolute_path
can return the absolute location of files that are referenced in the JSON file.get_absolute_path { filename }
— Returns the absolute path for the requested filename, which is assumed to be given relative to the current JSON file. If an absolute path to a file is passed, it will be returned unchanged.set_json_path
should have been used to set the correct path beforehand.generate_projection_counter_format { nProjections }
— Generates a number format string to get the correct number of digits in the consecutive projection file names.add_filters_to_list { filter_list jobj key_sequence }
— Add filters from a given key sequence in the json object to the given filter list.
read_json_file { filename }
— Read JSON file, check its validity, and return a dictionary using rl_json.read_csv_file { filename }
— Read CSV file, return dict of lists: one list for each column, columns identified by column number (0
...N-1
).load_csv_into_tab_separated_string { filename { skip_x_le_zero 0 } }
— Loads CSV or TSV into a tab-separated string where all value pairs are in a consecutive tab-separated stream.skip_x_le_zero
(if set to1
) allows to skip lines that contain x-values <= 0 (necessary for X-ray spectra: aRTist does not support acceleration energies <= 0.)load_csv_into_list { filename }
— Loads CSV or TSV into list of consecutive values (line by line).
The module uses its own little logging system that invokes aRTist's logging system if available. If aRTist is not available, messages are simply printed on the console.
fail { message }
— Handles error messages.warning { message }
— Handles warning messages.info { message }
— Handles information messages.debug { message }
— Handles debug messages.status_info { message }
— Shows a status note in the module's GUI (if aRTist is available).
is_valid { value valid_list }
— Checks ifvalue
is an item in the listvalid_list
. Returns1
on success,0
ifvalue
is not in the list of valid values.
value_is_null { value }
— Checks if a specific value is set tonull
.value_is_null_or_zero { value }
— Checks if a specific value is set tonull
or zero (0
).object_value_is_null { json_obj }
— Checks if a JSON object has avalue
parameter and if this parameter is set tonull
.object_value_is_null_or_zero { json_obj }
— Checks if a JSON object has avalue
parameter and if this parameter is set tonull
or zero (0
).
-
get_value { dictionary { keys {} } {fail_value 0} }
— Get the specific value of the parameter that is located at the given sequence ofkeys
in the JSON dictionary. Returns thefail_value
(standard is0
) if the key sequence cannot be found or the value is set tonull
.Example:
get_value $object {center x value} 10.0
-
json_exists { dictionary { keys {} } }
— Passthrough of::rl_json::json exists
. -
json_isnull { dictionary { keys {} } }
— Passthrough of::rl_json::json isnull
. -
json_exists_and_not_null { dictionary { keys {} } }
— Returns1
if the key sequence exists and its value is notnull
. Otherwise returns0
. -
json_type { dictionary { keys {} } }
— Get type of JSON item indictionary
located by thekeys
sequence. Passthrough of::rl_json::json type
. -
json_extract { dictionary keys }
— Get the JSON sub-object that is located by a given sequence ofkeys
in the JSONdictionary
. -
json_extract_from_possible_keys { dictionary key_sequences }
— Searches the JSONdictionary
for each key sequence in the given list ofkey_sequences
. For the first sequence that exists, an extracted JSON object will be returned.
Unit conversion functions take a JSON object that must contain a value
and a unit
. Each function supports the allowed units from the CTSimU file format specification.
in_mm { value unit }
— Converts a length to mm.in_rad { value { unit "deg" } }
— Converts an angle to radians.in_deg { value { unit "rad" } }
— Converts an angle to degrees.in_s { value unit }
— Converts a time to seconds.in_mA { value unit }
— Converts a current to mA.in_kV { value unit }
— Converts a voltage to kV.in_deg_per_s { value unit }
— Converts an angular velocity to deg/s.in_g_per_cm3 { value unit }
— Converts a mass density to g/cm³.in_lp_per_mm { value unit }
— Converts a resolution to lp/mm.from_bool { value }
— Convertstrue
to1
andfalse
to0
.convert_SNR_FWHM { SNR_or_FWHM intensity }
— Converts between SNR and Gaussian FWHM for a given intensity (i.e., more generally, the given distribution's mean value).convert_to_native_unit { given_unit native_unit value }
— Checks which native unit is requested, converts JSONvalue
accordingly. Possible native units are"mm"
,"rad"
,"deg"
,"deg/s"
,"s"
,"mA"
,"kV"
,"g/cm^3"
,"bool"
and"string"
.json_convert_to_native_unit { native_unit value_and_unit { fallback_json_unit ""} }
— Like the previous functionconvert_to_native_unit
, but takes a JSON objectvalue_and_unit
that must contain avalue
and an associatedunit
(the "given unit"). Checks which native unit is requested, converts JSONvalue
accordingly.fallback_json_unit
is used if the unit is not specified in thevalue_and_unit
JSON object.get_value_in_native_unit { native_unit dictionary keys {fail_value 0} }
— Takes a sequence of JSONkeys
from the givendictionary
where a JSON object with a value/unit pair must be located. Returns the value of this JSON object in the requestednative_unit
. Returns thefail_value
(standard is0
) if the key sequence cannot be found or the value is set tonull
.