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格式文件的大小并对其进行操作相关推荐
- python 视频清晰度_在opencvpython中调整视频分辨率
我想把我从我的网络摄像头得到的视频分辨率降低到一半(即从640x480到320x240),但我遇到了错误.在import numpy as np import cv2 cap = cv2.VideoC ...
- python 时间序列预测_使用Python进行动手时间序列预测
python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...
- python 概率分布模型_使用python的概率模型进行公司估值
python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...
- php中readfile的用法,怎么在php中利用readfile() 函数设置文件的大小
怎么在php中利用readfile() 函数设置文件的大小 发布时间:2020-12-18 15:51:48 来源:亿速云 阅读:77 作者:Leah 本篇文章为大家展示了怎么在php中利用readf ...
- c语言读取文件字节数,怎么在C语言中利用fstat函数获取文件的大小
怎么在C语言中利用fstat函数获取文件的大小 发布时间:2021-01-22 17:03:17 来源:亿速云 阅读:110 作者:Leah 怎么在C语言中利用fstat函数获取文件的大小?针对这个问 ...
- python getattr函数_[转]Python中的getattr()函数详解
看了下函数本身的doc getattr(object, name[, default]) -> value Get a named attribute from an object; getat ...
- python中立方表示_在Python中表示一个对象的方法
在 Python 中一切都是对象.如果要在 Python 中表示一个对象,除了定义 class 外还有哪些方式呢?我们今天就来盘点一下. 0x00 dict 字典或映射存储 KV 键值对,它对查找.插 ...
- python声音捕获_在Python中实现实时信号处理如何连续捕获音频?
我计划用Python实现一个类似DSP的信号处理器.它应该通过ALSA捕获音频片段,对其进行处理,然后通过ALSA播放.在 为了开始工作,我写了以下代码(非常简单).在import alsaaudio ...
- python画图模糊_使用python matplotlib 画图导入到word中如何保证分辨率
在写论文时,如果是菜鸟级别,可能不会花太多时间去学latex,直接用word去写,但是这有一个问题,当我们用其他工具画完实验彩色图时,放到word中会有比较模糊,这有两个原因导致的. 原因一:图片导入 ...
最新文章
- java静态代理与动态代理
- Vue+Flask看这篇就够了
- Qt学习(五):TCP通信
- oracle输出xml文件格式,在oracle中通过字段信息生成xml文件
- 图论 —— 图的连通性 —— 有桥连通图加边变边双连通图
- 分享改进 高性能通用分表归档存储过程测试结果更新
- 如何告别“芯繁魂乱”难题?这个 OS 来支招!
- 推荐写代码的软件(IDE)——VS code的安装与使用,VS code中运行C语言、C++、Java、Python
- regexp函数mysql_mysql中regexp_like()函数的例子解析
- 开发日志 2017年8月31日
- 硬件:Intel CPU发展史
- CVPR 2022 | 基于密度与深度分解的自增强非成对图像去雾
- Teamviewer使用方法
- 妥善处理的九大面试送命题
- 摄魄人心的独白,静静聆听,你会感悟很多
- 【转】 机器学习入门——浅谈神经网络
- macf1-f12按键失灵_枕头2-1-0失灵
- 用python将txt文件中的内容导入到excel文件中
- Dependency ‘taglibs:standard:1.1.2‘ not found
- 5个开源聊天应用程序
热门文章
- 学习java 的30个目标
- BestCoder-Round#38
- 百度2019暑期实习计算机视觉岗位笔试题
- 感知器的c++实现_使用FastAI和PyTorch的多层感知器
- python求corr_Python dataframe 算相关系数用corr(),算不出结果
- javascript 设计模式_开发者都应该了解的7种JavaScript设计模式
- php+堆排序算法,排序算法-堆排序-php
- freebsd mysql57_Freebsd7.2下Ports安装PHP5、MySql5.4、Apache22
- python多线程 不在main_Python多线程
- Java爬取校内论坛新帖