nirwals.physics.utils
Utility functions.
read_from_file(file, unit=u.dimensionless_unscaled)
Read wavelengths and corresponding values from a file.
The file must be in Numpy's .npz format, and it must contain arrays called "x" and "y". The x array is used for the wavelengths, which are supposed to be given in Angstrom. The values in the y array are supposed to be given in the unit specified by the unit parameter. If no unit is given, the values are assumed to be dimensionless.
The wavelengths in the x array are supposed to be sorted in ascending order, but this is not checked.
If the minimum wavelength defined in the file is greater than 1 A (or, more precisely, greater than 1.02 A), it is assumed that below the minimum wavelength in the file the values drop to 0 within 0.01 A, and the wavelength and value array are extended accordingly.
Similarly, if the maximum wavelength defined in the file is less than 50000 A, it is assumed that above the maximum wavelength the file the values drop to 0 within 0.01 A, and the wavelength and value array are extended accordingly.
These extensions ensure that the data returned by this function can safely be used across the whole wavelength range used by NIRWALS, even if the file data cover only part of that range.
Use the numpyfy.py script for converting csv files into data files that can be used with this function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file |
BinaryIO
|
The data file, in .npz format. |
required |
unit |
Unit
|
The unit to use for the values in the file's y array. |
dimensionless_unscaled
|
Returns:
| Type | Description |
|---|---|
tuple of Quantity
|
The wavelengths and corresponding values. |
Source code in nirwals/physics/utils.py
10 11 12 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 | |
shift(a, k)
Shift an array by k places.
A negative shift is to the left, a positive shift is to the right. "Gaps" resulting from the shift are filled with zeroes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a |
ndarray
|
Array to shift. |
required |
k |
int
|
Size of the shift. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The shifted array. |
Source code in nirwals/physics/utils.py
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 | |