示例#1
0
def test_classification():
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    try:
        os.remove("test_outputs/class_20180103T172709_20180319T172021.tif")
    except FileNotFoundError:
        pass
    pyeo.classify_image(
        "test_data/T13QFB_20180103T172709_20180329T171921.tif",
        "test_data/manantlan_v1.pkl",
        "test_outputs/class_T13QFB_20180103T172709_20180319T172021.tif",
        num_chunks=4)
    image = gdal.Open(
        "test_outputs/class_T13QFB_20180103T172709_20180319T172021.tif")
    assert image
    image_array = image.GetVirtualMemArray()
    assert not np.all(image_array == 0)
示例#2
0
def test_classify_change(managed_ml_geotiff_dir):
    test_dir = managed_ml_geotiff_dir
    test_path = os.path.join(test_dir.path, "training_data")
    model = None
    pyeo.classify_image(test_path, model, test_dir.path, test_dir.path)
        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***")
示例#4
0
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)
示例#5
0
            new_stack_path = pyeo.stack_image_with_composite(
                new_image_path, latest_composite_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,
                                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)
            latest_composite_path = new_composite_path

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