我在python中有字典问题。
我的代码是
import aplpy
import numpy as np
from astropy.io import fits
from astropy.coordinates import Angle
from astropy import units as u
import pandas as pd
##### Star parameters defined by user #####
#Input FITS file
inpim1 = '/home/juan/Escritorio/pg/LMC_D2.fits'
Data_Cluster='/home/juan/Escritorio/pg/DataCluster.dat'
region = '/home/juan/Escritorio/pg/trin.reg'
im_halfsize = 17. # half size of plotted image in arcsec
outfig='/home/juan/Escritorio/pg/ensayo'
df = pd.read_csv(Data_Cluster,sep='\t')
#Obtaining the coordinates
AR = (Angle(df["AS"].values*u.arcsec).deg + Angle(df["AH"].values*u.arcmin).deg + Angle(df["AH"].values*u.hour).deg)
DE = (Angle(df["DS"].values*u.arcsec).deg - Angle(df["DM"].values*u.arcmin).deg - Angle(df["DH"].values*u.deg).deg)
#Specify coordinates of markers
markers1 = {'source':np.linspace(1, len(AR), len(AR) ) ,'RA': AR ,'Dec': DE ,'Vel-Hel':np.linspace(1,2,len(DE)) }
# Only uncomments if need to read in the data itself
im1 = fits.open(inpim1)
headerdata=im1[0].header
mapdata=im1[0].data
# Create image object
fig = aplpy.FITSFigure(inpim1)
#Color scale
fig.show_colorscale(cmap='gist_heat_r',vmax=np.nanmax(mapdata),vmid=np.nanmin(mapdata),vmin=0.08,stretch='log')
#Markers
fig.show_regions(region)
fig.show_markers(markers1['RA'], markers1['Dec'],markers1['Vel-Hel'])
问题出在那一行:
---> 72 fig.show_markers(markers1['RA'], markers1['Dec'],markers1['Vel-Hel'])
最初,如果我删除了markers1 ['Vel-Hel']的值,python会向我显示以下问题:
ValueError: Second dimension of input values should match number of WCS coordinates
我认为最后一个问题是因为图像有3个尺寸,这就是我添加标记1 ['Vel-Hel']的原因(实际上,我不需要这个,但是我必须把它放在那里)。完成此操作后,显示的错误就是最初的问题
编辑:我通过安装早期版本的aplpy解决了此问题。我不知道为什么该库的更高版本存在此问题