Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/try to merge irregular grid develop #296

Open
wants to merge 76 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
db21278
add first quadtree construction
mathleur Jan 2, 2024
f9ca22c
remove unnecessary code
mathleur Jan 2, 2024
7fd6cb2
add first quad tree construction in slicer
mathleur Jan 2, 2024
a6b7fe1
start query polygon function
mathleur Jan 3, 2024
96a2467
add polygon slicing
mathleur Jan 4, 2024
19ca294
write all methods for quadtree slicer
mathleur Jan 4, 2024
e2fa53b
quadtree slicer tests
mathleur Jan 5, 2024
33e6e97
clean up
mathleur Jan 5, 2024
5ffd68a
refactor
mathleur Jan 8, 2024
a941be2
finish quad tree extract function
mathleur Jan 8, 2024
badae88
first performance test for quadtree
mathleur Jan 8, 2024
2dda6df
clean up
mathleur Jan 8, 2024
85b9b21
fix MAX number of nodes in QuadTree
mathleur Jan 9, 2024
a69cad0
optimise quadtree slicer to not slice quadrants when the polygon is a…
mathleur Jan 10, 2024
47024c3
clean up
mathleur Jan 10, 2024
b152235
Merge branch 'develop' of github.com:ecmwf/polytope into feature/quad…
mathleur Jan 10, 2024
b860b0d
pull develop and fix tests
mathleur Jan 10, 2024
c2e9df5
add index in quad node
mathleur Jan 10, 2024
97cabac
add index in quadtree construction from point cloud
mathleur Jan 10, 2024
5fedb73
extract in quadtree slicer using point indices instead of lat/lon
mathleur Jan 10, 2024
811e5f9
reformat
mathleur Jan 10, 2024
b571028
start creating a higher-level extract function to allow for different…
mathleur Jan 15, 2024
7ce4957
add higher level extract inside the Polytope class
mathleur Jan 15, 2024
dcc7399
make new polytope class extract work with old tests
mathleur Jan 16, 2024
be4ebdb
add find_point_cloud to xarray datacube
mathleur Jan 16, 2024
d33fa74
quadtree slicer create lat/lon in index tree and stashes the point in…
mathleur Jan 17, 2024
e967f1a
merge mappings on separate files branch
mathleur Jan 17, 2024
c356e70
add irregular grid mapper support for xarray backend
mathleur Jan 17, 2024
a959b71
make first test with irregular grid for xarray backend work
mathleur Jan 19, 2024
d0dd2e0
make irregular grid work with fdb backend
mathleur Jan 22, 2024
8ba1cbf
fix polytope extract test with xarray backend and irregular mapper
mathleur Jan 23, 2024
a261ea5
fix polytope extract test with xarray backend and irregular mapper
mathleur Jan 23, 2024
8b76621
pull develop
mathleur Jan 25, 2024
be3e74b
fix edge case
mathleur Feb 22, 2024
e4334c9
fix edge cases tests
mathleur Feb 22, 2024
0acb8dc
merge with develop
mathleur Feb 23, 2024
10886c7
clean up
mathleur Feb 23, 2024
b0c20bd
fix flake8
mathleur Feb 23, 2024
4d49503
mark tests using gribjump
mathleur Feb 23, 2024
ccd4498
fix missing gribjump tests
mathleur Feb 23, 2024
04a8a74
fix missing gribjump tests
mathleur Feb 23, 2024
9fb93c9
remove unnecessary file
mathleur Mar 15, 2024
d201087
add ORCA grid example
mathleur Mar 20, 2024
bc9596a
merge develop
mathleur Mar 20, 2024
74702c7
Merge pull request #120 from ecmwf/feature/irregular_grid_merged_develop
mathleur Mar 20, 2024
12b0eba
black and isort
mathleur Mar 20, 2024
85e1741
timings for irregular grid
mathleur Mar 21, 2024
29a4c7e
update gitignore
mathleur Jul 15, 2024
3043dc2
merge irregular grid branch WIP
mathleur Jul 16, 2024
ff33e31
fix non-irregular grid tests
mathleur Jul 16, 2024
cab5ed1
WIP make irregular grid work
mathleur Jul 17, 2024
2a72dc5
fix irregular grid
mathleur Jul 17, 2024
d36e2a2
small optimisation
mathleur Jul 17, 2024
cdc13fa
optimise quad tree construction
mathleur Jul 17, 2024
6046cd9
optimise quad tree
mathleur Jul 17, 2024
f7981d1
fix tests back
mathleur Jul 17, 2024
9425e73
optimise quad tree
mathleur Jul 17, 2024
0558ac8
optimise
mathleur Jul 17, 2024
0f337f6
clean up quad tree
mathleur Jul 17, 2024
c590e85
optimise quad tree
mathleur Jul 18, 2024
a2028e7
optimise and clean up
mathleur Jul 18, 2024
809d788
clean up
mathleur Jul 18, 2024
98b618d
clean up
mathleur Jul 18, 2024
4b99770
optimise more
mathleur Jul 18, 2024
fa70c55
clena up
mathleur Jul 18, 2024
142fd3f
rename module
mathleur Dec 19, 2024
ac86716
merge develop and fix errors
mathleur Dec 31, 2024
0717920
finish fixing all errors
mathleur Jan 2, 2025
db6dd32
clean up
mathleur Jan 2, 2025
e5a5de7
clean up
mathleur Jan 2, 2025
840cc68
Merge branch 'develop' of github.com:ecmwf/polytope into feature/irre…
mathleur Jan 2, 2025
6f8a0d7
fix flake8
mathleur Jan 2, 2025
a984b64
Merge pull request #297 from ecmwf/feature/irregular_grid_w_new_develop
mathleur Jan 2, 2025
169af74
add other unstructured grid example
mathleur Jan 10, 2025
af6fb90
Merge branch 'feature/try_to_merge_irregular_grid_develop' of github.…
mathleur Jan 10, 2025
4225e94
try to add icon grid example
mathleur Jan 10, 2025
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
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ site
*.grib
*.gif
*.html
*.req
.mypy_cache
example_eo
example_mri
.mypy_cache
*.req
polytope_python.egg-info
new_test_venv_polytope
new_venv_polytope
Expand All @@ -26,3 +26,9 @@ new_updated_numpy_venv
newest-polytope-venv
serializedTree
new_polytope_venv

