create_pcc_launch.py 1.76 KB
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys 
import os
import os.path as op
import glob
import numpy as np
import json
import csv


def open_csv(csv_path):
    locations = []
    clear_dates = []
    cloudy_dates = []
    with open(csv_path, 'rb') as csvfile:
        spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
        spamreader.next()
        for row in spamreader:
            locations.append(row[1])
            clear_dates.append(row[2])
            cloudy_dates.append(row[3])
    print(locations)
    print(clear_dates)
    print(cloudy_dates)
    return locations, clear_dates, cloudy_dates

def create_pcc_launch(locations, dates, out_file):
     
    commands = []
    for i in range(len(locations)):
        commands.append("cd /mnt/data/home/baetensl/clouds_detection_git/PCC\n")
        #~ commands.append("python all_run_pcc.py -l {} -d {} -m True\n".format(locations[i], dates[i]))
        commands.append("python all_run_pcc.py -l {} -d {}\n".format(locations[i], dates[i]))
    
        
    # write shell files to launch the PEPS download
    nb_commands = 2*4
    
    start = 0
    end = nb_commands
    for k in range(1+int(float(len(commands))/nb_commands)):
        outf = open('{}_{}.sh'.format(out_file, k), 'w')
        for line in commands[start:end]:
            outf.write(line)
        outf.close()
        start += nb_commands
        end += nb_commands        


def main():
    csv_path = '/mnt/data/home/baetensl/clouds_detection_git/Various_data/all_scenes.csv'
    locations, clear_dates, cloudy_dates = open_csv(csv_path)
    
    out_file_dir = '/mnt/data/home/baetensl/clouds_detection_git/Tools/pcc_launch/launch_pcc'
    create_pcc_launch(locations, cloudy_dates, out_file_dir)


    
if __name__ == '__main__':
    main()