Skip to content
This repository was archived by the owner on Mar 6, 2023. It is now read-only.
Open
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
19 changes: 1 addition & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pyproj = "^3"
xgboost = "^1.5.0"
rioxarray = "^0.9"
geopandas = "^0.10"
Equi7Grid = "^0.1.0"
#Equi7Grid = "^0.1.0"
datacube = "^1.8.4"
dask-geopandas = "^v0.1.0a7"
dask = {extras = ["array"], version = "^2022.02.1"}
Expand Down
4 changes: 2 additions & 2 deletions src/openeo_processes/cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def exec_xar(data, output_filepath='out', format='GTiff', options={}, write_prod
first_data_var = data.data_vars[list(data.data_vars.keys())[0]]
data.attrs["crs"] = first_data_var.geobox.crs.to_wkt()

tiles, gridder = get_equi7_tiles(data)


# Renaming the time dimension
if 'time' in data.dims:
Expand All @@ -275,7 +275,7 @@ def exec_xar(data, output_filepath='out', format='GTiff', options={}, write_prod
else:
ext = 'tif'

final_datasets, dataset_filenames = derive_datasets_and_filenames_from_tiles(gridder, times, datasets, tiles, output_filepath, ext)
final_datasets, dataset_filenames = derive_datasets_and_filenames_from_tiles(times,data, datasets, output_filepath, ext)
if (len(final_datasets) == 0) or (len(dataset_filenames) == 0):
raise Exception("No tiles could be derived from given dataset")

Expand Down
35 changes: 27 additions & 8 deletions src/openeo_processes/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
import functools
import os
import re
from datetime import timezone, timedelta, datetime
from typing import Any, Callable, Tuple, List
from datetime import datetime, timedelta, timezone
from typing import Any, Callable, List, Tuple

import dask
import dask.dataframe as dd
import numpy as np
import xarray as xr
import geopandas as gpd
import numpy as np
import rasterio
import xarray as xr

# This is a workaround for this package now requiring gdal, which isn't straightforward to install with pip.
# TODO: Remove this once we've figured out how to properly integrate the gdal dependency for this library
Expand All @@ -22,6 +22,7 @@
except ImportError:
osr = None



def eval_datatype(data):
"""
Expand Down Expand Up @@ -396,8 +397,22 @@ def get_equi7_tiles(data: xr.Dataset):

return tiles, gridder

def derive_datasets_and_filenames_from_tiles(gridder, times: List[str], datasets: List[xr.Dataset],
tiles: List[str], output_filepath: str, ext: str):
def derive_datasets_and_filenames_without_tiles(times: List[str], datasets: List[xr.Dataset],
output_filepath: str, ext: str):
final_datasets = []
dataset_filenames = []

for idx, time in enumerate(times):
dataset = datasets[idx]
file_time = np.datetime_as_string(time)[:19].replace('-', '_').replace(':', '_')
temp_file = output_filepath + '_{}.{}'.format(file_time, ext)
final_datasets.append(dataset)
dataset_filenames.append(temp_file)

return final_datasets, dataset_filenames

def derive_datasets_and_filenames_from_tiles(times: List[str], data, datasets: List[xr.Dataset],
output_filepath: str, ext: str):
"""
A function taking an xarray.Dataset and returning a list of EQUI7 Tiles at the relevant resolution layer along with
an EQUI7Grid object.
Expand All @@ -416,9 +431,13 @@ def derive_datasets_and_filenames_from_tiles(gridder, times: List[str], datasets
list[xarray.Dataset]: The resulting datasets split across the EQUI7 tile grid.
list[str]: The list of filepaths split across the EQUI7 tile grid, corresponding to the list of datasets.
"""
if equi7grid is None:
return derive_datasets_and_filenames_without_tiles(times, datasets, output_filepath, ext)

final_datasets = []
dataset_filenames = []


tiles, gridder = get_equi7_tiles(data)
for idx, time in enumerate(times):
dataset = datasets[idx]
file_time = np.datetime_as_string(time)[:19].replace('-', '_').replace(':', '_')
Expand Down