|
20 | 20 |
|
21 | 21 | from openeo import collection_property |
22 | 22 | from openeo.api.process import Parameter |
| 23 | +from openeo.metadata import SpatialDimension |
23 | 24 | from openeo.rest import BandMathException, OpenEoClientException |
24 | 25 | from openeo.rest._testing import build_capabilities |
25 | 26 | from openeo.rest.connection import Connection |
@@ -730,12 +731,144 @@ def test_apply_kernel(s2cube): |
730 | 731 |
|
731 | 732 |
|
732 | 733 | def test_resample_spatial(s2cube): |
733 | | - im = s2cube.resample_spatial(resolution=[2.0, 3.0], projection=4578) |
734 | | - graph = _get_leaf_node(im) |
735 | | - assert graph["process_id"] == "resample_spatial" |
736 | | - assert "data" in graph["arguments"] |
737 | | - assert graph["arguments"]["resolution"] == [2.0, 3.0] |
738 | | - assert graph["arguments"]["projection"] == 4578 |
| 734 | + cube = s2cube.resample_spatial(resolution=[2.0, 3.0], projection=4578) |
| 735 | + assert get_download_graph(cube, drop_load_collection=True, drop_save_result=True) == { |
| 736 | + "resamplespatial1": { |
| 737 | + "process_id": "resample_spatial", |
| 738 | + "arguments": { |
| 739 | + "data": {"from_node": "loadcollection1"}, |
| 740 | + "resolution": [2.0, 3.0], |
| 741 | + "projection": 4578, |
| 742 | + "method": "near", |
| 743 | + "align": "upper-left", |
| 744 | + }, |
| 745 | + } |
| 746 | + } |
| 747 | + |
| 748 | + assert cube.metadata.spatial_dimensions == [ |
| 749 | + SpatialDimension(name="x", extent=None, crs=4578, step=2.0), |
| 750 | + SpatialDimension(name="y", extent=None, crs=4578, step=3.0), |
| 751 | + ] |
| 752 | + |
| 753 | + |
| 754 | +def test_resample_spatial_no_metadata(s2cube_without_metadata): |
| 755 | + cube = s2cube_without_metadata.resample_spatial(resolution=(3, 5), projection=4578) |
| 756 | + assert get_download_graph(cube, drop_load_collection=True, drop_save_result=True) == { |
| 757 | + "resamplespatial1": { |
| 758 | + "process_id": "resample_spatial", |
| 759 | + "arguments": { |
| 760 | + "data": {"from_node": "loadcollection1"}, |
| 761 | + "resolution": [3, 5], |
| 762 | + "projection": 4578, |
| 763 | + "method": "near", |
| 764 | + "align": "upper-left", |
| 765 | + }, |
| 766 | + } |
| 767 | + } |
| 768 | + assert cube.metadata.spatial_dimensions == [ |
| 769 | + SpatialDimension(name="x", extent=[None, None], crs=4578, step=3.0), |
| 770 | + SpatialDimension(name="y", extent=[None, None], crs=4578, step=5.0), |
| 771 | + ] |
| 772 | + |
| 773 | + |
| 774 | +def test_resample_cube_spatial(s2cube): |
| 775 | + cube1 = s2cube.resample_spatial(resolution=[2.0, 3.0], projection=4578) |
| 776 | + cube2 = s2cube.resample_spatial(resolution=10, projection=32631) |
| 777 | + |
| 778 | + cube12 = cube1.resample_cube_spatial(target=cube2) |
| 779 | + assert get_download_graph(cube12, drop_load_collection=True, drop_save_result=True) == { |
| 780 | + "resamplespatial1": { |
| 781 | + "process_id": "resample_spatial", |
| 782 | + "arguments": { |
| 783 | + "align": "upper-left", |
| 784 | + "data": {"from_node": "loadcollection1"}, |
| 785 | + "method": "near", |
| 786 | + "projection": 4578, |
| 787 | + "resolution": [2.0, 3.0], |
| 788 | + }, |
| 789 | + }, |
| 790 | + "resamplespatial2": { |
| 791 | + "process_id": "resample_spatial", |
| 792 | + "arguments": { |
| 793 | + "align": "upper-left", |
| 794 | + "data": {"from_node": "loadcollection1"}, |
| 795 | + "method": "near", |
| 796 | + "projection": 32631, |
| 797 | + "resolution": 10, |
| 798 | + }, |
| 799 | + }, |
| 800 | + "resamplecubespatial1": { |
| 801 | + "arguments": { |
| 802 | + "data": {"from_node": "resamplespatial1"}, |
| 803 | + "method": "near", |
| 804 | + "target": {"from_node": "resamplespatial2"}, |
| 805 | + }, |
| 806 | + "process_id": "resample_cube_spatial", |
| 807 | + }, |
| 808 | + } |
| 809 | + assert cube12.metadata.spatial_dimensions == [ |
| 810 | + SpatialDimension(name="x", extent=None, crs=32631, step=10), |
| 811 | + SpatialDimension(name="y", extent=None, crs=32631, step=10), |
| 812 | + ] |
| 813 | + |
| 814 | + cube21 = cube2.resample_cube_spatial(target=cube1) |
| 815 | + assert get_download_graph(cube21, drop_load_collection=True, drop_save_result=True) == { |
| 816 | + "resamplespatial1": { |
| 817 | + "process_id": "resample_spatial", |
| 818 | + "arguments": { |
| 819 | + "align": "upper-left", |
| 820 | + "data": {"from_node": "loadcollection1"}, |
| 821 | + "method": "near", |
| 822 | + "projection": 32631, |
| 823 | + "resolution": 10, |
| 824 | + }, |
| 825 | + }, |
| 826 | + "resamplespatial2": { |
| 827 | + "process_id": "resample_spatial", |
| 828 | + "arguments": { |
| 829 | + "align": "upper-left", |
| 830 | + "data": {"from_node": "loadcollection1"}, |
| 831 | + "method": "near", |
| 832 | + "projection": 4578, |
| 833 | + "resolution": [2.0, 3.0], |
| 834 | + }, |
| 835 | + }, |
| 836 | + "resamplecubespatial1": { |
| 837 | + "arguments": { |
| 838 | + "data": {"from_node": "resamplespatial1"}, |
| 839 | + "method": "near", |
| 840 | + "target": {"from_node": "resamplespatial2"}, |
| 841 | + }, |
| 842 | + "process_id": "resample_cube_spatial", |
| 843 | + }, |
| 844 | + } |
| 845 | + assert cube21.metadata.spatial_dimensions == [ |
| 846 | + SpatialDimension(name="x", extent=None, crs=4578, step=2.0), |
| 847 | + SpatialDimension(name="y", extent=None, crs=4578, step=3.0), |
| 848 | + ] |
| 849 | + |
| 850 | + |
| 851 | +def test_resample_cube_spatial_no_source_metadata(s2cube, s2cube_without_metadata): |
| 852 | + cube = s2cube_without_metadata |
| 853 | + target = s2cube.resample_spatial(resolution=10, projection=32631) |
| 854 | + assert cube.metadata is None |
| 855 | + assert target.metadata is not None |
| 856 | + |
| 857 | + result = cube.resample_cube_spatial(target=target) |
| 858 | + assert result.metadata.spatial_dimensions == [ |
| 859 | + SpatialDimension(name="x", extent=None, crs=32631, step=10), |
| 860 | + SpatialDimension(name="y", extent=None, crs=32631, step=10), |
| 861 | + ] |
| 862 | + |
| 863 | + |
| 864 | +def test_resample_cube_spatial_no_target_metadata(s2cube, s2cube_without_metadata): |
| 865 | + cube = s2cube.resample_spatial(resolution=10, projection=32631) |
| 866 | + target = s2cube_without_metadata |
| 867 | + assert cube.metadata is not None |
| 868 | + assert target.metadata is None |
| 869 | + |
| 870 | + result = cube.resample_cube_spatial(target=target) |
| 871 | + assert result.metadata is None |
739 | 872 |
|
740 | 873 |
|
741 | 874 | def test_merge(s2cube, api_version, test_data): |
|
0 commit comments