Skip to content

Commit

Permalink
add data generator-geospatial-images (#11)
Browse files Browse the repository at this point in the history
* add geospatial-images datagenerator.

* remove poetry.lock files

* removed duplicate readme and updated devcontainer.json path

* removed build steps

---------

Co-authored-by: alianides <[email protected]>
  • Loading branch information
alexlianides and alianides authored Jul 19, 2024
1 parent 1606717 commit 6939437
Show file tree
Hide file tree
Showing 20 changed files with 445 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .devcontainer/geospatial-images-datagenerator/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/dotnet
{
"name": "geospatial-images-datagenerator",
"image": "mcr.microsoft.com/devcontainers/python:1-3.10-bullseye",
"runArgs": [
"--name",
"geospatial-images-datagenerator"
],
"workspaceFolder": "/workspace/geospatial-images-datagenerator",
"workspaceMount": "source=${localWorkspaceFolder}/datagenerators/geospatial-images/datagenerator,target=/workspace/geospatial-images-datagenerator,type=bind,consistency=cached",

"hostRequirements": {
"cpus": 8,
"memory": "8gb"
},
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest"
}
}
},
"remoteUser": "root",
"postStartCommand": "bash /workspace/geospatial-images-datagenerator/devcontainer_postStart.sh"
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,7 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

# poetry lock files

*/poetry.lock
3 changes: 3 additions & 0 deletions datagenerators/geospatial-images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Geospatial Images

TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARG PYTHON_CONTAINER_VARIANT="3.10-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${PYTHON_CONTAINER_VARIANT}

ARG SERVICE_NAME="datagenerator-geospatial-images"
ENV SERVICE_NAME=$SERVICE_NAME
ENV PYTHONUNBUFFERED 1

WORKDIR /workspace/${SERVICE_NAME}

