leejjoon / pywcsgrid2 Goto Github PK
View Code? Open in Web Editor NEWastromonical fits image for python matplotlib
Home Page: http://leejjoon.github.com/pywcsgrid2/
License: MIT License
astromonical fits image for python matplotlib
Home Page: http://leejjoon.github.com/pywcsgrid2/
License: MIT License
Floating axes in pywcsgrid2 seem very nice. For example:
http://leejjoon.github.com/pywcsgrid2/users/overview.html#floating-axis
But I can not figure out how to set the ticklabel type of a floating axes. In particular, I would like a floating equatorial axes with the ticklabel type set to 'absdeg'.
Is there a way to do this?
Thanks,
Hi,
I get an error massage when I try to run some files in the directory examples.
Traceback (most recent call last):
File "demo_skyview.py", line 60, in
im2 = ax2[header_radio].imshow_affine(d,
File "/home/tuahlamov/program/python/epd_free-7.2-2-rh5-x86/lib/python2.7/site-packages/pywcsgrid2/axes_wcs.py", line 1310, in getitem
ax = ParasiteAxesSky(self, key)
File "/home/tuahlamov/program/python/epd_free-7.2-2-rh5-x86/lib/python2.7/site-packages/pywcsgrid2/axes_wcs.py", line 989, in init
tr = WcsSky2SkyTransform(src_coord, dest_coord) +
File "/home/tuahlamov/program/python/epd_free-7.2-2-rh5-x86/lib/python2.7/site-packages/pywcsgrid2/wcs_transforms.py", line 189, in init
self.coord_conv_func = coord_conv(src_coord, dest_coord)
File "/home/tuahlamov/program/python/epd_free-7.2-2-rh5-x86/lib/python2.7/site-packages/pywcsgrid2/wcs_transforms.py", line 10, in coord_conv
return sky2sky(src, dest)
File "/home/tuahlamov/program/python/epd_free-7.2-2-rh5-x86/lib/python2.7/site-packages/pywcsgrid2/wcs_helper.py", line 59, in init
src = coord_system[src.lower()]
AttributeError: 'Header' object has no attribute 'lower'
Could I get your help?
Hi,
I am having an issue when attempting to plot a position-velocity diagram (x-axis position using an offset axis I created in arc min and y-axis in velocity). The program runs smoothly and outputs a plot, but the axes are wrong. I believe the x-axis is centred correctly at CPIX1 but the labels seem to be in pixels and I'm unsure about the y-axis. Here is the snippet of the program I am using:
def pv_plot(pvhdulist,plotname):
pvplotdata=numpy.where(pvhdulist[0].data>=0,numpy.sqrt(pvhdulist[0].data),0)
fig=plt.figure()
ax=pywcsgrid2.axes_wcs.AxesWcs(fig,[0.2,0.2,0.7,0.7],header=pvhdulist[0].header)
ax.set_ticklabel1_type("absval",nbins=5)
ax.set_ticklabel2_type("absval",scale=0.001,nbins=9)
pylab.imshow(pvplotdata, origin="low", interpolation="nearest", aspect=0.04, vmin=0, vmax=10,cmap=pylab.cm.gist_heat)
plt.savefig(plotname+".png",dpi=300,orientation="landscape",transparent="True",bbox_inches="tight")
No matter how I change with ax.set_ticklabel1_type (if I change it to "arcmin" and choose an offset for example for the x-axis), the axes ticks do not change.
Has this problem been encountered before?
imshow_affine method, which acts on parasite axes, currently does not autoscale the view limits. This needs to be improved.
"is_string_like" in axes_wcs.py is not supported by mpl. And it is not used in that file
Hi,
I am currently running a Mac with 0SX 10.7 Lion, python 2.7.2 and the latest stable versions of numpy, scipy, matplotlib, pyfits, pywcs and pywcsgrid2. When I try:
ap=pywcsgrid2.subplot(111,header=pywcs.WCS(h2[0].header))
I get the following error message, regardless of the fits file I use:
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pywcsgrid2/init.py", line 47, in subplot
ax = plt.subplot(ax)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py", line 766, in subplot
a = fig.add_subplot(_args, *_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 747, in add_subplot
key = self._make_key(_args, *_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 630, in _make_key
key = fixlist(args), fixitems(kwargs.items())
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 626, in fixlist
if iterable(a): a = tuple(a)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pywcsgrid2/axes_wcs.py", line 1270, in getitem
key = proj.sub([1,2])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pywcsgrid2/wcs_helper.py", line 240, in sub
return self.substitute(axis_nums_to_keep, [0] * self.naxis)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pywcsgrid2/wcs_helper.py", line 264, in _get_naxis
return self._pywcs.wcs.naxis
AttributeError: 'int' object has no attribute 'wcs'
Any ideas why this is happening and how to fix it?
Hi,
I think the arrow_length argument in the add_compass function is not working properly (if working at all). I have had a quick look at the code and I think the argument is not really connected to the actual code. While usually 0.15 is a fine value it sometimes results too large for my plots. Could you please fix this?
Thanks,
José
Hi, is there a way to change the font size of the axis tick labels? i.e., can one make the coordinates larger or smaller? The set_ticklabel1_type() command doesn't seem to recognize any logical kwarg choices for 'size'.
I can change ALL of the plot label sizes with matplotlib.rc('xtick', labelsize=....), but doesn't seem to be a way to have different subplots with different fontsizes.
P.S. - Thanks! This module has come in soooo handy!
Hi,
I am getting this error when trying to plot a figure:
186 h, d = f[0].header, f[0].data
187 #print h
--> 188 pywcsgrid2.subplot(121,header=h)
189 imshow(d, origin="lower")
190
/Library/Python/2.6/site-packages/pywcsgrid2/init.pyc in subplot(_args, *_kwargs)
45 fig = plt.gcf()
46 ax = Subplot(fig, _args, *_kwargs)
---> 47 ax = plt.subplot(ax)
48 return ax
49
/Library/Python/2.6/site-packages/matplotlib-1.1.0-py2.6-macosx-10.6-universal.egg/matplotlib/pyplot.pyc in subplot(_args, *_kwargs)
656
657 fig = gcf()
--> 658 a = fig.add_subplot(_args, *_kwargs)
659 bbox = a.bbox
660 byebye = []
/Library/Python/2.6/site-packages/matplotlib-1.1.0-py2.6-macosx-10.6-universal.egg/matplotlib/figure.pyc in add_subplot(self, _args, *_kwargs)
736 a = args[0]
737 assert(a.get_figure() is self)
--> 738 key = self._make_key(_args, *_kwargs)
739 else:
740 kwargs = kwargs.copy()
/Library/Python/2.6/site-packages/matplotlib-1.1.0-py2.6-macosx-10.6-universal.egg/matplotlib/figure.pyc in _make_key(self, _args, *_kwargs)
629 return tuple(ret)
630
--> 631 key = fixlist(args), fixitems(kwargs.items())
632 return key
633
/Library/Python/2.6/site-packages/matplotlib-1.1.0-py2.6-macosx-10.6-universal.egg/matplotlib/figure.pyc in fixlist(args)
625 ret = []
626 for a in args:
--> 627 if iterable(a): a = tuple(a)
628 ret.append(a)
629 return tuple(ret)
/Library/Python/2.6/site-packages/pywcsgrid2/axes_wcs.pyc in getitem(self, key)
1268 raise ValueError("invalide key : %s" % repr(key))
1269
-> 1270 key = proj.sub([1,2])
1271
1272 if key not in self._wcsgrid_wcsaxes:
/Library/Python/2.6/site-packages/pywcsgrid2/wcs_helper.pyc in sub(self, axes)
238 def sub(self, axes):
239 axis_nums_to_keep = [i-1 for i in axes]
--> 240 return self.substitute(axis_nums_to_keep, [0] * self.naxis)
241
242
/Library/Python/2.6/site-packages/pywcsgrid2/wcs_helper.pyc in _get_naxis(self)
262
263 def _get_naxis(self):
--> 264 return self._pywcs.wcs.naxis
265
266 naxis = property(_get_naxis)
AttributeError: 'int' object has no attribute 'wcs'
As far as I can tell this does not appear to be any issue with my code, but with pywcsgrid2 itself and it is not specific to the FITS file I am using - I've tried on a few different ones and get the same error each time.
Any suggestions as to how to fix this would be great! Thanks :)
pywcsgrid2 is amazing and is vastly improving the quality of the figures in my upcomming publication.
But I am having two minor issues to report. I can reproduce both of them with a very simple selfcontained script.
The first problem is that the axes label for b=-0.5 degrees is displayed as 0°30' when it should be -0°30'.
The second issue is that when markers have a zorder>2, they will spill over the axes.
Thanks,
import numpy, pyfits, pywcsgrid2, pylab
values = [
["NAXIS", 2, ],
["NAXIS1", 25, ],
["NAXIS2", 25, ],
["CTYPE1", 'GLON-ZEA' ],
["CRPIX1", -12.5, ],
["CRVAL1", 0, ],
["CDELT1", -0.1, ],
["CTYPE2", 'GLAT-ZEA', ],
["CRPIX2", 12.5, ],
["CRVAL2", 0, ],
["CDELT2", 0.1, ],
]
cards = [ pyfits.Card(*i) for i in values]
header=pyfits.Header(cards=cards)
ax=pywcsgrid2.subplot(111, header=header)
array=numpy.meshgrid(range(25),range(25))[0]
ax.imshow(array,origin='lower')
ax['gal'].plot([358.7],[-0.5],'*',ms=50,
color='none',mec='w',zorder=10,
mew=10)
pylab.savefig('plot.pdf')
Hello,
First, thank you so much for publishing this module, it's a great service to the community. I am getting errors in the very first step of creating the initial pywcsgrid2.Axes class.
f=fits.open("r_coadd_lensing2.fits")
h, d = f[0].header, f[0].data
pywcsgrid2.subplot(111, header=h)
returns the following error:
`/Users/jmcclear/anaconda/lib/python2.7/site-packages/pywcsgrid2/wcs_helper.pyc in _get_naxis(self)
262
263 def _get_naxis(self):
--> 264 return self._pywcs.wcs.naxis
265
266 naxis = property(_get_naxis)
AttributeError: 'Header' object has no attribute 'wcs'
`
I have tried this with several different fits files to no avail. I'm not sure what could be going on, because DS9 has no trouble opening the files' WCS systems. Here is an example of what the headers look like.
signal_header.txt
Thank you!
I, along with everyone I know that uses this package, have been unable to open the package due to this error. Any idea on how to fix it?
There are several deprecation warnings that pop up, it seems like from PyFITS. Below are the warnings:
[astrocaribe:/projects/python/astroplotlib] [common] master(+0/-248)* ± cd scripts//projects/python/astroplotlib/scripts] [common] master(+0/-472)* ± python contours_4_python.py
/Users/astrocaribe/projects/python/astroplotlib/scripts
⌁ [astrocaribe:
/Users/astrocaribe/Ureka/variants/common/lib/python2.7/site-packages/pywcsgrid2/wcs_helper.py:233: PyfitsDeprecationWarning: The ascard function is deprecated as of version 3.1 and may be removed in a future version.
Use the `.cards` attribute instead.
if hasattr(header, 'ascard'):
/Users/astrocaribe/Ureka/variants/common/lib/python2.7/site-packages/pyfits/card.py:70: PyfitsDeprecationWarning: The CardList class has been deprecated; all its former functionality has been subsumed by the Header class, so CardList objects should not be directly created. See the PyFITS 3.1.0 CHANGELOG for more details.
PyfitsDeprecationWarning)
WARNING: AstropyDeprecationWarning: The CardList class has been deprecated; all its former functionality has been subsumed by the Header class, so CardList objects should not be directly created. See the PyFITS 3.1.0 CHANGELOG for more details. [astropy.io.fits.card]
/Users/astrocaribe/Ureka/variants/common/lib/python2.7/site-packages/pywcsgrid2/wcs_helper.py:108: PyfitsDeprecationWarning: The key function is deprecated as of version 3.1 and may be removed in a future version.
Use the `.keyword` attribute instead.
if c.key in ["COMMENT", "HISTORY"]:
/Users/astrocaribe/Ureka/variants/common/lib/python2.7/site-packages/pywcsgrid2/wcs_helper.py:112: PyfitsDeprecationWarning: The key function is deprecated as of version 3.1 and may be removed in a future version.
Use the `.keyword` attribute instead.
if c.key.startswith("CUNIT") and c.value.lower().startswith("deg"):
/Users/astrocaribe/Ureka/variants/common/lib/python2.7/site-packages/pywcsgrid2/wcs_helper.py:117: PyfitsDeprecationWarning: The key function is deprecated as of version 3.1 and may be removed in a future version.
Use the `.keyword` attribute instead.
cards.append(pyfits.Card(c.key, c.value, c.comment))
WARNING: AstropyDeprecationWarning: The append function is deprecated and may be removed in a future version.
Use :meth:Header.append
instead. [astropy.utils.decorators]
WARNING: AstropyDeprecationWarning: The ascard function is deprecated and may be removed in a future version.
Use the .cards
attribute instead. [astropy.utils.decorators]
The script that generates these warnings can be found at https://github.com/astrocaribe/astroplotlib/blob/master/scripts/contours_4_python.py
The current module versions that I'm currently using can be found here https://github.com/astrocaribe/astroplotlib/blob/master/Requirements.txt
I have a FITS image with Galactic WCS coordinates. If I run the following code:
import pyfits
import matplotlib.pyplot as plt
import pywcsgrid2
f = pyfits.open("fake_pole.fits")
h, d = f[0].header, f[0].data
fig = plt.figure()
ax = pywcsgrid2.subplot(122, header=h)
fig.add_axes(ax)
ax.imshow(d, origin="lower")
ax.grid()
ax.set_display_coord_system("fk5")
ax.swap_tick_coord()
ax.set_display_coord_system("gal")
at the end, the labels are still the fk5 labels.
Hi. I have a question. I would like to have white tick marks, but I am not happy with the default format. I have a simple script to reproduce this issue.
import numpy, pyfits, pywcsgrid2, pylab
values = [
["NAXIS", 2, ],
["NAXIS1", 5, ],
["NAXIS2", 5, ],
["CTYPE1", 'GLON-ZEA' ],
["CRPIX1", -12.5, ],
["CRVAL1", 0, ],
["CDELT1", -0.1, ],
["CTYPE2", 'GLAT-ZEA', ],
["CRPIX2", 12.5, ],
["CRVAL2", 0, ],
["CDELT2", 0.1, ],
]
cards = [ pyfits.Card(*i) for i in values]
header=pyfits.Header(cards=cards)
ax=pywcsgrid2.subplot(111, header=header)
ax.imshow(numpy.ones((25,25)), origin='lower')
ax.axis[:].set_zorder(100) # I am not sure if htis is needed?
ax.tick_params(colors='white')
pylab.savefig('plot.pdf')
When I run it, the ticks are white, but they are half on top of and half below the axes. Is there an easy way to make the white ticks completely under (or over) the axes?
Hi,
I have managed to successfully use pywcsgrid2 for displaying a FITS image in the pixel reference frame (see below), but I would like to display it in the standard equatorial frame, where the negative x-axis is RA and the positive y-axis is Dec.
Is it possible to do this easily with pywcsgrid2? From looking at the docs, the only way I could see would be to make a fake FITS header that has the axes rotated, and then use that in a similar way to what is described here. But my first attempt at this failed, so I thought I would first ask if there might be an easier way.
Cheers
Will
I have some fits images where the image's X,Y direction is not the usual case (Y: North, X: West) but (Y: East, X: South). The WCS header describes this properly. Using the approach of demo_basic1.py (pywcsgrid2.subplot + imshow) the image is displayed as X,Y=0,0 bottom, left but the axes are not labelled at all. https://picasaweb.google.com/109233581849463376879/ImageDisplay?authuser=0&authkey=Gv1sRgCNW8woaP3a7lTA&feat=directlink
I am wondering whether there is an easy way to define which figure axis should be RA and DEC and the image would be transformed and displayed accordingly. While transforming the image numpy array is easy, I would like to avoid transforming the WCS header itself. Probably by adding some matplotlib.transformations to a custom imshow method for displaying a rotated/transposed image? Any idea?
Thanks.
First of all, I would like to say that I really love pywcsgrid2. Very nice job. This module is great.
This is more a question than an issue, but is there a nice way to plot objects (like circles, ellipses, ...) without having to first create a ds9 region file? Ideally, I would like some way to give in an ra, dec, size (and possible second size & angle) and having it add the object at the right spot in the sky.
Thanks,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.