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

Release 1.0.3 #117

Closed
wants to merge 391 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
391 commits
Select commit Hold shift + click to select a range
f29d9e8
merge with develop
mathleur Aug 30, 2023
1d9c3bc
Merge pull request #46 from ecmwf/feature/test_mappers
mathleur Aug 30, 2023
0064b2e
Merge branch 'develop' of github.com:ecmwf/polytope into develop
mathleur Aug 30, 2023
5f39743
start doing surrounding points option
mathleur Aug 30, 2023
63857e3
make surrounding method work for all transformations
mathleur Aug 31, 2023
7917b68
try to make cyclic surrounding method work
mathleur Aug 31, 2023
3bf4f2d
make surrounding method work with cyclic axes
mathleur Sep 1, 2023
2b7cd43
make all tests work
mathleur Sep 5, 2023
ce0661f
try to make cyclic without offsets
mathleur Sep 5, 2023
1449f4a
make all tests work together
mathleur Sep 6, 2023
c5167af
black
mathleur Sep 6, 2023
bb3ce15
add pyfdb to requirements
mathleur Sep 6, 2023
bb830f3
add pyfdb to requirements
mathleur Sep 6, 2023
6a980e9
remove specific FDB location
mathleur Sep 6, 2023
88f972b
add github CI
mathleur Sep 6, 2023
7199fc1
remove pyfdb
mathleur Sep 6, 2023
3acf341
Merge branch 'develop' of github.com:ecmwf/polytope into feature/nice…
mathleur Sep 6, 2023
7b36653
skip fdb test
mathleur Sep 6, 2023
38c40a7
flake8
mathleur Sep 6, 2023
1d9c035
make tests work
mathleur Sep 6, 2023
abc896b
make surrounding method work with the cyclic axis
mathleur Sep 7, 2023
c03b7a5
clean up
mathleur Sep 7, 2023
78306d0
refactor find_indices_between for cyclic axis
mathleur Sep 7, 2023
f04ded5
refactor the surrounding method code in datacube.py _look_up_datacube…
mathleur Sep 7, 2023
f82c8e8
black
mathleur Sep 7, 2023
2907486
Merge pull request #64 from ecmwf/feature/nicer_transformations_fdb
mathleur Sep 7, 2023
d0108da
merge with develop
mathleur Sep 7, 2023
adeebe0
Merge pull request #70 from ecmwf/feature/no_cyclic_offsets
mathleur Sep 7, 2023
8259033
Merge branch 'develop' of github.com:ecmwf/polytope into develop
mathleur Sep 7, 2023
dbf3895
add healpix mapper
mathleur Sep 7, 2023
85a314a
add healpix test
mathleur Sep 7, 2023
4c426b3
test healpix mapper
mathleur Sep 8, 2023
01c9746
add plotting of healpix mapper
mathleur Sep 8, 2023
54aaf0c
clean up
mathleur Sep 8, 2023
623591d
add plotting to example folder and test without plotting for healpix …
mathleur Sep 8, 2023
15efd14
update CI to work with eccodes develop branch
mathleur Sep 8, 2023
0fbe0ad
update CI to work with eccodes develop branch
mathleur Sep 8, 2023
ed8347f
Merge branch 'develop' of github.com:ecmwf/polytope into develop
mathleur Oct 9, 2023
4b0650b
download test data from nexus
mathleur Oct 9, 2023
3b77075
download nexus data to tests/data
mathleur Oct 9, 2023
fec89c8
black
mathleur Oct 9, 2023
ffbe4e1
remove change write permissions to test data folder in CI
mathleur Oct 9, 2023
b9bfdd4
add internet connection warning in tests
mathleur Oct 10, 2023
dd4b58b
mark tests with internet connection
mathleur Oct 10, 2023
f44af33
refactor download data function
mathleur Oct 10, 2023
6503e27
fix relative import error in tests
mathleur Oct 10, 2023
c906f9c
raise exception in helper functions
mathleur Oct 10, 2023
3a3113a
remove exception handling in helper functions
mathleur Oct 10, 2023
c95438f
add exception handling in helper functions
mathleur Oct 10, 2023
4231257
Merge branch 'develop' of github.com:ecmwf/polytope into develop
mathleur Oct 10, 2023
7090e06
make first fdb extraction work
mathleur Oct 12, 2023
f4b61f6
fix unmerging of date and time
mathleur Oct 12, 2023
c6385ab
add regular grid mapping for fdb and test, which does not work yet
mathleur Oct 13, 2023
a6f938c
fix regular grid test
mathleur Oct 13, 2023
17776a8
small fixes and first performance test
mathleur Oct 13, 2023
bb76ea4
make octahedral grid mapping faster and first fdb performance
mathleur Oct 18, 2023
6f2dbd8
create dictionary of latitude lines in octahedral mapping
mathleur Oct 18, 2023
7b18dce
add some sort of caching for longitude values in unmap
mathleur Oct 19, 2023
a898711
optimise second idx search
mathleur Oct 19, 2023
9faf711
optimise small bits
mathleur Oct 19, 2023
fb07954
calculate leaves' ancestors while finding leaves optimisation
mathleur Oct 20, 2023
03f5b17
small optimisation
mathleur Oct 20, 2023
5175919
store slice_axis_idx in hullslicer
mathleur Oct 20, 2023
fb2b110
try to make faster
mathleur Oct 24, 2023
722d0f0
add a null transformation and see effect on performance
mathleur Oct 24, 2023
a225c41
small optimisation
mathleur Oct 25, 2023
dd5c249
small optimisations
mathleur Oct 26, 2023
b32ff76
make new recursive get
mathleur Oct 27, 2023
0deab2e
time recursive get function
mathleur Oct 30, 2023
9a3f3bc
add scalability_plot
mathleur Oct 30, 2023
f2aa886
retrieve ranges of longitudes from FDB
mathleur Nov 2, 2023
245d0b4
make latlon requests to the fdb in a single path
mathleur Nov 7, 2023
15de427
request only 1 request to pyfdb
mathleur Nov 8, 2023
56d978a
clean up
mathleur Nov 10, 2023
7a7a2ac
clean up
mathleur Nov 10, 2023
2090029
black
mathleur Nov 10, 2023
f8922df
remove data
mathleur Nov 10, 2023
5842a1b
remove unnecessary code
mathleur Nov 10, 2023
1065c72
remove unnecessary code
mathleur Nov 14, 2023
6fffbff
renaming and small fixes
mathleur Nov 15, 2023
eef415d
renaming
mathleur Nov 16, 2023
0dfabef
fix regular grid problem with too many points found
mathleur Nov 20, 2023
458531d
make healpix grid work with cyclic axes
mathleur Nov 20, 2023
ec07170
black
mathleur Nov 20, 2023
d4697b8
fdb axes indices are not always in sorted order
mathleur Nov 21, 2023
4f72f1f
small fixes
mathleur Nov 22, 2023
27470ce
add repr for shapes and Point shape which supports surrounding method
mathleur Nov 22, 2023
7cffad1
add grib to gitignore
mathleur Nov 22, 2023
fe730ea
remove data from tests
mathleur Nov 22, 2023
8a77ed3
remove double print for convex polytope
mathleur Nov 22, 2023
487e6e9
make All shape work
mathleur Nov 22, 2023
086b343
add repr for shapes and Point shape which supports surrounding method
mathleur Nov 22, 2023
a14f976
remove data from tests
mathleur Nov 22, 2023
1b8facb
remove double print for convex polytope
mathleur Nov 22, 2023
3312772
clean up branch
mathleur Nov 23, 2023
2d4ea3f
make date axis a pandas datetime axis
mathleur Nov 23, 2023
bee5e54
pull develop
mathleur Nov 23, 2023
80d56c0
fix naming problem in tests
mathleur Nov 23, 2023
0086059
remove tests that depend on fdb
mathleur Nov 23, 2023
f1dc3e9
Merge pull request #76 from ecmwf/feature/test_date_ranges
mathleur Nov 23, 2023
ce0c4c5
quick fix to surrounding method
mathleur Dec 7, 2023
34da743
black
mathleur Dec 7, 2023
dd5911f
time components in example
mathleur Dec 7, 2023
583b0f0
remove the transformation keyword in datacube options
mathleur Dec 7, 2023
c918b6b
show fdb time
mathleur Dec 7, 2023
0d334ce
time different functions
mathleur Dec 7, 2023
dc47ba9
add shortcut if polytope is flat
mathleur Dec 8, 2023
9b34b4a
add fdb_time to xarray to make tests work
mathleur Dec 8, 2023
4f65e7a
small optimisations
mathleur Dec 8, 2023
7bf5b17
clean up branch
mathleur Dec 8, 2023
8ce60e5
clean up
mathleur Dec 8, 2023
07bf141
make caching for the sliceable values in hullslicer work
mathleur Dec 8, 2023
158c3e7
skip test with non-formatted datacube and clean up
mathleur Dec 11, 2023
1cc38ed
flake 8 tests
mathleur Dec 11, 2023
457bd76
skip tests that depend on fdb
mathleur Dec 11, 2023
3239323
add caching for unsliceable values
mathleur Dec 11, 2023
fbfc914
add more caching of functions in extract
mathleur Dec 12, 2023
a354ec8
clean up
mathleur Dec 12, 2023
de8ae19
ignore tests which need fdb
mathleur Dec 12, 2023
191fb4a
fix tests which didn't work
mathleur Dec 13, 2023
da2044d
mark fdb tests
mathleur Dec 13, 2023
5abd67f
make fdb backend work with gribjump instead of fdb
mathleur Dec 14, 2023
c4af86b
clean up
mathleur Dec 14, 2023
70fa4b0
clean up
mathleur Dec 14, 2023
8ffa3ce
remove gribjump test
mathleur Dec 14, 2023
fda49c6
don't skip gribjump test
mathleur Dec 14, 2023
c4ca9d2
reformat pytest markers
mathleur Dec 18, 2023
4df602a
add pytest mark
mathleur Dec 18, 2023
d141dc1
add pytest mark before test
mathleur Dec 18, 2023
06dc236
quick fix to surrounding method
mathleur Dec 7, 2023
0183685
black
mathleur Dec 7, 2023
2fb1735
time components in example
mathleur Dec 7, 2023
f0d4cbe
remove the transformation keyword in datacube options
mathleur Dec 7, 2023
9733d10
show fdb time
mathleur Dec 7, 2023
0f5d63c
time different functions
mathleur Dec 7, 2023
7959a1f
add shortcut if polytope is flat
mathleur Dec 8, 2023
902d4ac
add fdb_time to xarray to make tests work
mathleur Dec 8, 2023
5e12c05
small optimisations
mathleur Dec 8, 2023
72773fe
clean up branch
mathleur Dec 8, 2023
a634e1c
clean up
mathleur Dec 8, 2023
3c46c8a
special mark for fdb tests
mathleur Dec 8, 2023
48b3aea
put fdb marker on fdb test
mathleur Dec 8, 2023
58e05b4
add reduced_ll_grid with 1441 latitude values
mathleur Jan 3, 2024
5904a4c
test wave grid reduced_ll
mathleur Jan 3, 2024
fdc67ea
fix small bug
mathleur Jan 3, 2024
4c8d30f
skip fdb test
mathleur Jan 3, 2024
1efa99e
make plot in test reduced ll grid
mathleur Jan 4, 2024
8aba835
skip fdb tests
mathleur Jan 4, 2024
6b6e687
make tests more efficient and example of shipping route on wave model
mathleur Jan 4, 2024
bb65df5
black
mathleur Jan 4, 2024
8f4b379
add new point examples of date ranges
mathleur Dec 5, 2023
e2a5b5f
add test on operational ecmwf data
mathleur Dec 5, 2023
35458fc
merge develop
mathleur Jan 9, 2024
288c9a7
Merge pull request #79 from ecmwf/feature/fix_small_problems
mathleur Jan 9, 2024
3a59551
avoid gribjump import in tests
mathleur Jan 9, 2024
eb08619
merge develop
mathleur Jan 9, 2024
9e41b59
Merge pull request #85 from ecmwf/feature/gribjump
mathleur Jan 9, 2024
d21c190
Merge pull request #80 from ecmwf/feature/optimise_polytope_extents
mathleur Jan 9, 2024
d6a7f14
fix tests
mathleur Jan 10, 2024
0c6764a
rename fdb to gj
mathleur Jan 11, 2024
1dd0cb2
rename fdb to gj
mathleur Jan 11, 2024
06e6342
rename fdb to gj
mathleur Jan 11, 2024
76e73b9
replace |= operation with update
mathleur Jan 11, 2024
1d98c88
test for polytope higher level timeseries shape
mathleur Jan 11, 2024
ea909c6
add __init__ to transformations folder
mathleur Jan 12, 2024
20f4328
fix small test issues
mathleur Jan 12, 2024
c3c6221
remove {} as default argument in functions
mathleur Jan 12, 2024
3678ffe
add point with method=surrounding test
mathleur Jan 12, 2024
904828e
fix point test with method=surrounding on real data
mathleur Jan 12, 2024
643c91a
add logging to datacube/fdb backend
mathleur Jan 12, 2024
3fde030
add logging for hullslicer engine
mathleur Jan 12, 2024
12836ca
logging on mapping and merger transformations
mathleur Jan 12, 2024
3c1d417
update requirements
mathleur Jan 16, 2024
bf3e496
put the mappers in separate files for clarity
mathleur Jan 17, 2024
f02c03e
start nearest method by finding indices between like for surrounding …
mathleur Jan 17, 2024
cf4a199
make nearest method return only nearest point for end lat/lon grid
mathleur Jan 18, 2024
0a522db
fix small bug
mathleur Jan 18, 2024
ee50021
make sure nearest is only called on one point
mathleur Jan 18, 2024
ad5c029
fix bug
mathleur Jan 18, 2024
f42f37d
make tests work
mathleur Jan 19, 2024
e2161ca
fix tree merging for multiple params
mathleur Jan 19, 2024
721c53a
nicer fix
mathleur Jan 19, 2024
8566ff6
add decorators in individual transformation files
mathleur Jan 22, 2024
8eeb0b5
refactor some transformations
mathleur Jan 22, 2024
db04526
fix cyclic nearest method bug
mathleur Jan 22, 2024
b0fec5f
add init.py and requirements
jameshawkes Jan 22, 2024
9f50e54
start nearest method by finding indices between like for surrounding …
mathleur Jan 17, 2024
2d303c5
make nearest method return only nearest point for end lat/lon grid
mathleur Jan 18, 2024
544cf68
fix small bug
mathleur Jan 18, 2024
192bdcd
make sure nearest is only called on one point
mathleur Jan 18, 2024
0551725
fix bug
mathleur Jan 18, 2024
e5dfb8e
make tests work
mathleur Jan 19, 2024
de9cae8
fix merging of multiple params
mathleur Jan 19, 2024
d4746f3
replace |= operation with update
mathleur Jan 11, 2024
773967f
pull develop
mathleur Jan 23, 2024
740e917
black setup.py
mathleur Jan 23, 2024
aba71bc
pull develop
mathleur Jan 23, 2024
aba8295
fix CI
mathleur Jan 23, 2024
4f5667d
fix CI
mathleur Jan 23, 2024
2ae23da
fix CI
mathleur Jan 23, 2024
7853122
fix CI
mathleur Jan 23, 2024
c81c7f8
pull develop
mathleur Jan 23, 2024
fe4202f
pull develop
mathleur Jan 23, 2024
196842c
black setup.py
mathleur Jan 23, 2024
73e183f
Merge branch 'feature/nearest_method' into develop
jameshawkes Jan 23, 2024
56b10ad
logging
jameshawkes Jan 24, 2024
49838d0
better batching to fdb backend
mathleur Jan 24, 2024
b95c500
clean up unnecessary functions
mathleur Jan 24, 2024
38f2ade
change structure of transformations
mathleur Jan 25, 2024
9b14fcb
pull develop
mathleur Jan 25, 2024
627dfc0
merge caching sliceable values with develop
mathleur Jan 25, 2024
9faf412
merge develop into cache sliceable values branch
mathleur Jan 25, 2024
b5ce483
isort
mathleur Jan 25, 2024
10695a0
identical structure datacube
mathleur Jan 26, 2024
5235e7d
flake8
mathleur Jan 26, 2024
1efb658
clean up
mathleur Jan 29, 2024
9ddbbd8
add local regular grid mapper
mathleur Jan 29, 2024
aeb86eb
add __init__ file
mathleur Jan 29, 2024
daa503f
Merge branch 'feature/local_latlon_grid' of github.com:ecmwf/polytope…
mathleur Jan 29, 2024
491069c
merge develop
mathleur Jan 29, 2024
4f93535
merge develop
mathleur Jan 29, 2024
d63d52d
add nearest method to transformations
mathleur Jan 29, 2024
72af10f
isort
mathleur Jan 24, 2024
b4bb7ea
update gitignore
mathleur Jan 24, 2024
28328d8
fix local grid mapper issues
mathleur Feb 1, 2024
facc193
fix local grid test
mathleur Feb 1, 2024
19b4906
test local grid with cyclicity
mathleur Feb 1, 2024
df2ca21
black
mathleur Feb 1, 2024
c666d0f
ignore pygribjump test
mathleur Feb 1, 2024
f4573ac
Merge pull request #101 from ecmwf/feature/local_latlon_grid
mathleur Feb 1, 2024
fc8c47b
remove unnecessary requirements and files
mathleur Feb 5, 2024
73b532c
test which requirements are truly needed
mathleur Feb 6, 2024
90b52af
remove unnecessary requirements
mathleur Feb 6, 2024
360e583
merge develop
mathleur Feb 6, 2024
e322973
Merge pull request #87 from ecmwf/feature/test_fixes
mathleur Feb 6, 2024
b82f551
merge develop
mathleur Feb 6, 2024
c1aaa62
Merge pull request #89 from ecmwf/feature/small-fixes
mathleur Feb 6, 2024
dab4014
pull develop and fix bugs
mathleur Feb 6, 2024
d4c9b13
Merge pull request #100 from ecmwf/feature/identical_structure_datacube
mathleur Feb 6, 2024
05bd201
pull develop
mathleur Feb 6, 2024
2d15407
flake8
mathleur Feb 6, 2024
84805b8
Merge pull request #99 from ecmwf/feature/move_transformation_decorators
mathleur Feb 6, 2024
56e2d46
merge develop
mathleur Feb 6, 2024
2c8787d
Merge pull request #84 from ecmwf/feature/more_caching_in_extract_clean
mathleur Feb 6, 2024
df734b3
remove numpy version
mathleur Mar 1, 2024
23ce604
add __init__.py to subfolders
mathleur Mar 1, 2024
bd0eb3d
remove requirement versions
mathleur Mar 1, 2024
b117f83
remove test requirement versions
mathleur Mar 1, 2024
2b8dc06
remove example requirement versions
mathleur Mar 1, 2024
a0c56db
Version 1.0.3
jameshawkes Mar 1, 2024
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: 0 additions & 4 deletions .gitattributes

