日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python格式文件大小_在Python中调整NVSS FITS格式文件的大小并对其进行操作

發布時間:2025/3/13 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python格式文件大小_在Python中调整NVSS FITS格式文件的大小并对其进行操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這個問題可能主要是針對天文學家或多或少的進步。

您知道如何將NVSS擬合文件轉換為僅2個(非4!)軸的擬合嗎?或者,當我嘗試使用astropy和其他“ astro”庫為Python嘗試在光學DSS數據上重疊nvss countours時,如何處理具有4軸并在Python中產生以下錯誤的文件?(下面的代碼)

我嘗試這樣做,并且當NVSS FITS有上述4個軸時,會出現錯誤消息和警告:

WARNING: FITSFixedWarning: The WCS transformation has more axes (4) than the image it is associated with (2) [astropy.wcs.wcs]

WARNING: FITSFixedWarning: 'datfix' made the change 'Invalid parameter value: invalid date '19970331''. [astropy.wcs.wcs]

https://stackoverflow.com/questions/33107224/re-sizing-a-fits-image-in-python

WARNING: FITSFixedWarning: 'datfix' made the change 'Invalid parameter value: invalid date '19970331''. [astropy.wcs.wcs]

Traceback (most recent call last):

File "p.py", line 118, in

cont2 = ax[Header2].contour(opt.data, [-8,-2,2,4], colors="r", linewidth = 10, zorder = 2)

File "/home/ela/anaconda2/lib/python2.7/site-packages/mpl_toolkits/axes_grid1/parasite_axes.py", line 195, in contour

return self._contour("contour", *XYCL, **kwargs)

File "/home/ela/anaconda2/lib/python2.7/site-packages/mpl_toolkits/axes_grid1/parasite_axes.py", line 167, in _contour

ny, nx = C.shape

ValueError: too many values to unpack

我還嘗試過使用FITS_tools / match_images.py將NVSS FITS的大小首先調整為DSS文件的正常2軸大小,??然后使用更正后的文件而不是原始文件,但這只會給我一個錯誤:

Traceback (most recent call last):

File "p.py", line 64, in

im1,im2 = FITS_tools.match_fits(to_be_projected,reference_fits)

File "/home/ela/anaconda2/lib/python2.7/site-packages/FITS_tools/match_images.py", line 105, in match_fits

image1_projected = project_to_header(fitsfile1, header, **kwargs)

File "/home/ela/anaconda2/lib/python2.7/site-packages/FITS_tools/match_images.py", line 64, in project_to_header

**kwargs)

File "/home/ela/anaconda2/lib/python2.7/site-packages/FITS_tools/hcongrid.py", line 49, in hcongrid

grid1 = get_pixel_mapping(header1, header2)

File "/home/ela/anaconda2/lib/python2.7/site-packages/FITS_tools/hcongrid.py", line 128, in get_pixel_mapping

csys2 = _ctype_to_csys(wcs2.wcs)

File "/home/ela/anaconda2/lib/python2.7/site-packages/FITS_tools/hcongrid.py", line 169, in _ctype_to_csys

raise NotImplementedError("Non-fk4/fk5 equinoxes are not allowed")

NotImplementedError: Non-fk4/fk5 equinoxes are not allowed

我不知道該怎么做。FIRST.FITS文件沒有類似的問題。Python中的Imsize還告訴我,NVSS是唯一一個4維的(例如1、1、250、250)。因此,不能將其覆蓋在適當的位置。你有什么主意嗎?請幫助我,我可以捐贈您的項目。我花了幾天時間嘗試解決它,但它仍然無法正常工作,但是我迫切需要它。

# Import matplotlib modules

import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable

from matplotlib.axes import Axes

import matplotlib.cm as cm

from matplotlib.patches import Ellipse

import linecache

import FITS_tools

# Import numpy and scipy for filtering

import scipy.ndimage as nd

import numpy as np

import pyfits

import matplotlib.pyplot

import pylab

#Import astronomical libraries

from astropy.io import fits

import astropy.units as u

#from astroquery.ned import Ned

import pywcsgrid2

# Read and prepare the data

file1=open('/home/ela/file')

count=len(open('file', 'rU').readlines())

print count

for i in xrange(count):

wiersz=file1.readline()

title=str(wiersz)

print title

title2=title.strip("\n")

print title2

path = '/home/ela/'

fitstitle = path+title2+'_DSS.FITS'

fitstitle2 = path+title2+'_FIRST.FITS'

fitstitle3 = path+title2+'_NVSS.FITS'

datafile = path+title2

outtitle = path+title2+'.png'

print outtitle

print datafile

nvss = fits.open(fitstitle)[0]

first = fits.open(fitstitle2)[0]

opt = fits.open(fitstitle3)[0]

try:

fsock = fits.open(fitstitle3) #(2)

except IOError:

