Exemple #1
0
def full(event, context):
    """Handle full requests
    """
    logger.info(event)

    bucket = os.environ["OUTPUT_BUCKET"]
    scene = event['scene']
    bands = event.get('bands')
    expression = event.get('expression')
    if event.get('bands'):
        bands = bands.split(',') if isinstance(bands, str) else bands

    mem = cbers_full.create(scene, bands=bands, expression=expression)

    params = {
        'ACL': 'public-read',
        'Metadata': {
            'scene': scene
        },
        'ContentType': 'image/tiff'
    }

    if expression:
        params['Metadata']['expression'] = expression
    else:
        params['Metadata']['bands'] = ''.join(map(str, bands))

    str_band = ''.join(map(str, bands))
    prefix = 'Exp' if expression else 'RGB'
    key = f'data/cbers/{scene}_{prefix}{str_band}.tif'

    client = boto3.client('s3')
    client.upload_fileobj(mem, bucket, key, ExtraArgs=params)

    return {'scene': scene, 'path': f'https://s3.amazonaws.com/{bucket}/{key}'}
Exemple #2
0
def test_create_noExpreBands(monkeypatch):
    """Shoult raise an error on missing expression or band indexes."""
    monkeypatch.setattr(cbers_full, "CBERS_BUCKET", CBERS_BUCKET)
    with pytest.raises(Exception):
        cbers_full.create(CBERS_SCENE)
Exemple #3
0
def test_create_expression(monkeypatch):
    """Should work as expected (read data, create NDVI)."""
    expression = "(b8 - b7) / (b8 + b7)"
    monkeypatch.setattr(cbers_full, "CBERS_BUCKET", CBERS_BUCKET)
    assert cbers_full.create(CBERS_SCENE, expression=expression)
Exemple #4
0
def test_create_lessBand(monkeypatch):
    """Should raise an error."""
    monkeypatch.setattr(cbers_full, "CBERS_BUCKET", CBERS_BUCKET)
    bands = [7, 6]
    with pytest.raises(Exception):
        cbers_full.create(CBERS_SCENE, bands=bands)
Exemple #5
0
def test_create_bands(monkeypatch):
    """Should work as expected (read data, create RGB)."""
    monkeypatch.setattr(cbers_full, "CBERS_BUCKET", CBERS_BUCKET)
    bands = [7, 6, 5]
    assert cbers_full.create(CBERS_SCENE, bands=bands)