[yt-users] Creating image from FITS data

John ZuHone jzuhone at gmail.com
Sun Sep 10 09:22:16 PDT 2017


Hi Tazkera,

The issue here is that sp[“image_0”] is a 1-D array of the points in the sphere. If you want to make plots using yt, I would suggest checking out the plotting documentation:

http://yt-project.org/doc/visualizing/plots.html <http://yt-project.org/doc/visualizing/plots.html>

Specifically, since you have a 2D fits file, it’d probably be simplest to use plot_2d:

http://yt-project.org/doc/visualizing/plots.html#plots-of-2d-datasets <http://yt-project.org/doc/visualizing/plots.html#plots-of-2d-datasets>

If you want to cut out the data that isn’t in your sphere object, you can try passing the sphere object in as the data_source argument to plot_2d:

p = yt.plot_2d(ds, “image_0”, data_source=sp)
p.save()

That should give you a head start.

Best,

John

> On Sep 9, 2017, at 8:02 PM, tazkera haque <h.tazkera at gmail.com> wrote:
> 
> Hi People, 
> 
> I am trying to play around with FITS file format. I want to create an image from this file which will include data from center to 20 arc minutes. each pixel is 3x3 arc sec.
> 
> import yt
> ds = yt.load("signal_wfilt_sn.fits")
> ds.print_stats()
> ds.field_list
> ds.domain_width
> ds.derived_field_list
> dd = ds.all_data()
> dd
> sp = ds.sphere(ds.domain_center, (400, 'code_length'))  # create sphere of 20 arcminutes with 3x3 pixel size
> sp[("fits", "image_0")]                                                         # check array of data within the sphere
> #plot 1D histogram of data over pixel
> pplot = yt.ProfilePlot(sp, "image_0", ["pixel"], weight_field=None, n_bins=1024, 
> plot_spec=dict(color='red', linestyle="--"), y_log={'pixel':False})
> pplot.show()
> # convert data to numpy array
> import numpy as np
> image = np.array(sp['image_0'])
> 
> # create image?
> imgplot = plt.imshow(image)
> 
> imgplot
> plt.show()
> image
> 
> The code is failing at this point with error:
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> <ipython-input-21-6a83e68fbbf2> in <module>()
> ----> 1 imgplot = plt.imshow(image)
>       2 
>       3 imgplot
>       4 plt.show()
> 
> /home/trina/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.pyc in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, hold, data, **kwargs)
>    3155                         filternorm=filternorm, filterrad=filterrad,
>    3156                         imlim=imlim, resample=resample, url=url, data=data,
> -> 3157                         **kwargs)
>    3158     finally:
>    3159         ax._hold = washold
> 
> /home/trina/anaconda2/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
>    1896                     warnings.warn(msg % (label_namer, func.__name__),
>    1897                                   RuntimeWarning, stacklevel=2)
> -> 1898             return func(ax, *args, **kwargs)
>    1899         pre_doc = inner.__doc__
>    1900         if pre_doc is None:
> 
> /home/trina/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
>    5122                               resample=resample, **kwargs)
>    5123 
> -> 5124         im.set_data(X)
>    5125         im.set_alpha(alpha)
>    5126         if im.get_clip_path() is None:
> 
> /home/trina/anaconda2/lib/python2.7/site-packages/matplotlib/image.pyc in set_data(self, A)
>     598         if (self._A.ndim not in (2, 3) or
>     599                 (self._A.ndim == 3 and self._A.shape[-1] not in (3, 4))):
> --> 600             raise TypeError("Invalid dimensions for image data")
>     601 
>     602         self._imcache = None
> 
> TypeError: Invalid dimensions for image data
> 
> I am completely new to image processing, so I am interested to know how you create image for this type of data in yt. Your help is very appreciated. I also provided a link to the dataset:
> 
> https://www.dropbox.com/s/bftuihqcoun8tny/signal_wfilt_sn.fits?dl=0 <https://www.dropbox.com/s/bftuihqcoun8tny/signal_wfilt_sn.fits?dl=0>
> Thanks a lot
> Tazkera haque
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20170910/c20950a6/attachment-0001.htm>


More information about the yt-users mailing list