Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MAfarrag committed Jan 15, 2023
1 parent 4894285 commit 7e4cb29
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 63 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
python -m pip install --upgrade pip
pip install --no-cache-dir Cython
pip install --find-links=https://girder.github.io/large_image_wheels --no-cache GDAL
- name: Test GDAL installation
run: |
python -c "from osgeo import gdal"
Expand All @@ -49,4 +49,4 @@ jobs:
python -m pytest -vvv --cov=earth2observe --cov-report=xml
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v3
32 changes: 18 additions & 14 deletions tests/test_chirps.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import os
from typing import List
import glob
import os
import shutil
from typing import List

import pytest

from earth2observe.chirps import CHIRPS


@pytest.fixture(scope="session")
def test_create_chirps_object(
dates: List,
daily_temporal_resolution: str,
chirps_variables: List[str],
lat_bounds: List,
lon_bounds: List,
chirps_base_dir: str,
dates: List,
daily_temporal_resolution: str,
chirps_variables: List[str],
lat_bounds: List,
lon_bounds: List,
chirps_base_dir: str,
):
Coello = CHIRPS(
start=dates[0],
Expand All @@ -22,7 +24,7 @@ def test_create_chirps_object(
lon_lim=lon_bounds,
variables=chirps_variables,
temporal_resolution=daily_temporal_resolution,
path=chirps_base_dir
path=chirps_base_dir,
)
assert Coello.api_url == "data.chc.ucsb.edu"
assert Coello.lon_boundaries == [-180, 180]
Expand All @@ -34,14 +36,16 @@ def test_create_chirps_object(


def test_download(
test_create_chirps_object: CHIRPS,
chirps_base_dir: str,
number_downloaded_files: int,
test_create_chirps_object: CHIRPS,
chirps_base_dir: str,
number_downloaded_files: int,
):
fname = test_create_chirps_object.clipped_fname
test_create_chirps_object.download()

filelist = glob.glob(os.path.join(f"{chirps_base_dir}/chirps/precipitation", f"{fname}*.tif"))
filelist = glob.glob(
os.path.join(f"{chirps_base_dir}/chirps/precipitation", f"{fname}*.tif")
)
assert len(filelist) == number_downloaded_files
# delete the files
shutil.rmtree(f"{chirps_base_dir}/chirps/precipitation")
shutil.rmtree(f"{chirps_base_dir}/chirps/precipitation")
77 changes: 41 additions & 36 deletions tests/test_earth2observe.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import os
import glob
from typing import List
import os
import shutil
from typing import List

import pytest
from earth2observe.earth2observe import Earth2Observe

from earth2observe.chirps import CHIRPS
from earth2observe.earth2observe import Earth2Observe
from earth2observe.ecmwf import ECMWF

class TestChirpsBackend:

class TestChirpsBackend:
@pytest.fixture(scope="session")
def test_chirps_data_source_instantiate_object(
self,
chirps_data_source: str,
dates: List,
daily_temporal_resolution: str,
chirps_variables: List[str],
lat_bounds: List,
lon_bounds: List,
chirps_data_source_output_dir: str,
self,
chirps_data_source: str,
dates: List,
daily_temporal_resolution: str,
chirps_variables: List[str],
lat_bounds: List,
lon_bounds: List,
chirps_data_source_output_dir: str,
):
e2o = Earth2Observe(
data_source=chirps_data_source,
Expand All @@ -28,7 +30,7 @@ def test_chirps_data_source_instantiate_object(
lat_lim=lat_bounds,
lon_lim=lon_bounds,
temporal_resolution=daily_temporal_resolution,
path=chirps_data_source_output_dir
path=chirps_data_source_output_dir,
)
assert isinstance(e2o.DataSources, dict)
assert isinstance(e2o.datasource, CHIRPS)
Expand All @@ -37,33 +39,34 @@ def test_chirps_data_source_instantiate_object(
return e2o

def test_download_chirps_backend(
self,
test_chirps_data_source_instantiate_object: CHIRPS,
chirps_data_source_output_dir: str,
number_downloaded_files: int,
self,
test_chirps_data_source_instantiate_object: CHIRPS,
chirps_data_source_output_dir: str,
number_downloaded_files: int,
):
test_chirps_data_source_instantiate_object.download()
fname = "P_CHIRPS"
filelist = glob.glob(os.path.join(f"{chirps_data_source_output_dir}/chirps/precipitation", f"{fname}*.tif"))
filelist = glob.glob(
os.path.join(
f"{chirps_data_source_output_dir}/chirps/precipitation", f"{fname}*.tif"
)
)
assert len(filelist) == number_downloaded_files
# delete the files
shutil.rmtree(f"{chirps_data_source_output_dir}/chirps/precipitation")




class TestECMWFBackend:

@pytest.fixture(scope="session")
def test_ecmwf_data_source_instantiate_object(
self,
ecmwf_data_source: str,
dates: List,
daily_temporal_resolution: str,
ecmwf_variables: List[str],
lat_bounds: List,
lon_bounds: List,
ecmwf_data_source_output_dir: str,
self,
ecmwf_data_source: str,
dates: List,
daily_temporal_resolution: str,
ecmwf_variables: List[str],
lat_bounds: List,
lon_bounds: List,
ecmwf_data_source_output_dir: str,
):
e2o = Earth2Observe(
data_source=ecmwf_data_source,
Expand All @@ -73,21 +76,23 @@ def test_ecmwf_data_source_instantiate_object(
lat_lim=lat_bounds,
lon_lim=lon_bounds,
temporal_resolution=daily_temporal_resolution,
path=ecmwf_data_source_output_dir
path=ecmwf_data_source_output_dir,
)
assert isinstance(e2o.DataSources, dict)
assert isinstance(e2o.datasource, ECMWF)
assert e2o.datasource.vars == ecmwf_variables
return e2o

def test_download_chirps_backend(
self,
test_ecmwf_data_source_instantiate_object: CHIRPS,
ecmwf_data_source_output_dir: str,
number_downloaded_files: int,
self,
test_ecmwf_data_source_instantiate_object: CHIRPS,
ecmwf_data_source_output_dir: str,
number_downloaded_files: int,
):
test_ecmwf_data_source_instantiate_object.download()
filelist = glob.glob(os.path.join(f"{ecmwf_data_source_output_dir}/daily/Evaporation/", f"*.tif"))
filelist = glob.glob(
os.path.join(f"{ecmwf_data_source_output_dir}/daily/Evaporation/", f"*.tif")
)
assert len(filelist) == number_downloaded_files
# delete the files
shutil.rmtree(f"{ecmwf_data_source_output_dir}/daily")
shutil.rmtree(f"{ecmwf_data_source_output_dir}/daily")
25 changes: 14 additions & 11 deletions tests/test_ecmwf.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import pytest
import os
import glob
import os
import shutil
from typing import List

import pytest

from earth2observe.ecmwf import ECMWF


@pytest.fixture(scope="session")
def test_create_ecmwf_object(
dates: List,
lat_bounds: List,
lon_bounds: List,
ecmwf_base_dir: str,
ecmwf_variables: List[str],
dates: List,
lat_bounds: List,
lon_bounds: List,
ecmwf_base_dir: str,
ecmwf_variables: List[str],
):
Coello = ECMWF(
start=dates[0],
Expand All @@ -26,12 +29,12 @@ def test_create_ecmwf_object(


def test_download(
test_create_ecmwf_object: ECMWF,
ecmwf_base_dir: str,
number_downloaded_files: int,
test_create_ecmwf_object: ECMWF,
ecmwf_base_dir: str,
number_downloaded_files: int,
):
test_create_ecmwf_object.download()
filelist = glob.glob(os.path.join(f"{ecmwf_base_dir}/daily/Evaporation/", f"*.tif"))
assert len(filelist) == number_downloaded_files
# delete the files
shutil.rmtree(f"{ecmwf_base_dir}/daily")
shutil.rmtree(f"{ecmwf_base_dir}/daily")

0 comments on commit 7e4cb29

Please sign in to comment.