예제 #1
0
def test_composite_images_with_mask():
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    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)
예제 #2
0
def test_composite_images_with_mask():
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    try:
        os.remove(r"test_outputs/composite_test.tif")
    except FileNotFoundError:
        pass
    test_data = [
        r"test_data/S2A_MSIL2A_20180329T171921_N0206_R012_T13QFB_20180329T221746.tif",
        r"test_data/S2B_MSIL2A_20180103T172709_N0206_R012_T13QFB_20180103T192359.tif"
    ]
    out_file = r"test_outputs/composite_test.tif"
    pyeo.composite_images_with_mask(test_data, out_file)
    image = gdal.Open("test_outputs/composite_test.tif")
    assert image
    image_array = image.GetVirtualMemArray()
    assert image_array.max() > 10
예제 #3
0
def test_composite_across_projections_meters():
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    try:
        os.remove(r"test_outputs/composite_test.tif")
    except FileNotFoundError:
        pass
    try:
        shutil.rmtree(r"test_outputs/reprojected")
    except FileNotFoundError:
        pass
    os.mkdir(r"test_outputs/reprojected")
    epsg = 32736
    proj = osr.SpatialReference()
    proj.ImportFromEPSG(epsg)
    projection = proj.ExportToWkt()  # Refactor this terrible nonsense later

    test_data = [
        r"test_data/S2A_MSIL2A_20180703T073611_N0206_R092_T36MZE_20180703T094637.tif",
        r"test_data/S2B_MSIL2A_20180728T073609_N0206_R092_T37MBV_20180728T114325.tif"
    ]
    pyeo.reproject_image(test_data[0], r"test_outputs/reprojected/0.tif",
                         projection)
    pyeo.reproject_image(test_data[1], r"test_outputs/reprojected/1.tif",
                         projection)
    pyeo.reproject_image(pyeo.get_mask_path(test_data[0]),
                         r"test_outputs/reprojected/0.msk", projection)
    pyeo.reproject_image(pyeo.get_mask_path(test_data[1]),
                         r"test_outputs/reprojected/1.msk", projection)

    out_file = r"test_outputs/composite_test.tif"
    pyeo.composite_images_with_mask(
        [r"test_outputs/reprojected/0.tif", r"test_outputs/reprojected/1.tif"],
        out_file)
    image = gdal.Open("test_outputs/composite_test.tif")
    assert image
    image_array = image.GetVirtualMemArray()
    assert image_array.max() > 1
        if args.do_stack or do_all:
            log.info("Stacking images with composite")
            new_stack_path = pyeo.stack_old_and_new_images(
                latest_composite_path, new_image_path, stacked_image_dir)

        # Classify with composite
        if args.do_classify or do_all:
            log.info("Classifying with composite")
            new_class_image = os.path.join(
                catagorised_image_dir,
                "class_{}".format(os.path.basename(new_stack_path)))
            new_prob_image = os.path.join(
                probability_image_dir,
                "prob_{}".format(os.path.basename(new_stack_path)))
            pyeo.classify_image(new_stack_path,
                                model_path,
                                new_class_image,
                                new_prob_image,
                                num_chunks=10)

        # Update composite
        if args.do_update or do_all:
            log.info("Updating composite")
            new_composite_path = os.path.join(
                composite_dir, "composite_" + os.path.basename(image))
            pyeo.composite_images_with_mask(
                (latest_composite_path, new_image_path), new_composite_path)
            latest_composite_path = new_composite_path

    log.info("***PROCESSING END***")
예제 #5
0
        # Classify with composite
        if args.do_classify or do_all:
            log.info("Classifying with composite")
            new_class_image = os.path.join(
                catagorised_image_dir,
                "class_{}".format(os.path.basename(new_stack_path)))
            new_prob_image = os.path.join(
                probability_image_dir,
                "prob_{}".format(os.path.basename(new_stack_path)))
            pyeo.classify_image(new_stack_path,
                                model_path,
                                new_class_image,
                                new_prob_image,
                                num_chunks=10,
                                skip_existing=True,
                                apply_mask=True)

        # Build new composite
        if args.do_update or do_all:
            log.info("Updating composite")
            new_composite_path = os.path.join(
                composite_dir, "composite_{}.tif".format(
                    pyeo.get_sen_2_image_timestamp(os.path.basename(image))))
            pyeo.composite_images_with_mask(
                (latest_composite_path, new_image_path),
                new_composite_path,
                generate_date_image=True)
            latest_composite_path = new_composite_path

    log.info("***PROCESSING END***")