【发布时间】:2014-07-15 11:25:47
【问题描述】:
我有大量 .asc 文件,其中包含两个给定卫星的 (x,y) 坐标。每个卫星大约有 3,000 个单独的文件(例如 Satellite1 = [file1,file2,..., file3000] 和 Satellite2= [file1,file2,..., file3000])。
我正在尝试用 Python(版本 2.7.8 |Anaconda 2.0。)编写一些代码,以查找地球表面上两个卫星轨道交叉的多个点。 我编写了一些基本代码,使用 loadtxt 将两个文件作为输入(即一个来自 Sat1,一个来自 Sat2)。简而言之,代码如下所示:
sat1_in = loadtxt("sat1_file1.asc", usecols = (1,2), comments = "#")
sat2_in = loadtxt("sat2_file1.asc", usecols = (1,2), comments = "#")
def main():
xover_search() # Returns True or False whether a crossover is found.
xover_final() # Returns the (x,y) coordinates of the crossover.
write_output() # Appends this coordinates to a txt file for later display.
if __name__ == "__main__":
main()
我想将此代码实现到整个数据集,使用一个函数为卫星 1 和卫星 2 之间所有可能的文件组合输出“sat1_in”和“sat2_in”。到目前为止,这些是我的想法:
#Create two empty lists to store all the files to process for Sat1 and Sat2:
sat1_files = []
sat2_files = []
#Use os.walk to fill each list with the respective file paths:
for root, dirs, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, 'sat1*.asc'):
sat1_files.append(os.path.join(root, filename))
for root, dirs, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, 'sat2*.asc'):
sat2_files.append(os.path.join(root, filename))
#Calculate all possible combinations between both lists using itertools.product:
iter_file = list(itertools.product(sat1_files, sat2_files))
#Extract two lists of files for sat1 and sat2 to be compared each iteration:
sat1_ordered = [seq[0] for seq in iter_file]
sat2_ordered = [seq[1] for seq in iter_file]
这就是我卡住的地方。如何使用 loadtxt 遍历“sat1_ordered”和“sat2_ordered”以提取每个文件的坐标列表?我唯一尝试过的是:
for file in sat1_ordered:
sat1_in = np.loadtxt(file, usecols = (1,2),comments = "#")
但这将创建一个包含卫星 1 的所有测量值的巨大列表。
有人能给我一些关于如何解决这个问题的想法吗?
【问题讨论】: