Giter Site home page Giter Site logo

mtazzari / uvplot Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 10.0 850 KB

A simple package to make nice visibility plots and to export visibilites from MS tables

Home Page: https://uvplot.readthedocs.io/

License: GNU Lesser General Public License v3.0

Python 99.88% Makefile 0.12%

uvplot's Introduction

uvplot

image image image image image

A simple Python package to make nice plots of deprojected interferometric visibilities, often called uvplots (see an example below).

uvplot also makes it easy to export visibilities from MeasurementSets to uvtables, a handy format for fitting the data (e.g., using Galario).

uvplot can be used as a standalone Python package (available on PyPI) and also inside NRAO CASA 6.x. It can be installed in a Python environment and in a CASA terminal with:

pip install uvplot

An example uvplot made with this simple code:

If you are interested, have feature requests, or encounter issues, consider creating an Issue or writing me an email. I am happy to have your feedback!

Check out the documentation and the installation instructions.

uvplot is used in a growing number of publications; at this page you can find an updated list.

If you use uvplot for your publication, please cite the Zenodo reference:

@software{uvplot_tazzari,
  author       = {Marco Tazzari},
  title        = {mtazzari/uvplot},
  month        = oct,
  year         = 2017,
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.1003113},
  url          = {https://doi.org/10.5281/zenodo.1003113}
}

License

uvplot is free software licensed under the LGPLv3 License. For more details see the LICENSE.

© Copyright 2017-2021 Marco Tazzari and contributors.

uvplot's People

Contributors

mtazzari avatar pcoltsmann avatar equant avatar

Stargazers

Ujjwal Panda avatar Travis Thieme avatar Jianhang Chen avatar Shifan Zuo avatar Adam Kewley avatar Rachel Cochrane avatar Ian Czekala avatar  avatar Nick Reynolds Tran avatar Christophe Pinte avatar Rui Xue avatar Sébastien Maret avatar Miguel Cárcamo avatar Zhe-Yu Daniel Lin avatar  avatar Masayuki Yamaguchi avatar Javier Moldon avatar

Watchers

James Cloos avatar  avatar  avatar

uvplot's Issues

Add support for CASA 6

Errors were reported when using CASA 6.1.0 with pipeline.
This is weird because mstable_tmp.ms/SPECTRAL_WINDOW does exist.

CASA <1>: from uvplot import export_uvtable

