From 578e48be595ea2efaf57cd40aab9335b67e9e6d4 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Tue, 27 Aug 2019 16:01:31 +0200 Subject: [PATCH] Added download benchmark --- conf/hermes.conf | 14 ++--- hermesv3_bu/tools/__init__.py | 0 hermesv3_bu/tools/download_benchmark.py | 84 +++++++++++++++++++++++++ setup.py | 1 + 4 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 hermesv3_bu/tools/__init__.py create mode 100755 hermesv3_bu/tools/download_benchmark.py diff --git a/conf/hermes.conf b/conf/hermes.conf index 683290f..0858957 100755 --- a/conf/hermes.conf +++ b/conf/hermes.conf @@ -2,14 +2,14 @@ log_level = 3 input_dir = /home/Earth/ctena/Models/hermesv3_bu_data data_path = /esarchive/recon -output_dir = /scratch/Earth/HERMESv3_BU_OUT/serial -output_name = HERMESv3__traffic_area.nc +output_dir = /scratch/Earth/HERMESv3_BU_OUT/parallel +output_name = HERMESv3__residential.nc emission_summary = 0 start_date = 2016/11/29 00:00:00 # ----- end_date = start_date [DEFAULT] ----- # end_date = 2010/01/01 00:00:00 output_timestep_num = 24 -auxiliary_files_path = /scratch/Earth/HERMESv3_BU_aux/_ +auxiliary_files_path = /scratch/Earth/HERMESv3_BU_aux/parallel/_ erase_auxiliary_files = 0 @@ -69,7 +69,7 @@ vertical_description = /profiles/vertical/MONARCH_Global_48layers_ver #ny = 398 #inc_x = 12000 #inc_y = 12000 - #x_0 = -2131849.000 + #x_0 = -2131849.000point_sources #y_0 = -2073137.875 # IP @@ -88,7 +88,7 @@ vertical_description = /profiles/vertical/MONARCH_Global_48layers_ver #x_0 = -142848.422 #y_0 = -20137.891 -# if domain_type == mercator: +# if domain_type == mercator:point_sources # lat_ts = -1.5 # lon_0 = -18 # nx = 10 @@ -136,11 +136,11 @@ livestock_processors = 0 crop_operations_processors = 0 crop_fertilizers_processors = 0 agricultural_machinery_processors = 0 -residential_processors = 0 +residential_processors = 2 recreational_boats_processors = 0 point_sources_processors = 0 traffic_processors = 0 -traffic_area_processors = 1 +traffic_area_processors = 0 [SHAPEFILES] diff --git a/hermesv3_bu/tools/__init__.py b/hermesv3_bu/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hermesv3_bu/tools/download_benchmark.py b/hermesv3_bu/tools/download_benchmark.py new file mode 100755 index 0000000..90b949e --- /dev/null +++ b/hermesv3_bu/tools/download_benchmark.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +import sys +import os + + +def query_yes_no(question, default="yes"): + valid = {"yes": True, "y": True, "1": True, 1: True, + "no": False, "n": False, "0": False, 0: False} + if default is None: + prompt = " [y/n] " + elif default == "yes": + prompt = " [Y/n] " + elif default == "no": + prompt = " [y/N] " + else: + raise ValueError("invalid default answer: '%s'" % default) + + while True: + sys.stdout.write(question + prompt) + choice = input().lower() + if default is not None and choice == '': + return valid[default] + elif choice in valid: + return valid[choice] + else: + sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n") + + +def check_args(args, exe_str): + if len(args) == 0: + print("Missing destination path after '{0}'. e.g.:".format(exe_str) + + "\n\t{0} /home/user/HERMESv3_BU".format(exe_str)) + sys.exit(1) + elif len(args) > 1: + print("Too much arguments through '{0}'. Only destination path is needed e.g.:".format(exe_str) + + "\n\t{0} /home/user/HERMESv3_BU".format(exe_str)) + sys.exit(1) + else: + dir_path = args[0] + + if not os.path.exists(dir_path): + if query_yes_no("'{0}' does not exist. Do you want to create it? ".format(dir_path)): + os.makedirs(dir_path) + else: + sys.exit(0) + + return dir_path + + +def download_files(parent_path): + from ftplib import FTP + + ftp = FTP('bscesftp.bsc.es') + ftp.login() + dst_file = os.path.join(parent_path, 'HERMESv3_BU_Benchmark.zip') + + ftp.retrbinary('RETR HERMESv3_BU_Benchmark.zip', open(dst_file, 'wb').write) + + ftp.quit() + + return dst_file + + +def unzip_files(zippath, parent_path): + import zipfile + + zip_file = zipfile.ZipFile(zippath, 'r') + zip_file.extractall(parent_path) + zip_file.close() + os.remove(zippath) + + +def download_benchmark(): + argv = sys.argv[1:] + + parent_dir = check_args(argv, 'hermesv3_bu_download_benchmark') + + zippath = download_files(parent_dir) + unzip_files(zippath, parent_dir) + + +if __name__ == '__main__': + download_benchmark() diff --git a/setup.py b/setup.py index 4159598..9524d79 100755 --- a/setup.py +++ b/setup.py @@ -59,6 +59,7 @@ setup( entry_points={ 'console_scripts': [ 'hermesv3_bu = hermesv3_bu.hermes:run', + 'hermesv3_bu_download_benchmark = hermesv3_bu.tools.download_benchmark:download_benchmark', ], }, ) \ No newline at end of file -- GitLab