Code Description¶
MMG_Toolbox¶
Magnetic Materials Group Toolbox
Experiment
¶
Experiment class Monitors data folders for scan files and provies a convenient way to load scan data using only a scan number.
E.G. from mmg_toolbox import Experiment exp = Experiment('path/to/folder1', 'path/to/folder2', instrument='i06') print(scan) scan = exp.scan(-1) # latest scan scan_list = exp.scans(range(12345, 12355)) data = exp.join_scan_data(range(-100, 0), data_fields=['cmd', 'Ta']) # returns dict of arrays
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_paths
|
str
|
file directories containing .nxs files |
()
|
instrument
|
str | None
|
instrument name for configuration. |
None
|
Source code in mmg_toolbox/utils/experiment.py
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
add_data_paths(*folder_paths)
¶
Add additional paths
Source code in mmg_toolbox/utils/experiment.py
find_scans(*scan_files, hdf_map=None, first_only=False, **matches)
¶
Find scans files with matching metadata
matches = {
'name1': 'scan', # matches if 'scan' in file['name1']
'name2': value, # matches if file['name2'] ~= value
'name3': (value, tol), # matches if abs(file['name3'] - value) < tol
}
match_files = find_scans(*filenames, **matches)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_files
|
int | str
|
set of scan numbers or filenames, if not given will search all scans in folder. |
()
|
hdf_map
|
NexusMap | None
|
if given, uses this hdfmap rather than generating one. |
None
|
first_only
|
bool
|
if true, returns on the first result |
False
|
matches
|
str | float | tuple[float, float]
|
keyword arguments for matching parameters |
{}
|
Returns:
| Type | Description |
|---|---|
list[NexusScan]
|
list of scan files that match all requirements |
Source code in mmg_toolbox/utils/experiment.py
generate_mesh(*scan_files, hdf_map=None, axes='axes', signal='axes', values=None)
¶
Generate 2D mesh from scan or scans
x, y, z = generate_mesh(*range(-10, 0), axes='eta', signal='roi2_sum', values='Tsample')
# or, if scan 12345 is a 2D grid scan
x, y, z = generate_mesh(12345, axes=('sx', 'sy'), signal='roi2_sum')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_files
|
int | str
|
multiple files or single 2D grid scan |
()
|
hdf_map
|
NexusMap | None
|
hdfmap.NeXus map, or None to generate |
None
|
axes
|
str | tuple[str, str]
|
x-axis name, or for grid scans the names of ('xaxis', 'yaxis') |
'axes'
|
signal
|
str
|
signal name |
'axes'
|
values
|
str | None
|
name of the value that changes between multiple files |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray]
|
X, Y, IMAGE rank 2 arrays |
Source code in mmg_toolbox/utils/experiment.py
generate_scans_title(*scan_files, metadata_str=None, hdf_map=None)
¶
Generate title from multiple scan files
Source code in mmg_toolbox/utils/experiment.py
get_all_data(*fields, default=np.array([0.0]))
¶
Return dict of data for all files
get_scan_filename(scan_file=-1)
¶
Return the full filename of a scan number
Source code in mmg_toolbox/utils/experiment.py
join_scan_data(*scan_files, hdf_map=None, data_fields=None, default=np.array([0.0]))
¶
Join data from scans
Source code in mmg_toolbox/utils/experiment.py
load_xas(*scan_files, sample_name='')
¶
Read XAS spectra containers
Source code in mmg_toolbox/utils/experiment.py
scan(scan_file=-1)
¶
scan_str(scan_file=0, metadata_str=None, hdf_map=None)
¶
Read scan file and return metadata string
Source code in mmg_toolbox/utils/experiment.py
scans(*scan_files, hdf_map=None)
¶
Read Nexus files as lazy NexusScan. All files use the same HdfMap, based on the first scan
Source code in mmg_toolbox/utils/experiment.py
scans_str(*scan_files, metadata_str=None, hdf_map=None)
¶
Return string description for multiple files
Source code in mmg_toolbox/utils/experiment.py
data_file_reader(filename, beamline=None)
¶
Read Nexus or dat file as DataHolder