Plotting an image in Matplotlib and saving it at it's natural scale without any extra labels or padding turns out to be a bit akward:import sunpyplot = sunpy.make_map(sunpy.AIA_171_IMAGE).plot()plot.savefig('test.png')
Compare this with saving an (unscaled/grayscale) image with PIL:import sunpyimport matplotlib.pyplot as pltaia = sunpy.make_map(sunpy.AIA_171_IMAGE)fig = plt.figure(frameon=False)fig.set_size_inches(10.24, 10.24)ax = plt.Axes(fig, [0., 0., 1., 1.])ax.set_axis_off()fig.add_axes(ax)ax.imshow(aia, aspect='normal', norm=aia.norm(), cmap=aia.cmap)fig.savefig('test.png', dpi=100)
I'm thinking about adding a method to the BaseMap to help make it easier to achieve the above effect. One approach would be toimport sunpyimport Imageaia = sunpy.make_map(sunpy.AIA_171_IMAGE)im = Image.fromarray(aia)im.convert('L').save('test2.png')
cd C:\sunpy\ "%ProgramFiles(x86)%\Git\bin\git" pull Good things appeared to happen Then I opened Spyder using Python(x,y) to try Keith's second code block and it didn't like it. Anyone care to tell me what has happened? I use Windows 7. Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> import sunpy >>> import matplotlib.pyplot as plt >>> aia = sunpy.make_map(sunpy.AIA_171_IMAGE) Traceback (most recent call last): File "<console>", line 1, in <module> File "c:\sunpy\sunpy\map\__init__.py", line 58, in make_map return BaseMap.read(args[0]) File "c:\sunpy\sunpy\map\basemap.py", line 238, in read header, data = cls.parse_file(filepath) File "c:\sunpy\sunpy\map\basemap.py", line 211, in parse_file from sunpy.io import read_file File "c:\sunpy\sunpy\io\__init__.py", line 3, in <module> from sunpy.io import fits, jp2 File "c:\sunpy\sunpy\io\fits.py", line 27, in <module> import pyfits File "C:\Python27\lib\site-packages\pyfits-2.4.0-py2.7-win32.egg\pyfits\__init__.py", line 17, in <module> from core import * File "C:\Python27\lib\site-packages\pyfits-2.4.0-py2.7-win32.egg\pyfits\core.py", line 34, in <module> import gzip File "C:\Python27\lib\gzip.py", line 36, in <module> class GzipFile(io.BufferedIOBase): AttributeError: 'module' object has no attribute 'BufferedIOBase' >>>
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
Hi, Richard,
I think the first thing to try is to upgrade your PyFITS. It looks like you’re running 2.4.0, and the latest version is 3.0.4.
Albert
Hi, Keith,
Yeah, I just tried your code block to create “test.png”, and it works fine with the latest SunPy and PyFITS 3.0.3. It may be relevant that Python(x,y) appears to be broken on my machine right now – I have no clue why – so I ran the code from the command line.
Albert
Hi, Keith,
���� Yeah, I just tried your code block to create �test.png�, and it works fine with the latest SunPy and PyFITS 3.0.3.� It may be relevant that Python(x,y) appears to be broken on my machine right now � I have no clue why � so I ran the code from the command line.
�
Albert
�
From: su...@googlegroups.com [mailto:su...@googlegroups.com] On Behalf Of Keith Hughitt
Sent: Friday, January 20, 2012 2:26 PM
To: su...@googlegroups.com
Subject: Re: {SunPy} Creating a simple plot in SunPy and saving at an image's native resolution
�
I was just going to suggest the same thing... just to be sure though-are you able to run the example with the latest version of SunPy, Albert?
�
On Fri, Jan 20, 2012 at 2:25 PM, Shih, Albert Y. (GSFC-6710) <albert...@nasa.gov> wrote:
Hi, Richard,
���� I think the first thing to try is to upgrade your PyFITS.� It looks like you�re running 2.4.0, and the latest version is 3.0.4.
�
Albert
�
From: su...@googlegroups.com [mailto:su...@googlegroups.com] On Behalf Of Richard Schwartz
Sent: Friday, January 20, 2012 2:20 PM
To: su...@googlegroups.com
Subject: Re: {SunPy} Creating a simple plot in SunPy and saving at an image's native resolution
�
I think I just updated by Sunpy
cd C:\sunpy\"%ProgramFiles(x86)%\Git\bin\git" pull
�
Good things appeared to happen
Then I opened Spyder using Python(x,y) to try Keith's second code block and it didn't like it.� Anyone care to tell me what has happened?� I use Windows 7.�
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32Type "copyright", "credits" or "license" for more information.
�
>>> import sunpy>>> import matplotlib.pyplot as plt>>> aia = sunpy.make_map(sunpy.AIA_171_IMAGE)Traceback (most recent call last):
� File "<console>", line 1, in <module>� File "c:\sunpy\sunpy\map\__init__.py", line 58, in make_map��� return BaseMap.read(args[0])� File "c:\sunpy\sunpy\map\basemap.py", line 238, in read��� header, data = cls.parse_file(filepath)�� File "c:\sunpy\sunpy\map\basemap.py", line 211, in parse_file��� from sunpy.io import read_file� File "c:\sunpy\sunpy\io\__init__.py", line 3, in <module>��� from sunpy.io import fits, jp2� File "c:\sunpy\sunpy\io\fits.py", line 27, in <module>��� import pyfits� File "C:\Python27\lib\site-packages\pyfits-2.4.0-py2.7-win32.egg\pyfits\__init__.py", line 17, in <module>��� from core import *� File "C:\Python27\lib\site-packages\pyfits-2.4.0-py2.7-win32.egg\pyfits\core.py", line 34, in <module>��� import gzip� File "C:\Python27\lib\gzip.py", line 36, in <module>��� class GzipFile(io.BufferedIOBase):
AttributeError: 'module' object has no attribute 'BufferedIOBase'>>>
On 1/20/2012 9:21 AM, Keith Hughitt wrote:The plot() and show() methods of SunPy Map objects currently include axes labels, a title and color bar.
�
Further, saving such a plot will result in an image with a different number of pixels than the image that was used to make the Map, e.g.:
�
import sunpy
plot = sunpy.make_map(sunpy.AIA_171_IMAGE).plot()
plot.savefig('test.png')
�
Plotting an image in Matplotlib and saving it at it's natural scale without any extra labels or padding turns out to be a bit akward:
�
import sunpy
import matplotlib.pyplot as plt
�
aia = sunpy.make_map(sunpy.AIA_171_IMAGE)
�
fig = plt.figure(frameon=False)
fig.set_size_inches(10.24, 10.24)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
�
ax.imshow(aia, aspect='normal', norm=aia.norm(), cmap=aia.cmap)
fig.savefig('test.png', dpi=100)
�
Compare this with saving an (unscaled/grayscale) image with PIL:
�
import sunpy
import Image
�
aia = sunpy.make_map(sunpy.AIA_171_IMAGE)
im = Image.fromarray(aia)
im.convert('L').save('test2.png')
�
I'm thinking about adding a method to the BaseMap to help make it easier to achieve the above effect. One approach would be to
create a method like "save_image" to achieve the above effect. I wonder if we should also take a closer look at .plot() though
and consider making it possible to toggle on/off things like title, colorbar, and axes labels?
�
Keith
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
�
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
�
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
Hi, all,
I just helped Richard remove the older version of PyFITS. It had been installed by easy_install, which does not play nice with a subsequent upgrade using a Windows installer. The code block does not crash for him on the command line, but rather only in Spyder. Since I can’t run Spyder at all right now for whatever reason, I can’t duplicate his bug. We’ll try to figure out where the problem is in Spyder and/or Python(x,y).
But on a related note, it’d probably be good to have documentation telling people how to keep their packages up to date.
Albert
From: su...@googlegroups.com [mailto:su...@googlegroups.com] On Behalf Of Richard Schwartz
Sent: Friday, January 20, 2012 2:51 PM
To: su...@googlegroups.com
Subject: updating Pyfits. Re: {SunPy} Creating a simple plot in SunPy and saving at an image's native resolution
sunpy.org does not discuss the upgrade/update procedure for Pyfits. I just downloaded and ran pyfits-3.0.3.win32-py2.7(2).exe and that wasn't enough. I'll look around to see if I can figure this out. I hoped that I would have found out how under Sunpy.org
Richard
On 1/20/2012 2:30 PM, Shih, Albert Y. (GSFC-6710) wrote:
Hi, Keith,
Yeah, I just tried your code block to create “test.png”, and it works fine with the latest SunPy and PyFITS 3.0.3. It may be relevant that Python(x,y) appears to be broken on my machine right now – I have no clue why – so I ran the code from the command line.
Albert
From: su...@googlegroups.com [mailto:su...@googlegroups.com] On Behalf Of Keith Hughitt
Sent: Friday, January 20, 2012 2:26 PM
To: su...@googlegroups.com
Subject: Re: {SunPy} Creating a simple plot in SunPy and saving at an image's native resolution
I was just going to suggest the same thing... just to be sure though-are you able to run the example with the latest version of SunPy, Albert?
On Fri, Jan 20, 2012 at 2:25 PM, Shih, Albert Y. (GSFC-6710) <albert...@nasa.gov> wrote:
Hi, Richard,
I think the first thing to try is to upgrade your PyFITS. It looks like you’re running 2.4.0, and the latest version is 3.0.4.
Albert
From: su...@googlegroups.com [mailto:su...@googlegroups.com] On Behalf Of Richard Schwartz
Sent: Friday, January 20, 2012 2:20 PM
To: su...@googlegroups.com
Subject: Re: {SunPy} Creating a simple plot in SunPy and saving at an image's native resolution
I think I just updated by Sunpy
cd C:\sunpy\
"%ProgramFiles(x86)%\Git\bin\git" pull
Good things appeared to happen
Then I opened Spyder using Python(x,y) to try Keith's second code block and it didn't like it. Anyone care to tell me what has happened? I use Windows 7.
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import sunpy
>>> import matplotlib.pyplot as plt
>>> aia = sunpy.make_map(sunpy.AIA_171_IMAGE)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "c:\sunpy\sunpy\map\__init__.py", line 58, in make_map
return BaseMap.read(args[0])
File "c:\sunpy\sunpy\map\basemap.py", line 238, in read
header, data = cls.parse_file(filepath)
File "c:\sunpy\sunpy\map\basemap.py", line 211, in parse_file
from sunpy.io import read_file
File "c:\sunpy\sunpy\io\__init__.py", line 3, in <module>
File "C:\Python27\lib\site-packages\pyfits-2.4.0-py2.7-win32.egg\pyfits\__init__.py", line 17, in <module>
from core import *
File "C:\Python27\lib\site-packages\pyfits-2.4.0-py2.7-win32.egg\pyfits\core.py", line 34, in <module>
import gzip
File "C:\Python27\lib\gzip.py", line 36, in <module>
class GzipFile(io.BufferedIOBase):
AttributeError: 'module' object has no attribute 'BufferedIOBase'
>>>
On 1/20/2012 9:21 AM, Keith Hughitt wrote:
The plot() and show() methods of SunPy Map objects currently include axes labels, a title and color bar.
Further, saving such a plot will result in an image with a different number of pixels than the image that was used to make the Map, e.g.:
import sunpy
plot = sunpy.make_map(sunpy.AIA_171_IMAGE).plot()
plot.savefig('test.png')
Plotting an image in Matplotlib and saving it at it's natural scale without any extra labels or padding turns out to be a bit akward:
import sunpy
import matplotlib.pyplot as plt
aia = sunpy.make_map(sunpy.AIA_171_IMAGE)
fig = plt.figure(frameon=False)
fig.set_size_inches(10.24, 10.24)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(aia, aspect='normal', norm=aia.norm(), cmap=aia.cmap)
fig.savefig('test.png', dpi=100)
Compare this with saving an (unscaled/grayscale) image with PIL:
import sunpy
import Image
aia = sunpy.make_map(sunpy.AIA_171_IMAGE)
im = Image.fromarray(aia)
im.convert('L').save('test2.png')
I'm thinking about adding a method to the BaseMap to help make it easier to achieve the above effect. One approach would be to
create a method like "save_image" to achieve the above effect. I wonder if we should also take a closer look at .plot() though
and consider making it possible to toggle on/off things like title, colorbar, and axes labels?
Keith
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.
--
Hi, Keith,
Oh, I agree: pip is definitely the way to go over easy_install for packages without Windows installers. I do think that interacting with Windows installers are still preferable if possible, since Windows users will have a higher degree of familiarity with how to work with them.