misc_functions¶
Miscellaneous functions
DataHolder
¶
Bases: dict
Convert dict to object that looks like a class object with key names as attributes Replicates slightly the old scisoftpy.dictutils.DataHolder class, also known as DLS dat format. obj = DataHolder(**{'item1': 'value1'}) obj['item1'] -> 'value1' obj.item1 -> 'value1' obj.keys() -> dict.keys()
Source code in mmg_toolbox/utils/misc_functions.py
consolidate_numeric_strings(*args)
¶
Consolidate list of strings by finding numbers in strings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
str
|
list of strings |
()
|
Returns:
| Type | Description |
|---|---|
list
|
reduced list of strings |
Source code in mmg_toolbox/utils/misc_functions.py
consolidate_strings(*args, match_symbol='*', match_score=0.6)
¶
Consolidate list of strings by finding matching components and replace differences with a symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
tuple
|
list of strings |
()
|
match_symbol
|
str
|
str to replace non-matching |
'*'
|
match_score
|
float
|
float 0-1, difference score greater than this will be replaced |
0.6
|
Returns:
| Type | Description |
|---|---|
list
|
reduced list of strings |
Source code in mmg_toolbox/utils/misc_functions.py
data_holder(scan_data, metadata)
¶
Create DataHolder object from scan data and metadata Return object that slightly replicates the old scisoftpy.dictutils.DataHolder class, also known as DLS dat format.
Source code in mmg_toolbox/utils/misc_functions.py
findranges(scannos, sep=':')
¶
Convert a list of numbers to a simple string E.G. findranges([1,2,3,4,5]) = '1:5' findranges([1,2,3,4,5,10,12,14,16]) = '1:5,10:2:16'
Source code in mmg_toolbox/utils/misc_functions.py
numbers2string(scannos, sep=':')
¶
Convert a list of numbers to a simple string E.G. numbers2string([50001,50002,50003]) = '5000[1:3]' numbers2string([51020,51030,51040]) = '510[20:10:40]'
Source code in mmg_toolbox/utils/misc_functions.py
round_string_floats(string)
¶
Shorten string by removing long floats
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
string, e.g. '#810002 scan eta 74.89533603616637 76.49533603616636 0.02 pil3_100k 1 roi2' |
required |
Returns:
| Type | Description |
|---|---|
str
|
shorter string, e.g. '#810002 scan eta 74.895 76.495 0.02 pil3_100k 1 roi2' |
Source code in mmg_toolbox/utils/misc_functions.py
shorten_string(string, max_length=100)
¶
Return a shortend version of the first line of the string
Source code in mmg_toolbox/utils/misc_functions.py
stfm(value, error)
¶
Create standard form string from value and uncertainty" str = stfm(val,err) Examples: '35.25 (1)' = stfm(35.25,0.01) '110 (5)' = stfm(110.25,5) '0.0015300 (5)' = stfm(0.00153,0.0000005) '1.56(2)E+6' = stfm(1.5632e6,1.53e4)
Notes: - Errors less than 0.01% of values will be given as 0 - The maximum length of string is 13 characters - Errors greater than 10x the value will cause the value to be rounded to zero