create_alcd_rerun.py 2.85 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
import shutil

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_alcd_launch(locations, clear_dates, cloudy_dates, out_file):
      
    commands = []
    for i in range(len(locations)):
        commands.append("cd /mnt/data/home/baetensl/clouds_detection_git/ALCD\n")
        commands.append("python all_run_alcd.py -l {} -d {} -c {} -f true -s 0 \n".format(locations[i], cloudy_dates[i], clear_dates[i]))
        commands.extend(copy_all_masks(locations[i], cloudy_dates[i]))
        commands.append("python all_run_alcd.py -l {} -d {} -c {} -f true -s 1 \n\n".format(locations[i], cloudy_dates[i], clear_dates[i]))
        #~ commands.append("python all_run_alcd.py -l {} -d {} -c {} -f true -s 2 \n".format(locations[i], cloudy_dates[i], clear_dates[i]))

    outf = open(out_file, 'w')
    for line in commands:
        outf.write(line)
    outf.close() 
    
    
def kfold_alcd_launch(locations, clear_dates, cloudy_dates, out_file):
      
    commands = []
    for i in range(len(locations)):
        commands.append("cd /mnt/data/home/baetensl/clouds_detection_git/ALCD\n")
        commands.append("python all_run_alcd.py -l {} -d {} -c {} -f false -s 0 \n".format(locations[i], cloudy_dates[i], clear_dates[i]))
        commands.append("python all_run_alcd.py -f false -kfold true \n")
        commands.append("python metrics_exploitation.py \n\n")

    outf = open(out_file, 'w')
    for line in commands:
        outf.write(line)
    outf.close()     
    


def main():
    #~ location = 'Arles'
    #~ cloudy_date = '20170917'
    #~ copy_all_masks(location, cloudy_date)
    
    #~ return
    
    
    csv_path = '/mnt/data/home/baetensl/clouds_detection_git/Various_data/all_26_sites.csv'
    locations, clear_dates, cloudy_dates = open_csv(csv_path)
    
    #~ out_file_dir = '/mnt/data/home/baetensl/clouds_detection_git/Tools/tmp/launch_pcc'
    #~ create_pcc_launch(locations, cloudy_dates, out_file_dir)
    
    out_file = '/mnt/data/home/baetensl/clouds_detection_git/Tools/tmp/launch_alcd_rerun.sh'
    #~ create_alcd_launch(locations, clear_dates, cloudy_dates, out_file)
    
    out_file = '/mnt/data/home/baetensl/clouds_detection_git/Tools/tmp/kfold_launch_alcd.sh'    
    kfold_alcd_launch(locations, clear_dates, cloudy_dates, out_file)


    
if __name__ == '__main__':
    main()