Completed
Push — dev ( 82307e...8f1350 )
by
unknown
35s queued 24s
created

data.datasets.data_bundle.DataBundle.__init__()   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 12
rs 9.8
c 0
b 0
f 0
cc 1
nop 2
1
"""The central module containing all code dealing with small scale input-data
2
"""
3
4
5
from pathlib import Path
6
from urllib.request import urlretrieve
7
import shutil
8
import zipfile
9
10
from egon.data import config
11
from egon.data.datasets import Dataset
12
13
14 View Code Duplication
def download():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
15
    """
16
    Download small scale input data from Zenodo
17
    Parameters
18
    ----------
19
20
    """
21
    data_bundle_path = Path(".") / "data_bundle_egon_data"
22
    # Delete folder if it already exists
23
    if data_bundle_path.exists() and data_bundle_path.is_dir():
24
        shutil.rmtree(data_bundle_path)
25
    # Get parameters from config and set download URL
26
    sources = config.datasets()["data-bundle"]["sources"]["zenodo"]
27
    url = (
28
        f"https://zenodo.org/record/{sources['deposit_id']}/files/"
29
        "data_bundle_egon_data.zip"
30
    )
31
    target_file = config.datasets()["data-bundle"]["targets"]["file"]
32
33
    # check if file exists
34
    if not Path(target_file).exists():
35
        # Retrieve files
36
        urlretrieve(url, target_file)
37
38
    with zipfile.ZipFile(target_file, "r") as zip_ref:
39
        zip_ref.extractall(".")
40
41
42
class DataBundle(Dataset):
43
    def __init__(self, dependencies):
44
        deposit_id = config.datasets()["data-bundle"]["sources"][
45
            "zenodo"
46
        ]["deposit_id"]
47
        deposit_id_powerd = config.datasets()["data-bundle"]["sources"][
48
            "zenodo"
49
        ]["deposit_id"]
50
        super().__init__(
51
            name="DataBundle",
52
            version=f"{deposit_id}-{deposit_id_powerd}-0.0.3",
53
            dependencies=dependencies,
54
            tasks=(download,),
55
        )
56