-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_gdalstore.py
More file actions
55 lines (45 loc) · 1.73 KB
/
Copy pathtest_gdalstore.py
File metadata and controls
55 lines (45 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Module to test the :mod:`psyplot.gdal_store` module."""
# SPDX-FileCopyrightText: 2016-2024 University of Lausanne
# SPDX-FileCopyrightText: 2020-2021 Helmholtz-Zentrum Geesthacht
# SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum hereon GmbH
#
# SPDX-License-Identifier: LGPL-3.0-only
import unittest
import _base_testing as bt
import pandas as pd
import psyplot.data as psyd
try:
import gdal
except ImportError:
gdal = False
class TestGdalStore(unittest.TestCase):
"""Class to test the :class:`psyplot.gdal_store.GdalStore` class"""
@unittest.skipIf(not gdal, "GDAL module not installed")
def test_open_geotiff(self):
"""Test to open a GeoTiff file"""
ds_ref = psyd.open_dataset(bt.get_file("test-t2m-u-v.nc"))
ds_tiff = psyd.open_dataset(
bt.get_file("test-t2m-1979-01-31T18-00-00.tif"), engine="gdal"
)
self.assertListEqual(
ds_tiff.Band1.values.tolist(),
ds_ref.isel(time=0, lev=0).t2m.values.tolist(),
)
@unittest.skipIf(not gdal, "GDAL module not installed")
def test_open_mf_geotiff(self):
"""Test to open multiple GeoTiff files and extract the time from the
file name"""
ds_ref = psyd.open_dataset(bt.get_file("test-t2m-u-v.nc"))
ds_tiff = psyd.open_mfdataset(
bt.get_file("test-t2m-*.tif"),
engine="gdal",
t_format="test-t2m-%Y-%m-%dT%H-%M-%S",
)
self.assertListEqual(
ds_ref.isel(time=[0, 1], lev=0).t2m.values.tolist(),
ds_tiff.Band1.values.tolist(),
)
self.assertListEqual(
pd.to_datetime(ds_tiff.time.values).tolist(),
pd.to_datetime(ds_ref.time[:2].values).tolist(),
)