1818# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
2020import itertools
21+ import math
2122from typing import Tuple
2223
2324import numpy as np
@@ -62,6 +63,10 @@ def disaggregate(df_daily: pd.DataFrame, params: dict,
6263 df_disagg:
6364 A dataframe with sub-daily timeseries.
6465 """
66+ # adjust any longitude values to be within [-180, +180] range
67+ lon_var = params ['domain_vars' ]['lon' ]
68+ params [lon_var ] = math .remainder (params [lon_var ], 360 )
69+
6570 stop = (df_daily .index [- 1 ] + pd .Timedelta ('1 days' ) -
6671 pd .Timedelta ("{} minutes" .format (params ['time_step' ])))
6772 dates_disagg = date_range (df_daily .index [0 ], stop ,
@@ -71,6 +76,9 @@ def disaggregate(df_daily: pd.DataFrame, params: dict,
7176 n_days = len (df_daily )
7277 n_disagg = len (df_disagg )
7378 ts = int (params ['time_step' ])
79+ ### assume passthrough implies shortwave was computed using entire day not just daylight like mtclim uses to derive its shortwave
80+ if (params ['method' ] == 'passthrough' ) & (params .get ('sw_averaging' , '' ) != 'daylight' ):
81+ df_daily ['daylength' ] = 86400.0
7482 df_disagg ['shortwave' ] = shortwave (df_daily ['shortwave' ].values ,
7583 df_daily ['daylength' ].values ,
7684 df_daily .index .dayofyear ,
@@ -292,7 +300,7 @@ def prec_TRIANGLE(daily_prec, t_min, prec_peak, prec_dur, ts, do_mix):
292300 disagg_prec = np .zeros (int (n_days * ts_per_day ))
293301
294302 # Loop over days
295- for i , (t , P ) in enumerate (daily_prec .iteritems ()):
303+ for i , (t , P ) in enumerate (daily_prec .items ()):
296304
297305 if do_mix and t_min [t ] < 0 :
298306 prec_day = P * np .ones (ts_per_day ) / ts_per_day
@@ -637,7 +645,8 @@ def shortwave(sw_rad: np.array, daylength: np.array, day_of_year: np.array,
637645 if params ['method' ] == 'mtclim' or params .get ('sw_averaging' , '' ) == 'daylight' :
638646 tmp_rad = (sw_rad * daylength ) / (cnst .SEC_PER_HOUR * ts_hourly )
639647 else :
640- tmp_rad = sw_rad * 24
648+ ### if passthrough, still want to do this...but rather than using dailylight daylength uses entire day
649+ tmp_rad = (sw_rad * daylength ) / (cnst .SEC_PER_HOUR * ts_hourly ) #tmp_rad = sw_rad * 24
641650 n_days = len (tmp_rad )
642651 ts_per_day = int (cnst .HOURS_PER_DAY * cnst .MIN_PER_HOUR / ts )
643652 disaggrad = np .zeros (int (n_days * ts_per_day ))
0 commit comments