try: os.remove(r"test_outputs/composite_test.tif") except FileNotFoundError: pass test_data = [ r"test_data/20180103T172709.tif", r"test_data/20180319T172021.tif", r"test_data/20180329T171921.tif" ] out_file = r"test_outputs/composite_test.tif" pyeo.composite_images_with_mask(test_data, out_file) def test_ml_masking(): os.chdir(os.path.dirname(os.path.abspath(__file__))) pyeo.create_mask_from_model( r"test_data/20180103T172709.tif", r"test_data/cloud_model_v0.1.pkl", ) shutil.copy(r"test_data/20180103T172709.msk", r"test_outputs/model_mask.tif") if __name__ == "__main__": print(sys.path) os.chdir(os.path.dirname(os.path.abspath(__file__))) log = pyeo.init_log("test_log.log") pyeo.create_model_from_signatures( r"test_data/cloud_training_outlier_removal.csv", r"test_data/cloud_model_v0.1.pkl") test_ml_masking()
conf.read(args.config_path) sen_user = conf['sent_2']['user'] sen_pass = conf['sent_2']['pass'] project_root = conf['forest_sentinel']['root_dir'] aoi_path = conf['forest_sentinel']['aoi_path'] start_date = conf['forest_sentinel']['start_date'] end_date = conf['forest_sentinel']['end_date'] log_path = conf['forest_sentinel']['log_path'] cloud_cover = conf['forest_sentinel']['cloud_cover'] cloud_certainty_threshold = int( conf['forest_sentinel']['cloud_certainty_threshold']) model_path = conf['forest_sentinel']['model'] sen2cor_path = conf['sen2cor']['path'] pyeo.create_file_structure(project_root) log = pyeo.init_log(log_path) l1_image_path = os.path.join(project_root, r"images/L1") l2_image_path = os.path.join(project_root, r"images/L2") planet_image_path = os.path.join(project_root, r"images/planet") merged_image_path = os.path.join(project_root, r"images/merged") stacked_image_path = os.path.join(project_root, r"images/stacked") catagorised_image_path = os.path.join(project_root, r"output/categories") probability_image_path = os.path.join(project_root, r"output/probabilities") # Query and download if args.do_download or do_all: products = pyeo.check_for_s2_data_by_date(aoi_path, start_date, end_date, conf) log.info("Downloading")
if __name__ == "__main__": # Reading in config file parser = argparse.ArgumentParser( description='Compare old_image with new_image using model') parser.add_argument("old_image") parser.add_argument("new_image") parser.add_argument("model") parser.add_argument("output") parser.add_argument("-l", "--log_path", default=os.path.join(os.getcwd(), "comparison.log")) parser.add_argument("-c", "--chunks", default=16) parser.add_argument("-m", "--mask", action="store_true") args = parser.parse_args() log = pyeo.init_log(args.log_path) with TemporaryDirectory() as td: stacked_path = os.path.join(td, "stacked.tif") pyeo.stack_images([args.old_image, args.new_image], stacked_path, geometry_mode="intersect") pyeo.classify_image(stacked_path, args.model, args.output, prob_out_path=None, num_chunks=args.chunks, apply_mask=args.mask)
def setup_module(): os.chdir(os.path.dirname(os.path.abspath(__file__))) pyeo.init_log("test_log.log")
dest='config_path', action='store', default=r'model_creation.ini', help="Path to the .ini file specifying the job.") args = parser.parse_args() conf = configparser.ConfigParser() conf.read(args.config_path) training_shape_path = conf["pyeo"]["shapefile"] training_raster_path = conf["pyeo"]["raster"] model_out_path = conf["pyeo"]["model"] class_field = conf["pyeo"]["class_field"] log_path = conf["pyeo"]["log_path"] log = pc.init_log(log_path) # This will be changed in the near future as I'm planning to refactor core soon # to make the ML model building functions more granular learning_data, classes = pc.get_training_data(training_shape_path, training_raster_path, class_field) model = ens.ExtraTreesClassifier(bootstrap=False, criterion="gini", max_features=0.55, min_samples_leaf=2, min_samples_split=16, n_estimators=100, n_jobs=4, class_weight='balanced') model.fit(learning_data, classes)
import os, sys sys.path.insert( 0, os.path.abspath(os.path.join(__file__, '..', '..', '..', '..'))) import argparse import pyeo.core as pyeo if __name__ == "__main__": parser = argparse.ArgumentParser( description= "Removes any SAFEfile in directory without the 2,3,4 or 8m imagery" "in the 10m folder") parser.add_argument("l2_dir", help="Path to the directory that needs cleaning") parser.add_argument("-d", "--disable_warning", dest="do_warning", action='store_false', default=True, help="If present, do not prompt before removing files") parser.add_argument("-r", "--resolution", dest="resolution", action="store", default="10m", help="Resolution to check (10m, 20m or 60m") args = parser.parse_args() pyeo.init_log("clean_log.log") pyeo.clean_l2_dir(args.l2_dir, args.resolution, args.do_warning)
import sys, os sys.path.insert(0, os.path.abspath(os.path.join(__file__, '..', '..', '..', '..'))) import pyeo.core as pyeo import configparser import argparse if __name__ == "__main__": parser = argparse.ArgumentParser(description='Produces a trained model from a filder containing ' 'rasters and shapefiles') parser.add_argument("region_path", type=str, action='store', help="Path to the folder containing the region data") parser.add_argument("training_class", type=str, action='store', help="Attribute field holding the class to train on") parser.add_argument("out_path", type=str, action="store", help="Path for the output .pkl file") args = parser.parse_args() conf = configparser.ConfigParser() log = pyeo.init_log("model.log") log.info("***MODEL CREATION START***") pyeo.create_model_for_region(args.region_path, args.out_path, args.training_class.rsplit('.')[0]+"_scores.txt", args.training_class) log.info("***MODEL CREATION END***")