Ejemplo n.º 1
0
def extract_chips_from_scene(job):
    scene_dir = job.kwargs['scene_dir']

    from satlomasproc.chips import extract_chips

    rasters = glob(os.path.join(scene_dir, '*.tif'))
    logger.info("Num. rasters: %i", len(rasters))

    chips_dir = os.path.join(CHIPS_DIR, os.path.basename(scene_dir))
    logger.info("Extract chips on images from %s into %s", scene_dir,
                chips_dir)

    # TODO: Generate RGB image
    # TODO: Load RGB image

    # FIXME: Once RGB image is prepared, there is no need to rescale on chips...
    extract_chips(rasters,
                  aoi=AOI_PATH,
                  rescale_mode='values',
                  rescale_range=RESCALE_RANGE,
                  bands=BANDS,
                  type='tif',
                  size=SIZE,
                  step_size=STEP_SIZE,
                  output_dir=chips_dir)

    enqueue_job('eo_sensors.tasks.perusat1.predict_scene',
                chips_dir=chips_dir,
                queue='processing')
Ejemplo n.º 2
0
def pansharpen_scene(job):
    raw_scene_dir = job.kwargs['scene_dir']

    from perusatproc.console.process import process_product

    basename = os.path.basename(raw_scene_dir)
    proc_scene_dir = os.path.join(PROC_DIR, basename)

    logger.info("Process %s into %s", raw_scene_dir, proc_scene_dir)
    process_product(raw_scene_dir, proc_scene_dir)

    logger.info("Delete raw scene directory")
    shutil.rmtree(raw_scene_dir)

    enqueue_job('eo_sensors.tasks.perusat1.extract_chips_from_scene',
                scene_dir=proc_scene_dir,
                queue='processing')
Ejemplo n.º 3
0
    def post(self, request):
        serializer = ImportSFTPSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
        params = serializer.data

        sftp_conn_info = {
            'hostname': params['hostname'],
            'port': params['port'],
            'username': params['username'],
            'password': params['password']
        }

        for file in params['files']:
            enqueue_job('lomas_changes.tasks.perusat1.import_scene_from_sftp',
                        sftp_conn_info=sftp_conn_info,
                        file=file,
                        queue='processing')

        return Response({}, status=status.HTTP_204_NO_CONTENT)
Ejemplo n.º 4
0
def import_scene_from_sftp(job):
    """Connects to an SFTP server and downloads a scene"""

    sftp_conn_info = job.kwargs['sftp_conn_info']
    filepath = job.kwargs['file']

    client = SFTPClient(**sftp_conn_info)
    with tempfile.TemporaryDirectory() as tmpdir:
        basename = os.path.basename(filepath)
        id_s = f"{job.pk}_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
        scene_dir = os.path.join(RAW_DIR, id_s)

        # Download file and extract to RAW_DIR
        dst = os.path.join(tmpdir, basename)
        logger.info("Download %s to %s", filepath, dst)
        client.get(filepath, dst)
        logger.info("Unzip %s into %s", dst, scene_dir)
        unzip(dst, scene_dir)

        enqueue_job('eo_sensors.tasks.perusat1.pansharpen_scene',
                    scene_dir=scene_dir,
                    queue='processing')
Ejemplo n.º 5
0
    def post(self, request):
        serializer = ImportSFTPSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
        params = serializer.data

        sftp_conn_info = {
            "hostname": params["hostname"],
            "port": params["port"],
            "username": params["username"],
            "password": params["password"],
        }

        for file in params["files"]:
            enqueue_job(
                "eo_sensors.tasks.perusat1.import_scene_from_sftp",
                sftp_conn_info=sftp_conn_info,
                file=file,
                queue="processing",
            )

        return Response({}, status=status.HTTP_204_NO_CONTENT)
Ejemplo n.º 6
0
def predict_scene(job):
    chips_dir = job.kwargs['chips_dir']

    from satlomasproc.unet.predict import PredictConfig, predict

    predict_chips_dir = os.path.join(PREDICT_DIR, os.path.basename(chips_dir))
    cfg = PredictConfig(images_path=chips_dir,
                        results_path=predict_chips_dir,
                        batch_size=BATCH_SIZE,
                        model_path=MODEL_PATH,
                        height=SIZE,
                        width=SIZE,
                        n_channels=len(BANDS),
                        n_classes=len(CLASSES))
    logger.info("Predict chips on %s", predict_chips_dir)
    predict(cfg)

    logger.info("Delete chips directory")
    shutil.rmtree(chips_dir)

    enqueue_job('eo_sensors.tasks.perusat1.postprocess_scene',
                predict_chips_dir=predict_chips_dir,
                queue='processing')