Skip to content

Commit 5dca985

Browse files
authored
Merge pull request #211 from arbennett/cleanup/polar_latitudes
Cleanup/polar latitudes
2 parents e702ff2 + 556a3f1 commit 5dca985

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

docs/whats-new.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ What's New
55

66
.. _whats-new.2.2.0:
77

8+
v2.2.l
9+
------
10+
Bug fixes
11+
~~~~~~~~~
12+
- Fixed bug where timestamps got duplicated for sub-hourly
13+
disaggregation time periods
14+
- Fixed bug where polar latitudes caused error in setting
15+
the rise and set times for temperature disaggregation
16+
817
v2.2.0
918
-------
1019
Enhancements
1120
~~~~~~~~~~~~
12-
- Can now specify ``period_ending`` in the configuration to move
21+
- Can now specify ``period_ending`` in the configuration to move
1322
timestamps to end of period instead of beginning of period
1423
- Addition of tutorial in README.md and main documentation
1524
- Addition of paper to be submitted to JOSS

metsim/disaggregate.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

metsim/metsim.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,20 +421,14 @@ def run_slice(self):
421421
self.setup_output()
422422
times = self.met_data['time']
423423
params = self.params.copy()
424-
#
425-
# START OF FIX
426-
#
427-
# transform input parameters to floating point values (some parameters don't get teated as floats)
424+
# transform input parameters to floating point values
428425
params['sw_prec_thresh'] = float(params['sw_prec_thresh'])
429426
params['rain_scalar'] = float(params['rain_scalar'])
430427
params['tdew_tol'] = float(params['tdew_tol'])
431428
params['tmax_daylength_fraction'] = float(params['tmax_daylength_fraction'])
432429
params['tday_coef'] = float(params['tday_coef'])
433430
params['tmax_daylength_fraction'] = float(params['tmax_daylength_fraction'])
434431
params['lapse_rate'] = float(params['lapse_rate'])
435-
#
436-
# END OF FIX
437-
#
438432
for index, mask_val in np.ndenumerate(self.domain['mask'].values):
439433
if mask_val > 0:
440434
locs = {d: i for d, i in zip(self.domain['mask'].dims, index)}

0 commit comments

Comments
 (0)