Ejemplo n.º 1
0
def test_preprocessing():
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    try:
        shutil.rmtree("test_outputs/L2")
    except FileNotFoundError:
        pass
    conf = load_test_conf()
    pyeo.atmospheric_correction("test_data/L1", "test_outputs/L2",
                                conf['sen2cor']['path'])
    assert os.path.isfile(
        "test_outputs/L2/S2B_MSIL2A_20180103T172709_N0206_R012_T13QFB_20180103T192359.SAFE/GRANULE/L2A_T13QFB_A004328_20180103T172711/IMG_DATA/R10m/T13QFB_20180103T172709_B08_10m.jp2"
    )
    assert os.path.isfile(
        "test_outputs/L2/S2A_MSIL2A_20180329T171921_N0206_R012_T13QFB_20180329T221746.SAFE/GRANULE/L2A_T13QFB_A014452_20180329T173239/IMG_DATA/R10m/T13QFB_20180329T173239_B08_10m.jp2"
    )
Ejemplo n.º 2
0
    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")
        pyeo.download_new_s2_data(products, l1_image_path)

    # Atmospheric correction
    if args.do_preprocess or do_all:
        log.info("Applying sen2cor")
        pyeo.atmospheric_correction(l1_image_path,
                                    l2_image_path,
                                    sen2cor_path,
                                    delete_unprocessed_image=True)

    # Aggregating layers into single image
    if args.do_merge or do_all:
        log.info("Aggregating layers")
        pyeo.aggregate_and_mask_10m_bands(l2_image_path, merged_image_path,
                                          cloud_certainty_threshold)

    # Stack layers
    if args.do_stack or do_all:
        log.info("Stacking before and after images")
        pyeo.create_new_stacks(merged_image_path, stacked_image_path)

    # Classify stacks
    if args.do_classify or do_all:
        start_date = args.start_date
    if args.end_date == "TODAY":
        end_date = dt.date.today().strftime("%Y%m%d")
    elif args.end_date:
        end_date = args.end_date

    # Download and build the initial composite. Does not do by default
    if args.build_composite:
        log.info("Downloading for initial composite between {} and {}".format(
            composite_start_date, composite_end_date))
        composite_products = pyeo.check_for_s2_data_by_date(
            aoi_path, composite_start_date, composite_end_date, conf)
        pyeo.download_new_s2_data(composite_products, composite_l1_image_dir)
        log.info("Preprocessing composite products")
        pyeo.atmospheric_correction(composite_l1_image_dir,
                                    composite_l2_image_dir,
                                    sen2cor_path,
                                    delete_unprocessed_image=True)
        log.info("Aggregating composite layers")
        pyeo.aggregate_and_mask_10m_bands(composite_l2_image_dir,
                                          composite_merged_dir,
                                          cloud_certainty_threshold)
        log.info("Building initial cloud-free composite")
        pyeo.composite_directory(composite_merged_dir, composite_dir)

    # Query and download all images since last composite
    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")
        pyeo.download_new_s2_data(products, l1_image_dir)