newest-polytope-venv
*.pstats
*.profile
new_polytope_venv
*.json
6 changes: 3 additions & 3 deletions examples/3D_shipping_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import numpy as np
from earthkit import data

from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Ellipsoid, Path, Select
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Ellipsoid, Path, Select


class Test:
Expand Down
8 changes: 4 additions & 4 deletions examples/3D_shipping_route_wave_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import pytest
from eccodes import codes_grib_find_nearest, codes_grib_new_from_file

from polytope.datacube.backends.fdb import FDBDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Ellipsoid, Path, Select
from polytope_feature.datacube.backends.fdb import FDBDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Ellipsoid, Path, Select
from tests.helper_functions import download_test_data


Expand Down
8 changes: 4 additions & 4 deletions examples/4D_flight_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from earthkit import data
from PIL import Image

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Box, Path, Select
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Box, Path, Select


class Test:
Expand Down
8 changes: 4 additions & 4 deletions examples/country_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from earthkit import data
from shapely.geometry import shape

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Polygon, Select, Union
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Polygon, Select, Union


class Test:
Expand Down
8 changes: 4 additions & 4 deletions examples/cyclic_route_around_earth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np
from earthkit import data

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Box, PathSegment, Select
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Box, PathSegment, Select


class Test:
Expand Down
8 changes: 4 additions & 4 deletions examples/healpix_grid_box_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from earthkit import data
from eccodes import codes_grib_find_nearest, codes_grib_new_from_file

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Box, Select
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Box, Select