This file was deleted.

2 changes: 0 additions & 2 deletions .gitconfig

This file was deleted.

39 changes: 11 additions & 28 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
name: ci

on:
# Trigger the workflow on push to master or develop, except tag creation
push:
branches:
- 'main'
- 'develop'

# Trigger the workflow on pull request
pull_request: ~

# Trigger the workflow manually
workflow_dispatch: ~

# Trigger after public PR approved for CI
pull_request_target:
types: [labeled]

release:
types: [created]

jobs:
qa:
name: qa
Expand Down Expand Up @@ -48,7 +42,6 @@ jobs:

- name: Check flake8
run: flake8 .

setup:
name: setup
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -95,7 +88,6 @@ jobs:
run: |
echo inputs=$(echo "${{ inputs.build_package_inputs || '{}' }}" | yq eval '.' --output-format json --indent 0 -) >> $GITHUB_OUTPUT
echo inputs-for-ubuntu=$(echo "${{ inputs.build_package_inputs || '{}' }}" | yq eval '. * {"os":"ubuntu-20.04","compiler":"gnu-10","compiler_cc":"gcc-10","compiler_cxx":"g++-10","compiler_fc":"gfortran-10"}' --output-format json --indent 0 -) >> $GITHUB_OUTPUT

test:
name: test
needs:
Expand All @@ -106,20 +98,16 @@ jobs:
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install eccodes and Dependencies
id: install-dependencies
uses: ecmwf-actions/build-package@v2
with:
fetch-depth: 3 # enable full clone to download Git LFS files
- name: Change write permission
run: chmod -R 777 ./tests/data/
- name: Install Git LFS
run: |
sudo apt-get install git-lfs
git lfs install
- name: Download Git LFS file
run: |
git lfs pull
- name: Install eccodes
run: sudo apt-get install -y libeccodes-dev
self_build: false
dependencies: |
ecmwf/ecbuild@develop
MathisRosenhauer/libaec@master
ecmwf/eccodes@develop