CASA <2>: export_uvtable('uvtable.txt', tb, split=split, split_args={'vis': 'continuum.ms', 'field': '1', 'spw': '16,17,18', '
     ...: datacolumn': 'DATA'}, datacolumn='DATA')

2020-09-18 01:35:59 SEVERE  open::~/mstable_tmp.ms/SPECTRAL_WINDOW   Exception Reported: Table ~/mstable_tmp.ms/SPECTRAL_WINDOW does not exist

---------------------------------------------------------------------------

RuntimeError                              Traceback (most recent call last)
<ipython-input-2-a4826b303ad5> in <module>()
----> 1 export_uvtable('uvtable.txt', tb, split=split, split_args={'vis': 'continuum.ms', 'field': '1', 'spw': '16,17,18', 'datacolumn': 'DATA'}, datacolumn='DATA')

/home/.casa/lib/python/site-packages/uvplot/io.pyc in export_uvtable(uvtable_filename, tb, vis, split_args, split, dualpol, fmt, datacolumn, keep_tmp_ms, verbose)
    160 
    161     # get the mean observing frequency
--> 162     tb.open(spw_path)
    163     freqs = tb.getcol('CHAN_FREQ'.encode())  # [GHz]
    164     tb.close()

/Applications/CASA.app/Contents/Resources/python/__casac__/table.pyc in open(self, *args, **kwargs)
    453 
    454         """
--> 455         return _table.table_open(self, *args, **kwargs)
    456 
    457 

RuntimeError: Table ~/mstable_tmp.ms/SPECTRAL_WINDOW does not exist

plot: do deproject, rotate and binning inside

So that it can be used as:

from uvplot import UVTable
uv = UVTable(filename='uvtable.txt', wle=0.88e-3)
axes = uv.plot("uvplot.pdf", linestyle='-', color='r', label='Model', yerr=False, 
                         dRA=-0.3*arcsec, dDec=0.07*arcsec, inc=np.radians(30.), PA=np.radians(120.))

Avoid state in UVTable.uvdist

It is dangerous to have state in the UVTable.uvdist property implemented as:

@property
def uvdist(self):
    if self._uvdist is None:
        self._uvdist = np.hypot(self._u, self._v)

    return self._uvdist

For example, an innocent line as:

print(uv_mod.u.shape, uv_mod.uvdist.max())

forces uvdist to be computed. But, if you operate on u,v arrays in such a way that the uvdist should change, e.g. by deprojecting:

uv_mod.deproject(inc, PA)

such change is not propagated to uvdist causing internal inconsistency.
I implemented a state to cache the computation of uvdist, but since it is fast anyway, it is more robust to compute it every time. Therefore, the state should be removed.

Add a matplotlibrc

For better control of the output plot, add a matplotlibrc and an option to pass the matplotlibrc to uvplot().

Avoid matplotlib backend warning

In 6955136 I set

import matplotlib
matplotlib.use('TkAgg')

in the __init__.py to avoid a Runtime error on the mac. However, in some cases (perhaps because maptlotlib is imported before uvplot?) this warning is issued:

/Users/Stefano/anaconda/envs/galario2/lib/python2.7/site-packages/matplotlib/__init__.py:1405: UserWarning: 
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

Find a way to set the backend only if not already set.

Unable to read uvtables due to allow_pickle=False

It seems with a new version of numpy it is not possible to read uvtables anymore.

 File "/opt/conda/lib/python3.7/site-packages/uvplot/uvtable.py", line 107, in __init__
   self.read_binary_uvtable(filename, columns=columns)
 File "/opt/conda/lib/python3.7/site-packages/uvplot/uvtable.py", line 232, in read_binary_uvtable
   self.header = loaded['header'].item()
 File "/opt/conda/lib/python3.7/site-packages/numpy/lib/npyio.py", line 262, in __getitem__
   pickle_kwargs=self.pickle_kwargs)
 File "/opt/conda/lib/python3.7/site-packages/numpy/lib/format.py", line 722, in read_array
   raise ValueError("Object arrays cannot be loaded when "
ValueError: Object arrays cannot be loaded when allow_pickle=False

TypeError: argument tablename must be a string

e.g. when running
export_uvtable('uvtable.txt',
tb,
vis= 'test.ms')

produces error:
/Applications/CASA.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py in export_uvtable(uvtable_filename, tb, vis, split_args, split, dualpol, fmt, datacolumn, keep_tmp_ms, verbose)

/Applications/CASA.app/Contents/Resources/python/casac/table.pyc in open(self, *args, **kwargs)
453
454 """
--> 455 return _table.table_open(self, *args, **kwargs)
456
457

TypeError: argument tablename must be a string

Automate releases on PyPI

In order to ensure quick roll out of new versions, implement an automated process to release uvplot versions for every tagged commit. GitHub Actions are probably the best way to do that.

export_uvtable: specify columns to extract

In 0.2.1 the ascii table contained u, v, Re, Im, weights

In 0.2.2 the ascii table contains u, v, w, Re, Im, weights

It would be more elegant to refine this and allow the user provide a list of columns to extract.

plot kwargs

Perhaps allow the user to pass matplotlib-style kwargs for the various text, captions computed inside plot() etc.

Move to GitHub Actions

Travis CI essentially dropped support for open source projects by reducing the free credits, and by requiring you to apply to request credits.

See an excellent summary here

So, let's move to GitHub Actions, which is completely Free for open source (i.e., public on GitHub) projects! Jaaaaay!

Create UVTable object

Perhaps I could use a UVTable object which incorporates:

  • properties:
    • u, v: units of wavelength
    • re, im: units Jy
    • weights
    • uvdist: it is a computed attribute, see how to do it here
  • methods:
    • init(uvtablefilename, wavelength, format=): import uvtable from file (1st step: uv ascii table, format= parameter)
    • binning(binsize, inc=0, PA=0): perform the uv binning
    • uvplot(**kwargs): do the uv plot

UnicodeDecodeError when PIP_INSTALLing

when I $ pip install --user uvplot,
I receive this UnicodeDecodeError. The sys module on my python3 informs me that the default encoding is 'utf-8', not 'ascii' as pointed out in the error.

ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/anaconda3/envs/galario3/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-m63xu8td/uvplot/setup.py'"'"'; __file__='"'"'/tmp/pip-install-m63xu8td/uvplot/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /tmp/pip-install-m63xu8td/uvplot/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-m63xu8td/uvplot/setup.py", line 15, in <module>
        long_description=open('README.rst').read(),
      File "/usr/local/bin/anaconda3/envs/galario3/lib/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 6942: ordinal not in range(128)
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'

Issue installing uvplot in CASA 6.1 on linux

Hi,
Running pip install uvplot results in:

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/uvplot/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/uvplot/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/uvplot/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/uvplot/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/uvplot/
Could not fetch URL https://pypi.org/simple/uvplot/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/uvplot/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
ERROR: Could not find a version that satisfies the requirement uvplot (from versions: none)
ERROR: No matching distribution found for uvplot
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
Note: you may need to restart the kernel to use updated packages.

I'm on ubuntu 20.10 and use Anaconda, CASA works fine and I'm not sure if this is a error on my end as the package installs on my MacOS. Any tips?

Return fig instead of axes in plot()

So that the usage is similar to that of the corner package.
Inside plot the axes can be accessed with fig.gca() and from the user perspective, it is simpler to do:

fig = uv.plot()
fig = uv.plot(fig=fig)
fig.savefig("uvplot.png")

numpy > 1.9 causes issues with casa-pip

Setting numpy>1.9 in the setup.py causes casa-pip to install the most recent numpy version (1.13) inside CASA which fails.
Better to check what CASA version has numpy>1.9 and then state that uvplot can be installed inside CASA from that version onwards.

Add export_uvtable function to run in CASA

Add a function that allows the user to export visibilities into a uv table.

Currently, there is now way to access an MS table from outside CASA. The only way to export visibilities to a uvtable is to run a function from within CASA.

Datacolumn `data' not available

When a datacolumn is not available, provide the user with an informative message stating the available columns:

CASA <36>: export_uvtable('uvtable.txt',tb,vis='data.ms',verbose=True,datacolumn='data')
2018-03-29 13:38:19  SEVERE getcol::data  Exception Reported: TableProxy::getColumn: column data does not exist

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.