Skip to content

Commit 18cbb82

Browse files
Merge branch 'main' of https://github.com/geo-engine/geoengine-python into pydantic-2
2 parents 8da1228 + b35bad6 commit 18cbb82

File tree

6 files changed

+53
-26
lines changed

6 files changed

+53
-26
lines changed
File renamed without changes.

examples/data_usage.ipynb

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,33 @@
2929
"cell_type": "markdown",
3030
"metadata": {},
3131
"source": [
32-
"## Connect to the Virtual Data Trustee"
32+
"## Note\n",
33+
"\n",
34+
"1. It is important that the Geo Engine is running with\n",
35+
"```toml\n",
36+
"[quota]\n",
37+
"mode = \"track\"\n",
38+
"```\n",
39+
"\n",
40+
"2. You have to do some work beforehand to get the data from the log.\n",
41+
"\n",
42+
"This is a simple example to show how to access the log."
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"metadata": {},
48+
"source": [
49+
"## Connect to Geo Engine"
3350
]
3451
},
3552
{
3653
"cell_type": "code",
37-
"execution_count": 2,
54+
"execution_count": null,
3855
"metadata": {},
3956
"outputs": [],
4057
"source": [
41-
"ge.initialize(\"http://localhost:3030/api\", (\"admin@localhost\", \"adminadmin\")) # TODO: load from .env for demo TODO: set remote url"
58+
"ge.initialize(\"http://localhost:3030/api\", (\"admin@localhost\", \"adminadmin\"))"
4259
]
4360
},
4461
{
@@ -296,7 +313,7 @@
296313
},
297314
{
298315
"cell_type": "code",
299-
"execution_count": 5,
316+
"execution_count": null,
300317
"metadata": {},
301318
"outputs": [
302319
{
@@ -312,6 +329,9 @@
312329
],
313330
"source": [
314331
"df = ge.data_usage_summary(ge.UsageSummaryGranularity.MINUTES)\n",
332+
"if df.empty:\n",
333+
" print('No data usage found')\n",
334+
" exit()\n",
315335
"df['timestamp'] = pd.to_datetime(df['timestamp']).dt.tz_localize(None)\n",
316336
"\n",
317337
"pivot_df = df.pivot(index='timestamp', columns='data', values='count').fillna(0)\n",
@@ -324,13 +344,6 @@
324344
"plt.legend(title='Data')\n",
325345
"plt.show()"
326346
]
327-
},
328-
{
329-
"cell_type": "code",
330-
"execution_count": null,
331-
"metadata": {},
332-
"outputs": [],
333-
"source": []
334347
}
335348
],
336349
"metadata": {

examples/plots.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
},
1111
{
1212
"cell_type": "code",
13-
"execution_count": 1,
13+
"execution_count": null,
1414
"metadata": {},
1515
"outputs": [],
1616
"source": [
1717
"from datetime import datetime\n",
18+
"from IPython.display import display\n",
1819
"\n",
1920
"import geoengine as ge"
2021
]

geoengine/raster.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ def spatial_partition(self) -> gety.SpatialPartition2D:
213213
def spatial_resolution(self) -> gety.SpatialResolution:
214214
return self.geo_transform.spatial_resolution()
215215

216+
def is_empty(self) -> bool:
217+
''' Returns true if the tile is empty'''
218+
num_pixels = self.size_x * self.size_y
219+
num_nulls = self.data.null_count
220+
return num_pixels == num_nulls
221+
216222
@staticmethod
217223
def from_ge_record_batch(record_batch: pa.RecordBatch) -> RasterTile2D:
218224
'''Create a RasterTile2D from an Arrow record batch recieved from the Geo Engine'''

geoengine/raster_workflow_rio_writer.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,37 @@ def __create_new_dataset(self, query: QueryRectangle):
168168
**self.rio_kwargs
169169
)
170170

171+
for i, b in enumerate(self.bands, start=1):
172+
b_n = b.name
173+
b_m = str(b.measurement)
174+
rio_dataset.update_tags(i, band_name=b_n, band_measurement=b_m)
175+
171176
self.current_dataset = rio_dataset
172177

173-
async def query_and_write(self, query: QueryRectangle):
174-
''' Query the raster workflow and write the tiles to the dataset.'''
178+
async def query_and_write(self, query: QueryRectangle, skip_empty_times=True):
179+
'''
180+
Query the raster workflow and write the resulting tiles to a GDAL dataset per timeslice.
181+
182+
:param query: The QueryRectangle to write to GDAL dataset(s)
183+
:param skip_empty_times: Skip timeslices where all pixels are empty/nodata
184+
'''
175185

176186
self.create_tiling_geo_transform_width_height(query)
177187

178-
assert self.workflow is not None, "The workflow must be set"
188+
assert self.bands is not None, "The bands must be set"
189+
bands = list(range(0, len(self.bands)))
179190

191+
assert self.workflow is not None, "The workflow must be set"
180192
try:
181-
async for tile in self.workflow.raster_stream(query):
193+
async for tile in self.workflow.raster_stream(query, bands=bands):
182194
if self.current_time != tile.time:
183195
self.close_current_dataset()
184196
self.current_time = tile.time
197+
198+
if tile.is_empty() and skip_empty_times:
199+
continue
200+
201+
if self.current_dataset is None:
185202
self.__create_new_dataset(query)
186203

187204
assert self.current_time == tile.time, "The time of the current dataset does not match the tile"

test_all_notebooks.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
import shutil
88
import sys
99

10-
# TODO: fix the blacklisted notebooks
11-
BLACKLIST = [
12-
'copernicus_dataspace.ipynb',
13-
'data_usage.ipynb',
14-
'plots.ipynb',
15-
]
16-
1710

1811
def eprint(*args, **kwargs):
1912
'''Print to stderr.'''
@@ -57,9 +50,6 @@ def main() -> int:
5750
if not file.endswith('.ipynb'):
5851
eprint(f"Skipping non-notebook file {file}")
5952
continue
60-
if file in BLACKLIST:
61-
eprint(f"Skipping blacklisted notebook {file}")
62-
continue
6353
notebook_path = os.path.join(root, file)
6454
if not run_test_notebook(notebook_path):
6555
return -1

0 commit comments

Comments
 (0)