io
Module for handling input/output of data
read_h5(filename, format)
Reads data from an HDF5 file based on the specified format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The path to the HDF5 file to read. |
required |
format |
str
|
The format of the data to read. Should be either "phonodark" or "darkmagic". |
required |
Returns:
Type | Description |
---|---|
The data read from the HDF5 file based on the specified format. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided format is not recognized. |
Source code in darkmagic/io.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
read_darkmagic(filename)
Reads data from an HDF5 file in the 'darkmagic' format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The path to the HDF5 file in DarkMAGIC format. |
required |
Returns:
Type | Description |
---|---|
Tuple[dict, dict, dict, dict]
|
Tuple containing the calculated values, numerics, model, and data in 'darkmagic' format. |
Source code in darkmagic/io.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
read_phonodark(filename)
Reads data from an HDF5 file in the 'phonodark' format and converts it to the 'darkmagic' format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The path to the HDF5 file in 'phonodark' format. |
required |
Returns:
Type | Description |
---|---|
Tuple[dict, dict, dict, dict]
|
Tuple containing the calculated values, numerics, model, and data converted to 'DarkMAGIC' format. |
Source code in darkmagic/io.py
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 |
|
write_darkmagic(out_file, material, model, numerics, m_chi, time, v_e, total_rate, diff_rate, binned_rate, comm=None)
Write data to hdf5 file in DarkMAGIC format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out_file |
Path to the output HDF5 file. |
required | |
material |
Material object. |
required | |
model |
Model object. |
required | |
numerics |
Numerics object. |
required | |
m_chi |
List of masses for the jobs. |
required | |
time |
List of times for the jobs. |
required | |
all_total_rate_list |
List of total rate data. |
required | |
all_diff_rate_list |
List of differential rate data. |
required | |
all_binned_rate_list |
List of binned rate data. |
required | |
comm |
MPI communicator for parallel writing (default is None). |
None
|
Returns:
Type | Description |
---|---|
None |
Source code in darkmagic/io.py
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 |
|
write_phonodark(out_file, material, model, numerics, masses, times, v_e, all_total_rate_list, all_diff_rate_list, all_binned_rate_list, comm=None)
Write data to hdf5 file in PhonoDark format
all_*_rate_list has a complicated format. For starters, it has as many elements as there are jobs. Each element is a list of the (m_chi, time) pairs that have been computed. Each of those elements is a two element array. The first element is a tuple of the mass and time index. The second element is either a scalar (total) or an array (binned and diff). For binned and diff, the dimensions of the array are num_bins and num_modes respectively.
So for example, if we have 4 masses and 2 times, distributed over 4 jobs, then diff_rate list will look like this: [ # This is the job 1 array, which does mass index 0 at time indices 0,1 [ [ [0, 0], [num_bins elements]], [[0, 1], [num_bins_elements], ...], # job 1 # This is the job 1 array, which does mass index 1 at time indices 0,1 [ [ [1, 0], [num_bins elements]], [[1, 1], [num_bins_elements], ...], # job 2 ... ] This format is temporary, just for backwards compatibility with PhonoDark.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out_file |
Path to the output HDF5 file. |
required | |
material |
Material object. |
required | |
model |
Model object. |
required | |
numerics |
Numerics object. |
required | |
masses |
List of masses for the jobs. |
required | |
times |
List of times for the jobs. |
required | |
all_total_rate_list |
List of total rate data. |
required | |
all_diff_rate_list |
List of differential rate data. |
required | |
all_binned_rate_list |
List of binned rate data. |
required | |
comm |
MPI communicator for parallel writing (default is None). |
None
|
Returns:
Type | Description |
---|---|
None |
Source code in darkmagic/io.py
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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
dict_from_h5group(group)
Recurses through an h5py group and creates a dictionary with the same structure.
Source code in darkmagic/io.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
|
h5group_to_dict(hdf5_file, group_name, data_dict)
Recurses through a dictionary and creates appropriate groups or datasets This is parallel friendly, nothing is variable length.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hdf5_file |
File
|
The h5py file object to write to |
required |
group_name |
str
|
The name of the group to write to |
required |
data_dict |
dict
|
The dictionary to write |
required |
Returns:
Type | Description |
---|---|
None |
Source code in darkmagic/io.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
phonodark_to_darkmagic(n, pp, times, m_chi)
Convert the dictionaries from PhonoDark to DarkMAGIC
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
dict
|
Numerics dictionary from PhonoDark |
required |
pp |
dict
|
Particle physics dictionary from PhonoDark |
required |
times |
ndarray
|
Array of times |
required |
m_chi |
ndarray
|
Array of dark matter masses |
required |
Returns:
Type | Description |
---|---|
Tuple[dict, dict, dict]
|
Tuple of Calculator, Numerics, Model dictionaries |
Source code in darkmagic/io.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|