ApplyBaseline([ws, parfile]) | Usage: |
CalcBaseline([ws, parfile]) | Usage: |
FitBaseline([ws, parfile]) | Usage: |
fitbaseline_calc_freqs(self) | |
fitbaseline_calc_numax_i(self) | |
fitbaseline_calc_numin_i(self) |
Module author: Heino Falcke <h.falcke@astro.ru.nl>
Usage:
>>> sp=cr.hArrayRead('/Users/falcke/data/Pulses/oneshot_level4_CS017_19okt_no-0.h5.spec.pcr') ... old (to be updated)
Usage:
>>> ApplyBaseline(spectrum)contains spectrum.par.baseline
Also does RFI excision.
Input parameters
Output parameters
Usage:
>>> CalcBaseline(spectrum,par1=...,par2=...)Calculate a smooth baseline from a set of coefficients that determine the baseline (e.g., as calculated by :class:FitBaseline) and an array of frequencies (which need not be equi-spaced).
The frequencies can be provided with the .par.xvalues array of the input spectrum (if available). Otherwise, they have to be explicitly provided.
The result will be returned in an array Task.baseline. This baseline will also be attached to the .par dict of the input spectrum, i.e. spectrum.par.baseline.
The task can return the inverse of the baseline (if invert=True), i.e. what one needs to multiply a measured spectrum with.
Note, sometimes the fit can go wrong if logfit=True the interpolation has wiggles. In this case the exponent of a large number is calculated, yielding a numerical error. In this case switch set logfit=False (to see what is going on).
Gain Calibration (DRAFT!)
Knowing that the antenna is exposed to a noise with a certain power, one can use this to make a rough estimate of the absolute gain of the antenna. E.g., in case for LOFAR antennas the spectrum measured in one antenna should follow a
power law due to emission from the Galaxy (Milky Way). Hence, one can multiply the baseline one has fitted to the measured spectrum with a power law, so that after dividing the gain curve one reproduces the expected behaviour (i.e., Galactic noise). Note: if one wants to use calcbaseline for gain calibration one obviously has to provide a power law that is the inverse of the desired function.
Powerlaws can be specified with the Task.powerlaw parameter, which is either just the power law index, or a tuple with amplitude and index, or a keyword (e.g., ‘Galactic’, of ‘GalacticT’).
The noise temperature of an antenna is:
Tnoise = Power [Watts] /Bandwidth [Hz] / kb (Boltzmann constant) = 7.24296*10^22 K
The sky tempertature is according to Falcke & Gorham (2004) roughly: T_sky = 32*( (freq/408e6)^-2.5 ) (T_sky in K, freq in Hz)
The recevied power of an antenna is Prec = Aeff * S, where S is the power density (in W/m^2).
The effective area is
Aeff = gain* lambda^2/(4 pi)
The power density is S=E^2/R (i.e., Electric field^2 / free space impedance (376.7 Ohm))
The System Equivalent Flux Density (SEFD) is
Flux density for bandwidth limited pulses can be rougly converted to Field strength through Snu= Enu epsilon_0 c Bandwidth (Enu in Volt/Meter/MHz in SI units ..., check this formula)
to be continued ....
In the following a short description from Andreas Horneffer (in German) on how to do a simple gain correction.
Unter der Annahme, dass der ganze Himmel eine konstante, und bekannte Strahlungstemperatur hat, das gemessene Rauschen davon dominiert ist, und man das Gain (die Richtwirkung) der Antennen kennt. Die Strahlungstemperatur des Himmels ist nach Falcke & Gorham (2002) etwa: T_sky = 32*( (freq/408e6)^-2.5 ); (T_sky in K, freq in Hz) Die gemessene "Rauschtemperatur" ist: T_noise = P_noise / dNu / kB (T_noise in K, P_noise in W, dNu (Bandbreite) in Hz, kB die Boltzmann-Konstante) Die Rauschleistung ist: P_noise = V^2/R (P_noise in W, V (gemessene Spannung) in V, R (angenommene ADC-Impedanz) in Ohm) Die ADC-Impedanz kuertzt sich nachher weg. Wenn Du die Rauschleistung als Funktion der Frequenz nach der FFT fuers Kalibrieren verwenden willst, aber die Kalibration fuer die Zeitreihe nutzen willst, musst du noch die Normierung der FFT korrigieren. (Haengt von der verwendeten FFT-Routine ab.) Die Verstaerkung der Elektronik ist dann: K = T_sky / T_noise (K ist einheitenloses Verhaeltnis der Leistungen) Die Feldstaerke an der Antenne ist dann: E = sqrt( 4*pi*freq^2*mu0 / G(d,freq) * K * V^2/R ) (E in V/m, mu0 die magnetische Feldkonstante, G(d,freq) das Gain der Antennen in die Richtung d, bei Frequenz freq als einheitenloses Verhaeltnis der Empfindlichkeit der Antennen zu der Empfindlichkeit eine isotropen Strahlers) Als Gain der LOFAR Antennen kann man vermutlich einfach das Gain der LOPES Antennen verwenden. (Natuerlich fuer die Ausrichtung der Dipole rotiert.)
Input parameters
fittype
logfit
Output parameters
Usage:
FitBaseline(input_spectrum, **keywords)Description:
Function to fit a baseline using a polynomial function (fittype='POLY') or a basis spline fit (default: fittype='BSPLINE') to a spectrum while trying to ignore positive spikes in the fit (e.g., those coming from RFI = Radio Frequency Interference).
The input_spectrum is a float array with input spectrum either of dimension [nofAntennas,nofChannels] or just [nofChannels] for a single spectrum. Note that the frequency values for the array are expected to be provided as input_spectrum.par.xvalues=cr.hArray(float,[nofChannels],fill=...) the same you would use to provide xvalues for plotting. You can also provide the frequencies explicitly in the keyword frequency, otherwise a simple numbering is assumed frequency=[0,1,2,3...].
RFI Treatment:
The spectra are then downsampled and checked which bins have a large RMS (when divided by the mean in each bin). Those bins are affected by interference and are ignored for the fitting. The final fit is done to the clean bins only.
Quality check:
At the end the fitted baselines are compared to each other (divided by the average spectrum of all antennas) and a list of deviant antennas is returned in Task.badantennas.
Results:
The main results are the fit coefficients Task.coeffs.
Bad antennas are listed in Task.badantennas.
Use baseline.polynomial(Task.frequency,Task.coeffs,Task.powers) to caluclate the baseline from the coefficients for the polynomial fit, or:
>>> task.xpowers[...,[0]:task.nselected_bins].linearfitpolynomialx(task.clean_bins_x[...,[0]:task.nselected_bins],task.powers[...]) >>> task.clean_bins_y[...,[0]:task.nselected_bins].bspline(task.xpowers[...,[0]:(task.nselected_bins)],task.coeffs[...])Parameters can be provided as additional keywords, e.g.:
baseline.polynomial(frequency,coeffs,powers, parameter1=value1, parameter2=value2)or in a WorkSpace, e.g.:
baseline.polynomial(frequency,coeffs,powers, ws=WorkSpace),or in a mix of the two. Otherwise default values are used.
Input parameters
Output parameters
Run the program.