brukeropus.file.labels
1import warnings 2from brukeropus.file.constants import TYPE_CODE_LABELS, CODE_3_ABR 3 4 5__docformat__ = "google" 6 7 8def get_type_code_label(pos_idx: int, val: int): 9 '''Returns the type code label of a file block given the position index and value of the type code. 10 11 **Depreciation Warning:** function will be removed soon. Functionality has been integrated into `BlockType` class. 12 13 The file blocks on an OPUS file feature six-integer type codes, for example (3, 1, 1, 2, 0, 0), that categorize the 14 contents of the file block. The positional index defines the category, while the value at that index defines the 15 specific type of that category. For example, the first integer (pos_idx=0), describes the type of data in the 16 block, if applicable: 17 18 0: Undefined or N/A, 19 1: Real Part of Complex Data, 20 2: Imaginary Part of Complex Data, 21 3: Amplitude 22 23 This package includes the majority of type codes that OPUS uses, but in the event a type code label is not known, 24 this function will return: "Unknown 0 4" where the first number is the position index, and the second is the 25 unknown value integer. 26 27 Args: 28 pos_idx: positional index of the type code (0 - 5) 29 val: value of the type code 30 31 Returns: 32 label (str): human-readable string label that describes the type code. 33 ''' 34 warnings.warn('Depreciation warning: get_type_code_label will soon be removed. This functionality has moved to `BlockType` class') 35 try: 36 return TYPE_CODE_LABELS[pos_idx][val] 37 except KeyError: 38 return 'Unknown ' + str(pos_idx) + ' ' + str(val) 39 40 41def get_block_type_label(block_type: tuple): 42 '''Converts a six-integer tuple block type into a human readable label. 43 44 **Depreciation Warning:** function will be removed soon. Functionality has been integrated into `BlockType` class. 45 46 Args: 47 block_type: six integer tuple found in the OPUS file directory that describes the block type 48 49 Returns: 50 label (str): human-readable string label 51 ''' 52 warnings.warn('Depreciation warning: get_block_type_label will soon be removed. This functionality has moved to `BlockType` class') 53 labels = [get_type_code_label(idx, val) for idx, val in enumerate(block_type) if val > 0 54 and get_type_code_label(idx, val) != ''] 55 return ' '.join(labels) 56 57 58def get_data_key(block_type: tuple): 59 '''Returns a shorthand key for a given data block type: sm, rf, igsm, a, t, r, etc. 60 61 Determines if the data block type is an interferogram, single-channel, absorption, etc. and whether it is associated 62 with the sample or reference channel and returns a shortand key-like label: sm, rf, igsm, igrf, a, t, r, etc. For 63 the full data label (e.g. Sample Spectrum, Absorbance) use: get_block_type_label. 64 This package includes the majority of type codes that OPUS uses, but in the event a type code label is not known, 65 this function will return: "_33" or "sm_33" where 33 will change to the unkown block_type integer value. 66 67 Args: 68 block_type: six integer tuple found in the OPUS file directory that describes the block type 69 70 Returns: 71 key (str): shorthand string label that can be utilized as a data key (e.g. "sm", "igrf", "a")''' 72 warnings.warn('Depreciation warning: get_data_key will soon be removed. This functionality has moved to `FileBlock` class') 73 if block_type[3] in CODE_3_ABR.keys(): 74 key = CODE_3_ABR[block_type[3]] 75 if block_type[1] == 1: 76 key = merge_key(key, 'sm') 77 elif block_type[1] == 2: 78 key = merge_key(key, 'rf') 79 elif block_type[1] > 3: 80 key = key + '_' + str(block_type[1]) 81 else: 82 key = '_' + str(block_type[3]) 83 if block_type[1] == 1: 84 key = 'sm' + key 85 elif block_type[1] == 2: 86 key = 'rf' + key 87 elif block_type[1] > 3: 88 key = '_' + str(block_type[1]) + key 89 if block_type[5] == 4: 90 key = key + '_c' 91 return key 92 93 94def merge_key(key: str, sm: str): 95 '''Merges "sm" or "rf" into an abreviated data key. For special cases like ig or pw, the addition is appended 96 (e.g. igsm, phrf), but for other cases, the addition is prepended (e.g. sm_2ch, rf_3ch)''' 97 warnings.warn('Depreciation warning: merge_key will soon be removed. This functionality has moved to `FileBlock` class') 98 if key[:2] in ['ig', 'ph', 'pw']: 99 return key[:2] + sm + key[2:] 100 else: 101 return sm + key
9def get_type_code_label(pos_idx: int, val: int): 10 '''Returns the type code label of a file block given the position index and value of the type code. 11 12 **Depreciation Warning:** function will be removed soon. Functionality has been integrated into `BlockType` class. 13 14 The file blocks on an OPUS file feature six-integer type codes, for example (3, 1, 1, 2, 0, 0), that categorize the 15 contents of the file block. The positional index defines the category, while the value at that index defines the 16 specific type of that category. For example, the first integer (pos_idx=0), describes the type of data in the 17 block, if applicable: 18 19 0: Undefined or N/A, 20 1: Real Part of Complex Data, 21 2: Imaginary Part of Complex Data, 22 3: Amplitude 23 24 This package includes the majority of type codes that OPUS uses, but in the event a type code label is not known, 25 this function will return: "Unknown 0 4" where the first number is the position index, and the second is the 26 unknown value integer. 27 28 Args: 29 pos_idx: positional index of the type code (0 - 5) 30 val: value of the type code 31 32 Returns: 33 label (str): human-readable string label that describes the type code. 34 ''' 35 warnings.warn('Depreciation warning: get_type_code_label will soon be removed. This functionality has moved to `BlockType` class') 36 try: 37 return TYPE_CODE_LABELS[pos_idx][val] 38 except KeyError: 39 return 'Unknown ' + str(pos_idx) + ' ' + str(val)
Returns the type code label of a file block given the position index and value of the type code.
Depreciation Warning: function will be removed soon. Functionality has been integrated into BlockType
class.
The file blocks on an OPUS file feature six-integer type codes, for example (3, 1, 1, 2, 0, 0), that categorize the contents of the file block. The positional index defines the category, while the value at that index defines the specific type of that category. For example, the first integer (pos_idx=0), describes the type of data in the block, if applicable:
0: Undefined or N/A,
1: Real Part of Complex Data,
2: Imaginary Part of Complex Data,
3: Amplitude
This package includes the majority of type codes that OPUS uses, but in the event a type code label is not known, this function will return: "Unknown 0 4" where the first number is the position index, and the second is the unknown value integer.
Arguments:
- pos_idx: positional index of the type code (0 - 5)
- val: value of the type code
Returns:
label (str): human-readable string label that describes the type code.
42def get_block_type_label(block_type: tuple): 43 '''Converts a six-integer tuple block type into a human readable label. 44 45 **Depreciation Warning:** function will be removed soon. Functionality has been integrated into `BlockType` class. 46 47 Args: 48 block_type: six integer tuple found in the OPUS file directory that describes the block type 49 50 Returns: 51 label (str): human-readable string label 52 ''' 53 warnings.warn('Depreciation warning: get_block_type_label will soon be removed. This functionality has moved to `BlockType` class') 54 labels = [get_type_code_label(idx, val) for idx, val in enumerate(block_type) if val > 0 55 and get_type_code_label(idx, val) != ''] 56 return ' '.join(labels)
Converts a six-integer tuple block type into a human readable label.
Depreciation Warning: function will be removed soon. Functionality has been integrated into BlockType
class.
Arguments:
- block_type: six integer tuple found in the OPUS file directory that describes the block type
Returns:
label (str): human-readable string label
59def get_data_key(block_type: tuple): 60 '''Returns a shorthand key for a given data block type: sm, rf, igsm, a, t, r, etc. 61 62 Determines if the data block type is an interferogram, single-channel, absorption, etc. and whether it is associated 63 with the sample or reference channel and returns a shortand key-like label: sm, rf, igsm, igrf, a, t, r, etc. For 64 the full data label (e.g. Sample Spectrum, Absorbance) use: get_block_type_label. 65 This package includes the majority of type codes that OPUS uses, but in the event a type code label is not known, 66 this function will return: "_33" or "sm_33" where 33 will change to the unkown block_type integer value. 67 68 Args: 69 block_type: six integer tuple found in the OPUS file directory that describes the block type 70 71 Returns: 72 key (str): shorthand string label that can be utilized as a data key (e.g. "sm", "igrf", "a")''' 73 warnings.warn('Depreciation warning: get_data_key will soon be removed. This functionality has moved to `FileBlock` class') 74 if block_type[3] in CODE_3_ABR.keys(): 75 key = CODE_3_ABR[block_type[3]] 76 if block_type[1] == 1: 77 key = merge_key(key, 'sm') 78 elif block_type[1] == 2: 79 key = merge_key(key, 'rf') 80 elif block_type[1] > 3: 81 key = key + '_' + str(block_type[1]) 82 else: 83 key = '_' + str(block_type[3]) 84 if block_type[1] == 1: 85 key = 'sm' + key 86 elif block_type[1] == 2: 87 key = 'rf' + key 88 elif block_type[1] > 3: 89 key = '_' + str(block_type[1]) + key 90 if block_type[5] == 4: 91 key = key + '_c' 92 return key
Returns a shorthand key for a given data block type: sm, rf, igsm, a, t, r, etc.
Determines if the data block type is an interferogram, single-channel, absorption, etc. and whether it is associated with the sample or reference channel and returns a shortand key-like label: sm, rf, igsm, igrf, a, t, r, etc. For the full data label (e.g. Sample Spectrum, Absorbance) use: get_block_type_label. This package includes the majority of type codes that OPUS uses, but in the event a type code label is not known, this function will return: "_33" or "sm_33" where 33 will change to the unkown block_type integer value.
Arguments:
- block_type: six integer tuple found in the OPUS file directory that describes the block type
Returns:
key (str): shorthand string label that can be utilized as a data key (e.g. "sm", "igrf", "a")
95def merge_key(key: str, sm: str): 96 '''Merges "sm" or "rf" into an abreviated data key. For special cases like ig or pw, the addition is appended 97 (e.g. igsm, phrf), but for other cases, the addition is prepended (e.g. sm_2ch, rf_3ch)''' 98 warnings.warn('Depreciation warning: merge_key will soon be removed. This functionality has moved to `FileBlock` class') 99 if key[:2] in ['ig', 'ph', 'pw']: 100 return key[:2] + sm + key[2:] 101 else: 102 return sm + key
Merges "sm" or "rf" into an abreviated data key. For special cases like ig or pw, the addition is appended (e.g. igsm, phrf), but for other cases, the addition is prepended (e.g. sm_2ch, rf_3ch)