Skip to content

Commit

Permalink
Merge pull request #176 from NREL/sp/fix_clearsky
Browse files Browse the repository at this point in the history
fix get_clearsky_ghi function to use correct time slice
  • Loading branch information
spodgorny9 authored Nov 13, 2023
2 parents a7eeb09 + 6dbb29a commit b24736f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions sup3r/preprocessing/data_handling/nc_data_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,11 @@ def get_clearsky_ghi(self):
ti_deltas = ti_nsrdb - np.roll(ti_nsrdb, 1)
ti_deltas_hours = pd.Series(ti_deltas).dt.total_seconds()[1:-1] / 3600
time_freq = float(mode(ti_deltas_hours).mode)
t_start = self.temporal_slice.start or 0
t_end_target = self.temporal_slice.stop or len(self.raw_time_index)
t_start = int(t_start * 24 * (1 / time_freq))
t_end = int(t_end_target * 24 * (1 / time_freq))
t_end = np.minimum(t_end, len(ti_nsrdb))
t_start = np.where((self.time_index[0].month == ti_nsrdb.month)
& (self.time_index[0].day == ti_nsrdb.day))[0][0]
t_end = 1 + np.where(
(self.time_index[-1].month == ti_nsrdb.month)
& (self.time_index[-1].day == ti_nsrdb.day))[0][-1]
t_slice = slice(t_start, t_end)

# pylint: disable=E1136
Expand Down Expand Up @@ -685,16 +685,20 @@ def get_clearsky_ghi(self):
self._nsrdb_smoothing,
mode='nearest')

if cs_ghi.shape[-1] < t_end_target:
n = int(np.ceil(t_end_target / cs_ghi.shape[-1]))
if cs_ghi.shape[-1] < len(self.time_index):
n = int(np.ceil(len(self.time_index) / cs_ghi.shape[-1]))
cs_ghi = np.repeat(cs_ghi, n, axis=2)
cs_ghi = cs_ghi[..., :t_end_target]
cs_ghi = cs_ghi[..., :len(self.time_index)]

logger.info(
'Reshaped clearsky_ghi data to final shape {} to '
'correspond with CC daily average data over source '
'temporal_slice {} with (lat, lon) grid shape of {}'.format(
cs_ghi.shape, self.temporal_slice, self.grid_shape))
msg = ('nsrdb clearsky GHI time dimension {}'
'does not match the GCM time dimension {}'
.format(cs_ghi.shape[2], len(self.time_index)))
assert cs_ghi.shape[2] == len(self.time_index), msg

return cs_ghi

Expand Down

0 comments on commit b24736f

Please sign in to comment.