Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

jobs:
check:
uses: geo-engine/geoengine-python/.github/workflows/test-python.yml@main
uses: geo-engine/geoengine-python/.github/workflows/test-python.yml@ruff

strategy:
fail-fast: false
Expand All @@ -28,7 +28,7 @@ jobs:
# Checks the library using minimum version resolution
# `uv` has this feature built-in, c.f. https://github.com/astral-sh/uv
check-min-version:
uses: geo-engine/geoengine-python/.github/workflows/test-python.yml@main
uses: geo-engine/geoengine-python/.github/workflows/test-python.yml@ruff

with:
python-version: "3.10"
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ on:
use-uv:
type: boolean
default: false
description: 'Use `uv` for minimum version resolution'
description: "Use `uv` for minimum version resolution"
coverage:
type: boolean
default: false
description: 'Generate coverage report'
description: "Generate coverage report"

jobs:
check:
Expand Down Expand Up @@ -70,11 +70,11 @@ jobs:
- name: Check Formatting
run: |
${{ steps.vars.outputs.VENV_CALL }}
python -m pycodestyle
python -m ruff format --check
- name: Lint code
run: |
${{ steps.vars.outputs.VENV_CALL }}
python -m pylint geoengine
python3 -m ruff check
- name: Type-check code
# mypy seems buggy with uv
if: ${{ !inputs.use-uv }}
Expand All @@ -89,10 +89,6 @@ jobs:
run: |
${{ steps.vars.outputs.VENV_CALL }}
${{ steps.vars.outputs.PIP_INSTALL }} -e .[test]
- name: Lint tests
run: |
${{ steps.vars.outputs.VENV_CALL }}
python -m pylint tests
- name: Type-check tests
# mypy seems buggy with uv
if: ${{ !inputs.use-uv }}
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,30 @@ python3 -m build

## Formatting

This package is formatted according to `pycodestyle`.
This package is formatted according to `ruff`.
You can check it by calling:

```bash
python3 -m pycodestyle
python3 -m ruff format --check
```

Our tip is to install `autopep8` and use it to format the code.
Our tip is to install `ruff` and use it to format the code.

### VSCode

If you use VSCode, you can install the [ruff extension](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) and set it as the default formatter.

## Lints

Our CI automatically checks for lint errors.
We use `pylint` to check the code.
We use `ruff` to check the code.
You can check it by calling:

```bash
python3 -m pylint geoengine
python3 -m pylint tests
python3 -m ruff check
```

Our tip is to activate linting with `pylint` in your IDE.
Our tip is to activate linting with `ruff` in your IDE.

## Type Checking