class TestOctahedralGrid:
Expand Down
8 changes: 4 additions & 4 deletions examples/octahedral_grid_box_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from eccodes import codes_grib_find_nearest, codes_grib_new_from_file
from matplotlib import markers

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Box, Select
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Box, Select


def find_nearest_latlon(grib_file, target_lat, target_lon):
Expand Down
8 changes: 4 additions & 4 deletions examples/octahedral_grid_country_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from matplotlib import markers
from shapely.geometry import shape

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Polygon, Select, Union
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Polygon, Select, Union


def find_nearest_latlon(grib_file, target_lat, target_lon):
Expand Down
4 changes: 2 additions & 2 deletions examples/read_me_example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
from earthkit import data

from polytope.polytope import Polytope, Request
from polytope.shapes import Box, Select
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Box, Select

ds = data.from_source("file", "./examples/data/winds.grib")
array = ds.to_xarray()
Expand Down
8 changes: 4 additions & 4 deletions examples/slicing_all_ecmwf_countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from earthkit import data
from shapely.geometry import shape

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Polygon, Select, Union
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Polygon, Select, Union


class Test:
Expand Down
8 changes: 4 additions & 4 deletions examples/timeseries_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from earthkit import data
from shapely.geometry import shape

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Polygon, Select, Union
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Polygon, Select, Union


class Test:
Expand Down
8 changes: 4 additions & 4 deletions examples/wind_farms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from osgeo import gdal
from shapely.geometry import shape

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Polygon, Select, Union
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Polygon, Select, Union


class Test:
Expand Down
8 changes: 4 additions & 4 deletions performance/fdb_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import pandas as pd

from polytope.datacube.backends.fdb import FDBDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Box, Select
from polytope_feature.datacube.backends.fdb import FDBDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Box, Select


class TestSlicingFDBDatacube:
Expand Down
8 changes: 4 additions & 4 deletions performance/fdb_performance_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import pandas as pd

from polytope.datacube.backends.fdb import FDBDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Box, Select, Span
from polytope_feature.datacube.backends.fdb import FDBDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Box, Select, Span


class TestSlicingFDBDatacube:
Expand Down
6 changes: 2 additions & 4 deletions performance/fdb_slice_many_numbers_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import pandas as pd
import pygribjump as gj

from polytope.polytope import Polytope, Request
from polytope.shapes import All, Point, Select
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import All, Point, Select

time1 = time.time()
# Create a dataarray with 3 labelled axes using different index types

