银河系(Ra,Dec)地区的地图与温度

时间:2016-10-15 11:12:24

标签: python mapping coordinates histogram astropy

我必须创建一个银河系地区的地图; (用射电望远镜收集的数据)。

我有文件.txt,其中有 dec ra ,并且记录了相应的温度

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="mappingResources">
        <list>
            <value>.......hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.connection.autocommit">false</prop> 
            <prop key="current_session_context_class">thread</prop >
        </props>
    </property>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
    .......
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:advice id="transactionalAdvice" transaction-manager="transactionManager">
    <tx:attributes> 
        <tx:method name="get*" read-only="true"/>
        <tx:method name="find*" read-only="true"/>
        <tx:method name="*" />  
    </tx:attributes>
</tx:advice>
<aop:config>
    <!-- applying this aop on other job classes -->
</aop:config>

<tx:advice id="traxSupportedAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="*" propagation="SUPPORTS" />
    </tx:attributes>
</tx:advice>
<aop:config>
    <aop:advisor pointcut="execution(* my.pkg.entity.*Home.*(..))" advice-ref="traxSupportedAdvice" />
</aop:config>

.txt中的每个文件都对应一个高程(23,24,25,26,27,30)。

我想要这样的事情:

enter image description here

但是我无法在python中找到一种方法来绘制它。我想我应该使用像histo2D这样的东西,但我无法弄清楚温度数据的设定方式。 我尝试过这段代码,但错了,(也许逻辑上):

244.785416667;-13.5105555556;-2.96409416136
246.039166667;-13.5086111111;4.7494842185
247.292083333;-13.5066666667;4.85067698715

如果你知道在这种情况下我应该使用的组织或图形的类型,请告诉我。

1 个答案:

答案 0 :(得分:0)

对于这种热图,我喜欢使用matplotlib中的imshow

使用此代码的一些代码示例如下所示:

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable

fig = plt.figure()
ax = plt.add_subplot(111)

heat = ax.imshow(tempmat,
                 cmap=plt.cm.viridis,
                 interpolation='none')

# include a colorbar to show the temperature corresponding to each colour
curax = make_axes_locatable(plt..agca())
cbax = curax.append_axes('right', '5%', pad='3%')
fig.colorbar(heat, cax=cbax)

fig.savefig("temperature_heatmap.pdf")
# or instead of saving, just use fig.show()

在这里,我们已将2D数组tempmat传递给imshow函数。在您的情况下,对于给定的.txt文件,这将包含RA和Dec中固定的一组箱的温度值。您可以使用numpy的histogram2d函数执行此操作:

import numpy as np

# since your example shows semicomma-separated values
dat = np.loadtxt("filename.txt", delimiter=';')

# bin the data in a space of RA and Dec bins, with
# - RAbins = number of bins you want in RA
# - Decbins = number of bins you want in Dec
#   (alternatively, supply arrays of bin edges for uneven bin widths)
# - [0, 360] and [-90, 90] or your preferred range 
#   of RA and Dec to plot temperature bins for
# - weight counts by the temperature of each data point
tsums = np.histogram2d(dat[:, 1], dat[:, 0], 
                       bins=[RAbins, Decbins],
                       range=[[0, 360], [-90, 90]],
                       weights=dat[:, 2])

# here we repeat as above without the weighting, 
# so that we can find the average temperature in each bin
bincounts = np.histogram2d(dat[:, 1], dat[:, 0], 
                           bins=[RAbins, Decbins],
                           range=[[0, 360], [-90, 90]],
                           weights=dat[:, 2])

# divide the resulting 2d arrays to get bin temperatures
tempmat = tsums[0] / bincounts[0]

这是我用一些随机数据做的一个例子:

enter image description here