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: radis.spectrum.spectrum.Spectrum) radis.spectrum.spectrum.Spectrum [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: radis.spectrum.spectrum.Spectrum) radis.spectrum.spectrum.Spectrum [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: radis.spectrum.spectrum.Spectrum) radis.spectrum.spectrum.Spectrum [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
- Transmittance(s: radis.spectrum.spectrum.Spectrum) radis.spectrum.spectrum.Spectrum [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: radis.spectrum.spectrum.Spectrum) radis.spectrum.spectrum.Spectrum [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
- 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: radis.spectrum.spectrum.Spectrum, wmin: Optional[float] = None, wmax: Optional[float] = None, wunit: Optional[str] = None, inplace: str = False) radis.spectrum.spectrum.Spectrum [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: radis.spectrum.spectrum.Spectrum, offset: float, unit: str, name: Optional[str] = None, inplace: bool = False) radis.spectrum.spectrum.Spectrum [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
.
- Other Parameters
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