NatLabRockies / NatLabRockies/rdtools
Method for estimating ambient temperature from measured GHI and clear sky conditions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 189
- Forks
- 82
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem? Please describe.
In my experience, the SURFRAD datasets were missing a lot of air temperature measurements so I needed a way to estimate ambient air temperature when working SURFRAD data on https://github.com/mikofski/PVRW2021
Describe the solution you'd like
What I did was to scale the clear sky air temps from rdtools using the ratio of total daily measured GHI to total daily clear sky GHI according to this formula:

which is expressed in this function:estimate_air_temp
def estimate_air_temp(year_start, surfrad, lat, lon, cs):
"""
Use clear sky temps scaled by daily ratio of measured to clear sky global
insolation.
Parameters
----------
year_start : str
SURFRAD data year
surfrad : pandas.DateFrame
surfrad data frame
lat : float
latitude in degrees north of equator [deg]
lon : float
longitude in degrees east of prime meridian [deg]
cs : pandas.DataFrame
clear sky irradiances [W/m^2]
Returns
-------
est_air_temp : pandas.DataFrame
estimated air temperature in Celsius [C]
temp_adj : pandas.Series
temperature adjustment [C}
ghi_ratio : pandas.Series
ratio of daily SURFRAD to clearsky GHI insolation
daily_delta_temp : numpy.array
daily temperature range, max - min, in Kelvin [K]
cs_temp_air : pandas.Series
clear sky air temperatures in Celsius [C]
"""
daze = 367 if calendar.isleap(int(year_start)) else 366
# create a leap year of minutes for the given year at UTC
year_minutes = pd.date_range(
start=year_start, freq='T', periods=daze*DAYMINUTES, tz='UTC')
# clear sky temperature
cs_temp_air = rdtools.clearsky_temperature.get_clearsky_tamb(
year_minutes, lat, lon)
# organize by day
cs_temp_daily = cs_temp_air.values.reshape((daze, DAYMINUTES)) + KELVINS
# get daily temperature range
daily_delta_temp = np.array([td.max()-td.min() for td in cs_temp_daily])
daily_delta_temp = pd.Series(
daily_delta_temp, index=cs_temp_air.resample('D').mean().index)
# calculate ratio of daily insolation versus clearsky
ghi_ratio = surfrad.ghi.resample('D').sum() / cs.ghi.resample('D').sum()
ghi_ratio = ghi_ratio.rename('ghi_ratio')
# apply ghi ratio to next day, wrap days to start at day 1
day1 = ghi_ratio.index[0]
ghi_ratio.index = ghi_ratio.index + to_offset('1D')
# set day 1 estimated air temp equal to last day
ghi_ratio[day1] = ghi_ratio.iloc[-1]
# fix day 1 is added last, so out of order
ghi_ratio = ghi_ratio.sort_index()
# scale daily temperature delta by the ratio of insolation from day before
temp_adj = (ghi_ratio - 1.0)*daily_delta_temp[ghi_ratio.index] # use next day
temp_adj = temp_adj.rename('temp_adj')
# interpolate smoothly, but fill forward minutes in last day
est_air_temp = pd.concat(
[cs_temp_air,
ghi_ratio.resample('1min').interpolate(),
temp_adj.resample('1min').interpolate()], axis=1).pad()
# Tadj = Tcs + (GHI/CS_GHI - 1) * DeltaT
# if GHI/CS_GHI > 1 then adjustment > DeltaT
est_air_temp['Adjusted Temp (C)'] = (
est_air_temp['Clear Sky Temperature (C)'] + est_air_temp.temp_adj)
return est_air_temp, temp_adj, ghi_ratio, daily_delta_temp, cs_temp_air
Describe alternatives you've considered
- back fill the missing air temp data in the SURFRAD datasets
- Check in ERA or MERRA or somewhere else
- just use the ambient temperature in the SURFRAD data and don't worry about missing data
Additional context
I've already implemented this in the PVRW2021 repo above, and if you look near the bottom of this notebook: multiyear_data.ipynb you can see what the temperatures look like compared to GHI and clear sky conditions:
for 1st week in January:
blue = Tclearsky, green = Tadj, red = clear sky GHI, orange = GHI

for last week in December:
blue = Tclearsky, green = Tadj, red = clear sky GHI, orange = GHI

Sorry for lack of legend and axes, they're there but I can't change the transparent background. To me this looks like it's working as expected. If the day has higher GHI then clear sky, then the ambient air temp is higher than clear sky, and v. v. Also the temperature curve is smooth.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked estimate_air_temp implementation in PVRW2021/multiyear_data.py and the corresponding section of multiyear_data.ipynb, then inspect rdtools.clearsky_temperature.get_clearsky_tamb. The issue does not name an rdtools entry point or tests; done should include a defined integration point and validation of the estimated temperature against the described GHI and clear-sky inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100