# config = {"class": "od", "expver": "0001", "levtype": "sfc", "type": "pf"}
options = {
"axis_config": [
{"axis_name": "step", "transformations": [{"name": "type_change", "type": "int"}]},
Expand Down Expand Up @@ -62,7 +61,6 @@
Select("class", ["od"]),
Select("stream", ["enfo"]),
Select("type", ["pf"]),
# Select("latitude", [0.035149384216], method="surrounding"),
Point(["latitude", "longitude"], [[0.04, 0]], method="surrounding"),
All("number"),
)
Expand Down
6 changes: 3 additions & 3 deletions performance/performance_many_num_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import pandas as pd
from earthkit import data

from polytope.datacube.backends.fdb import FDBDatacube
from polytope.polytope import Polytope, Request
from polytope.shapes import All, Point, Select, Span
from polytope_feature.datacube.backends.fdb import FDBDatacube
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import All, Point, Select, Span

time1 = time.time()
# Create a dataarray with 3 labelled axes using different index types
Expand Down
8 changes: 4 additions & 4 deletions performance/scalability_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np
import xarray as xr

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Box, Disk, Ellipsoid, Select
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Box, Disk, Ellipsoid, Select


class Test:
Expand Down
8 changes: 4 additions & 4 deletions performance/scalability_test_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np
import xarray as xr

from polytope.datacube.backends.xarray import XArrayDatacube
from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Box, Select, Union
from polytope_feature.datacube.backends.xarray import XArrayDatacube
from polytope_feature.engine.hullslicer import HullSlicer
from polytope_feature.polytope import Polytope, Request
from polytope_feature.shapes import Box, Select, Union


class Test:
Expand Down
26 changes: 23 additions & 3 deletions polytope_feature/datacube/backends/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,40 @@ def remap_path(self, path: DatacubePath):
return path

@staticmethod
def create(datacube, config={}, axis_options={}, compressed_axes_options=[], alternative_axes=[], context=None):
def create(
datacube,
config={},
axis_options={},
compressed_axes_options=[],
point_cloud_options=None,
alternative_axes=[],
context=None,
):
# TODO: get the configs as None for pre-determined value and change them to empty dictionary inside the function
if type(datacube).__name__ == "DataArray":
from .xarray import XArrayDatacube

xadatacube = XArrayDatacube(datacube, axis_options, compressed_axes_options, context)
xadatacube = XArrayDatacube(datacube, axis_options, compressed_axes_options, point_cloud_options, context)
return xadatacube
if type(datacube).__name__ == "GribJump":
from .fdb import FDBDatacube

fdbdatacube = FDBDatacube(
datacube, config, axis_options, compressed_axes_options, alternative_axes, context
datacube,
config,
axis_options,
compressed_axes_options,
point_cloud_options,
alternative_axes,
context,
)
return fdbdatacube
if type(datacube).__name__ == "MockDatacube":
return datacube

def check_branching_axes(self, request):
pass

@abstractmethod
def find_point_cloud(self):
pass
19 changes: 17 additions & 2 deletions polytope_feature/datacube/backends/fdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@

class FDBDatacube(Datacube):
def __init__(
self, gj, config=None, axis_options=None, compressed_axes_options=[], alternative_axes=[], context=None
self,
gj,
config=None,
axis_options=None,
compressed_axes_options=[],
point_cloud_options=None,
alternative_axes=[],
context=None,
):
if config is None:
config = {}
Expand All @@ -23,6 +30,7 @@ def __init__(

self.unwanted_path = {}
self.axis_options = axis_options
self.has_point_cloud = point_cloud_options # NOTE: here, will be True/False

partial_request = config
# Find values in the level 3 FDB datacube
Expand Down Expand Up @@ -70,7 +78,12 @@ def __init__(
val = self._axes[name].type
self._check_and_add_axes(options, name, val)

logging.info("Polytope created axes for %s", self._axes.keys())
logging.info("Polytope created axes for: " + str(self._axes.keys()))

def find_point_cloud(self):
# TODO: somehow, find the point cloud of irregular grid if it exists
if self.has_point_cloud:
return self.has_point_cloud

def check_branching_axes(self, request):
polytopes = request.polytopes()
Expand Down Expand Up @@ -282,6 +295,7 @@ def get_2nd_last_values(self, requests, leaf_path=None):

leaf_path_copy = deepcopy(leaf_path)
leaf_path_copy.pop("values", None)
leaf_path_copy.pop("index")
return (leaf_path_copy, current_start_idxs, fdb_node_ranges, lat_length)

def get_last_layer_before_leaf(self, requests, leaf_path, current_idx, fdb_range_n):
Expand All @@ -290,6 +304,7 @@ def get_last_layer_before_leaf(self, requests, leaf_path, current_idx, fdb_range
for i, c in enumerate(requests.children):
# now c are the leaves of the initial tree
key_value_path = {c.axis.name: c.values}
leaf_path["index"] = c.indexes
ax = c.axis
(key_value_path, leaf_path, self.unwanted_path) = ax.unmap_path_key(
key_value_path, leaf_path, self.unwanted_path
Expand Down
Loading
Loading