Class: HdfLoader¶
HDF Loader contains the filename and hdfmap for a HDF file, the hdfmap contains all the dataset paths and a namespace, allowing data to be called from the file using variable names, loading only the required datasets for each operation.
E.G.¶
hdf = HdfLoader('file.hdf')
[data1, data2] = hdf.get_data(*['dataset_name_1', 'dataset_name_2'])
data = hdf.eval('dataset_name_1 * 100 + 2')
string = hdf.format('my data is {dataset_name_1:.2f}')
print(hdf.summary())
Source code in src/hdfmap/reloader_class.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
eval(expression, default=DEFAULT)
¶
Evaluate an expression using the namespace of the hdf file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expression
|
str
|
str expression to be evaluated |
required |
default
|
returned if varname not in namespace |
DEFAULT
|
Returns:
Type | Description |
---|---|
eval(expression) |
Source code in src/hdfmap/reloader_class.py
find_hdf_paths(string, name_only=True, whole_word=False)
¶
Find any dataset paths that contain the given string argument
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
str to find in list of datasets |
required |
name_only
|
bool
|
if True, search only the name of the dataset, not the full path |
True
|
whole_word
|
bool
|
if True, search only for case in-sensitive name |
False
|
Returns:
Type | Description |
---|---|
list[str]
|
list of hdf paths |
Source code in src/hdfmap/reloader_class.py
find_names(string)
¶
Find any dataset names that contain the given string argument, searching names in self.combined
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
str to find in list of datasets |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list of names |
Source code in src/hdfmap/reloader_class.py
format(expression, default=DEFAULT)
¶
Evaluate a formatted string expression using the namespace of the hdf file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expression
|
str
|
str expression using {name} format specifiers |
required |
default
|
returned if varname not in namespace |
DEFAULT
|
Returns:
Type | Description |
---|---|
eval_hdf(f"expression") |
Source code in src/hdfmap/reloader_class.py
get_data(*name_or_path, index=(), default=None, direct_load=False)
¶
Return data from dataset in file, converted into either datetime, str or squeezed numpy.array objects See hdfmap.eval_functions.dataset2data for more information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_or_path
|
str name or path pointing to dataset in hdf file |
()
|
|
index
|
slice
|
index or slice of data in hdf file |
()
|
default
|
value to return if name not found in hdf file |
None
|
|
direct_load
|
return str, datetime or squeezed array if False, otherwise load data directly |
False
|
Returns:
Type | Description |
---|---|
dataset2data(dataset) -> datetime, str or squeezed array as required. |
Source code in src/hdfmap/reloader_class.py
get_hdf_path(name_or_path)
¶
get_image(index=None)
¶
Get image data from file, using default image path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
slice
|
(slice,) or None to take the middle image |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
numpy array of image |
Source code in src/hdfmap/reloader_class.py
get_scannables()
¶
get_string(*name_or_path, index=(), default='', units=False)
¶
Return data from dataset in file, converted into summary string See hdfmap.eval_functions.dataset2data for more information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_or_path
|
str name or path pointing to dataset in hdf file |
()
|
|
index
|
slice
|
index or slice of data in hdf file |
()
|
default
|
value to return if name not found in hdf file |
''
|
|
units
|
if True and attribute 'units' available, append this to the result |
False
|
Returns:
Type | Description |
---|---|
dataset2str(dataset) -> str |