Example #1
0
def cutout_era5_reduced(tmp_path_factory):
    tmp_path = tmp_path_factory.mktemp("era5_red")
    cutout = Cutout(path=tmp_path / "era5",
                    module="era5",
                    bounds=BOUNDS,
                    time=TIME)
    return cutout
Example #2
0
def test_transform():
    """Test the affine transform. It always has to point to cell origin."""
    cutout = Cutout(path="resolution", module="era5",
                    time=slice('2013-01-01', '2013-01-01'),
                    x=slice(X0, X1), y = slice(Y0, Y1))
    assert cutout.transform * (0.5, 0.5) == (X0, Y0)
    assert cutout.transform * cutout.shape[::-1] == (X1 + cutout.dx/2,
                                                     Y1 + cutout.dy/2)
Example #3
0
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())
Example #4
0
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())
Example #5
0
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)
Example #6
0
def test_dx_dy_dt():
    """
    Test the properties dx, dy, dt of atlite.Cutout. The spatial resolution
    can be changed through the creation_params dx and dy, the time resolution
    is hard coded (deep in the modules...) to one hour.
    """
    dx = 0.5
    dy = 1
    cutout = Cutout(path="resolution", module="era5",
                    time=slice('2013-01-01', '2013-01-01'),
                    x=slice(X0, X1), y = slice(Y0, Y1),
                    dx=dx, dy=dy)
    assert dx == cutout.dx
    assert dy == cutout.dy
    assert 'H' == cutout.dt
Example #7
0
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)
Example #8
0
countrynames = pd.DataFrame(Package(
    'https://raw.githubusercontent.com/datasets/country-codes/5b645f4ea861be1362539d06641e5614353c9895/datapackage.json'
    ).get_resource('country-codes').read(keyed=True)).set_index(['official_name_en'])\
    ['ISO3166-1-Alpha-2'].to_dict()

hyd = pd.read_csv(os.path.join( config['directories']['archive'], 'EIA-annual-hydro-generation.csv'),
        skiprows=4, index_col=1
    ).drop(['Unnamed: 0', 'Unnamed: 2'], axis=1).dropna().loc[:, str(year)]
hyd = hyd.rename(index={'Czech Republic': 'Czechia'}).\
    rename(index=countrynames).T
hyd *= 1e3  # billion kWh -> MWh


path = building.download_data('sftp://5.35.252.104/home/rutherford/atlite/cutouts/eu-2015.zip',
                              username='******', unzip_file='eu-2015/')
inflows = Cutout(cutout_dir='cache/eu-2015', name='eu-2015').\
    runoff(shapes=nuts0).to_pandas().T

inflows = inflows * (hyd / inflows.sum())

technologies = pd.DataFrame(
    Package('https://raw.githubusercontent.com/ZNES-datapackages/technology-cost/features/add-2015-data/datapackage.json')
    .get_resource('electricity').read(keyed=True)).set_index(
        ['year', 'carrier', 'tech', 'parameter'])

ror_shares = pd.read_csv(
    os.path.join(
        config['directories']['archive'], 'ror_ENTSOe_Restore2050.csv'),
    index_col='Country Code (ISO 3166-1)')['ror ENTSO-E\n+ Restore']

capacities = pd.read_csv(building.download_data(
    'https://zenodo.org/record/804244/files/hydropower.csv?download=1'),
Example #9
0
def wrong_recreation(cutout):
    with pytest.warns(UserWarning):
        Cutout(path=cutout.path, module='somethingelse')
Example #10
0
def test_xy_reversed_coords(ref):
    cutout = Cutout(path="xy_r", module="era5", time=TIME,
                    x=slice(X1, X0), y = slice(Y1, Y0))
    assert_equal(cutout.coords.to_dataset(), ref.coords.to_dataset())
Example #11
0
def test_xy_coords(ref):
    cutout = Cutout(path="xy", module="era5", time=TIME,
                    x=slice(X0, X1), y = slice(Y0, Y1))
    assert_equal(cutout.coords.to_dataset(), ref.coords.to_dataset())
Example #12
0
def ref():
    return Cutout(path="creation_ref", module="era5", bounds=(X0, Y0, X1, Y1), time=TIME)