Skip to content
Snippets Groups Projects
Commit 895c81e8 authored by Felix Kleinert's avatar Felix Kleinert
Browse files

move abstract b2share to abstract file

parent 21565c00
No related branches found
No related tags found
3 merge requests!253include current develop,!252Resolve "release v1.3.0",!229Resolve "Make IntelliO3-ts v1.0 available as reference"
Pipeline #58495 passed with warnings
...@@ -2,8 +2,13 @@ __author__ = "Felix Kleinert" ...@@ -2,8 +2,13 @@ __author__ = "Felix Kleinert"
__date__ = "2021-01-29" __date__ = "2021-01-29"
import os import os
import sys
from abc import ABC from abc import ABC
import wget
from mlair.configuration import check_path_and_create
class AbstractReferenceModel(ABC): class AbstractReferenceModel(ABC):
""" """
...@@ -30,3 +35,30 @@ class AbstractReferenceModel(ABC): ...@@ -30,3 +35,30 @@ class AbstractReferenceModel(ABC):
res = False res = False
return res return res
class AbstractReferenceb2share(AbstractReferenceModel):
"""
Abstract class for reference models located on b2share (eudat or fz-juelich)
See also https://github.com/EUDAT-Training/B2SHARE-Training/blob/master/api/01_Retrieve_existing_record.md
"""
def __init__(self, b2share_hosturl: str, b2share_bucket: str, b2share_key: str):
super().__init__()
self.b2share_hosturl = b2share_hosturl
self.b2share_bucket = b2share_bucket
self.b2share_key = b2share_key
@property
def b2share_url(self):
return f"{self.b2share_hosturl}/api/files/{self.b2share_bucket}"
def bar_custom(self, current, total, width=80):
progress_message = f"Downloading {self.b2share_key}: {round(current / total * 100)}% [{current} / {total}] bytes"
sys.stdout.write("\r" + progress_message)
sys.stdout.flush()
def download_from_b2share(self, tmp_download_path: str):
check_path_and_create(tmp_download_path)
wget.download(f"{self.b2share_url}/{self.b2share_key}",
out=f"{tmp_download_path}{self.b2share_key}",
bar=self.bar_custom)
\ No newline at end of file
...@@ -8,40 +8,10 @@ __date__ = "2021-01-29" ...@@ -8,40 +8,10 @@ __date__ = "2021-01-29"
import os import os
import xarray as xr import xarray as xr
import wget
import sys
import shutil import shutil
from mlair.configuration.path_config import check_path_and_create from mlair.configuration.path_config import check_path_and_create
from mlair.reference_data_handler.abstract_reference_data_handler import AbstractReferenceModel from mlair.reference_data_handler.abstract_reference_data_handler import AbstractReferenceb2share
class AbstractReferenceb2share(AbstractReferenceModel):
"""
Abstract class for reference models located on b2share (eudat or fz-juelich)
See also https://github.com/EUDAT-Training/B2SHARE-Training/blob/master/api/01_Retrieve_existing_record.md
"""
def __init__(self, b2share_hosturl: str, b2share_bucket: str, b2share_key: str):
super().__init__()
self.b2share_hosturl = b2share_hosturl
self.b2share_bucket = b2share_bucket
self.b2share_key = b2share_key
@property
def b2share_url(self):
return f"{self.b2share_hosturl}/api/files/{self.b2share_bucket}"
def bar_custom(self, current, total, width=80):
progress_message = f"Downloading {self.b2share_key}: {round(current / total * 100)}% [{current} / {total}] bytes"
sys.stdout.write("\r" + progress_message)
sys.stdout.flush()
def download_from_b2share(self, tmp_download_path: str):
check_path_and_create(tmp_download_path)
wget.download(f"{self.b2share_url}/{self.b2share_key}",
out=f"{tmp_download_path}{self.b2share_key}",
bar=self.bar_custom)
class IntelliO3Reference(AbstractReferenceb2share): class IntelliO3Reference(AbstractReferenceb2share):
...@@ -107,7 +77,7 @@ class IntelliO3Reference(AbstractReferenceb2share): ...@@ -107,7 +77,7 @@ class IntelliO3Reference(AbstractReferenceb2share):
data.coords['type'] = (self.ref_name) data.coords['type'] = (self.ref_name)
data.to_netcdf(f"{self.ref_store_path}{infile}") data.to_netcdf(f"{self.ref_store_path}{infile}")
def make_reference_available_locally(self): def make_reference_available_locally(self, remove_tmp_dir: bool = True):
""" """
:return: :return:
...@@ -118,6 +88,7 @@ class IntelliO3Reference(AbstractReferenceb2share): ...@@ -118,6 +88,7 @@ class IntelliO3Reference(AbstractReferenceb2share):
self.download_from_b2share(tmp_download_path=self.tmp_extract_path) self.download_from_b2share(tmp_download_path=self.tmp_extract_path)
self.untar_forecasts() self.untar_forecasts()
self.read_and_drop() self.read_and_drop()
if remove_tmp_dir:
shutil.rmtree(self.tmp_extract_path) shutil.rmtree(self.tmp_extract_path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment