@@ -78,6 +78,7 @@ def disaggregate(df_daily: pd.DataFrame, params: dict,
7878
7979 t_Tmin , t_Tmax = set_min_max_hour (solar_geom ['tiny_rad_fract' ],
8080 df_daily .index .dayofyear - 1 ,
81+ solar_geom ['daylength' ],
8182 n_days , ts , params )
8283
8384 df_disagg ['temp' ] = temp (
@@ -115,8 +116,8 @@ def disaggregate(df_daily: pd.DataFrame, params: dict,
115116 return df_disagg .fillna (method = 'ffill' ).fillna (method = 'bfill' )
116117
117118
118- def set_min_max_hour (tiny_rad_fract : np .array , yday : np .array , n_days : int ,
119- ts : int , params : dict ) -> Tuple [np .array ]:
119+ def set_min_max_hour (tiny_rad_fract : np .ndarray , yday : np .ndarray , daylength : np . ndarray ,
120+ n_days : int , ts : int , params : dict ) -> Tuple [np .ndarray ]:
120121 """
121122 Determine the time at which min and max temp
122123 is reached for each day.
@@ -147,34 +148,26 @@ def set_min_max_hour(tiny_rad_fract: np.array, yday: np.array, n_days: int,
147148 # calculate minute of sunrise and sunset for each day of the year
148149 rad_mask = 1 * (tiny_rad_fract > 0 )
149150 mask = np .diff (rad_mask )
150- #
151- # START OF FIX
152- #
151+
153152 # north of the polar circle radiation values of mask </> 0 are eleminated for
154153 # sunset/sunrise resulting in an array containing less than 365 days for one year
155154 rise_times = np .zeros (mask .shape [0 ])
156- for i , j in zip (np .where (mask > 0 )[0 ],np .where (mask > 0 )[1 ]):
155+ loc , mult = np .where (mask > 0 )
156+ for i , j in zip (loc , mult ):
157157 rise_times [i ] = j * (cnst .SW_RAD_DT / cnst .SEC_PER_MIN )
158+
158159 set_times = np .zeros (mask .shape [0 ])
159- for i , j in zip (np .where (mask < 0 )[0 ],np .where (mask < 0 )[1 ]):
160+ loc , mult = np .where (mask < 0 )
161+ for i , j in zip (loc , mult ):
160162 set_times [i ] = j * (cnst .SW_RAD_DT / cnst .SEC_PER_MIN )
161- for i in range (mask .shape [0 ]):
162- if rise_times [i ] == 0 :
163- if i in range (int (n_days / 2 - n_days / 4 ),int (n_days / 2 + n_days / 4 )):
164- rise_times [i ] = 0 * (cnst .SW_RAD_DT / cnst .SEC_PER_MIN )
165- else :
166- rise_times [i ] = (cnst .SEC_PER_DAY / cnst .SW_RAD_DT ) * (cnst .SW_RAD_DT / cnst .SEC_PER_MIN ) / 2
167- if set_times [i ] == 0 :
168- if not i in range (int (n_days / 2 - n_days / 4 ),int (n_days / 2 + n_days / 4 )):
169- set_times [i ] = (cnst .SEC_PER_DAY / cnst .SW_RAD_DT ) * (cnst .SW_RAD_DT / cnst .SEC_PER_MIN ) / 2
170- else :
171- set_times [i ] = (cnst .SEC_PER_DAY / cnst .SW_RAD_DT ) * (cnst .SW_RAD_DT / cnst .SEC_PER_MIN )
172- #
173- # END OF FIX
174- #
163+
164+ # Set rise and set times to be equally spaced when in polar region
165+ day_tot = ((cnst .SEC_PER_DAY / cnst .SW_RAD_DT )
166+ * (cnst .SW_RAD_DT / cnst .SEC_PER_MIN ))
167+ rise_times [rise_times == 0 ] = day_tot / 6
168+ set_times [set_times == 0 ] = 4 * day_tot / 6
175169
176170 if params ['utc_offset' ]:
177- # not used elsewhere:
178171 # rad_fract_per_day = int(cnst.SEC_PER_DAY/cnst.SW_RAD_DT)
179172 utc_offset = int (((params .get ("lon" , 0 ) - params .get ("theta_s" , 0 )) /
180173 cnst .DEG_PER_REV ) * cnst .MIN_PER_DAY )
0 commit comments