11from typing import Union
22from time import process_time
3-
3+ from datetime import datetime
44import numpy as np
55import rasters as rt
66from rasters import Raster , RasterGeometry
77from geos5fp import GEOS5FP
8+ from solar_apparent_time import solar_day_of_year_for_area , solar_hour_of_day_for_area
89from sun_angles import calculate_SZA_from_DOY_and_hour
910from koppengeiger import load_koppen_geiger
1011
1415from .run_FLiES_ANN_inference import run_FLiES_ANN_inference
1516
1617def process_FLiES_ANN (
17- day_of_year : Union [Raster , np .ndarray ],
18- hour_of_day : Union [Raster , np .ndarray ],
1918 albedo : Union [Raster , np .ndarray ],
2019 COT : Union [Raster , np .ndarray ] = None ,
2120 AOT : Union [Raster , np .ndarray ] = None ,
@@ -25,8 +24,11 @@ def process_FLiES_ANN(
2524 SZA : Union [Raster , np .ndarray ] = None ,
2625 KG_climate : Union [Raster , np .ndarray ] = None ,
2726 geometry : RasterGeometry = None ,
27+ time_UTC : datetime = None ,
28+ day_of_year : Union [Raster , np .ndarray ] = None ,
29+ hour_of_day : Union [Raster , np .ndarray ] = None ,
2830 GEOS5FP_connection : GEOS5FP = None ,
29- GEOS5FP_directory : str = None ,
31+ resampling : str = "cubic" ,
3032 ANN_model = None ,
3133 model_filename = DEFAULT_MODEL_FILENAME ,
3234 split_atypes_ctypes = SPLIT_ATYPES_CTYPES ) -> dict :
@@ -82,6 +84,16 @@ def process_FLiES_ANN(
8284 if geometry is None and isinstance (albedo , Raster ):
8385 geometry = albedo .geometry
8486
87+ if (day_of_year is None or hour_of_day is None ) and time_UTC is not None and geometry is not None :
88+ day_of_year = solar_day_of_year_for_area (time_UTC = time_UTC , geometry = geometry )
89+ hour_of_day = solar_hour_of_day_for_area (time_UTC = time_UTC , geometry = geometry )
90+
91+ if time_UTC is None and day_of_year is None and hour_of_day is None :
92+ raise ValueError ("no time given between time_UTC, day_of_year, and hour_of_day" )
93+
94+ if GEOS5FP_connection is None :
95+ GEOS5FP_connection = GEOS5FP (working_directory = DEFAULT_WORKING_DIRECTORY , download_directory = GEOS5FP_DIRECTORY )
96+
8597 ## FIXME need to fetch default values for parameters: COT, AOT, vapor_gccm, ozone_cm, elevation_km, SZA, KG_climate
8698
8799 if SZA is None and geometry is not None :
@@ -101,6 +113,34 @@ def process_FLiES_ANN(
101113 if KG_climate is None :
102114 raise ValueError ("Koppen Geieger climate classification or geometry must be given" )
103115
116+ if COT is None and geometry is not None and time_UTC is not None :
117+ COT = GEOS5FP_connection .COT (
118+ time_UTC = time_UTC ,
119+ geometry = geometry ,
120+ resampling = resampling
121+ )
122+
123+ if AOT is None and geometry is not None and time_UTC is not None :
124+ AOT = GEOS5FP_connection .AOT (
125+ time_UTC = time_UTC ,
126+ geometry = geometry ,
127+ resampling = resampling
128+ )
129+
130+ if vapor_gccm is None and geometry is not None and time_UTC is not None :
131+ vapor_gccm = GEOS5FP_connection .vapor_gccm (
132+ time_UTC = time_UTC ,
133+ geometry = geometry ,
134+ resampling = resampling
135+ )
136+
137+ if ozone_cm is None and geometry is not None and time_UTC is not None :
138+ ozone_cm = GEOS5FP_connection .ozone_cm (
139+ time_UTC = time_UTC ,
140+ geometry = geometry ,
141+ resampling = resampling
142+ )
143+
104144 # Preprocess COT and determine aerosol/cloud types
105145 COT = np .clip (COT , 0 , None ) # Ensure COT is non-negative
106146 COT = rt .where (COT < 0.001 , 0 , COT ) # Set very small COT values to 0
0 commit comments