Skip to content
Snippets Groups Projects
Select Git revision
  • ada9dab60cf357fe081e83c3c830d6d040ea638a
  • bing_issues#190_tf2
  • bing_tf2_convert
  • bing_issue#189_train_modular
  • simon_#172_integrate_weatherbench
  • develop
  • bing_issue#188_restructure_ambs
  • yan_issue#100_extract_prcp_data
  • bing_issue#170_data_preprocess_training_tf1
  • Gong2022_temperature_forecasts
  • bing_issue#186_clean_GMD1_tag
  • yan_issue#179_integrate_GZAWS_data_onfly
  • bing_issue#178_runscript_bug_postprocess
  • michael_issue#187_bugfix_setup_runscript_template
  • bing_issue#180_bugs_postprpocess_meta_postprocess
  • yan_issue#177_repo_for_CLGAN_gmd
  • bing_issue#176_integrate_weather_bench
  • michael_issue#181_eval_era5_forecasts
  • michael_issue#182_eval_subdomain
  • michael_issue#119_warmup_Horovod
  • bing_issue#160_test_zam347
  • ambs_v1
  • ambs_gmd_nowcasting_v1.0
  • GMD1
  • modular_booster_20210203
  • new_structure_20201004_v1.0
  • old_structure_20200930
27 results

prepare_era5_data.py

Blame
  • run_environment.py 1.79 KiB
    __author__ = "Lukas Leufen"
    __date__ = '2019-11-25'
    
    import logging
    import os
    import shutil
    import time
    
    from src.helpers import Logger
    from src.datastore import DataStoreByScope as DataStoreObject
    from src.datastore import NameNotFoundInDataStore
    from src.helpers import TimeTracking
    
    
    class RunEnvironment(object):
        """
        basic run class to measure execution time. Either call this class calling it by 'with' or delete the class instance
        after finishing the measurement. The duration result is logged.
        """
    
        del_by_exit = False
        data_store = DataStoreObject()
        logger = Logger()
    
        def __init__(self):
            """
            Starts time tracking automatically and logs as info.
            """
            self.time = TimeTracking()
            logging.info(f"{self.__class__.__name__} started")
    
        def __del__(self):
            """
            This is the class finalizer. The code is not executed if already called by exit method to prevent duplicated
            logging (__exit__ is always executed before __del__) it this class was used in a with statement.
            """
            if not self.del_by_exit:
                self.time.stop()
                logging.info(f"{self.__class__.__name__} finished after {self.time}")
                self.del_by_exit = True
            if self.__class__.__name__ == "RunEnvironment":
                try:
                    new_file = os.path.join(self.data_store.get("experiment_path", "general"), "logging.log")
                    shutil.copyfile(self.logger.log_file, new_file)
                except (NameNotFoundInDataStore, FileNotFoundError):
                    pass
                self.data_store.clear_data_store()
    
        def __enter__(self):
            return self
    
        def __exit__(self, exc_type, exc_val, exc_tb):
            self.__del__()
    
        @staticmethod
        def do_stuff(length=2):
            time.sleep(length)