import FPIprocess
import os

# Specify where the data are located and where results should be saved
data_dir =     './data/' # This folder should have other folders in it, one per night of data
bw_cloud_file_1 = '' # cloud data not yet supported by this script. It would take some work to match up cloud data with FPI data.
bw_cloud_file_2 = ''
results_dir =  './results/'

# Specify plotting parameters
Tmin = 200.
Tmax = 1600.

# Specify instrument parameters and site parameters
site= {
        'Abbreviation': 'uao', # arbitrary site code
        'Location':     (40.167, -88.159, 200), # Latitude [deg], Longitude [deg], Altitude [m]
        'Timezone':     'US/Central', # This is the computer's time zone. See list:
                                      # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
        'Directions':   {
	            'Zenith': {'ze':   0, 'az': 0,}, 
	            'North':  {'ze':  45, 'az': 0,}, 
	            'South':  {'ze': -45, 'az': 0,}, 
	            'East':   {'ze':  45, 'az': 90,}, 
	            'West':   {'ze': -45, 'az': 90,},
                },
    }

instrument = {
        'name'          : 'minime05',   # arbitrary name for instrument   
        'N'             : 500,          # Number of annuli
        'N0'            : 0,            # First annulus to use
        'N1'            : 500,          # Last annulus to use
        'focal_length'  : 300e-3,       # focal length of lens in m
        'pix_size'      : 13e-6,        # pixel size on CCD in m
        'lam_laser'     : 632.8e-9,     # laser wavelength in m
        'lam0'          : 630.0e-9,     # nominal line center wavelength in m
        'nominal_t'     : 1.5e-2,       # approximate etalon gap in m
        'many_fringes'  : True,         # indicates whether radial falloff terms should be used
        'skyI_quality_thresh': [0.0,0.0],  # The brightness [counts/sec] below which we raise the quality flag
    }

# Search the data directory for sub directories
dirs = os.listdir(data_dir)
for d in dirs:
    ddir = data_dir + d + '/' # full path to subfolder    
    print 'Running %s' % ddir

    try:
        # Make the call to the processing function
        msg = FPIprocess.process_directory(ddir, results_dir, instrument, site, reference='laser', Tmin=Tmin, Tmax=Tmax, 
                                   bw_cloud_file_1=bw_cloud_file_1, bw_cloud_file_2=bw_cloud_file_2)
    except Exception as e:
        print 'Folder failed: %s' % e
        continue

    if msg: # if a warning was issued, print it
    	print msg