Expand Down
5 changes: 2 additions & 3 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ function echoerr() {

echoerr "Check code style"

python3 -m pycodestyle
python3 -m ruff format --check

echoerr "Check code with linter"

python3 -m pylint geoengine
python3 -m pylint tests
python3 -m ruff check

echoerr "Check code with type checker"

Expand Down
106 changes: 56 additions & 50 deletions examples/add_public_raster_dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
"metadata": {},
"outputs": [],
"source": [
"import geoengine as ge\n",
"import geoengine_openapi_client\n",
"from datetime import datetime\n",
"\n",
"import geoengine_openapi_client\n",
"\n",
"import geoengine as ge\n",
"from geoengine.types import RasterBandDescriptor"
]
},
Expand Down Expand Up @@ -110,19 +112,21 @@
"\n",
"file_not_found_handling = geoengine_openapi_client.FileNotFoundHandling.NODATA\n",
"\n",
"gdal_params = geoengine_openapi_client.GdalDatasetParameters.from_dict({\n",
" \"filePath\": file_path,\n",
" \"rasterbandChannel\": rasterband_channel,\n",
" \"geoTransform\": geo_transform.to_api_dict(),\n",
" \"width\": width,\n",
" \"height\": height,\n",
" \"fileNotFoundHandling\": file_not_found_handling,\n",
" \"noDataValue\": None,\n",
" \"propertiesMapping\": None,\n",
" \"gdalOpenOptions\": None,\n",
" \"gdalConfigOptions\": None,\n",
" \"allowAlphabandAsMask\": True\n",
"})\n",
"gdal_params = geoengine_openapi_client.GdalDatasetParameters.from_dict(\n",
" {\n",
" \"filePath\": file_path,\n",
" \"rasterbandChannel\": rasterband_channel,\n",
" \"geoTransform\": geo_transform.to_api_dict(),\n",
" \"width\": width,\n",
" \"height\": height,\n",
" \"fileNotFoundHandling\": file_not_found_handling,\n",
" \"noDataValue\": None,\n",
" \"propertiesMapping\": None,\n",
" \"gdalOpenOptions\": None,\n",
" \"gdalConfigOptions\": None,\n",
" \"allowAlphabandAsMask\": True,\n",
" }\n",
")\n",
"\n",
"result_descriptor_measurement = ge.ClassificationMeasurement(\n",
" measurement=\"Land Cover\",\n",
Expand All @@ -143,9 +147,8 @@
" \"13\": \"Urban and Built-Up\",\n",
" \"14\": \"Cropland-Natural Vegetation Mosaics\",\n",
" \"15\": \"Snow and Ice\",\n",
" \"16\": \"Barren or Sparsely Vegetated\"\n",
" }\n",
"\n",
" \"16\": \"Barren or Sparsely Vegetated\",\n",
" },\n",
")\n",
"\n",
"\n",
Expand All @@ -154,22 +157,24 @@
" [RasterBandDescriptor(\"band\", result_descriptor_measurement)],\n",
" \"EPSG:4326\",\n",
" spatial_bounds=ge.SpatialPartition2D(-180.0, -90.0, 180.0, 90.0),\n",
" spatial_resolution=ge.SpatialResolution(0.1, 0.1)\n",
" spatial_resolution=ge.SpatialResolution(0.1, 0.1),\n",
")\n",
"\n",
"meta_data = geoengine_openapi_client.GdalMetaDataStatic.from_dict({\n",
" \"type\": \"GdalStatic\",\n",
" \"time\": None,\n",
" \"params\": gdal_params,\n",
" \"resultDescriptor\": result_descriptor.to_api_dict().to_dict(),\n",
"})\n",
"meta_data = geoengine_openapi_client.GdalMetaDataStatic.from_dict(\n",
" {\n",
" \"type\": \"GdalStatic\",\n",
" \"time\": None,\n",
" \"params\": gdal_params,\n",
" \"resultDescriptor\": result_descriptor.to_api_dict().to_dict(),\n",
" }\n",
")\n",
"\n",
"meta_data"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -197,21 +202,21 @@
" breakpoints=[\n",
" ge.ColorBreakpoint(value=0, color=(0, 0, 255, 255)),\n",
" ge.ColorBreakpoint(value=8, color=(0, 255, 0, 255)),\n",
" ge.ColorBreakpoint(value=16, color=(255, 0, 0, 255))\n",
" ge.ColorBreakpoint(value=16, color=(255, 0, 0, 255)),\n",
" ],\n",
" no_data_color=(0, 0, 0, 0),\n",
" over_color=(0, 0, 0, 0),\n",
" under_color=(0, 0, 0, 0)\n",
" )\n",
" )\n",
" under_color=(0, 0, 0, 0),\n",
" ),\n",
" ),\n",
" ),\n",
" provenance=[ge.Provenance(\n",
" citation=\"The data was obtained from <https://lpdaac.usgs.gov/products/mcd12c1v006>. The layer Majority_Land_Cover_Type_1 was extracted, downscaled and saved as landcover.tif.\",\n",
" uri=\"https://lpdaac.usgs.gov/products/mcd12c1v006/\",\n",
" license=\"All data distributed by the LP DAAC contain no restrictions on the data reuse. (https://lpdaac.usgs.gov/resources/faqs/#am-i-allowed-to-reuse-lp-daac-data).\"\n",
" )],\n",
"\n",
"\n",
" provenance=[\n",
" ge.Provenance(\n",
" citation=\"The data was obtained from <https://lpdaac.usgs.gov/products/mcd12c1v006>. The layer Majority_Land_Cover_Type_1 was extracted, downscaled and saved as landcover.tif.\", # noqa: E501\n",
" uri=\"https://lpdaac.usgs.gov/products/mcd12c1v006/\",\n",
" license=\"All data distributed by the LP DAAC contain no restrictions on the data reuse. (https://lpdaac.usgs.gov/resources/faqs/#am-i-allowed-to-reuse-lp-daac-data).\",\n",
" )\n",
" ],\n",
")\n",
"\n",
"add_dataset_properties.to_api_dict()"
Expand Down Expand Up @@ -280,7 +285,7 @@
}
],
"source": [
"ge.datasets.list_datasets(name_filter='MCD12C1')"
"ge.datasets.list_datasets(name_filter=\"MCD12C1\")"
]
},
{
Expand Down Expand Up @@ -314,15 +319,17 @@
"ge.reset()\n",
"ge.initialize(\"http://localhost:3030/api\")\n",
"\n",
"workflow = ge.register_workflow({\n",
" \"type\": \"Raster\",\n",
" \"operator\": {\n",
" \"type\": \"GdalSource\",\n",
" \"params\": {\n",
" \"data\": \"MCD12C1\",\n",
" }\n",
"workflow = ge.register_workflow(\n",
" {\n",
" \"type\": \"Raster\",\n",
" \"operator\": {\n",
" \"type\": \"GdalSource\",\n",
" \"params\": {\n",
" \"data\": \"MCD12C1\",\n",
" },\n",
" },\n",
" }\n",
"})\n",
")\n",
"\n",
"workflow.get_result_descriptor()"
]
Expand Down Expand Up @@ -370,14 +377,13 @@
}
],
"source": [
"time = datetime.strptime(\n",
" '2014-04-01T12:00:00.000Z', \"%Y-%m-%dT%H:%M:%S.%f%z\")\n",
"time = datetime.strptime(\"2014-04-01T12:00:00.000Z\", \"%Y-%m-%dT%H:%M:%S.%f%z\")\n",
"\n",
"data = workflow.get_xarray(\n",
" ge.QueryRectangle(\n",
" ge.BoundingBox2D(-180.0, -90.0, 180.0, 90.0),\n",
" ge.TimeInterval(time, time),\n",
" resolution=ge.SpatialResolution(360. / 16, 180. / 16),\n",
" resolution=ge.SpatialResolution(360.0 / 16, 180.0 / 16),\n",
" )\n",
")\n",
"\n",
Expand Down Expand Up @@ -439,7 +445,7 @@
" ge.QueryRectangle(\n",
" ge.BoundingBox2D(-180.0, -90.0, 180.0, 90.0),\n",
" ge.TimeInterval(time, time),\n",
" resolution=ge.SpatialResolution(360. / 16, 180. / 16),\n",
" resolution=ge.SpatialResolution(360.0 / 16, 180.0 / 16),\n",
" )\n",
" )\n",
"except Exception as e:\n",
Expand Down
Loading