{"id":26820434,"url":"https://github.com/zvdy/sentinel-2_l2a_pyapi","last_synced_at":"2025-03-30T06:32:22.982Z","repository":{"id":201062527,"uuid":"706870921","full_name":"zvdy/Sentinel-2_L2A_pyAPI","owner":"zvdy","description":"Python REST API that exposes two endpoints that interact with Sentinel-2 satellite images. ","archived":false,"fork":false,"pushed_at":"2023-10-22T17:21:47.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-10-22T18:24:47.792Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/zvdy/py-backend","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zvdy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-18T19:24:16.000Z","updated_at":"2023-10-19T13:22:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"de8cc381-1425-4104-9e7d-03bdb6dad33e","html_url":"https://github.com/zvdy/Sentinel-2_L2A_pyAPI","commit_stats":null,"previous_names":["zvdy/sentinel-2_l2a_pyapi"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2FSentinel-2_L2A_pyAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2FSentinel-2_L2A_pyAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2FSentinel-2_L2A_pyAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2FSentinel-2_L2A_pyAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zvdy","download_url":"https://codeload.github.com/zvdy/Sentinel-2_L2A_pyAPI/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246285628,"owners_count":20752951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-30T06:32:08.135Z","updated_at":"2025-03-30T06:32:22.975Z","avatar_url":"https://github.com/zvdy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sentinel-2 Image Processing API\n\n## Description\n\nThis is a Python backend that uses FastAPI to expose a REST API. \n\nThe API works with Sentinel-2 satellite images. It has two endpoints: \n\n- `/attributes`: Returns the attributes of the image \n\n    - width: The width of the raster in pixels.\n    - height: The height of the raster in pixels.\n    - bands: The number of bands in the raster. Each band represents a different channel of data, such as red, green, and blue.\n    - crs: The coordinate reference system (CRS) of the raster. The CRS defines how the raster is projected onto the Earth.\n    - bbox: The bounding box of the raster. The bounding box defines the minimum and maximum latitude and longitude values of the raster.\n    - driver: The driver that was used to create the raster file. The driver defines the format of the raster file.\n    - dtype: The data type of the raster image. The data type defines the type of data that is stored in each pixel of the image.\n    - transform: The transform of the raster image. The transform defines how the raster image is georeferenced.\n    - nodata: The nodata value of the raster image. The nodata value defines which pixels are not valid data.\n\n\u003e To retrieve all attributes, you can use the following snippet, which uses the `rasterio` library to read the image and retrieve the metadata _(alternatively, you can use dataset.attr)_: \n\n```python\nimport rasterio\n\nwith rasterio.open(\"S2L2A_2022-06-09.tiff\") as dataset:\n    metadata = dataset.meta\n\nprint(metadata)\n```\n\n- `/thumbnail`: Returns a thumbnail of the image at a given resolution (e.g. 200x200)\n\n\nThe application uses Rasterio to read the image and Pillow to create the thumbnail.\n\n## Installation\n\nThis guide explains how to install and deploy the `Sentinel-2_L2A_pyAPI` application using Docker and Kubernetes.\n\n### Prerequisites\n\nBefore you begin, you'll need the following:\n\n- Docker installed on your machine\n- A Kubernetes cluster (e.g. Minikube) installed on your machine\n- kubectl installed on your machine\n- Python 3.9 or higher installed on your machine\n- pip installed on your machine\n- git installed on your machine\n- Docker hub account (or other Docker registry account)\n\n\n\n### Step 1: Clone the Repository\n\nClone the repository to your local machine:\n\n```bash\ngit clone https://github.com/zvdy/Sentinel-2_L2A_pyAPI.git\ncd Sentinel-2_L2A_pyAPI\n```\n\n\n\n### Step 2: Install the requirements and virtual environment\n\n\n```bash\npython3 -m venv venv \u0026\u0026 source venv/bin/activate \u0026\u0026 pip install -r requirements.txt\n```\n\n\n### Step 3: Build or pull the docker image\n\n```bash\ndocker pull zvdy/py-backend:tag\n``` \n\n### Step 4: Run minikube\n\n```bash\nminikube start\n```\n\n### Step 5: Run the deployment\n\n```bash\nkubectl apply -f kubernetes/deployment.yaml\n```\n\n### Step 6: Run the service\n\n``` bash\nkubectl apply -f kubernetes/service.yaml\n```\n\n### Step 7: Expose the external IP \n\n\u003e Or use nodePort if you don't have a load balancer _(not recommended for production)_\n\n```bash\nminikube tunnel\n```\n\n### Step 8: Check the external IP\n\n```bash\nkubectl get service\n```\n\n### Step 9: Test the deployed app\n\n![image](/img/img.png)\n\n\n## Tests\n\n### /attributes\n\n```bash \ncurl -X POST -F \"image_file=@S2L2A_2022-06-09.tiff\" http://localhost:8000/attributes\n```\n\n\n### /thumbnail\n\n```bash \ncurl -X POST -F \"image_file=@S2L2A_2022-06-09.tiff\" -F \"target_resolution=200\" http://localhost:8000/thumbnail --output output.png\n```\n\n\n## Deployment Manifest\n\nThe project has two yaml files, `deployment.yaml` and `service.yaml`. The `deployment.yaml` file contains the deployment manifest, which defines the deployment of the application. The `service.yaml` file contains the service manifest, which defines the service that exposes the application.\n\n## Scaling\n\nTo scale the application, you can modify the `spec.replicas` field in the deployment manifest. For example, to scale to 3 replicas, you can run the following command:\n\n```\nkubectl scale deployment py-backend --replicas=3\n```\n\n## Monitoring\n\nTo monitor the application, you can use Kubernetes tools such as `kubectl logs` and `kubectl exec`. You can also use external monitoring tools such as Prometheus and Grafana.\n\n## Considerations\n\nWhen deploying the application, consider the following:\n\n- Security: Ensure that the container image is secure and that the Kubernetes cluster is properly secured.\n- High availability: Consider using multiple replicas and configuring Kubernetes to automatically recover from failures.\n- Load balancing: Consider using a load balancer to distribute traffic across multiple replicas.\n- Storage: Consider using persistent volumes to store data that needs to persist across container restarts.\n- Upgrades: Consider using rolling updates to deploy new versions of the container without downtime.\n- Logging: Consider using a logging solution to collect logs from the application.\n\n## References  \n\n- [Kubernetes documentation](https://kubernetes.io/docs/home/)\n- [Rasterio documentation](https://rasterio.readthedocs.io/en/latest/)\n- [Sentinel2](https://docs.sentinel-hub.com/api/latest/data/sentinel-2-l2a/)\n- [FastAPI documentation](https://fastapi.tiangolo.com/)\n- [Docker documentation](https://docs.docker.com/)\n- [Minikube documentation](https://minikube.sigs.k8s.io/docs/)\n- [RGB Composites](https://custom-scripts.sentinel-hub.com/custom-scripts/sentinel-2/composites/)\n- [Convert to RGB](https://stackoverflow.com/questions/56760139/convert-16-bit-tiff-image-to-8-bit-rgb)\n- [Python multipart](https://andrew-d.github.io/python-multipart/)\n- [Numpy](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html)\n- [Pillow](https://pillow.readthedocs.io/en/stable/reference/Image.html)\n- [Uvicorn](https://www.uvicorn.org/)\n\n## License\n\nThis work is licensed under the Creative Commons Attribution-NonCommercial (CC BY-NC) license. \n\nSee [LICENSE](LICENSE) for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzvdy%2Fsentinel-2_l2a_pyapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzvdy%2Fsentinel-2_l2a_pyapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzvdy%2Fsentinel-2_l2a_pyapi/lists"}