FittingFunction
Documentation for FittingFunction.
A set of functions I am often using in carrying out regressions.
FittingFunction.Band
FittingFunction.CPL
FittingFunction.Counts2Mag
FittingFunction.Ecm2sA2Jy
FittingFunction.Extinction
FittingFunction.FourierPeriodogram
FittingFunction.GaussAbs
FittingFunction.Gaussian
FittingFunction.GetAtomicData
FittingFunction.Jy2Ecm2sA
FittingFunction.Mag2Counts
FittingFunction.NorrisPulse
FittingFunction.PL
FittingFunction.Pol2Stokes
FittingFunction.SBPL
FittingFunction.SBPL2
FittingFunction.SigmaClip
FittingFunction.Stokes2Pol
FittingFunction.TauVoigt
FittingFunction.VoigtFunctTG
FittingFunction.XAbs
FittingFunction.Z2N
FittingFunction.Band
— MethodBand(E,α,β,E₀,A)
Compute the so-called 'Band function'
#Arguments
E
input energy.α
low-energy index.β
high-energy index.E₀
break energy.A
normalization.
The peak-energy is then $Ep = (2+α)E₀$.
Examples
Band(300.,-2.,-1.,200.,1.)
# output
-0.45304697140984085
FittingFunction.CPL
— MethodCPL(E,N,α,Ec;E0=1.)
Compute a cut-off power-law.
Arguments
α
spectral index.N
normalization.E
input energy.Ec
cut-off energy.E0
energy for power-law normalization.
Examples
CPL(3.,1.,-1.,2.)
# output
0.0743767200494766
FittingFunction.Counts2Mag
— MethodCounts2Mag(cts,ects;zp=25.0,ezp=0.0)
Convert counts (or flux) to magntudes,
Arguments
cts
counts.ects
count uncertainty.zp
magnitude zero-pointzp
zero-point uncertainty.
Examples
Counts2Mag(100,10)
# output
(20.0, 0.10857362047581294)
FittingFunction.Ecm2sA2Jy
— MethodEcm2sA2Jy(fluden, lambd)
Convert flux densities in $erg~s^{-1} cm^{-2} Angstrom^{-1}$ to $Jy$.
Arguments
fluden
flux density ($erg~s^{-1} cm^{-2} Angstrom^{-1}$).lambd
wavelength ($Angstrom$).
Examples
Ecm2sA2Jy([1.2e-15,2e-15,2.5e-15],[5000,5500,6000])
# output
3-element Vector{Float64}:
0.001
0.002016666666666667
0.0029999999999999996
FittingFunction.Extinction
— MethodExtinction(wave,EBV;gal="SMC",Rv=FFGals["SMC"],z=0.)
Compute the UV/optical/extinction.
Argguments
wave
input wavelengths (Angstrom).EBV
color excess E(B-V) (magnitude).gal
one of the galaxy extinction recipes listed in the 'FFGals' (exported) dictionary.Rv
selective extinction.z
redshift of the absorpber.
References about the adopted extinction curves are discussed in the documentation of the DustExtinction package.
Examples
Extinction(5500.,1,gal="MW",Rv=FFGals["MW"],z=0.)
# output
0.06017150537641227
FittingFunction.FourierPeriodogram
— MethodFourierPeriodogram(signal,fs;zerofreq=true)
Compute the discrete Fourier periodogram for the inpout signal.
Arguments
signal
array of input data.fs
sampling in frequency of the input data (1/dt).- 'zerofreq' is true (false) to (not) include the zero frequency in the output.
Outputs are two arrays: the frequencies and the powers.
Examples
FourierPeriodogram([1.,2.,3.,4.],1.)
# output
([0.0, 0.25], [100.0, 8.000000000000002])
FittingFunction.GaussAbs
— MethodGaussAbs(E,Ed,σ,El)
Compute a Gaussian absorption.
Arguments
Ed
depth. atE
input energy.El
absorption center.σ
absorption width ($FWHM/2.35$).A
normalization.
Examples
GaussAbs(2.,1.,0.1,2.)
# output
0.018510395162776326
FittingFunction.Gaussian
— MethodGaussian(E,A,σ,El)
Compute a Gaussian.
Arguments
E
input energy.El
Gussian center.σ
absorption width ($FWHM/2.35$).A
normalization.
Examples
Gaussian(3.,1.,0.1,2.)
# output
4.009419869036418
FittingFunction.GetAtomicData
— FunctionGetAtomicData(table::String="")::DataFrame
Return a table with atomic data among those available.
Calling the function with no parameter shows the available tables. At present we have:
- "FitLyman". This is the original table generated for the "FitLyman" ESO-MIDAS package.
- "JitrikBunge04". This is a collection of atomic data prepared by Jitrik & Bunge (2004).
- "VALD03". This is a collection of atomic data extracted from the VALD3 database.
Examples
fly = GetAtomicData("FitLyman")
FittingFunction.Jy2Ecm2sA
— MethodJy2Ecm2sA(fluden, lambd)
Convert flux densities in $Jy$ to $erg~s^{-1} cm^{-2} Angstrom^{-1}$.
Arguments
fluden
flux density ($Jy$).lambd
wavelength ($Angstrom$).
Examples
Jy2Ecm2sA([1e-3,2e-3,3e-3],[5000,5500,6000])
# output
3-element Vector{Float64}:
1.2000000000000002e-15
1.9834710743801656e-15
2.5e-15
FittingFunction.Mag2Counts
— MethodMag2Counts(mag,emag;zp=25.0)
Convert magnitudes to counts (or flux).
Arguments
mag
input magnitude.emag
magnitude uncertainty.zp
zero-point.
Examples
Mag2Counts(20,0.1)
# output
(100.0, 9.210340371976184)
FittingFunction.NorrisPulse
— MethodNorrisPulse(x;pulsNorm,tmax,σ_rise,σ_decay,pulsSharpness,base)
Compute an asymmetric pulse shape according to the recipe reported in Norris et al. (1996)..
Arguments
x
input vector.pulsNorm
the nornalization of the pulse.tmax
the maximum of the pulse.σ_rise
the time-scale of the rising phase.σ_decay
the time-scale of the decaying phase.pulsSharpness
pulse sharpness parameter.base
signal level without the pulse.
Examples
NorrisPulse([1.,2.,3.,4.,5.],pulsNorm=1.5,tmax=3.,σ_rise=1.,σ_decay=2.,pulsSharpness=1.1,base=0.3)
# output
5-element Vector{Float64}:
0.47585740398559895
0.8518191617571635
1.8
1.2407748943132098
0.8518191617571635
FittingFunction.PL
— MethodPL(E,N,α;E0=1.)
Compute a power-law with.
Arguments
α
spectral index.N
normalization.E
input energy.E0
power-law energy normalization.
Examples
PL(3.,1.,-1.)
# output
0.3333333333333333
FittingFunction.Pol2Stokes
— MethodPol2Stokes(i, p, t, c; ep=0.0, et=0.0, ec=0.0)
Compute the Stokes parameters for a given polarisation degree and position angle.
Arguments
i
total intensity.p
polarisation degree.t
position angle (randians).c
the circular polarisation.ep
polarization uncertainty.et
position angle uncertainty.ec
circular polarization uncertainty.
The ouput is: intensity q
, u
, v
Stokes parameters and respective errors.
Examples
Pol2Stokes(1.,0.1,0.1,0.)
# output
(1.0, 0.09800665778412417, 0.019866933079506124, 0.0, 0.0, 0.0, 0.0)
FittingFunction.SBPL
— MethodSBPL(E,N,α,β,Eb)
Compute a smoothly joint broken power-law.
Arguemnts
α
pre-break spectral index.β
post-break spectral index.Eb
break energy.N
normalization.E
input energy.
Examples
SBPL(6.,1.,-1.,-1.5,5.)
# output
0.15214515486254615
FittingFunction.SBPL2
— MethodSBPL2(E,N,α,β,γ,Eb1,Eb2)
Compute a smoothly joint double broken power-law.
Arguments
α
pre-break spectral index.β
inter-break spectral index.γ
post-break spectral index.Eb1
first break energy.Eb2
second break energy.N
normalization.E
input energy.
Examples
SBPL2([4.,6.,8.],1.,-1.,-1.5,-2.,5.,7.)
# output
3-element Vector{Float64}:
0.25
0.06804138174397717
0.04133986423538423
FittingFunction.SigmaClip
— FunctionSigmaClip(x, ex=ones(size(x)); sigmacutlevel=2)
Sigma-clipping filtering of an input array,
Arguments
x
input array.ex
uncertainties.sigmacutlevel
sigma-clipping level.
It performs a one-iteration sigma clipping and reports a mask to select the surviving elements in the input arrays or other related arrays.
Examples
x = [4.,6.,8.,1.,3.,5.,20.]
mask = SigmaClip(x)
x[mask]
# output
6-element Vector{Float64}:
4.0
6.0
8.0
1.0
3.0
5.0
FittingFunction.Stokes2Pol
— MethodStokes2Pol(i, q, u, v; eq=0.0, eu=0.0, ev=0.0)
Compute the polarisation degree and position angle from the Stokes parameters.
Arguments
i
total intensity.q
verical/horizontal polarization.u
oblique polarization.v
circular polarisation.eq
uncertainty on theq
parameter.eu
uncertainty on theu
parameter.ev
uncertainty on thev
parameter.
The ouput is given by the intensity i
, polarisation degree, p
, position angle (randians) theta
and circular polarisation chi
, with respective errors.
Examples
Stokes2Pol(1.,0.1,0.1,0.)
# output
(1.0, 0.14142135623730953, 0.39269908169872414, 0.0, 0.0, 0.0, 0.0)
FittingFunction.TauVoigt
— MethodTauVoigt(λ,NHI,DopplerBroadening,z,transition)
Compute the opacity due to a given absorption transition.
Arguments
λ
is the wavelenghths ($cm$).N
the column density ($cm^{-2}$).DopplerBroadening
is the Doppler broadening ($cm~s^{-1}$).z
is the source redshift.transition
is a tuple formed by the central wawelength ($cm$), the oscillator strength and the damping coefficient ($s^{-1}$) for the given transition.
The Doppler broadening factor is typicaly due to either an intrinsic thermal broadening ($b_K = \sqrt{2KT/m}$) or to a turbulent motion of the gas ($b_T = \sqrt{σ_T}$, where $σ_T$ is the inner velocity dispersion). These two factors can be summed in quadrature, i.e. $b = \sqrt{b_K^2 + b_T^2}$.
Examples
TauVoigt(range(start=1494.5,stop=1495.5,step=0.1) .* 1e-8,1e18,1e5,0.,[1495.05*1e-8,0.54,8.106e8])
# output
11-element Vector{Float64}:
0.5408331361420329
0.8079604230648749
1.3357686994197793
2.618871809580839
7.282358478732964
66.40911467182524
66.40911467182524
7.282358478732964
2.618871809580839
1.3357686994184856
0.8079604230648749
FittingFunction.VoigtFunctTG
— MethodVoigtFuncTG(a,v)
Approximate the Voigt (or line broadening function) function.
It was introduced by Tepper-Garcia (2006). It is of high accuracy provided that $a \le 10^{-4}$. The $a$ and $v$ parameters are defined as: $a = \frac{\Gamma \lambda_c}{4\pi b 10^{13}}$ and $v = \frac{(\lambda_c - \lambda)c}{b \lambda_c \sqrt{2 \log 2}}$, where $\lambda_c$ is the central wavelength of the transition, $c$ the speed of light, $b$ the Doppler broadening factor and $\Gamma$ the damping coefficient.
Examples
FittingFunction.VoigtFunctTG(1e-5,1.)
# output
0.36788094737611143
FittingFunction.XAbs
— MethodXAbs(E; NH=1e20, z=0)
Compute the effective absorption cross section per hydrogen atom.
It is based on the Morrison & McCammon (1983) recipe.
Arguments
E
is the energy (KeV, in the 0.03-10 KeV range).N
is the column density (particle per square cm).z
is the redshift.
Examples
XAbs([0.5,1.25,2.], NH=1e20, z=0)
# output
3-element Vector{Float64}:
0.9290803992951834
0.9868927382232576
0.9957079871273042
FittingFunction.Z2N
— MethodZ2N(freqs, time)
Compute the Rayleigh power spectrum of a time series in a given range of frequencies.
Arguments
freqs
is an array with frequencies in units of 1/[time].time
is an array with the time series where to find a period.harm
is the number of harmonics to be used in the analysis.
Examples
Z2N([1.,0.5,0.25], [1.,2.,2.5,3.5,5.])
# output
3-element Vector{Any}:
0.4
0.4000000000000002
0.537258300203048