因此我需要一些特定问题的帮助。我有.composite(例如:RR0063_0011.composite)文件,其中第二列(强度)被读入数组中,但我需要在单独文件的第二列中添加日期(Modified Julian Date)两次在数组转换并保存之前,每行的数量。示例性输入文件:Python:在数组中的单独文件的数据末尾添加数据两次
数据(.composite)文件:
滨#.....强度
1. -0.234987
2. 0.87734
...
512. -0.65523
修正儒略日期的文件:
文件从MJD是抓住..... MJD
RR0063_0011.profs 55105.07946
RR0023_0061.profs 53495.367377
RR0022_0041.profs 53492.307631
这是用于将数据读入数组并生成mjd.txt文件的代码。所有这些工作到目前为止,我只需要将MJD 两次添加到相应的.composite行的末尾。现在,我对Python知之甚少,但这是我目前的代码。
#!/usr/bin/python
import sys
import glob
import numpy as np
import os
psrname = sys.argv[1]
file_list = glob.glob('*.composite')
cols = [1]
data = []
for f in file_list:
# Split the filename from the extension to use later
filename = os.path.splitext('{0}'.format(f))
data.append(np.loadtxt(f, usecols=cols))
print data
# Run 'vap' (a PSRCHIVE command) to grap the MJD from the .profs file for each observation and write out to a file called 'mjd.txt'
os.system('vap -nc mjd ../{0}/{0}.profs >> mjd.txt' .format(filename[0]))
# Put the MJDs only (from 'mjd.txt') in an array called mjd_array
mjd_array = np.genfromtxt('mjd.txt', dtype=[('filename_2','S40'),('mjd','f8')])
# Check if working
print mjd_array['mjd'][7]
arr = np.vstack(data)
transposed_arr = np.transpose(arr)
print transposed_arr
fout = np.savetxt(psrname + '.total', transposed_arr, delimiter=' ')
的MJDS是不是为了与.composite文件,并在年底,我需要在保存之前由MJD所有列进行排序。
谢谢你的帮助!
希望的输出:
强度
.....
强度
MJD
MJD
-0.234987
2. 0.87734
...
-0.65523
55105.07946
55105.07946
你能提供两个输入文件的例子,所需的输出文件,请? – albert
@albert编辑清晰!谢谢 – astrokid