Coverage for aixweather/definitions.py: 93%

15 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2025-12-31 11:58 +0000

1""" 

2This module includes variables or functions which define central variables for the whole project. 

3""" 

4 

5import os 

6 

7 

8class CoreDataFormat: 

9 """ 

10 Information on core data: 

11 Time of measurement is always at the indicated time. 

12 Units as in TMY3 https://www.nrel.gov/docs/fy08osti/43156.pdf 

13 Only exception to TMY3 format is pressure, as all TMY3 data file 

14 actually use "Pa" instead of mbar 

15 """ 

16 format: dict = { 

17 "DryBulbTemp": {"unit": "degC"}, 

18 "DewPointTemp": {"unit": "degC"}, 

19 "RelHum": {"unit": "percent"}, 

20 "ExtHorRad": {"unit": "Wh/m2"}, 

21 "ExtDirNormRad": {"unit": "Wh/m2"}, 

22 "HorInfra": {"unit": "Wh/m2"}, 

23 "GlobHorRad": {"unit": "Wh/m2"}, 

24 "DirNormRad": {"unit": "Wh/m2"}, 

25 "DirHorRad": {"unit": "Wh/m2"}, 

26 "DiffHorRad": {"unit": "Wh/m2"}, 

27 "GlobHorIll": {"unit": "lux"}, 

28 "DirecNormIll": {"unit": "lux"}, 

29 "DiffuseHorIll": {"unit": "lux"}, 

30 "ZenithLum": {"unit": "Cd/m2"}, 

31 "WindDir": {"unit": "deg"}, 

32 "WindSpeed": {"unit": "m/s"}, 

33 "TotalSkyCover": {"unit": "1tenth"}, 

34 "OpaqueSkyCover": {"unit": "1tenth"}, 

35 "Visibility": {"unit": "km"}, 

36 "CeilingH": {"unit": "m"}, 

37 "PrecWater": {"unit": "mm"}, 

38 "Aerosol": {"unit": "1thousandth"}, 

39 "LiquidPrecD": {"unit": "mm/h"}, 

40 # exception to TMY3 format as all TMY3 data file actually use "Pa" instead of mbar 

41 "AtmPressure": {"unit": "Pa"}, 

42 # additional variables 

43 "Soil_Temperature_5cm": {"unit": "degC"}, 

44 "Soil_Temperature_10cm": {"unit": "degC"}, 

45 "Soil_Temperature_20cm": {"unit": "degC"}, 

46 "Soil_Temperature_50cm": {"unit": "degC"}, 

47 "Soil_Temperature_1m": {"unit": "degC"}, 

48 } 

49 

50 

51format_core_data = CoreDataFormat.format 

52 

53# creates the path to the root directory to be used in other modules 

54ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), "..")) 

55 

56# local temporary folder 

57local_folder_temp = os.path.join(ROOT_DIR, "temp_local") 

58 

59 

60def result_folder_path() -> str: 

61 """ 

62 Creates the path to the resultsfolder. 

63 """ 

64 folder_path = os.path.join(f"{ROOT_DIR}", "results") 

65 return folder_path 

66 

67 

68def results_file_path(filename: str, folder_path: str = None) -> str: 

69 """ 

70 create a path to a results file 

71 

72 Args: 

73 filename: name of file 

74 folder_path: path to result folder 

75 

76 Returns: 

77 str: path to result file 

78 """ 

79 # if required specify folder_path e.g. for Django WebApp 

80 if folder_path is None: 

81 folder_path = result_folder_path() 

82 

83 # Ensure that the results folder exists 

84 os.makedirs(folder_path, exist_ok=True) 

85 

86 # create file path 

87 filepath = os.path.join(folder_path, filename) 

88 return filepath