我有大量包含两个给定卫星的(x,y)坐标的.asc文件。每个卫星大约有3,000个单独的文件(例如Satellite1 = [file1,file2,...,file3000]和Satellite2 = [file1,file2,...,file3000])。使用loadtxt递归读取文件
我想在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之间的所有可能的组合“sat1_in”和“sat2_in”功能和卫星2.这些是我的想法到目前为止:
#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]
而这就是我卡住的地方。如何通过迭代“sat1_ordered”和“sat2_ordered”使用loadtxt提取坐标的名单,每一个文件我已经尝试了唯一的一点是:
for file in sat1_ordered:
sat1_in = np.loadtxt(file, usecols = (1,2),comments = "#")
但是,这将创建一个包含所有测量一个巨大的名单对于卫星1.
有人能给我一些关于如何解决这个问题的想法吗?
谢谢您的回答罗马。根据我所看到的,这会生成两个数组,其中包含(x,y)坐标sat_1和sat_2以正确的顺序进行比较。但是如何迭代这两个数组来为每个卫星提取一个文件? – Pau
即sat1_file1 sat2_file1 ---->用作main()的输入sat1_file1 sat2_file2 ---->用作main()的输入等等 – Pau
Sry,但我无法理解你。请提供更多信息。你想迭代sat1_in和sat2_in,如果找到交叉打印出来的输出文件? – RomanHotsiy