Skip to content

Normalized difference

Goal

Create a container and run the norm_diff step in the container image tagged localhost/norm-diff:latest.

Lab

This step has a dedicated lab available at /workspace/mastering-app-package/practice-labs/Containers/norm-diff.ipynb

Container

Each step has its own recipe to build the container image.

The norm_diff step container image recipe is:

norm_diff/Dockerfile
1
2
3
4
5
6
7
8
FROM docker.io/library/python:3.10-slim@sha256:80619a5316afae7045a3c13371b0ee670f39bac46ea1ed35081d2bf91d6c3dbd

RUN pip install --no-cache-dir rasterio click loguru && \
    python -c "import rasterio"

ADD app.py /app/app.py

ENTRYPOINT []

Build the container image with:

terminal
1
2
3
export WORKSPACE=/workspace/mastering-app-package

podman build --format docker -t localhost/norm-diff:latest ${WORKSPACE}/water-bodies/command-line-tools/norm_diff

Run the container

The command to run the norm_diff step in the container is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
podman \
    run \
    -i \
    --userns=keep-id \
    --mount=type=bind,source=/workspace/mastering-app-package/runs,target=/runs \
    --mount=type=bind,source=/workspace/mastering-app-package/runs/crop_green.tif,target=/inputs/crop_green.tif,readonly \
    --mount=type=bind,source=/workspace/mastering-app-package/runs/crop_nir.tif,target=/inputs/crop_nir.tif,readonly \
    --workdir=/runs \
    --read-only=true \
    --user=1001:100 \
    --rm \
    --env=HOME=/runs \
    --env=PYTHONPATH=/app \
    localhost/norm-diff:latest \
    python \
    -m \
    app \
    /inputs/crop_green.tif \
    /inputs/crop_nir.tif

Step

Run the command to run the norm_diff step with:

sh -x ${WORKSPACE}/scripts/podman-norm-diff.sh

Expected outcome

The folder /workspace/mastering-app-package/runs contains:

(base) jovyan@coder-mrossi:~/runs$ tree .
.
├── crop_green.tif
├── crop_nir.tif
└── norm_diff.tif

0 directories, 3 files