radis.spectrum.operations module¶
Handy functions for manipulation of Spectrum
objects
Routine Listing¶
Operators:
multiply()
: simply uses*2
add_constant()
: simply uses+1
add_array()
: simply uses+a
add_spectra()
: simply uses1+s2
substract_spectra()
: simply uses1-s2
Note that these operators are purely algebraic and should not be used in place
of the line-of-sight functions, i.e, SerialSlabs()
(>
)
and MergeSlabs()
(//
)
Functions to manipulate one spectrum:
Play with baselines:
Functions to discard all but one spectral quantity:
Keeps all spectral quantities, but make emission equal to 0 (useful when calculating contributions of line of sight slabs):
Examples
Most of these functions are implemented with the standard operators. Ex:
((s_exp - 0.1)*10).plot() # works for a Spectrum s_exp
- PerfectAbsorber(s)[source]¶
Makes a new Spectrum with the same transmittance/absorbance as Spectrum
s
, but with radiance set to 0. Useful to get contribution of different slabs in line-of-sight calculations (see example).- Parameters
s (Spectrum) –
Spectrum
object- Returns
s_tr –
Spectrum
object, with only thetransmittance
,absorbance
and/orabscoeff
part ofs
, whereradiance_noslit
,emisscoeff
andemissivity_noslit
(if they exist) have been set to 0- Return type
Examples
Let’s say you have a total line of sight:
s_los = s1 > s2 > s3
If you now want to get the contribution of
s2
to the line-of-sight emission, you can do:(s2 > PerfectAbsorber(s3)).plot('radiance_noslit')
And the contribution of
s1
would be:(s1 > PerfectAbsorber(s2>s3)).plot('radiance_noslit')
See more examples in Line-of-Sight module
- Radiance(s)[source]¶
Returns a new Spectrum with only the
radiance
component ofs
- Parameters
s (Spectrum) –
Spectrum
object- Returns
s_tr –
Spectrum
object, with onlyradiance
defined- Return type
Examples
This function is useful to use Spectrum algebra operations:
s = calc_spectrum(...) # contains emission & absorption arrays rad = Radiance(s) # contains radiance array only rad -= 0.1 # arithmetic operation is applied to Radiance only
Equivalent to:
rad = s.take('radiance')
See also
Radiance_noslit()
,Transmittance_noslit()
,Transmittance()
,take()
- Radiance_noslit(s)[source]¶
Returns a new Spectrum with only the
radiance_noslit
component ofs
- Parameters
s (Spectrum) –
Spectrum
object- Returns
s_tr –
Spectrum
object, with onlyradiance_noslit
defined- Return type
Examples
This function is useful to use Spectrum algebra operations:
s = calc_spectrum(...) # contains emission & absorption arrays rad = Radiance_noslit(s) # contains 'radiance_noslit' array only rad -= 0.1 # arithmetic operation is applied to Radiance_noslit only
Equivalent to:
rad = s.take('radiance_noslit')
See also
Radiance()
,Transmittance_noslit()
,Transmittance()
,take()
- Transmittance(s)[source]¶
Returns a new Spectrum with only the
transmittance
component ofs
- Parameters
s (Spectrum) –
Spectrum
object- Returns
s_tr –
Spectrum
object, with only thetransmittance
,absorbance
and/orabscoeff
part ofs
, whereradiance_noslit
,emisscoeff
andemissivity_noslit
(if they exist) have been set to 0- Return type
Examples
This function is useful to use Spectrum algebra operations:
s = calc_spectrum(...) # contains emission & absorption arrays tr = Transmittance(s) # contains 'radiance_noslit' array only tr -= 0.1 # arithmetic operation is applied to Transmittance only
Equivalent to:
rad = s.take('transmittance')
See also
Transmittance_noslit()
,Radiance_noslit()
,Radiance()
,take()
- Transmittance_noslit(s)[source]¶
Returns a new Spectrum with only the
transmittance_noslit
component ofs
- Parameters
s (Spectrum) –
Spectrum
object- Returns
s_tr –
Spectrum
object, with onlytransmittance_noslit
defined- Return type
Examples
This function is useful to use Spectrum algebra operations:
s = calc_spectrum(...) # contains emission & absorption arrays tr = Transmittance_noslit(s) # contains 'radiance_noslit' array only tr -= 0.1 # arithmetic operation is applied to Transmittance_noslit only
Equivalent to:
rad = s.take('transmittance_noslit')
See also
Transmittance()
,Radiance_noslit()
,Radiance()
,take()
- add_array(s, a, unit=None, var=None, inplace=False)[source]¶
Return a new spectrum with a constant added to s[var]. Equivalent to:
s + array
- Parameters
s (Spectrum objects) – Spectrum you want to modify
a (numpy array, or
Quantity
) – array to add. Must have the same length as variablevar
in Spectrums
. Can be dimensioned withunits
.unit (str) – unit for
a
. IfNone
, uses the default unit ins
for variablevar
.var (str, or
None
) – ‘radiance’, ‘transmittance’, … IfNone
, get the unique spectral quantity ofs
or raises an error if there is any ambiguityinplace (bool) – if
True
, modifiess
directly. Else, returns a copy. DefaultFalse
- Returns
s – Spectrum object where array
a
is added to intensity of s[‘var’] Ifinplace=True
,s
has been modified directly.- Return type
Notes
Use only for rough work. If you want to work properly with spectrum objects, see MergeSlabs.
Examples
Add Gaussian noise to your Spectrum (assuming there is only one spectral quantity defined):
s += np.random.normal(0,1,len(s.get_wavelength()))
- add_constant(s, cst, unit=None, var=None, inplace=False)[source]¶
Return a new spectrum with a constant added to s[var]. Equivalent to:
s + constant
- Parameters
s (Spectrum objects) – Spectrum you want to modify
cst (float) – Constant to add.
unit (str) – unit for
cst
. IfNone
, uses the default unit ins
for variablevar
.var (str, or
None
) – ‘radiance’, ‘transmittance’, … IfNone
, get the unique spectral quantity ofs
or raises an error if there is any ambiguityinplace (bool) – if
True
, modifiess
directly. Else, returns a copy. DefaultFalse
- Returns
s – Spectrum object where cst is added to intensity of s[‘var’] If
inplace=True
,s
has been modified directly.- Return type
Notes
Use only for rough work. If you want to work properly with spectrum objects, see
MergeSlabs()
.
- add_spectra(s1, s2, var=None, force=False)[source]¶
Return a new spectrum with
s2
added tos1
. Equivalent to:s1 + s2
Warning
we are just algebrically adding the quantities. If you want to merge spectra while preserving the radiative transfer equation, see
MergeSlabs()
andSerialSlabs()
- Parameters
s1, s2 (Spectrum objects) – Spectrum you want to substract
var (str) – quantity to manipulate: ‘radiance’, ‘transmittance’, … If
None
, get the unique spectral quantity ofs1
, or the unique spectral quantity ofs2
, or raises an error if there is any ambiguity
- Returns
s – Spectrum object with the same units and waveunits as
s1
- Return type
See also
- concat_spectra(s1, s2, var=None)[source]¶
Concatenate two spectra
s1
ands2
side by side.Note: their spectral range should not overlap
- Returns
s – Spectrum object with the same units and waveunits as
s1
- Return type
- Parameters
s1, s2 (Spectrum objects) – Spectrum you want to concatenate
var (str) – quantity to manipulate: ‘radiance’, ‘transmittance’, … If
None
, get the unique spectral quantity ofs1
, or the unique spectral quantity ofs2
, or raises an error if there is any ambiguity
Notes
Warning
the output Spectrum has the sum of the spectral ranges of s1 and s2. It won’t be evenly spaced. This means that you cannot apply a slit without side effects. Typically, you want to use this function for convolved quantities only, such as experimental spectra. Else, use
MergeSlabs()
with the optionsresample='full', out='transparent'
See also
- crop(s, wmin=None, wmax=None, wunit=None, inplace=False)[source]¶
Crop spectrum to
wmin-wmax
range inwunit
- Parameters
s (Spectrum object) – object to crop
wmin, wmax (float, or None) – boundaries of spectral range (in
wunit
)- wunit:
'nm'
,'cm-1'
,'nm_vac'
which waveunit to use for
wmin, wmax
. Ifdefault
: use the default Spectrum wavespace defined withget_waveunit()
.
- wunit:
- Other Parameters
inplace (bool) – if
True
, modifiys
directly. Else, returns a copy.- Returns
s_crop – a cropped Spectrum. if using
inplace
, thens_crop
ands
are still the same object- Return type
Examples
crop(s, 420, 480, 'nm', 'air')
Or in
cm-1
:crop(s, 2000, 2300, 'cm-1')
- get_baseline(s, var='radiance', Iunit=None)[source]¶
Calculate and returns a baseline
- Parameters
s (Spectrum) – Spectrum which needs a baseline
var (str) – on which spectral quantity to read the baseline. Default
'radiance'
. SeeSPECTRAL_QUANTITIES
- Returns
baseline – Spectrum object where intenisity is the baseline of s is computed by peakutils
- Return type
See also
- multiply(s, coef, unit=None, var=None, inplace=False)[source]¶
Multiply s[var] by the float ‘coef’
- Parameters
s (Spectrum object) – The spectrum to multiply.
coef (float) – Coefficient of the multiplication.
unit (str, or
Unit
) – unit forcoef
. IfNone
,coef
is considered to be adimensioned. Else, the spectrumunits
is multiplied.var (str, or
None
) – ‘radiance’, ‘transmittance’, … IfNone
, get the unique spectral quantity ofs
or raises an error if there is any ambiguityinplace (bool) – if
True
, modifiess
directly. Else, returns a copy. DefaultFalse
- Returns
s – Spectrum object where intensity of s[‘var’] is multiplied by coef If
inplace=True
,s
has been modified directly.- Return type
- offset(s, offset, unit, name=None, inplace=False)[source]¶
Offset the spectrum by a wavelength or wavenumber
- Parameters
s (Spectrum) – Spectrum you want to modify
offset (float) – Constant to add to all quantities in the Spectrum.
unit (‘nm’ or ‘cm-1’) – unit for
offset
.name (str) – name of output spectrum
inplace (bool) – if
True
, modifiess
directly. Else, returns a copy. DefaultFalse
- Returns
s – Spectrum object where cst is added to intensity of s[‘var’] If
inplace=True
,s
has been modified directly.- Return type
See also
call
- sub_baseline(s, left, right, unit=None, var=None, inplace=False)[source]¶
Return a new spectrum with a baseline substracted to s[var]
- Parameters
s (Spectrum objects) – Spectrum you want to modify
left (Float) – Constant to substract on the left of the spectrum.
right (Float) – Constant to substract on the right of the spectrum.
unit (str) – unit for
cst
. IfNone
, uses the default unit ins
for variablevar
.var (str) – ‘radiance’, ‘transmittance’, … If
None
, get the unique spectral quantity ofs
or raises an error if there is any ambiguityinplace (bool) – if
True
, modifiess
directly. Else, returns a copy. DefaultFalse
- Returns
s – Spectrum object where the baseline was substracted to intensity of s[‘var’] If
inplace=True
,s
has been modified directly.- Return type
Notes
Use only for rough work.
See also
- substract_spectra(s1, s2, var=None)[source]¶
Return a new spectrum with
s2
substracted froms1
. Equivalent to:s1 - s2
- Parameters
s1, s2 (Spectrum objects) – Spectrum you want to substract
var (str) – quantity to manipulate: ‘radiance’, ‘transmittance’, … If
None
, get the unique spectral quantity ofs1
, or the unique spectral quantity ofs2
, or raises an error if there is any ambiguity
- Returns
s – Spectrum object with the same units and waveunits as
s1
- Return type
See also