From Morgan's notes here:
file://cvfiler/cv-cdl-sis/Software/FEIC/Stability/python/PwrSpecTools0.5/README.txt
#*******************************************************************************
# ALMA - Atacama Large Millimiter Array
# (c) Associated Universities Inc., 2010
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
pwrSpecTools library - Python tools for displaying IF spectrum plots and computing
total power, in-band power, and power variations according to ALMA specifications.
Morgan
McLeod
mmcleod@nrao.edu
These tools are intended to be used interactively in a Pyton shell
or, even better, with IPython:
http://ipython.scipy.org/
They were developed and tested with Python 2.6.
The matplotlib library is required:
http://matplotlib.sourceforge.net/
See the setup help document at
http://www.cv.nrao.edu/~mmcleod/Python-PyLab-setup.pdf
for setup instructions on Windows.
Revisions:
0.5
Corrected power var in 31 MHz calculation.
Added global noiseFloorData which for compensating in-band and total power results for
the spectrum analyzer noise floor.
Added global cablePad = 6.0 which adds the specified offset in dB for total and in-band
power and to the IF spectrum plots.
Made smoothingPts = 0 global rather than parameter.
0.4
Modified to work with filenames like "IF0-Pol0Sb1-92-15.txt"
Fixed bug where the legend could be out of order.
Added options for pre-smoothing of spectrum data before performing calculations.
This was in response to accidentally taking spectrum data with no input attenuation
and therefore too much ripple due to poor match.
0.3 2010-10-01
Added powerVarAveraging() and updated allPowerVar31MHz() for 31 MHz band:
Now averages data in 31 MHz bins and then plots differences. See updated usage below.
between adjacent points.
0.2 unreleased
Added allPowerVarFullBand()
Writes prototype XML document format, function saveXML()
Naming and default parameter improvements.
0.1 2010-06-10
initial release
The following is a sample session with the tools.
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 0.9.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: cd l:
L:
In [2]: cd /python/pwrSpecTools/src/
L:\python\pwrSpecTools\src
In [3]: import pwrSpecTools
In [5]: cd z:
Z:
In [6]: cd Cryostat13/IF\ Spectra/Band3/traces
Z:\Cryostat13\IF Spectra\Band3\traces
In [8]: ls
Volume in drive Z is ALMA-NA-FEIC
Volume Serial Number is 6A08-CC0D
Directory of Z:\Cryostat13\IF Spectra\Band3\traces
02/03/2011 11:01 AM <DIR> .
02/03/2011 11:26 AM <DIR> ..
02/03/2011 07:51 AM 182,288 IF0-Pol0Sb1-100-0.txt
02/03/2011 07:51 AM 182,288 IF0-Pol0Sb1-100-15.txt
02/03/2011 07:52 AM 182,288 IF0-Pol0Sb1-104-0.txt
02/03/2011 07:52 AM 182,288 IF0-Pol0Sb1-104-15.txt
02/03/2011 07:53 AM 182,288 IF0-Pol0Sb1-108-0.txt
02/03/2011 07:53 AM 182,288 IF0-Pol0Sb1-108-15.txt
02/03/2011 07:49 AM 182,288 IF0-Pol0Sb1-92-0.txt
02/03/2011 07:49 AM 182,288 IF0-Pol0Sb1-92-15.txt
02/03/2011 07:50 AM 182,288 IF0-Pol0Sb1-96-0.txt
02/03/2011 07:50 AM 182,288 IF0-Pol0Sb1-96-15.txt
02/03/2011 08:03 AM 182,288 IF1-Pol1Sb1-100-0.txt
02/03/2011 08:03 AM 182,288 IF1-Pol1Sb1-100-15.txt
02/03/2011 08:04 AM 182,288 IF1-Pol1Sb1-104-0.txt
02/03/2011 08:04 AM 182,288 IF1-Pol1Sb1-104-15.txt
02/03/2011 08:04 AM 182,288 IF1-Pol1Sb1-108-0.txt
02/03/2011 08:04 AM 182,288 IF1-Pol1Sb1-108-15.txt
02/03/2011 08:01 AM 182,288 IF1-Pol1Sb1-92-0.txt
02/03/2011 08:01 AM 182,288 IF1-Pol1Sb1-92-15.txt
02/03/2011 08:02 AM 182,288 IF1-Pol1Sb1-96-0.txt
02/03/2011 08:02 AM 182,288 IF1-Pol1Sb1-96-15.txt
02/03/2011 08:13 AM 182,288 IF2-Pol0Sb2-100-0.txt
02/03/2011 08:13 AM 182,288 IF2-Pol0Sb2-100-15.txt
02/03/2011 08:14 AM 182,288 IF2-Pol0Sb2-104-0.txt
02/03/2011 08:14 AM 182,288 IF2-Pol0Sb2-104-15.txt
02/03/2011 08:14 AM 182,288 IF2-Pol0Sb2-108-0.txt
02/03/2011 08:15 AM 182,288 IF2-Pol0Sb2-108-15.txt
02/03/2011 08:11 AM 182,288 IF2-Pol0Sb2-92-0.txt
02/03/2011 08:12 AM 182,288 IF2-Pol0Sb2-92-15.txt
02/03/2011 08:12 AM 182,288 IF2-Pol0Sb2-96-0.txt
02/03/2011 08:12 AM 182,288 IF2-Pol0Sb2-96-15.txt
02/03/2011 08:22 AM 182,288 IF3-Pol1Sb2-100-0.txt
02/03/2011 08:22 AM 182,288 IF3-Pol1Sb2-100-15.txt
02/03/2011 08:23 AM 182,288 IF3-Pol1Sb2-104-0.txt
02/03/2011 08:23 AM 182,288 IF3-Pol1Sb2-104-15.txt
02/03/2011 08:24 AM 182,288 IF3-Pol1Sb2-108-0.txt
02/03/2011 08:24 AM 182,288 IF3-Pol1Sb2-108-15.txt
02/03/2011 08:21 AM 182,288 IF3-Pol1Sb2-92-0.txt
02/03/2011 08:21 AM 182,288 IF3-Pol1Sb2-92-15.txt
02/03/2011 08:21 AM 182,288 IF3-Pol1Sb2-96-0.txt
02/03/2011 08:22 AM 182,288 IF3-Pol1Sb2-96-15.txt
02/03/2011 09:34 AM 182,288 noiseFloorSpareAn.txt
41 File(s) 7,473,808 bytes
2 Dir(s) 65,178,046,464 bytes free
### check or set the additional IF cable pad which is compensated for in the total power calculations:
In [9]: pwrSpecTools.cablePad
Out[9]: 6.0
# it defaults to 6.0.
In [10]: pwrSpecTools.cablePad = 6.0
# you can set it to a new value.
### load a noise floor trace, taken with the cable and pad installed but not connected to the front end:
In [11]: pwrSpecTools.loadNoiseFloor("noiseFloorSpareAn.txt")
### Load a single data file:
In [12]: D = pwrSpecTools.loadFile("IF0-Pol0Sb1-92-15.txt")
### Compute total power and in-band power from the data (dBm):
### Parameters are data, fMin, fMax
In [13]: pwrSpecTools.ifOutputPower(D, 4.0e9, 8.0e9)
Out[13]: (-13.048737093063313, -14.102746031353135)
# this compensates for the cablePad. E.g. the results would be 6 dB lower if cablePad = 0.0
### Compute full-band power variation from the data (dB):
### Parameters are data, fMin, fMax
In [14]: pwrSpecTools.powerVarFullBand(D, 4.0e9, 8.0e9)
Out[14]: 3.3009454717423665
### Compute power variation in a 2 GHz window from the data:
### Parameters are data, fMin, fMax, windowSize
In [15]: F, V = pwrSpecTools.powerVarWindow(D, 4.0e9, 8.0e9, 2.0e9)
In [16]: import pylab
In [17]: pylab.plot(F, V, '-')
Out[17]: [<matplotlib.lines.Line2D object at 0x01F36730>]
In [18]: pylab.show()
# See figure1.png for output.
### Compute power variation in a 31 MHz window from the data:
In [20]: F, V = pwrSpecTools.powerVarWindow(D, 4.0e9, 8.0e9, 31.0e6)
In [21]: pylab.plot(F, V, '-')
Out[21]: [<matplotlib.lines.Line2D object at 0x020B2390>]
# See figure2.png for output.
### Next we demonstrate functions which deal with batches of files rather than
### one file at a time. The library assumes the following about the source files:
### Components are separated by dashes:
### IF channel (IF0, IF1, IF2, IF3)
### Pol and sideband corresponding to the IF channel, like 'Pol0SB1'.
### LO frequency in GHZ.
### IF the filename ends in "-0" it is for 0 dB IF switch gain.
### If the filename ends in "-15" it is for 15 dB IF Switch gain.
### They are text files ending in ".txt"
### Example: IF0-Pol0Sb1-92-15.txt is at 92 GHz LO and 15 dB IF switch gain.
### Compute total power and in-band power for all 'IF0' files in the working directory:
In [22]: pwrSpecTools.allIfOutputPower('IF0', 4.0e9, 8.0e9)
allIfOutputPower: cablePad = 6.0 dB, noiseFloor compensation = True
channel, LO, inBand(0), inBand(15), total(15), difference
IF0-Pol0Sb1, 92, -29.36, -14.10, -13.05, 1.05
IF0-Pol0Sb1, 96, -27.74, -12.63, -11.60, 1.03
IF0-Pol0Sb1, 100, -27.58, -12.47, -11.46, 1.01
IF0-Pol0Sb1, 104, -27.52, -12.41, -11.33, 1.08
IF0-Pol0Sb1, 108, -28.08, -12.90, -11.89, 1.00
# Note that the cablePad and loaded noise floor profile are being used to correct the data.
# The noise floor trace, if provided, is subtracted from the 0 dB and 15 dB traces.
### Compute power variation in a 2 GHz window for all files:
### Uses the "-15" files only:
In [25]: pwrSpecTools.allPowerVarWindow('IF0', 2.0e9, '2 GHz', 4.0e9, 8.0e9, 6.0, 0, 7.0)
allPowerVarWindow: smoothingPts = 0 , averaging = False
### See figure3.png for output.
### The parameters are:
### fWindow = 2.0e9 The window size in Hz
### fWindowText = '2 GHz' The text for the X axis label
### fMin = 4.0e9, fMax = 8.0e9 In-band frequency range
### spec = 6.0 Where to put the spec line
### xMax = 0 Maximum X axis on plot: means same as fMax.
### yMax = 7.0 Maxumum Y axis on plot
### Some shortcut methods:
In [26]: pwrSpecTools.allPowerVar2GHz('IF0', 4.0e9, 8.0e9, 6.0, 0, 7.0)
allPowerVarWindow: smoothingPts = 0 , averaging = False
### Same as above. See figure3.png
In [29]: pwrSpecTools.allPowerVar31MHz('IF0', 4.0e9, 8.0e9, 1.35, 0, 3.0)
allPowerVarWindow: smoothingPts = 0 , averaging = False
### See figure4.png
In [30]: pwrSpecTools.allPowerVarBand3('IF0')
allPowerVarWindow: smoothingPts = 0 , averaging = False
### Same as above. See figure3.png
### Note that there are separate shortcut methods for the 2 GHz windo for each band
### which provide band-specific values for the frequency limits and other processing:
### pwrSpecTools.allPowerVarBand3('IF0')
### pwrSpecTools.allPowerVarBand6('IF0')
### pwrSpecTools.allPowerVarBand7('IF0')
### pwrSpecTools.allPowerVarBand9('IF0')
### IF Spectrum plotting:
In [31]: pwrSpecTools.plotSpectrum("IF0-Pol0Sb1-92-15.txt")
IF0-Pol0Sb1-92-15.txt
### See figure5.png.
### Note that the spectrum plot does
not compensate for the cablePad.
### If it were to compensate, then it would raise both the peak power and the noise floor power.
In [32]: pwrSpecTools.allSpectra('IF0')
IF0-Pol0Sb1-92-15.txt
IF0-Pol0Sb1-96-15.txt
IF0-Pol0Sb1-100-15.txt
IF0-Pol0Sb1-104-15.txt
IF0-Pol0Sb1-108-15.txt
### See figure6.png
### This function uses the 15 dB gain files by default ("-15").
### If you want the 0 dB files pass '0' as the 2nd parameter:
In [33]: pwrSpecTools.allSpectra('IF0', '0')
IF0-Pol0Sb1-92-0.txt
IF0-Pol0Sb1-96-0.txt
IF0-Pol0Sb1-100-0.txt
IF0-Pol0Sb1-104-0.txt
IF0-Pol0Sb1-108-0.txt
Pol0USB-96-0.txt
### See figure7.png
--
JohnEffland - 2011-05-06