Skip to content

Commit

Permalink
update tests, and test data path
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhahn committed May 6, 2024
1 parent ad5ba16 commit 62e033f
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 312 deletions.
1 change: 0 additions & 1 deletion docs/index.rst
Expand Up @@ -16,7 +16,6 @@ Contents
xarray_readers_tutorial.ipynb
License <license>
Authors <authors>
Changelog <changelog>
Module Reference <api/modules>


Expand Down
42 changes: 42 additions & 0 deletions tests/get_path.py
@@ -0,0 +1,42 @@
# Copyright (c) 2024, TU Wien
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of TU Wien, Department of Geodesy and Geoinformation
# nor the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL TU WIEN DEPARTMENT OF GEODESY AND
# GEOINFORMATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from pathlib import Path


def get_current_path():
"""
Get current file path.
"""
return Path(__file__).resolve().parent


def get_testdata_path():
"""
Get test data path.
"""
return Path(__file__).resolve().parent / "ascat-test-data"
21 changes: 9 additions & 12 deletions tests/test_cgls.py
@@ -1,4 +1,4 @@
# Copyright (c) 2024, TU Wien, Department of Geodesy and Geoinformation
# Copyright (c) 2024, TU Wien
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand All @@ -24,24 +24,23 @@
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
Tests for reading CGLOPS SWI data.
"""

from ascat.cgls import SWI_TS
import os
import pandas as pd
import numpy as np
import pytest

from get_path import get_testdata_path
from ascat.cgls import SWI_TS


def test_swi_ts_reader():
"""
Test SWI time series reader.
"""
data_path = os.path.join(
os.path.dirname(__file__), 'ascat_test_data', 'cglops', 'swi_ts')
data_path = get_testdata_path() / "cglops" / "swi_ts"

rd = SWI_TS(data_path)
data = rd.read(3002621, mask_frozen=False)
Expand All @@ -68,8 +67,7 @@ def test_swi_ts_reader_no_data_in_folder():
"""
Test SWI time series reader when no data is in folder.
"""
data_path = os.path.join(
os.path.dirname(__file__), 'ascat_test_data', 'cglops', 'swi_ts_non_existing')
data_path = get_testdata_path() / "cglops" / "swi_ts_non_existing"

with pytest.raises(IOError):
SWI_TS(data_path)
Expand All @@ -79,15 +77,14 @@ def test_swi_ts_qflag_reading():
"""
Test SWI time series quality flag reader.
"""
data_path = os.path.join(
os.path.dirname(__file__), 'ascat_test_data', 'cglops', 'swi_ts')
data_path = get_testdata_path() / "cglops" / "swi_ts"
rd = SWI_TS(data_path, parameters=['SWI_001', 'QFLAG_001', 'SSF'])
data = rd.read(3002621, mask_frozen=True)
# check if QFLAG is correctly read. It should have as many NaN values as
# SWI
assert len(data[data.loc[:, 'QFLAG_001'] != np.nan]) > 0
assert (len(data[data.loc[:, 'QFLAG_001'] == np.nan]) ==
len(data[data.loc[:, 'SWI_001'] == np.nan]))
assert (len(data[data.loc[:, 'QFLAG_001'] == np.nan]) == len(
data[data.loc[:, 'SWI_001'] == np.nan]))


if __name__ == "__main__":
Expand Down
31 changes: 21 additions & 10 deletions tests/test_download.py
@@ -1,4 +1,4 @@
# Copyright (c) 2024, TU Wien, Department of Geodesy and Geoinformation
# Copyright (c) 2024, TU Wien
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand All @@ -24,7 +24,6 @@
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
Test download.
"""
Expand All @@ -37,10 +36,17 @@
from ascat.download.connectors import HsafConnector
from ascat.download.connectors import EumConnector

credentials = {'EUM': {'consumer_key': os.getenv('EUM_CONSUMER_KEY'),
'consumer_secret': os.getenv('EUM_CONSUMER_SECRET')},
'HSAF': {'user': os.getenv('HSAF_FTP_USER'),
'password': os.getenv('HSAF_FTP_PASSWORD')}}
credentials = {
'EUM': {
'consumer_key': os.getenv('EUM_CONSUMER_KEY'),
'consumer_secret': os.getenv('EUM_CONSUMER_SECRET')
},
'HSAF': {
'user': os.getenv('HSAF_FTP_USER'),
'password': os.getenv('HSAF_FTP_PASSWORD')
}
}


class TestDownload(unittest.TestCase):

Expand Down Expand Up @@ -74,8 +80,8 @@ def test_eumetsat_download(self):

connector = EumConnector()
connector.connect(credentials['EUM'])
connector.download(product, self.local_path, self.start_date,
self.end_date, limit=1)
connector.download(
product, self.local_path, self.start_date, self.end_date, limit=1)

@unittest.skipIf(credentials['HSAF']['user'] is None,
"Skip H SAF connection test")
Expand All @@ -97,9 +103,14 @@ def test_hsaf_download(self):

connector = HsafConnector()
connector.connect(credentials['HSAF'])
connector.download(remote_path, self.local_path, self.start_date,
self.end_date, limit=1)
connector.download(
remote_path,
self.local_path,
self.start_date,
self.end_date,
limit=1)
connector.close()


if __name__ == '__main__':
unittest.main()

0 comments on commit 62e033f

Please sign in to comment.