useful_functions
Useful generics functions.
useful_functions.degre2(x, a, b, c)
2nd degree polynomial.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
array - like or float
|
|
required |
a |
float
|
|
required |
b |
float
|
|
required |
c |
float
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
y |
float
|
|
Source code in omegapy/useful_functions.py
useful_functions.degre3(x, a, b, c, d)
3rd degree polynomial.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
array - like or float
|
|
required |
a |
float
|
|
required |
b |
float
|
|
required |
c |
float
|
|
required |
d |
float
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
y |
float
|
|
Source code in omegapy/useful_functions.py
useful_functions.f_lin(x, a, b)
Linear function: returns f(x) = a*x + b
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
float or ndarray
|
|
required |
a |
float
|
The line slope. |
required |
b |
float
|
The origin ordinate. |
required |
Returns:
Type | Description |
---|---|
f(x) = a*x + b : float or ndarray
|
|
Source code in omegapy/useful_functions.py
useful_functions.fit_black_body(lam, sp, T_bounds=(0, 1000000.0))
Return the temperature associated to the fitted black body thermical spectrum.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lam |
array - like
|
The wavelength array (in m). |
required |
sp |
array - like
|
The spectral radiance (in W.m-2.sr-1.m-1) to be fitted. |
required |
T_bounds |
2 - tuple
|
The bounds for the temperature fitting. |
(0, 1e6)
|
Returns:
Name | Type | Description |
---|---|---|
T |
float
|
The temperature of the fitted Planck's law radiance (in K). |
Source code in omegapy/useful_functions.py
useful_functions.idl_spline(X, Y, T, sigma=1.0)
Performs a cubic spline interpolation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
ndarray
|
The abcissa vector. Values MUST be monotonically increasing. |
required |
Y |
ndarray
|
The vector of ordinate values corresponding to X. |
required |
T |
ndarray
|
The vector of abcissae values for which the ordinate is desired. The values of T MUST be monotonically increasing. |
required |
Sigma |
float
|
The amount of "tension" that is applied to the curve. The default value is 1.0. If sigma is close to 0, (e.g., .01), then effectively there is a cubic spline fit. If sigma is large, (e.g., greater than 10), then the fit will be like a polynomial interpolation. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
spl |
ndarray
|
Vector of interpolated ordinates. Result(i) = value of the function at T(i). |
Source code in omegapy/useful_functions.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
|
useful_functions.load_pickle(filename, disp=True)
Load and return a previously saved object with pickle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The file path. |
required |
disp |
bool
|
Control the display.
| |
True
|
Returns:
Name | Type | Description |
---|---|---|
obj |
Object
|
The loaded object. |
Source code in omegapy/useful_functions.py
useful_functions.median_filter(sp, n)
Apply a median filter on the values of the spectrum, by replacing each value by the median of the values in a 2n+1 wide window, centered on the considered value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sp |
ndarray
|
Array of transmittance values. |
required |
n |
int
|
The len of the window the moving median is 2n+1. |
required |
Returns:
Name | Type | Description |
---|---|---|
sp_med |
ndarray
|
Filtered transmittance array. |
Source code in omegapy/useful_functions.py
useful_functions.moving_average(sp, n)
Apply a moving average filter on the values of the spectrum, by replacing each value by the average of the values in a 2n+1 wide window, centered on the considered value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sp |
ndarray
|
Array of the transmittance values. |
required |
n |
int
|
The len of the window of the moving average is 2n+1. |
required |
Returns:
Name | Type | Description |
---|---|---|
sp_med |
ndarray
|
Filtered transmittance array. |
Source code in omegapy/useful_functions.py
useful_functions.myglob(basename, exclude=[], recursive=False)
Return the absolute path according to the input basename
.
If multiple files corresponds to basename
, the user will be asked
to choose one.
int
→ Select the corresponding filename.q
/quit
/exit
→ ReturnNone
.a
/all
→ Return the list of all filenames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
basename |
str
|
The basename of the target file. |
required |
exclude |
array-like of str
|
List of sub-strings to exclude from the results. |
[]
|
recursive |
bool
|
If recursive is True, the pattern |
False
|
Returns:
Name | Type | Description |
---|---|---|
fname |
str
|
The absolute path of the selected file. |
Source code in omegapy/useful_functions.py
useful_functions.planck(lam, T)
Return the Black body radiance, associated to the input wavelength and temperature. According to the Planck's law.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lam |
float or array - like
|
The wavelength (in m). |
required |
T |
float
|
The temperature (in K). |
required |
Returns:
Name | Type | Description |
---|---|---|
B_lam |
float or array - like
|
The spectral radiance (in W.m-2.sr-1.m-1). |
Source code in omegapy/useful_functions.py
useful_functions.reg_lin(X, Y, **kwargs)
Return the result of the linear regression ( f(x) = a*x + b ) on the input values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
ndarray
|
The X-values. |
required |
Y |
ndarray
|
The Y-values. |
required |
**kwargs |
Optional keyword arguments to pass to the |
{}
|
Returns:
Name | Type | Description |
---|---|---|
a |
float
|
Slope of the fitted line. |
b |
float
|
Origin ordinate of the fitted line. |
Source code in omegapy/useful_functions.py
useful_functions.save_pickle(obj, target_path, disp=True)
Save an object at the selected path using the pickle module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Object
|
The object to save. |
required |
target_path |
str
|
The saving path name. |
required |
disp |
bool
|
Control the display.
| |
True
|
Source code in omegapy/useful_functions.py
useful_functions.sort_dict(dico)
Sort a dictionary by its keys values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dico |
dict
|
The input unsorted dictionary. |
required |
Returns:
Name | Type | Description |
---|---|---|
dico_sorted |
dict
|
The sorted dictionary. |
Source code in omegapy/useful_functions.py
useful_functions.test_security_overwrite(path)
Test if a file already exists, and if yes ask the user if he wants to ovewrite it or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The target file path. |
required |
Returns:
Name | Type | Description |
---|---|---|
overwrite |
bool
|
| |
Source code in omegapy/useful_functions.py
useful_functions.where_closer(value, array)
Return the index of the closest value to value
in array
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
float
|
Searched value. |
required |
array |
ndarray
|
The array. |
required |
Returns:
Name | Type | Description |
---|---|---|
i |
int
|
The index of the closer value to |
Source code in omegapy/useful_functions.py
useful_functions.where_closer_array(values, array)
Return the list of the indexes of the closest values to values
in array
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
ndarray
|
Array of searched values. |
required |
array |
ndarray
|
The array. |
required |
Returns:
Name | Type | Description |
---|---|---|
I |
ndarray
|
Array of the index of the closest values in |