Coder Social home page Coder Social logo

haavee / jiveplot Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 9.0 2.61 MB

Python based plotting package for CASA MeasurementSet

License: GNU General Public License v3.0

Python 99.89% Dockerfile 0.07% Shell 0.04% Singularity 0.01%
plot python visualization pgplot casa-measurementset singularity-container singularity-image

jiveplot's Introduction

https://www.singularity-hub.org/static/img/hosted-singularity--hub-%23e32929.svg

jplotter / jiveplot

Python based visualization tool for AIPS++/CASA MeasurementSet data

The jplotter command line tool allows the user to quickly visualize the radio-astronomical data contained in a MeasurementSet (ms).

Python support

Starting from 20 Jul 2023 the master branch has been updated to support Py2 and Py3 based systems simultaneously. This version is tagged v2.0. The previous latest Py2-only master was tagged as v1.1 and last-python2-only-master.

5 second workflow

After downloading and having the dependencies installed (as of 30 Oct 2018 you can run from a singularity or Docker image) type:

$ /path/to/jiveplot/jplotter
+++++++++++++++++++++ Welcome to cli +++++++++++++++++++
$Id: command.py,v 1.16 2015-11-04 13:30:10 jive_cc Exp $
  'exit' exits, 'list' lists, 'help' helps
jcli>

and you're in the command line environment. Then open a MS, select data, select what to plot and go.

This README will not explain any further because there is a colourful PDF cookbook/tutorial/explanation with far more detail.

What can be visualized?

Quantities that can be visualized are, e.g., amplitude-versus-time, phase-versus-frequency, amplitude-versus-uv-distance, weight-versus-time, to name but a few.

Some key features:

  • the package focuses on powerful selection syntax
  • has built-in help for all commands
  • the ability to difference whole sets of plots, e.g. to visualize before-after changes or to compare output of different correlators
  • time- or frequency averaging of the data before plotting
  • plots can be saved to file (postscript).
  • plots/data sets can be organized at will
  • the data can be indexed (> indexr) to create a scan list, after which powerful scan-based selection can be used
  • plotting can be scripted/play back stored commands from text file
  • open/visualize multiple data sets at the same time or the same data set from different 'angles'
  • the current selection can be written out as a new reference ms; data is not copied but the newly created ms references rows of data in the parent ms. It can be treated as a real ms.

Data selection

ms's can contain several GBs of binary data. Therefore, data selection is desirable, preferably in a fairly natural way, even without knowing the exact details of the experiment's data.

The jplotter selection commands take a stab at suiting the needs of a radio astronomer:

# select a time range near the end of the experiment
jcli> time $end-1h to +2m20s

# select IF 0,1,2 with parallel hand polarizations
jcli> fq  0-2/p
# equivalent, but would not work for XX, YY whereas the former would
jcli> fq  0-2/rr,ll

# select sources whose name matches this
jcli> src j(19|30)*

# select all cross baselines, remove those to stations xx and yy, but add xx-ef
jcli> bl cross -(xx|yy)* +xx(ef)

# select 80% of the band, irrespective of how many channels
# the correlator produced
jcli> ch 0.1*last:0.9*last

# after running indexr, extract a bit of data (trimming 1 minute from either
# end) from scans on sources matching 042* and who are longer than three minutes
jcli> scan start+1m to end-1m where length>3m and field ~ '042*'

Dependencies

The package uses the pyrap, python casacore Python binding to access data.

