1
1
from typing import Union
2
2
from time import process_time
3
-
3
+ from datetime import datetime
4
4
import numpy as np
5
5
import rasters as rt
6
6
from rasters import Raster , RasterGeometry
7
7
from geos5fp import GEOS5FP
8
+ from solar_apparent_time import solar_day_of_year_for_area , solar_hour_of_day_for_area
8
9
from sun_angles import calculate_SZA_from_DOY_and_hour
9
10
from koppengeiger import load_koppen_geiger
10
11
14
15
from .run_FLiES_ANN_inference import run_FLiES_ANN_inference
15
16
16
17
def process_FLiES_ANN (
17
- day_of_year : Union [Raster , np .ndarray ],
18
- hour_of_day : Union [Raster , np .ndarray ],
19
18
albedo : Union [Raster , np .ndarray ],
20
19
COT : Union [Raster , np .ndarray ] = None ,
21
20
AOT : Union [Raster , np .ndarray ] = None ,
@@ -25,8 +24,11 @@ def process_FLiES_ANN(
25
24
SZA : Union [Raster , np .ndarray ] = None ,
26
25
KG_climate : Union [Raster , np .ndarray ] = None ,
27
26
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 ,
28
30
GEOS5FP_connection : GEOS5FP = None ,
29
- GEOS5FP_directory : str = None ,
31
+ resampling : str = "cubic" ,
30
32
ANN_model = None ,
31
33
model_filename = DEFAULT_MODEL_FILENAME ,
32
34
split_atypes_ctypes = SPLIT_ATYPES_CTYPES ) -> dict :
@@ -82,6 +84,16 @@ def process_FLiES_ANN(
82
84
if geometry is None and isinstance (albedo , Raster ):
83
85
geometry = albedo .geometry
84
86
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
+
85
97
## FIXME need to fetch default values for parameters: COT, AOT, vapor_gccm, ozone_cm, elevation_km, SZA, KG_climate
86
98
87
99
if SZA is None and geometry is not None :
@@ -101,6 +113,34 @@ def process_FLiES_ANN(
101
113
if KG_climate is None :
102
114
raise ValueError ("Koppen Geieger climate classification or geometry must be given" )
103
115
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
+
104
144
# Preprocess COT and determine aerosol/cloud types
105
145
COT = np .clip (COT , 0 , None ) # Ensure COT is non-negative
106
146
COT = rt .where (COT < 0.001 , 0 , COT ) # Set very small COT values to 0
0 commit comments