Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_odd_bounds():
cutout = Cutout(path = tmp_dir / (path + '_odd_bounds'), module="era5", time=time,
bounds=(x0-0.1, y0-0.02, x1+0.03, y1+0.13))
cutout.prepare()
assert_allclose(cutout.data.wnd100m, ref.data.wnd100m,
atol=1e-5, rtol=1e-5)
def test_available_features(ref):
modules = ref.available_features.index.unique('module')
assert len(modules) == 1
assert modules[0] == 'era5'
cutout = Cutout(path="sarah_first", module=['sarah', 'era5'],
time=slice('2013-01-01', '2013-01-01'),
x=slice(X0, X1), y = slice(Y0, Y1))
modules = cutout.available_features.index.unique('module')
assert len(modules) == 2
assert len(cutout.available_features) > len(ref.available_features)
import atlite
from atlite import Cutout
from xarray.testing import assert_allclose, assert_equal
time='2013-01-01'
x0 = -4
y0 = 56
x1 = 1.5
y1 = 61
path="era5_test"
tmp_dir = Path('tmp_files_test')
tmp_dir.mkdir()
ref = Cutout(path=tmp_dir / path, module="era5", bounds=(x0, y0, x1, y1), time=time)
ref.prepare()
# Backwards compatibility with name and cutout_dir
def test_old_style_loading_args():
cutout = Cutout(name=path, cutout_dir=tmp_dir)
assert_equal(cutout.data.coords.to_dataset(), ref.data.coords.to_dataset())
def test_odd_bounds():
cutout = Cutout(path = tmp_dir / (path + '_odd_bounds'), module="era5", time=time,
bounds=(x0-0.1, y0-0.02, x1+0.03, y1+0.13))
cutout.prepare()
assert_allclose(cutout.data.wnd100m, ref.data.wnd100m,
atol=1e-5, rtol=1e-5)
def cutout_era5(tmp_path_factory):
tmp_path = tmp_path_factory.mktemp("era5")
cutout = Cutout(path=tmp_path / "era5", module="era5", bounds=BOUNDS, time=TIME)
cutout.prepare()
return cutout
def test_odd_bounds_coords(ref):
cutout = Cutout(path="odd_bounds", module="era5", time=TIME,
bounds=(X0-0.1, Y0-0.02, X1+0.03, Y1+0.13))
assert_equal(cutout.coords.to_dataset(), ref.coords.to_dataset())
def cutout_sarah(tmp_path_factory):
tmp_path = tmp_path_factory.mktemp("sarah")
cutout = Cutout(path=tmp_path / "sarah", module=["sarah", "era5"],
bounds=BOUNDS, time=TIME, sarah_dir=SARAH_DIR)
cutout.prepare()
return cutout
def test_time_sclice_coords(ref):
cutout = Cutout(path="time_slice", module="era5",
time=slice('2013-01-01', '2013-01-01'),
x=slice(X0, X1), y = slice(Y0, Y1))
assert_equal(cutout.coords.to_dataset(), ref.coords.to_dataset())
def test_compare_with_get_data_era5(cutout_era5, tmp_path):
"""
The prepared data should be exactly the same as from the low level function
"""
influx = atlite.datasets.era5.get_data(cutout_era5, 'influx', tmpdir=tmp_path)
assert_allclose(influx.influx_toa, cutout_era5.data.influx_toa, atol=1e-5, rtol=1e-5)
def test_compare_with_get_data_era5():
period = pd.Period(time)
influx = atlite.datasets.era5.get_data(ref.coords, period, 'influx', tmpdir=tmp_dir)
influx = influx.compute()
assert_allclose(influx.influx_toa, ref.data.influx_toa, atol=1e-5, rtol=1e-5)
def test_get_era5_data_in_sarah_module():
period = pd.Period(time)
influx = atlite.datasets.sarah.get_data_era5(ref.coords, period, 'influx',
tmpdir=tmp_dir, x=None, y=None, sarah_dir=None)
influx = influx.compute()
assert_allclose(influx.influx_toa, ref.data.influx_toa, atol=1e-5, rtol=1e-5)