# GDAL needed for rasterio
RUN apt-get update \
&& apt-get -y install libgdal-dev \
&& rm -rf /var/lib/apt/lists/*

COPY ./src /workspace/${SERVICE_NAME}/src
COPY ./data /workspace/${SERVICE_NAME}/data
COPY ./config /workspace/${SERVICE_NAME}/config
COPY ./pyproject.toml /workspace/${SERVICE_NAME}
COPY ./README.md /workspace/${SERVICE_NAME}/README.md

RUN pip3 install .

ENTRYPOINT ["python3", "src/image_provider/main.py"]
76 changes: 76 additions & 0 deletions datagenerators/geospatial-images/datagenerator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Geospatial Images

This repository provides a simple data generator that, given a location expressed as `[lat, lon]`, returns the first requested file type (image, geotiff) in the `data` directory that contains that location or returns an `HTTP 400` response is returned if no such file is found.

## Configuration

Configurable values for the Geospatial Images may be viewed and edited in `config/config.ini` as needed

~~~~
[GEOSPATIAL_IMAGES]
PORT (Integer) The port that will be used to host the service
~~~~

## Installation

### Devcontainer Setup

1. Re-open this repository within the provided devcontainer.

## Execution

1. execute the image-provider via:
```python3 ./src/datagenerator_geospatial_images/main.py```


1. request a geotiff for a desired lat/long via:
http://127.0.0.1:8080/get_geotiff?lat=47.6062&lon=-122.3321

This can be done in a terminal via:
```curl "http://127.0.0.1:8080/get_geotiff?lat=47.6062&lon=-122.3321" --output output.tif```

Note that your port may vary depending upon the `PORT` value specified in `config/config.ini`


1. request a image for a desired lat/long via:
http://127.0.0.1:8080/get_image?lat=47.6062&lon=-122.3321

This can be done in a terminal via:
```curl "http://127.0.0.1:8080/get_image?lat=47.6062&lon=-122.3321" --output output.jpg```

Note that your port may vary depending upon the `PORT` value specified in `config/config.ini`


## Inputting your own Data

### Geotiffs

Place your tif/tiff files within `data/geotiffs`.

### Images

Place your data files within `data/images`. Each file should be accomponied by a equivalent named json file formatted as such:
```json
{
"datafile": "Filename for image file",
"crs": "Define the Coordinate Reference System (CRS) the bbox values are listed in",
"bbox": {
"left", "right", "bottom", "top" bounding box coordinates from the above defined CRS
}
}

```
if you are unfamilar with what `crs` and `bbox` your image utilizes, go ahead copy the bottom provided code and you will be able to query the image with the following query to `datagenerator-geospatial-images`: ```curl "http://127.0.0.1:8080/get_image?lat=47.6062&lon=-122.3321"```

```json
{
"datafile": <filename in data/images>,
"crs": "EPSG:32610",
"bbox": {
"left": 471285.0,
"right": 704415.0,
"bottom": 5136885.0,
"top": 5373315.0
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[IMAGE_PROVIDER]
PORT = 8080
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"datafile": "LC08_L1TP_046027_20220728_20220728_02_RT_refl.jpg",
"crs": "EPSG:32610",
"bbox": {
"left": 471285.0,
"right": 704415.0,
"bottom": 5136885.0,
"top": 5373315.0
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"datafile": "LC08_L1TP_047027_20220719_20220725_02_T1_refl",
"crs": "EPSG:32610",
"bbox": {
"left": 354585.0,
"right": 590715.0,
"bottom": 5135085.0,
"top": 5374215.0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash
#
# Runs after the container is started to finish configuration from within the container
#
#
#
# Example Usage:
#
# bash ./.devcontainer/devcontainer_postStart.sh -d geospatial-images-datagenerator

# Script Flags
SCRIPT_NAME=$(basename "$0")
DEBUG_APP_NAME=""

############################################################
# Help #
############################################################
show_help() {
# Display Help
echo "Post start script to finalize configuration for data-generator"
echo
echo "Syntax: bash .devcontainer/devcontainer_postStart.sh --debug_app_name geospatial-images-datagenerator"
echo "options:"
echo "--debug_app_name | -d [REQUIRED] name of the app from the devcontainer.json"

echo
exit 1
}

############################################################
# Process the input options. Add options as needed. #
############################################################
# Get the options

echo "START: processing parameters"
while [[ "$#" -gt 0 ]]; do
case $1 in
-h | --help) show_help ;;
-d | --debug_app_name)
shift
DEBUG_APP_NAM=$1
;;
*)
echo "Unknown parameter passed: $1"
show_help
;;
esac
shift
done

install_poetry() {
echo "START: ${FUNCNAME[0]}"
curl -sSL https://install.python-poetry.org | POETRY_HOME=/root/.local python3 -
chmod +x /root/.local/bin/poetry
echo "END: ${FUNCNAME[0]}"
}

install_package() {
echo "START: ${FUNCNAME[0]}"
/root/.local/bin/poetry config virtualenvs.create false
rm -f -- /workspace/${DEBUG_APP_NAME}/poetry.lock
/root/.local/bin/poetry install --with dev
rm -f -- /workspace/${DEBUG_APP_NAME}/poetry.lock
echo "END: ${FUNCNAME[0]}"
}

clean_up() {
echo "START: ${FUNCNAME[0]}"
echo "rm -rf /workspace/${DEBUG_APP_NAME}/.devcontainer/tmp"
rm -rf /workspace/${DEBUG_APP_NAME}/.devcontainer/tmp
echo "END: ${FUNCNAME[0]}"
}

main() {
echo "START: ${SCRIPT_NAME}"
echo "------------------------------------------"
install_poetry
install_package
clean_up
mkdir /workspace/${DEBUG_APP_NAME}/output
echo "------------------------------------------"
echo "END: ${SCRIPT_NAME}"
}

main
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
apiVersion: v1
kind: Service
metadata:
name: datagenerator-geospatial-images
namespace: platformsvc
spec:
type: ClusterIP
ports:
- port: 8080
targetPort: 8080
selector:
app: datagenerator-geospatial-images
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: datagenerator-geospatial-images
namespace: platformsvc
labels:
app: datagenerator-geospatial-images
spec:
replicas: 1
selector:
matchLabels:
app: datagenerator-geospatial-images
template:
metadata:
labels:
app: datagenerator-geospatial-images
annotations:
spec:
containers:
- name: datagenerator-geospatial-images
image: registry.spacefx.local:5000/datagenerator-geospatial-images:0.11.0-nightly
imagePullPolicy: IfNotPresent
resources:
limits:
memory: 7Gi
requests:
memory: 50Mi
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions datagenerators/geospatial-images/datagenerator/poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
create = false
35 changes: 35 additions & 0 deletions datagenerators/geospatial-images/datagenerator/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[tool.poetry]
name = "datagenerator-geospatial-images"
description = "..."
authors = [ "Azure Space SDK" ]
version = "0.10.0"
readme = "README.md"
packages = [
{ include = "datagenerator_geospatial_images", from = "src" },
]

[tool.poetry.scripts]
datagenerator-geospatial-images = 'datagenerator_geospatial_images.main:main'

[tool.poetry.dependencies]
python = "^3.8"
flask = "^2.2.2"
rasterio = "1.3.3"
waitress = "^2.1.2"
pyproj = "^3.5.0"
grpcio-tools = "^1.26.0"
grpcio = "^1.26.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.1"

[build-system]
requires = ["poetry>=1.3.2"]
build-backend = "poetry.masonry.api"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q"
testpaths = [
"test",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import configparser


config = configparser.ConfigParser()
config.read('/workspace/geospatial-images-datagenerator/config/config.ini')

PORT = int(config['IMAGE_PROVIDER']['PORT']) # required
Loading

0 comments on commit 6939437

Please sign in to comment.