These scripts are available under the GNU General Public License.
Note that there is no warranty! Although I have put some effort into making them generally useful, they were mainly written to help with a task at hand. So they may not yet work for all cases, and you may have some fixing to do. Please send me any fixes or enhancements.
| suggestalmaconfig.py | Last modified 2008-02-12 16:43:22.000000000 -0500 suggestalmaconfig.py | 2189 bytes |
suggestalmaconfig(res, frequency, declination) Returns a suggested ALMA configuration for a desired resolution and frequency. It assumes a 4h observation, but the observation length should not matter. @param res: desired FWHM naturally weighted dirty beam major axis in \". @type res: float or int @param frequency: Center frequency to use in GHz. @type frequency: float or int @param declination: declination to use in degrees. @type declination: float or int beamsizes(declin) Reads almabeams
|
||
| summarize.py | Last modified 2008-02-12 16:43:22.000000000 -0500 summarize.py | 6168 bytes |
summarize(imlist, collist = 'bunit, bmaj, bmin, bpa')
For each image in imlist, prints the values of collist, and returns the
output of ia.summary() for each image as a dictionary keyed by the image
names.
Except for the special values listed in the default of collist, its
columns should be keys of ia.summary()'s output.
imlist and collist can both be either single valued strings, comma
separated strings, or lists of strings, i.e.
summarize('robust0_nonoise.image',
['bmaj', 'bmin']);
summarize(['robust0_nonoise.image', 'robust0_nonoise.residual'],
['bunit']);
and
summarize('robust0_nonoise.im*, robust0_nonoise.residual',
'bmaj, bmin');
are all valid.
N.B.
1. The above lines all end in ; to *skip the return value* in ipython.
2. The items in imlist can have wildcards.
Sample output:
Image bunit bmaj (mas) bmin (mas) bpa (deg)
input672GHz_50pc.image Jy/pixel
robust0_nonoise.image Jy/beam 28.8220365 25.5090762 97.6345
casa_robust0intclean.image 15.7047883 14.4392923 101.9130
str_or_list_to_list(strorlist)
Returns a list made from splitting strorlist at commas and/or whitespace
|
||
| tabplotter.py | Last modified 2008-02-12 16:43:22.000000000 -0500 tabplotter.py | 7130 bytes |
A module for plotting ASCII or AIPS++/CASA tables using CASA.
News:
1/22/2008: simpleplot()'s output is much more customizable now.
It passes its keyword arguments to plotfunc, and takes a
list of symbols for plotting each y column. Column labels
are now filtered in case you are using LaTeX.
Use: From casapy,
# Preferred
execfile 'tabplotter.py'
example:
# Set btb to be a tb tool filled with the contents of
# ./cfgres_10to20.csv. The contents will be
# fetched from ./cfgres_10to20.tb if it already
# exists, and ./cfgres_10to20.csv otherwise.
btb = filetotable('cfgres_10to20.csv')
# Normal tb commands work.
btb.browse() # You may need btb.clearlocks()
btb.colnames()
# As does help.
help simpleplot
# Plot everything in btb except the first column vs. the first column,
# with a logarithmic y axis.
simpleplot(btb, plotfunc=pl.semilogy)
# Plot Nom.rms.res vs. Actual_res.
simpleplot(btb, 'Nom.rms.res', 'Actual_res')
# Plot Nom.rms.res and Actual_res vs. Nom.avg.res
simpleplot(btb, ['Nom.rms.res', 'Actual_res'], 'Nom.avg.res')
# timeaxis() is just a helper function now, but Gene DuVall might
# extend it to use minutes, hours, etc., and/or to supply a time axis
# for customized plots.
# tablename() returns the table's filename without any directory or
# .csv.
uniquify_strlist(duplist) Goes through the list of strings duplist, and appends a count number
to any duplicates. i.e. given
['a', 'b', 'c', 'a', 'c', 'd', 'a', 'e'],
it returns
['a_0', 'b', 'c_0', 'a_1', 'c_1', 'd', 'a_2', 'e'].
Note that
['a', 'a', 'a_0']
would go to
['a_0', 'a_1', 'a_0'].
If you have a list like that, you could run uniquify_strlist on the
result.
filetotable(fn, overwrite=False)
Returns a CASA table (tb) tool as read from the comma separated value (CSV)
file fn. Built around the fromascii line by Debra Shepherd.
The first row in the CSV is assumed to be, and used as, column names,
not as data values. If you want to use the tb for plotting, all other
rows should be numbers.
I usually produce my tables with whitespace separation for readability, but
they can be easily converted to CSV format with this bash alias:
# Use: csvize < table.readable > table.csv
alias csvize='perl -wp -e "s/[ \t]+/,/g"'
csvize will silently FAIL if there are any commas in table.readable!
timeaxis(datatb)
Attempts to return a reasonable time axis and label for it from datatb.
tablename(datatb)
Returns a slightly cleaned up name for datatb.
simpleplot(datatb, ycolnames=[], xcolname='', colnames=[],
Graph datatb[ycolname] vs. datatb[xcolname] for each ycolname in ycolnames,
on the same plot.
xcolname defaults to the first column in colnames or datatb.colnames().
ycolnames defaults to all but xcolname in colnames or
datatb.colnames().
symblist is a list of symbols to plot each y column with, in plotfunc's
format.
**kwargs is passed on to plotfunc.
raw_to_latex(a)
Returns a copy of s that has been converted from plain text to valid LaTeX
input. Do not run on strings that already have LaTeX markup!
|
||
| taskutil.py | Last modified 2008-02-12 16:43:22.000000000 -0500 taskutil.py | 2526 bytes |
Functions used in converting other functions into tasks. Use: import taskutil get_global_namespace(ns_label='ipython console') Returns a dictionary of the globals in the lowest stacklevel containing ns_label in its label. update_myf(myf) Fills unfilled parameters with defaults, and handles globals or user override of arguments. check_param_types(taskname, arg_desc) Checks the values of taskname's arguments against their allowed types. Suitable for tasks without any menu parameters. Returns None if everything seems OK, and the exception otherwise (after printing an error message). startlog(casalog, taskname) Starts an entry in casalogger for taskname. endlog(casalog, taskname) Finishes an entry in casalogger for taskname.
|
||
| uvsamp_from_psf.py | Last modified 2008-02-12 16:43:22.000000000 -0500 uvsamp_from_psf.py | 43 bytes |
uvsamp_from_psf(psf, longestbll)
|
||
| almasimmos_helpers.py | Last modified 2008-02-12 16:43:21.000000000 -0500 almasimmos_helpers.py | 6548 bytes |
readantenna(antab=None, pl=None) Read a text antenna table antab with columns X, Y, Z, and Diameter (all in m). mul_scal_qa(scal, q, qa=None) Returns the product of a dimensionless number scal and quantity q. calc_pointings(direction, spacing, imsize, cell, relmargin=0.5) If direction is a list, simply returns direction and the number of pointings in it. Otherwise, returns a hexagonally packed list of pointings separated by spacing and fitting inside an image specified by direction, imsize and cell, and the number of pointings. The hexagonal packing starts with a horizontal row centered on direction, and the other rows alternate being horizontally offset by a half spacing. All of the pointings will be within a rectangle relmargin * spacing smaller than the image on all sides, unless none can fit. In that case direction is returned (i.e. single pointing). plot_pointings(pointings, img, beamsize, dolab = True) average_direction(directions) Returns the average of directions as a string. direction_splitter(direction, qa=None) Given a direction, return its epoch, x, and y parts. Epoch will be '' if absent, or '%s ' % epoch if present. x and y will be angle qa's in degrees. wrapang(ang, target, period = 360.0, pl=None) Returns ang wrapped so that it is within +-period/2 of target.
|
||
| annular_mask.py | Last modified 2008-02-12 16:43:21.000000000 -0500 annular_mask.py | 4770 bytes |
annular_mask(template, outer, inner=None, center=None,
NOTE: setting center doesn't work yet! It defaults to the center of
template. Also, it only masks the first xy plane.
Returns the name of a float "mask" based on template with pixel values of 1
for positions with distances from center between outer and inner and 0
elsewhere. center will default to the center of template if not specified.
The output name will be template.mask if not specified.
template will get a new mask corresponding to masktool. If name is not
supplied, it will default to something like 'mask0'.
No antialiasing attempt is made, partly because I don't know if it would do
any good. The annulus is circular in template's projection, not
necessarily on the sky.
Example:
masktool = annular_mask('fascinating.im', '5arcsec',
center='J2000 18h00m00.03s -23d0m0.0s',
output='fascinating_5arcsec_disk.mask')
sets masktool to an open ia tool containing a mask which is a disk
(inner defaults to 0) centered around J2000 18h00m00.03s -23d0m0.0s with
radius 5 arcseconds. The mask will be written to
fascinating_5arcsec_disk.mask on disk when masktool.close() or .done()
is called.
setdisk(radas, value)
Sets the elements within radas of (cx, cy) to value.
|
||
| beam_nongaussianity.py | Last modified 2008-02-12 16:43:21.000000000 -0500 beam_nongaussianity.py | 2622 bytes |
beam_minus_gaussian(beam, bmaj=None, bmin=None, bpa=None, x=None, y=None) Returns an image of beam with a gaussian of FWHM bmaj and bmin and position angle bpa subtracted. The gaussian will be fit to beam if its parameters are not specified. Any specifcations should have units. x and y are assumed to be in J2000. Do not specify them unless you are sure they are close to the correct values! quantity_or_nothing(q, qa=None) If q is a quantity, or a string which can be turned into a quantity, returns q as a quantity. Otherwise returns None.
|
||
| cfgsummary.py | Last modified 2008-02-12 16:43:21.000000000 -0500 cfgsummary.py | 994 bytes |
cfgsummary(cfgfile, freq) Essentially translates avgsep < cfgfile's output into a python structure.
|
||
| coherence.py | Last modified 2008-02-12 16:43:21.000000000 -0500 coherence.py | 4052 bytes |
coherence(vis=None, deltal=None, deltam=None, nvisperbin=50) Analyze phase noise of an ALMA dataset: Keyword arguments: vis -- Name of measurement set. Example: vis='mysim.ms' deltal -- East-west component of (peak position - phase tracking center), in arcsec. deltam -- North-south component of (peak position - phase tracking center), in arcsec. nvisperbin -- How many visibilities to include in each bin for determining phase dispersions.
|
||
| fidelity.py | Last modified 2008-02-12 16:43:21.000000000 -0500 fidelity.py | 10178 bytes |
12/13/2007: Added logging,
inclusion of a component list if used,
and
the ability to use an image with a different name from
the project.
calc_fidelity(project = None, image = None, mod_w_complist = None)
Calculates both the image and uv plane fidelities for the specified
simulation project as in
http://www.alma.nrao.edu/memos/html-memos/alma398/memo398.pdf
If project is given it can be used to find image and the component list (if
any), assuming the information is in project.almasimmos. Otherwise image
and vis must be specified, and project will be extracted from image.
Because almasimmos does not necessarily use the same modelimage as
specified in its parameters when ignorecoords is True, the modelimage MUST
be project.input_model!
mod_w_complist is a input model image with the input component list added
to it. It will be used if specified, and otherwise generated if necessary.
fidel_im(convmod, diff, imroot, ia = None)
Calculates and returns the filename of the image fidelity for convmod and
diff as in http://www.alma.nrao.edu/memos/html-memos/alma398/memo398.pdf
One difference is that the median |value - median| is used instead of the
rms to prevent division by 0. The median |value - median| is close to the
0.675 * the rms, but is less sensitive to outliers (i.e. catastrophic
errors confined to a small region of the image).
fidel_uv(convmod, diff, project, imroot = None, longestbllinl = None)
Calculates and returns the filename of the uv fidelity for convmod and
diff as in http://www.alma.nrao.edu/memos/html-memos/alma398/memo398.pdf
The image will be chopped down to 2*longestbll on a side, where longestbll
is returned as the longest baseline length.
If longestbllinl, the longest baseline length in wavelengths, is not
supplied, it will be looked for in project.almasimmos.
uvamp(img, longestbll, outname = None)
FFTs the image with directory name img and returns the directory name of
the resulting amplitudes. That directory name will be outname if supplied,
and img + '_amp' otherwise. Each axis of the amplitude image will go from
-longestbll to longestbll (which should be in world coordinates).
im_plus_complist(im, complist, im_w_complist = None, ia = None)
Returns an image equal to im + complist. The name will be im_w_complist
if specified, and im + '_w_complist' otherwise.
|
||
| pbsize.py | Last modified 2008-02-12 16:43:21.000000000 -0500 pbsize.py | 215 bytes |
pbsize(freq, d=12.0) Returns the primary beam size in arcseconds for a dish with diameter d (default 12) m at frequency freq GHz.
|
||
| psfsize.py | Last modified 2008-02-12 16:43:21.000000000 -0500 psfsize.py | 523 bytes |
psfsize(cfgfile, freq) Returns the PSF FWHM of cfgfile in arcsec. Only really works for snapshots at zenith.
|
||
| skyimg2plarr.py | Last modified 2008-02-12 16:43:21.000000000 -0500 skyimg2plarr.py | 529 bytes |
skyimg2plarr(img) Returns CASA image with directory name img as a matplotlib array suitable for plotting, followed by the maximum and minimum pixel values.
|
||
| regrid4d.py | Last modified 2008-01-23 10:53:49.000000000 -0500 regrid4d.py | 5170 bytes |
1/23/2008: Fixed typo preventing regridding when no axis rearrangment was
needed.
thorough_regrid(inim, template, outim, keep_inim_Stokes=False)
CASA uses a different order for the frequency and Stokes axes from the rest
of the world. This function swaps the freq and Stokes axes of a newly
loaded FITS file (inim) into CASA's convention (template), makes the RA
nonnegative, and puts the result in outim.
The output image header will have the same Stokes parameter as the template
image, unless keep_inim_Stokes is True. No actual Stokes conversion is
done (i.e. RR can get called I without being averaged with LL). Even if
keep_inim_Stokes is True, the output image will only have a Stokes axis if
the template does. If keep_inim_Stokes is True and template has a Stokes
axis, but inim does not, outim will default with a warning to I.
index_or_minus1(lis, item)
Returns the index of item in list lis, or -1 if it is not found.
|
||
| plotcfgs.py | Last modified 2008-01-22 13:09:01.000000000 -0500 plotcfgs.py | 6399 bytes |
cfgfile_to_dict(cfgfile) Reads cfgfile (in almasimmos format with optional pad numbers as comments) and returns a dictionary with 'x', 'y', 'z', and 'pad' columns. uniquify_strlist(duplist) Goes through the list of strings duplist, and appends a count number to any duplicates. i.e. given ['a', 'b', 'c', 'a', 'c', 'd', 'a', 'e'], it returns ['a_0', 'b', 'c_0', 'a_1', 'c_1', 'd', 'a_2', 'e']. Note that ['a', 'a', 'a_0'] would go to ['a_0', 'a_1', 'a_0']. If you have a list like that, you could run uniquify_strlist on the result. filetotable(fn, overwrite=False) Returns a CASA table (tb) tool as read from the comma separated value (CSV) file fn. Built around the fromascii line by Debra Shepherd. The first row in the CSV is assumed to be, and used as, column names, not as data values. If you want to use the tb for plotting, all other rows should be numbers. I usually produce my tables with whitespace separation for readability, but they can be easily converted to CSV format with this bash alias: # Use: csvize < table.readable > table.csv alias csvize='perl -wp -e "s/[ \t]+/,/g"' csvize will silently FAIL if there are any commas in table.readable! timeaxis(datatb) Attempts to return a reasonable time axis and label for it from datatb. tablename(datatb) Returns a slightly cleaned up name for datatb. simpleplot(datatb, ycolnames=[], xcolname='', colnames=[], Graph datatb[ycolname] vs. datatb[xcolname] for each ycolname in ycolnames, on the same plot. xcolname defaults to the first column in colnames or datatb.colnames(). ycolnames defaults to all but xcolname in colnames or datatb.colnames().
|
||
| avgsep | Last modified 2008-01-17 13:57:59.000000000 -0500 avgsep | 5009 bytes |
|
|
||
| airydisk.py | Last modified 2008-01-15 23:22:56.000000000 -0500 airydisk.py | 3262 bytes |
Function objects for primary beams of circular apertures. airypat Returns the normalized* intensity value at salfa = sin(alfa) for a circular aperture. The aperture radius and frequency should be set when the airypat instance is created. * i.e. airypat(salfa = 0) = 1. pb_of_circaper Returns the normalized* intensity value at r arcseconds for a possibly blocked circular aperture. The aperture radii and frequency should be set when the pb_of_blockeddisk instance is created. * i.e. pb_of_blockeddisk(r = 0) = 1.
|
||
| radplot.py | Last modified 2007-12-17 11:14:55.000000000 -0500 radplot.py | 10435 bytes |
radplot(img=None, Plots the azimuthal average of an image about a point. For now it assumes you are only interested in the first plane of img, and that it has square pixels. Keyword arguments: img -- Name of image to made a radial plot of. wc -- World coordinate to use as center. rs -- An optional list or array of radii to use instead of calculating. azav -- An optional list or array of azimuthal averages to use instead of calculating. blunit -- Unit of the radii. Derived from img if necessary. title -- Title for the plot. Defaults to 'Azimuthal average of %s about %s' % (img, wc). rlab -- Label for the radial axis. Defaults to 'Radius (runit)'. azavlab -- Label for the azimuthal average axis. Defaults to 'Azimuthal average (azavunit)' radplot_defaults(param = None) radplot_description(key='radplot', subkey = None) radplot_check_params(param=None, value=None) radav(img, wc, maxrad=None) Returns the azimuthal average of image with name img about the world coordinate wc, and the weights and baseline unit used to calculate that average. The baseline unit is taken from maxrad, or from img's axisunits if maxrad is not specified. For now it assumes you are only interested in the first plane of img, and that it has square pixels.
|
||
| cleansim.py | Last modified 2007-12-10 10:28:54.000000000 -0500 cleansim.py | 641 bytes |
cleansim(project, nfld=1, alg='clark',imsize=[512,512],
|
||
| makefids.py | Last modified 2007-12-07 11:37:24.000000000 -0500 makefids.py | 944 bytes |
Makes fidelity images for each configuration.
|
||
| makemses.py | Last modified 2007-12-07 11:37:24.000000000 -0500 makemses.py | 2728 bytes |
Runs almasimmos for each configuration, putting the results for each config in its own directory. The ppdisk image is scaled for each config so its width is a constant number of PSF widths across. Assumes ptgs_to_ann.py and suggestalmaconfig.py have been loaded.
|
||
| ptgs_to_ann.py | Last modified 2007-12-05 17:06:00.000000000 -0500 ptgs_to_ann.py | 1522 bytes |
ptgs2ann(ptgs, diam, ann, color = 'green') Given a list of pointings ptgs, make a kvis annotation file ann with a cross and circle of diameter diam (an angle qa) at each pointing. direction_splitter(direction) Given a direction, return its epoch, x, and y parts. Epoch will be '' if absent, or '%s ' % epoch if present. x and y will be angle qa's in degrees.
|
||
| task_radplot.py | Last modified 2007-12-02 17:27:20.000000000 -0500 task_radplot.py | 1822 bytes |
radplot(img, wc, maxrad, rs, azav, runit, title, rlab, azavlab) Plots the azimuthal average of an image about a point. For now it assumes you are only interested in the first plane of img, and that it has square pixels. Keyword arguments: img -- Name of image to made a radial plot of. wc -- World coordinate to use as center. rs -- An optional list or array of radii to use instead of calculating. azav -- An optional list or array of azimuthal averages to use instead of calculating. blunit -- Unit of the radii. Derived from img if necessary. title -- Title for the plot. Defaults to 'Azimuthal average of %s about %s' % (img, wc). rlab -- Label for the radial axis. Defaults to 'Radius (runit)'. azavlab -- Label for the azimuthal average axis. Defaults to 'Azimuthal average (azavunit)'
|
||
| psi_archive_plotter_wrcas.py | Last modified 2007-10-11 19:09:34.000000000 -0400 psi_archive_plotter_wrcas.py | 11801 bytes |
A module for plotting ALMA ATF PSI archive data using CASA.
Use: From casapy,
execfile 'psi_archive_plotter.py'
example:
# Set vadtxtb to be a tb tool filled with the contents of
# ./VA--1-DTX----0x050-2007-09-26-test02.csv. The contents will be
# fetched from ./VA--1-DTX----0x050-2007-09-26-test02.tb if it already
# exists, and ./VA--1-DTX----0x050-2007-09-26-test02.csv otherwise.
vadtxtb = filetotable('VA--1-DTX----0x050-2007-09-26-test02.csv')
vadtxtb.colnames()
# Plot V____DG_VOLTAGE_3.1_-_3.5V vs. time.
simpleplot(vadtxtb, 'V____DG_VOLTAGE_3.1_-_3.5V')
# Plot a list of voltages vs. time.
simpleplot(vadtxtb, ['V____DG_VOLTAGE_3.1_-_3.5V',
'V____DG_VOLTAGE_4.8_-_5.2V'])
# Plot two arbitrary variables vs. time.
two_y_axes(vadtxtb, 'V____DG_VOLTAGE_4.8_-_5.2V',
'V____DG_VOLTAGE_3.1_-_3.5V')
# Create a dictionary containing a tb for each .csv file in the
# current directory (slow if there are a lot of new ones):
pap = PSI_archive_plotter()
# timeaxis() is just a helper function now, but Gene DuVall might
# extend it to use minutes, hours, etc., and/or to supply a time axis
# for customized plots.
# tablename() returns the table's filename without any directory or
# .csv.
Sample directory: /groups/psi/Public_PSI/Data/Daily/2007/2007-10-05-ACU_02
truer_glob(patlist = '*') Unfortunately glob.glob('a b.*') doesn't work. This function returns a
list of filenames matching the string patlist like it would in a shell
(i.e. like perl's ).
uniquify_strlist(duplist) Goes through the list of strings duplist, and appends a count number
to any duplicates. i.e. given
['a', 'b', 'c', 'a', 'c', 'd', 'a', 'e'],
it returns
['a_0', 'b', 'c_0', 'a_1', 'c_1', 'd', 'a_2', 'e'].
Note that
['a', 'a', 'a_0']
would go to
['a_0', 'a_1', 'a_0'].
If you have a list like that, you could run uniquify_strlist on the
result.
filetotable(fn, overwrite=false) Returns a CASA table as read from the comma separated value file
fn. Borrows heavily from an example by Debra Shepherd.
timeaxis(datatb)
Attempts to return a reasonable time axis and label for it from datatb.
tablename(datatb)
Returns a slightly cleaned up name for datatb.
simpleplot(datatb, colnames)
Graph datatb[colname] vs. datatb['time'] for each colname in colnames,
on the same plot.
two_y_axes(datatb, lcol, rcol)
Graph datatb[lcol] and datatb[rcol] vs. datatb['time']
with lcol's y axis on the left, and rcol's y axis on the
right, on the same plot.
Unfortunately lcol and rcol cannot be lists like in simpleplot,
because the second y axis essentially starts a new plot and resets
the color cycler.
PSI_archive_plotter(object) Reads all directory/files and stores the data in a
dictionary of dictionaries of dictionaries for each column:
self.tables[tkey][colname][dtype],
where tkey = filename with directory/ and .csv stripped off,
colname = column name
There is always a key 'colnames' with a list of column names
in tkey as its value.
dtype = data type
|
||
| testconfigs.py | Last modified 2007-10-01 12:56:08.000000000 -0400 testconfigs.py | 1895 bytes |
testconfigs(avgsepsf="configs.avgsep") Test ALMA configurations.
|
||
| writebeams.py | Last modified 2007-09-23 18:20:23.000000000 -0400 writebeams.py | 5080 bytes |
summary_start(weighting, dec) write_beam_stats(bim, ofile, relsens, beam, confnum) do_other_weightings(dec, avgsepsf="../configs.avgsep") Make robust and uniform weighted dirty beams for measurement sets have already been made at declination dec. writebeams() Export beam images to FITS. summarize_beams(outfileroot='almabeams_briggs') Write a summary of the ALMA beams into outfileroot_dec.summary.
|
||
| idlfitstocasaim.py | Last modified 2007-07-06 17:43:13.000000000 -0400 idlfitstocasaim.py | 1035 bytes |
idlfitstocasaim(imname, reffreq, freqincrement) One of IDL's many crimes is claiming to write FITS files when it doesn't. This function (based on what Kumar Golap suggested) tries to get an IDL 'fits' file into casa. imname - this function copies imname.fits in the current directory to imname.im reffreq - Reference frequency in Hz. freqincrement - Frequency increment in Hz.
|
||