Skip to content

Commit

Permalink
map daily cs_ghi for a single year to arbitrary GCM time index using …
Browse files Browse the repository at this point in the history
…reindex function with month-day strings
  • Loading branch information
grantbuster committed Dec 13, 2024
1 parent 3697e29 commit 13b11dc
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions sup3r/preprocessing/data_handlers/nc_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,15 @@ def get_clearsky_ghi(self):
Dimension.FLATTENED_SPATIAL
)

# reindex to target time index using only months/days
# (year-independent), this will handle multiple years and leap days
cs_ghi['time'] = pd.to_datetime(cs_ghi['time']).strftime('%m.%d')
reindex = {'time': self.rasterizer.time_index.strftime('%m.%d')}
cs_ghi = cs_ghi.reindex(reindex)

cs_ghi = cs_ghi.transpose(*Dimension.dims_3d())
cs_ghi = cs_ghi['clearsky_ghi'].data

# concatenate multiple years, need to consider leap years explicitly
# so decadal timeseries dont get shifted
if cs_ghi.shape[-1] < len(self.rasterizer.time_index):
multi_year = []
for year in self.rasterizer.time_index.year.unique():
n = (self.rasterizer.time_index.year == year).sum()
multi_year.append(cs_ghi[..., :n])
cs_ghi = da.concatenate(multi_year, axis=-1)

cs_ghi = cs_ghi[..., :len(self.rasterizer.time_index)]

self.run_wrap_checks(cs_ghi)

return cs_ghi
Expand Down

0 comments on commit 13b11dc

Please sign in to comment.