Создание файла IPython FITS дает разные результаты
Я столкнулся с проблемой при запуске скрипта (пожалуйста, найдите код ниже).
Я пытаюсь построить массив значений, записать его в файл формата FITS, прочитать его снова и построить его ---> Я не получаю те же графики!
Если бы вы могли помочь мне с этим, было бы здорово.
Ниже приведены версии моих пакетов и компилятора:
matplotlib: '2.0.0b1'
numpy: '1.11.0'
астропия: u'1.1.2 '
питон: 2,7
С уважением, Аник Халдер
import numpy as np
from pylab import *
from astropy.io import fits
# Just making a 10x10 meshgrid
x = np.arange(10)
X , Y = np.meshgrid(x,x)
# finding the distance of different points on the meshgrid from a point suppose at (5,5)
Z = ((X-5)**2 + (Y-5)**2)**0.5
# plotting Z (see image [link below] - left one)
imshow(Z, origin = "lower")
colorbar()
show()
# writing the Z data into a fits file
fits.writeto("my_file.fits", Z)
# reading the same fits file and storing the data
Z_read = fits.open("my_file.fits")[0].data
# plotting Z_read : we expect it to show the same plot as before
imshow(Z_read, origin = "lower")
colorbar()
show()
# Lo! That's not the case for me! It's not the same plot! (see image - right one)
# Hence, I try to check whether the values stored in Z and Z_read are different..
print Z - Z_read
# No! It returns an array full of zeros! This means Z and Z_read are the same! I don't get why the plots look different!
Пожалуйста, найдите изображение по этой ссылке: http://imgur.com/1TklSjU
1 ответ
На самом деле оказывается, что это связано с версией matplotlib.
Ответ от разработчика matplotlib - Йенс Нильсен
Это не происходит в Matplotlib версии 1.51
В бета-версии 1 версии 2 данные FITS конвертируются из float32 в формат с прямым порядком байтов8. Пожалуйста, посмотрите на следующую ссылку:
https://gist.github.com/jenshnielsen/86d4a86d8f667fadddc09f88c5fb87e6
Вопрос был опубликован, и вы можете посмотреть его здесь:
https://github.com/matplotlib/matplotlib/issues/6671
В то же время для того, чтобы иметь одинаковые графики (Z и Z _read), мы должны использовать следующий код (для matplotlib 2 beta 1):
imshow(Z_read.astype('float64'), origin = "lower")