It uses pgplot to visualize (it was faster and easier than matplotlib): Python binding to pgplot (the github version is preferred over this old link: http://www.jive.eu/~verkout/ppgplot-1.4.tar.gz)

The github version became online during the course of 2018 and has a setup.py which has support for Python2 and 3, where the ppgplot-1.4.tar.gz lacks this.

Note: if the original PGPLOT is giving too many headaches, the Giza library can be used as drop-in replacement for ppgplot to link against for its libpgplot.so. My ppgplot fork's setup.py has support for having both FORTRAN PGPLOT and Giza installed and allows for compile-time selection of which actual pgplot backend to use.

Singularity and Docker container images

As of 30 October 2018 Singularity and Docker images are available. In fact, the Singularity image just runs the Docker image. The jiveplot Docker image contains jiveplot and all its dependencies and is built on top of the excellent kernsuite/kern-4 project.

Even though all functionality is in the Docker image, we advise to run/install Singularity (if you have a choice) for the following reasons:

  • X11 forwarding works out of the box with Singularity, which is convenient if you wish to actually see the plots on your screen. According to the interwebs X forwarding can be done through Docker as well but it didn't for me (see below)

  • Your ${HOME} directory is visible by default inside the Singularity container. This has the nice effect that your jiveplot command history and aliases are persisted between runs of the image (~/.jcli.history for the history). This in turn means that ^r (reverse-search-history) is actually useful

  • I'm not even going to mention the security issues of Docker which has to run as root

Running the Singularity image

UPDATE November 2019 - because of Singularity security changes it is now recommended to use the following method of running the jiveplot container:

$ singularity pull shub://haavee/jiveplot:latest
# this will give you a local `path/to/*.simg` file
$ singularity run --bind <local dir>:<container dir> path/to/*.simg

where <local dir> is the/a directory on your host where your CASA MeasurementSet(s) live and <container dir> is the desired mount point inside the container.

Running the Docker image

Allegedly, running Docker like this:

$ docker run -it --init --network=host -v /tmp/.X11-unix:/tmp/.X11-unix:ro -e DISPLAY="$DISPLAY" -v <local dir>:<container dir> haavee/jiveplot

does X11 forwarding but yours truly has seen it also not work. YMMV.

Both commands should drop you immediately into the jiveplot command line interface:

+++++++++++++++++++++ Welcome to cli +++++++++++++++++++
$Id: command.py,v 1.16 2015-11-04 13:30:10 jive_cc Exp $
  'exit' exits, 'list' lists, 'help' helps
jcli> ms <container dir>/path/to/my_data.ms
MS my_data.ms opened &cet
jcli> 

jiveplot's People

Contributors

bmarcote avatar haavee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jiveplot's Issues

Baseline selection fails for an AARTFAAC MS

Executing:
jcli> bl (A12_380)A12_382
results in:
the command 'bl (A12_380)A12_382' is unknown.
However,
jcli> taql ANTENNA1=380 and ANTENNA2 in [381,382] taqlStr: ANTENNA1=380 and ANTENNA2 in [381,382]
works.
The antenna entries in the MS are like:
listAntennas: A12_564 (564) A12_565 (565) A12_566 (566) A12_567 (567)
listAntennas: A12_568 (568) A12_569 (569) A12_570 (570) A12_571 (571)
etc.

standardplots anptime plots ckey is incorrect

Currently amp+phase versus time plots use "ckey src" which is great for the one that produces a plot for the whole experiment.
This is a change from previous plots that showed the polarisations in different colours.
The "zoomed in plot" ($start-5m to +55m) should use "ckey p['RR']=2 p['LL']=3."

We now seem to also be plotting multiple subbands. This should probably be changed back to only one in both plots as this makes them very difficult to interpret/follow.

This will likely require a rewrite for the plot functions to support kwargs.
Additionally command line argument should be replaced to use argparse.

Compatibility issues for Python 3.7 or higher

The current version of jiveplot cannot be used in Python 3.7 or higher (works fine up to 3.6) due to changes in the standard library. Relevant ones seems to be in the re module:

Changed in version 3.6: Unknown escapes in pattern consisting of '\' and an ASCII letter now are errors.
Changed in version 3.7: Unknown escapes in repl consisting of '\' and an ASCII letter now are errors.

The latter seems to trigger the following error when parsing any str in most of the functions (e.g. bl):

invalid escape sequence \w

standardplots when ms ends in "/" outputs wrong file names

I thought we had fixed this, but apparently not.

If you run standardplots where the MS option (the MS path name) ends with a "/", then all output files are saved with a wrong name. Instead of the expected "{MS}-{##}.ps", they are called "-{##}.ps".

Control-C during plotting triggers AttributeError: 'Dict' object has no attribute 'xlim'

Every now and then I saw this error popping up: 'Dict' object has no attribute 'xlim', but did not now how to reproduce.

Accidentally, when running with debug info and playing around, seem to have found a way to reproduce: press ^C whilst the system is generating the plots. The next attempt to plot will give this error at the end.

As a bonus, here's the backtrace:

jcli> cd /jop98_2/scratch/cook/VLA; ms line1.ms; indexr; pt phachan; scan 2-5; avt vector; nxy 4 12; new time t; sort bl time; show noheader; pl
ms: Current MS is 'line1.ms' containing 388700 rows of Spectral data for uid://evla/pdb/36820386 [DATA]
Running indexr. This may take some time.
indexr: found  10  scans. (use 'listr' to inspect)
plotType:                 phachan [phase versus channel]
  2: 04-Aug-2019/09:25:57.000  11m31.50s dT:12.00s J0542+4951      (0) (ARRAY_ID 0)
  3: 04-Aug-2019/09:37:39.000  42m24.00s dT:12.00s 3C84            (1) (ARRAY_ID 0)
  4: 04-Aug-2019/10:20:18.000  13m45.00s dT:12.00s J0542+4951      (0) (ARRAY_ID 0)
  5: 04-Aug-2019/10:34:15.000  42m24.00s dT:12.00s 3C84            (1) (ARRAY_ID 0)
averageTime:              Vector
layout[phachan]:          48 plots organized as 4 x 12 [flexible,rows]
new plots on:             FQ BL TIME
sort order [phachan]: bl time
show[phachan]:            NoHeader
Query took		0.067s
Data munching took      21.293s
WARNING: 200 out of 2600 data sets contained only NaN values (7.69%)!
min/max processing took	0.015s
Traceback (most recent call last):
  File "/jop98_0/scratch/verkout/src/jiveplot/command.py", line 439, in run
    drap(lambda x: self.parseOneCmd(x) if not self.exit else None, \
  File "/jop98_0/scratch/verkout/src/jiveplot/functional.py", line 95, in <lambda>
    drap        = lambda *args, **kwargs: drain(map(*args, **kwargs))
  File "/jop98_0/scratch/verkout/src/jiveplot/command.py", line 439, in <lambda>
    drap(lambda x: self.parseOneCmd(x) if not self.exit else None, \
  File "/jop98_0/scratch/verkout/src/jiveplot/command.py", line 544, in parseOneCmd
    cmd.cb()
  File "/jop98_0/scratch/verkout/src/jiveplot/jplotter.py", line 2499, in <lambda>
    cb=lambda : do_plot(env()), id="pl") )
  File "/jop98_0/scratch/verkout/src/jiveplot/jplotter.py", line 2463, in do_plot
    redraw_after_new(e)
  File "/jop98_0/scratch/verkout/src/jiveplot/jplotter.py", line 2486, in redraw_after_new
    do_redraw(e)
  File "/jop98_0/scratch/verkout/src/jiveplot/jplotter.py", line 2495, in do_redraw
    j().drawFunc(e.plots, ppgplot, e.first, foo[o.curdev].navigable(), ncol=e.devNColor)
  File "/jop98_0/scratch/verkout/src/jiveplot/jplotter.py", line 1687, in drawFunc
    plotter.drawfunc(dev, plotar, fst, onePage, **opts)
  File "/jop98_0/scratch/verkout/src/jiveplot/plots.py", line 1529, in drawfunc
    xmin     = reduce(min, map(lambda x: plotar.limits[x].xlim[0], self.yAxis), float('inf'))
  File "/jop98_0/scratch/verkout/src/jiveplot/plots.py", line 1529, in <lambda>
    xmin     = reduce(min, map(lambda x: plotar.limits[x].xlim[0], self.yAxis), float('inf'))
AttributeError: 'Dict' object has no attribute 'xlim'
'Dict' object has no attribute 'xlim'

Jiveplot animate by time fails as 'Page' object has no attribute '_growlayout'

To reproduce:
on ee:
cd /data0/immer/ES089

jcli> ms es089_line.ms
ms: Current MS is 'es089_line.ms' containing 626062 rows of Spectral data for ES089 [DATA]
jcli> pt ampfreq; bl EfJb; solint 5m; avt vector; src G30.198
plotType: ampfreq [amplitude versus frequency]
baselines: EfJb
solint: 300.0s
averageTime: Vector
sources: G30.198
jcli> pl
Query took 0.850s
Data munching took 1.595s
min/max processing took 0.000s
drawing took 0.015s
jcli> animate by time
Preparing 132 datasets for animation
Preparing animation took 0.123s
Press ^C to stop the animation [0.7fps]
Traceback (most recent call last):
File "/eee/jiveplot/command.py", line 407, in run
quote_split(stripcomment(line)))
File "/eee/jiveplot/command.py", line 406, in
map(lambda x: self.parseOneCmd(x) if not self.exit else None,
File "/eee/jiveplot/command.py", line 511, in parseOneCmd
cmd.cb(args)
File "/eee/jiveplot/jplotter.py", line 2321, in animate_fn
j().drawFunc(page_plots, ppgplot, 0, plots.AllInOne, ncol=env().devNColor)
File "/eee/jiveplot/jplotter.py", line 1750, in drawFunc
plotter.drawfunc(dev, plotar, fst, onePage, **opts)
File "/eee/jiveplot/plots.py", line 1568, in drawfunc
page = self.pagestyle(device, onePage, plotar, expandy=True)
File "/eee/jiveplot/plots.py", line 1326, in pagestyle
return Page(self, device, onePage, nplots, **kwargs)
File "/eee/jiveplot/plots.py", line 579, in init
self._growlayout(nplot, **kwargs)
AttributeError: 'Page' object has no attribute '_growlayout'
'Page' object has no attribute '_growlayout'
jcli>

jplotter command line arguments

Allow jplotter to take command line arguments that will be executed from within the program.
I.e., instead of doing
$ printf "" | jplotter
allow the user to do
$ jplotter -c

Baseline selection: order matters

When doing a selection of a determine baseline, I found the following behavior:

bl EfSr
baselines: EfSr

bl SrEf
No baselines matched your selection
baselines: No baselines selected yet

bl EfSr
baselines: EfSr

The MS contains several antennas, including "Sr" and "Ef". Depending on the order I write them, it finds the desired baseline or not. Is it the expected behavior?
I think the selection should search for both possibilities (e.g. when looking for "SrEf" -> search for the data with "SrEf" and "EfSr"), as it can give an unexpected result.

List of plots (lp) command not working

At least in all the Python 3 (+3.6) code.
When running lp an error is produced:

jcli> lp
Known plot-types:
unsupported format string passed to EnumValueMeta.__format__

`lp` does not work in Python 3

I noticed another of the unexpected changes when moving to Python 3.8+:

jcli> lp
Known plot-types:
unsupported format string passed to EnumValueMeta.__format__
jcli>

lp doesn't return any value.
This has been observed in the current issue-18 and python23-compact branches that are in eee.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.