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 098f956
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions sup3r/preprocessing/data_handlers/nc_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import os

import dask.array as da
import numpy as np
import pandas as pd
from scipy.spatial import KDTree
Expand Down Expand Up @@ -216,20 +215,17 @@ 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_ti = pd.to_datetime(cs_ghi[Dimension.TIME]).strftime('%m.%d')
target_ti = self.rasterizer.time_index.strftime('%m.%d')
cs_ghi[Dimension.TIME] = cs_ghi_ti
reindex = {Dimension.TIME: target_ti}
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 098f956

Please sign in to comment.