print "Plik nie istnieje"

print "Ta linia zawsze zostanie wypisana" #(3)

opt.verify('fix')

first.verify('fix')

nvss.verify('fix')

Header = nvss.header

Header2 = first.header

Header3 = opt.header

to_be_projected = path+title2+'_NVSS.FITS'

reference_fits = path+title2+'_DSS.FITS'

im1,im2 = FITS_tools.match_fits(to_be_projected,reference_fits)

print(opt.shape)

print(first.shape)

print(nvss.shape)

print(im2.shape)

#We select the range we want to plot

minmax_image = [np.average(nvss.data)-6.*np.std(nvss.data), np.average(nvss.data)+5.*np.std(nvss.data)] #Min and max value for the image

minmax_PM = [-500., 500.]

# PREPARE PYWCSGRID2 AXES AND FIGURE

params = {'text.usetex': True,'font.family': 'serif', 'font.serif': 'Times New Roman'}

plt.rcParams.update(params)

#INITIALIZE FIGURE

fig = plt.figure(1)

ax = pywcsgrid2.subplot(111, header=Header)

#CREATE COLORBAR AXIS

divider = make_axes_locatable(ax)

cax = divider.new_horizontal("5%", pad=0.1, axes_class=Axes)

#fig.add_axes(cax)

#Configure axis

ax.grid() #Will plot a grid in the figure

# ax.set_ticklabel_type("arcmin", center_pixel=[Header['CRPIX1'],Header['CRPIX2']]) #Coordinates centered at the galaxy

ax.set_ticklabel_type("arcmin") #Coordinates centered at the galaxy

ax.set_display_coord_system("fk5")

# ax.add_compass(loc=3) #Add a compass at the bottom left of the image

#Plot the u filter image

i = ax.imshow(nvss.data, origin="lower", interpolation="nearest", cmap=cm.bone_r, vmin= minmax_image[0], vmax = minmax_image[1], zorder = 0)

#Plot contours from the infrared image

cont = ax[Header2].contour(nd.gaussian_filter(first.data,4),2 , colors="r", linewidth = 20, zorder = 2)

# cont = ax[Header2].contour(first.data, [-2,0,2], colors="r", linewidth = 20, zorder = 1)

# cont2 = ax[Header2].contour(opt.data, [-8,-2,2,4], colors="r", linewidth = 10, zorder = 2)

#Plot PN positions with color coded velocities

# Velocities = ax['fk5'].scatter(Close_to_M31_PNs['RA(deg)'], Close_to_M31_PNs['DEC(deg)'], c = Close_to_M31_PNs['Velocity'], s = 30, cmap=cm.RdBu, edgecolor = 'none',

# vmin = minmax_PM[0], vmax = minmax_PM[1], zorder = 2)

f2=open(datafile)

count2=len(open('f2', 'rU').readlines())

print count2

for i in xrange(count):

xx=f2.readline()

# print xx

yy=f2.readline()

xxx=float(xx)

print xxx

yyy=float(yy)

print yyy

Velocities = ax['fk5'].scatter(xxx, yyy ,c=40, s = 200, marker='x', edgecolor = 'red', vmin = minmax_PM[0], vmax = minmax_PM[1], zorder = 1)

it2 = ax.add_inner_title(title2, loc=1)

# Plot the colorbar, with the v_los of the PN

# cbar = plt.colorbar(Velocities, cax=cax)

# cbar.set_label(r'$v_{los}[$m s$^{-1}]$')

# set_label('4444')

plt.show()

plt.savefig(outtitle)

#plt.savefig("image1.png")

解決方案

為了澄清一般用途:這是一個有關如何處理具有退化軸的FITS文件的問題,這些軸通常由CASA數據縮減程序和其他無線電數據縮減工具生成;簡并軸是頻率/波長和行程。一些天災的附屬工具知道如何處理這些工具(例如aplpy),但許多工具卻不知道。

最簡單的答案是只使用squeeze將退化的軸放入數據中。但是,如果您要在執行此操作時保留元數據,則需要做更多的工作:

from astropy.io import fits

from astropy import wcs

fh = fits.open('file.fits')

data = fh[0].data.squeeze() # drops the size-1 axes

header = fh[0].header

mywcs = wcs.WCS(header).celestial

new_header = mywcs.to_header()

new_fh = fits.PrimaryHDU(data=data, header=new_header)

new_fh.writeto('new_file.fits')

該方法將為您提供一個帶有有效天文(RA / Dec)標題的文件,但是它將丟失所有其他標題信息。

如果要保留其他標頭信息,則可以使用該FITS_tools工具flatten_header代替上面的WCS操作:

new_header = FITS_tools.strip_headers.flatten_header(header)

總結

以上是生活随笔為你收集整理的python格式文件大小_在Python中调整NVSS FITS格式文件的大小并对其进行操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。