clip5imgs = ["/Users/phoetrymaster/Documents/School/Geography/Thesis/Data/MODIS_KANSAS_2007-2012/reprojected/clips/KansasNDVI_2012_clip5.tif", "/Users/phoetrymaster/Documents/School/Geography/Thesis/Data/MODIS_KANSAS_2007-2012/reprojected/clips/KansasEVI_2012_clip5.tif"]
clip6imgs = ["/Users/phoetrymaster/Documents/School/Geography/Thesis/Data/MODIS_KANSAS_2007-2012/reprojected/clips/KansasNDVI_2012_clip6.tif", "/Users/phoetrymaster/Documents/School/Geography/Thesis/Data/MODIS_KANSAS_2007-2012/reprojected/clips/KansasEVI_2012_clip6.tif"]

imagelist = [clip1imgs, clip2imgs, clip3imgs, clip4imgs, clip5imgs, clip6imgs]

searchstrings = ["soy", "corn", "wwheat", "sorghum", "wwheatsoydbl"]
fitmethods = ["SLSQP"]#, "TNC"]


for method in fitmethods:
    for images in imagelist:
        for img in images:
            name = os.path.splitext(os.path.basename(img))[0]
            if "NDVI" in name:
                type = "NDVI"
            else:
                type = "EVI"

            for reffile, outfolder in zip(reffiles, outfolders):

                refs = {}
                for f in reffile:
                    if type in f:
                        for string in searchstrings:
                            if string + "_" + type in f:
                                error, refs[string] = read_reference_file(f)
                if not error:
                    print refs
                    phenological_classificaion(img, outfolder, name + "_" + method, refs, "ENVI", 17, 16, -500, 0, method, toprint=False)
                else:
                    print "ERROR +++++++++++++++++++++++++++++++++++++++++++++++++++ ERROR"
imagelist = []
clip1imgs = ["/Users/phoetrymaster/Documents/School/Geography/Thesis/Data/MODIS_KANSAS_2007-2012/reprojected/clips/KansasNDVI_2012_clip1.tif"]#, "/Users/phoetrymaster/Documents/School/Geography/Thesis/Data/MODIS_KANSAS_2007-2012/reprojected/clips/KansasEVI_2012_clip1.tif"]
imagelist.append(clip1imgs)

searchstrings = ["soy", "corn", "wwheat", "sorghum", "wwheatsoydbl"]
fitmethods = ["SLSQP"]#, "TNC"]

fullpixels = get_px_coords_from_points(clip1imgs[0], "/Users/phoetrymaster/Documents/School/Geography/Thesis/Data/MODIS_KANSAS_2007-2012/reprojected/clips/clip1_fullcells_points.shp")

for method in fitmethods:
    for images in imagelist:
        for img in images:
            name = os.path.splitext(os.path.basename(img))[0]
            if "NDVI" in name:
                type = "NDVI"
            else:
                type = "EVI"

            for reffile, outfolder in zip(reffiles, outfolders):

                refs = {}
                for f in reffile:
                    if type in f:
                        for string in searchstrings:
                            if string + "_" + type in f:
                                error, refs[string] = read_reference_file(f)
                if not error:
                    print refs
                    phenological_classificaion(img, outfolder, name + "_" + method, refs, "ENVI", 17, 16, 1000, 0, method, toprint=False, subset=fullpixels)
                else:
                    print "ERROR +++++++++++++++++++++++++++++++++++++++++++++++++++ ERROR"