Duncan Butler
Duncan Butler

Reputation: 13

project numpy array to aitoff projection

I have an (as yet incomplete) image of the whole sky. In order to display it properly it needs to be projected onto an ellipse (specifically an Aitoff projection).

I have tried various versions of this:

plt.subplot(111, projection="aitoff")
plt.imshow(image, vmin=0.004, vmax=0.01, extent=[0,360,-90,90])
plt.show()

...and have tried changing the values in the extent kwarg to radians, as well as using pcolor or pcolormesh instead of imshow.

These have given me: an empty Aitoff plot, various Aitoff plots with all or part of my image sitting inside it, but not filling it, or an Aitoff plot with a small part of my image (one or two pixels by the looks of things) completely filling it.

My whole image sitting within a plot

The unprojected image

I also do not have access to things like Basemap or astroproj as I'm using a machine owned by my university.

Edit: As was pointed out by another user the above example is not Minimal, Complete, and Verifiable. Below is a version which should be:

A=np.random.rand(180,360)
plt.imshow(A)
plt.show()

plt.subplot(111, projection="aitoff")
plt.pcolormesh(A)
plt.show()

I want the entire image generated in the plt.imshow() command to be projected in the Aitoff figure. Instead only a few pixels are. Any ideas?

Thanks!

Upvotes: 1

Views: 1483

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339280

Using imshow in non-rectilinear projections will mostly fail. But instead pcolormesh may be used.

The aitoff projection ranges from -π to π in horizontal and from -π/2 to π/2 in vertical direction. This is the range of values to use when plotting the pcolormesh plot.

import numpy as np
import matplotlib.pyplot as plt

im = plt.imread("house.jpg")
x = np.linspace(-np.pi,np.pi,im.shape[1])
y = np.linspace(-np.pi/2,np.pi/2,im.shape[0])
X,Y = np.meshgrid(x,y)

plt.subplot(111, projection="aitoff")
plt.pcolormesh(X,Y[::-1],im[:,:,2])
plt.show()

enter image description here

Upvotes: 2

Related Questions