- name: Setup Python
uses: actions/setup-python@v4
Expand All @@ -143,23 +131,18 @@ jobs:
LD_LIBRARY_PATH: ${{ steps.install-dependencies.outputs.lib_path }}
shell: bash -eux {0}
run: |
DYLD_LIBRARY_PATH=${{ env.LD_LIBRARY_PATH }} python -m pytest tests --cov=./ --cov-report=xml
DYLD_LIBRARY_PATH=${{ env.LD_LIBRARY_PATH }} python -m pytest -m "not fdb" tests --cov=./ --cov-report=xml
python -m coverage report

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: coverage.xml

deploy:
needs: test

if: ${{ github.event_name == 'release' }}

name: Upload to Pypi

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand All @@ -176,4 +159,4 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist
twine upload dist/*
twine upload dist/*
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@
polytope.egg-info
.pytest_cache
*.prof
*.idx
*.idx
*.grib
*.xml
site
.coverage
*.grib
*.gif
*.html
example_eo
example_mri
.mypy_cache
*.req
8 changes: 8 additions & 0 deletions ACKNOWLEDGEMENTS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Acknowledgements
================

Destination Earth
This software is developed with co-funding by the European Union under the Destination Earth initiative.

LEXIS
This software is part of a project that has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 825532.
20 changes: 20 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Contributing to *polytope*
========================================

Please report bug_ reports or pull-requests_ on GitHub_

.. _bug: https://github.com/ecmwf/polytope/issues

.. _pull-requests: https://github.com/ecmwf/polytope/pulls

.. _GitHub: https://github.com/ecmwf/polytope

We want your feedback, please e-mail: user-services@ecmwf.int

The package is installed from PyPI with::

$ pip install polytope-python

How you could use polytope:
* plot outputs, examples are provided in the examples folder
* go further than our examples and let us know how it goes
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include requirements.txt
18 changes: 7 additions & 11 deletions examples/3D_shipping_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

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


class Test:
def setup_method(self):
ds = data.from_source("file", "./examples/data/winds.grib")
array = ds.to_xarray()
array = array.isel(time=0).isel(surface=0).isel(number=0)
array = array.isel(time=0).isel(surface=0).isel(number=0).u10
self.array = array
self.slicer = HullSlicer()
self.API = Polytope(datacube=array, engine=self.slicer)
Expand Down Expand Up @@ -58,29 +58,25 @@ def test_slice_shipping_route(self):
# Then somehow make this list of points into just a sequence of points

ship_route_polytope = Path(["latitude", "longitude", "step"], initial_shape, *new_points)
request = Request(ship_route_polytope)
request = Request(
ship_route_polytope, Select("number", [0]), Select("surface", [0]), Select("time", ["2022-09-30T12:00:00"])
)
result = self.API.retrieve(request)

# Associate the results to the lat/long points in an array
lats = []
longs = []
parameter_values = []
winds_u = []
winds_v = []
for i in range(len(result.leaves)):
cubepath = result.leaves[i].flatten()
lat = cubepath["latitude"]
long = cubepath["longitude"]
lats.append(lat)
longs.append(long)

u10_idx = result.leaves[i].result["u10"]
u10_idx = result.leaves[i].result[1]
wind_u = u10_idx
v10_idx = result.leaves[i].result["v10"]
wind_v = v10_idx
winds_u.append(wind_u)
winds_v.append(wind_v)
parameter_values.append(math.sqrt(wind_u**2 + wind_v**2))
parameter_values.append(wind_u)

parameter_values = np.array(parameter_values)
# Plot this last array according to different colors for the result on a world map
Expand Down
131 changes: 131 additions & 0 deletions examples/3D_shipping_route_wave_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
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 tests.helper_functions import download_test_data


class TestReducedLatLonGrid:
def setup_method(self, method):
nexus_url = "https://get.ecmwf.int/test-data/polytope/test-data/wave.grib"
download_test_data(nexus_url, "wave.grib")
self.options = {
"values": {
"transformation": {
"mapper": {"type": "reduced_ll", "resolution": 1441, "axes": ["latitude", "longitude"]}
}
},
"date": {"transformation": {"merge": {"with": "time", "linkers": ["T", "00"]}}},
"step": {"transformation": {"type_change": "int"}},
"number": {"transformation": {"type_change": "int"}},
"longitude": {"transformation": {"cyclic": [0, 360]}},
}
self.config = {"class": "od", "stream": "wave"}
self.fdbdatacube = FDBDatacube(self.config, axis_options=self.options)
self.slicer = HullSlicer()
self.API = Polytope(datacube=self.fdbdatacube, engine=self.slicer, axis_options=self.options)

def find_nearest_latlon(self, grib_file, target_lat, target_lon):
messages = grib_file

# Find the nearest grid points
nearest_points = []
for message in [messages[0]]:
nearest_index = codes_grib_find_nearest(message, target_lat, target_lon)
nearest_points.append(nearest_index)

return nearest_points

@pytest.mark.internet
@pytest.mark.skip(reason="can't install fdb branch on CI")
def test_reduced_ll_grid(self):
shapefile = gpd.read_file("./examples/data/Shipping-Lanes-v1.shp")
geometry_multiline = shapefile.iloc[2]
geometry_object = geometry_multiline["geometry"]

lines = []
i = 0

for line in geometry_object[:7]:
for point in line.coords:
point_list = list(point)
if list(point)[0] < 0:
point_list[0] = list(point)[0] + 360
lines.append(point_list)

# Append for each point a corresponding step

new_points = []
for point in lines[:7]:
new_points.append([point[1], point[0], 1])

# Pad the shipping route with an initial shape

padded_point_upper = [0.24, 0.24, 1]
padded_point_lower = [-0.24, -0.24, 1]
initial_shape = Ellipsoid(["latitude", "longitude", "step"], padded_point_lower, padded_point_upper)

# Then somehow make this list of points into just a sequence of points

ship_route_polytope = Path(["latitude", "longitude", "step"], initial_shape, *new_points)

request = Request(
ship_route_polytope,
Select("date", [pd.Timestamp("20231129T000000")]),
Select("domain", ["g"]),
Select("expver", ["0001"]),
Select("param", ["140251"]),
Select("direction", ["1"]),
Select("frequency", ["1"]),
Select("class", ["od"]),
Select("stream", ["wave"]),
Select("levtype", ["sfc"]),
Select("type", ["fc"]),
)
result = self.API.retrieve(request)
result.pprint()

lats = []
lons = []
eccodes_lats = []
eccodes_lons = []
tol = 1e-8
f = open("./tests/data/wave.grib", "rb")
messages = []
message = codes_grib_new_from_file(f)
messages.append(message)

leaves = result.leaves
for i in range(len(leaves)):
cubepath = leaves[i].flatten()
lat = cubepath["latitude"]
lon = cubepath["longitude"]
del cubepath
lats.append(lat)
lons.append(lon)
nearest_points = codes_grib_find_nearest(message, lat, lon)[0]
eccodes_lat = nearest_points.lat
eccodes_lon = nearest_points.lon
eccodes_lats.append(eccodes_lat)
eccodes_lons.append(eccodes_lon)
assert eccodes_lat - tol <= lat
assert lat <= eccodes_lat + tol
assert eccodes_lon - tol <= lon
assert lon <= eccodes_lon + tol
print(i)
f.close()

worldmap = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
fig, ax = plt.subplots(figsize=(12, 6))
worldmap.plot(color="darkgrey", ax=ax)

plt.scatter(lons, lats, s=18, c="red", cmap="YlOrRd")
plt.scatter(eccodes_lons, eccodes_lats, s=6, c="green")
plt.colorbar(label="Temperature")
plt.show()
14 changes: 7 additions & 7 deletions examples/4D_flight_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
from earthkit import data
from PIL import Image

from polytope.datacube.xarray import XArrayDatacube
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
from polytope.shapes import Box, Path, Select


class Test:
def setup_method(self):
ds = data.from_source("file", "./examples/data/temp_model_levels.grib")
array = ds.to_xarray()
array = array.isel(time=0)
options = {"longitude": {"Cyclic": [0, 360.0]}}
array = array.isel(time=0).t
axis_options = {"longitude": {"cyclic": [0, 360.0]}}
self.xarraydatacube = XArrayDatacube(array)
for dim in array.dims:
array = array.sortby(dim)
self.array = array
self.slicer = HullSlicer()
self.API = Polytope(datacube=array, engine=self.slicer, options=options)
self.API = Polytope(datacube=array, engine=self.slicer, axis_options=axis_options)

def test_slice_shipping_route(self):
colorscale = [
Expand Down Expand Up @@ -84,7 +84,7 @@ def sphere(size, texture):

flight_route_polytope = Path(["latitude", "longitude", "step", "hybrid"], initial_shape, *route_point_CDG_LHR)

request = Request(flight_route_polytope)
request = Request(flight_route_polytope, Select("time", ["2022-12-02T12:00:00"]))
result = self.API.retrieve(request)

lats = []
Expand All @@ -99,7 +99,7 @@ def sphere(size, texture):
lats.append(lat)
longs.append(long)
levels.append(level)
t_idx = result.leaves[i].result["t"]
t_idx = result.leaves[i].result[1]
parameter_values.append(t_idx)
parameter_values = np.array(parameter_values)

Expand Down
Loading
Loading