Skip to content

Commit

Permalink
DuraMAT Live Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-springer committed Sep 27, 2023
1 parent c017e46 commit db6d586
Show file tree
Hide file tree
Showing 8 changed files with 921 additions and 928 deletions.
14 changes: 7 additions & 7 deletions pvdeg/fatigue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def _avg_daily_temp_change(time_range, temp_cell):
Average of Daily Maximum Temperature for 1-year (Celsius)
"""

if time_range.dtype == 'object':
time_range = pd.to_datetime(time_range)

# Setup frame for vector processing
timeAndTemp_df = pd.DataFrame(columns=['Cell Temperature'])
timeAndTemp_df['Cell Temperature'] = temp_cell
Expand Down Expand Up @@ -111,7 +111,7 @@ def solder_fatigue(weather_df, meta,
This function uses the default values for 60-min input intervals from Table 4 of the above
paper. For other use cases, please refer to the paper for recommended values of C1 and
the reversal temperature.
Parameters
------------
weather_df : pd.dataframe
Expand Down Expand Up @@ -143,9 +143,9 @@ def solder_fatigue(weather_df, meta,
"""

# TODO this, and many other functions with temp_cell or temp_module would benefit from an
# TODO this, and many other functions with temp_cell or temp_module would benefit from an
# optional parameter "conf = 'open_rack_glass_glass' or equivalent"

# TODO Make this function have more utility.
# People want to run all the scenarios from the bosco paper.
# Currently have everything hard coded for hourly calculation
Expand All @@ -158,10 +158,10 @@ def solder_fatigue(weather_df, meta,

if time_range is None:
time_range = weather_df.index

if temp_cell is None:
temp_cell = temperature.cell(weather_df, meta)

temp_amplitude, temp_max_avg = _avg_daily_temp_change(time_range, temp_cell)

temp_max_avg = convert_temperature(temp_max_avg, 'Celsius', 'Kelvin')
Expand Down
75 changes: 60 additions & 15 deletions pvdeg/geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import pandas as pd
from dask.distributed import Client, LocalCluster

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader


def start_dask(hpc=None):
"""
Expand Down Expand Up @@ -97,7 +101,6 @@ def calc_gid(ds_gid, meta_gid, func, **kwargs):
"""

df_weather = ds_gid.to_dataframe()

df_res = func(weather_df=df_weather, meta=meta_gid, **kwargs)
ds_res = xr.Dataset.from_dataframe(df_res)

Expand Down Expand Up @@ -170,14 +173,15 @@ def analysis(weather_ds, meta_df, func, template=None, **func_kwargs):

stacked = weather_ds.map_blocks(calc_block, kwargs=kwargs, template=template).compute()

lats = stacked.latitude.values.flatten()
lons = stacked.longitude.values.flatten()
#stacked = stacked.drop(['gid'])
stacked = stacked.drop_vars(['latitude', 'longitude'])
stacked.coords['gid'] = pd.MultiIndex.from_arrays([lats, lons], names=['latitude', 'longitude'])

res = stacked.unstack('gid', sparse=True)
# lats = stacked.latitude.values.flatten()
# lons = stacked.longitude.values.flatten()
stacked = stacked.drop(['gid'])
# stacked = stacked.drop_vars(['latitude', 'longitude'])
stacked.coords['gid'] = pd.MultiIndex.from_arrays([
meta_df['latitude'], meta_df['longitude']],
names=['latitude', 'longitude'])

res = stacked.unstack('gid') #, sparse=True
return res


Expand Down Expand Up @@ -210,7 +214,7 @@ def output_template(ds_gids, shapes, attrs=dict(), add_dims=dict()):
output_template = xr.Dataset(
data_vars = {var: (dim, da.empty([dims_size[d] for d in dim])
) for var, dim in shapes.items()},
coords = {'gid': ds_gids['gid']},
coords = {dim: ds_gids[dim] for dim in dims},
attrs = attrs
).chunk({dim: ds_gids.chunks[dim] for dim in dims})

Expand All @@ -227,16 +231,16 @@ def template_parameters(func):
Dictionary of variable names and their associated dimensions.
attrs : dict
Dictionary of attributes for each variable (e.g. units).
add_dims : dict
Dictionary of dimensions to add to the output template.
"""

if func == standards.standoff:

shapes = {'x': ('gid',),
'T98_inf': ('gid',),
'T98_0': ('gid',),
'latitude': ('gid',),
'longitude':('gid',),
}
'T98_inf': ('gid',),
'T98_0': ('gid',),
}

attrs = {'x' : {'units': 'cm'},
'T98_0' : {'units': 'Celsius'},
Expand All @@ -263,4 +267,45 @@ def template_parameters(func):
'attrs': attrs,
'add_dims': add_dims}

return parameters
return parameters


def plot_USA(xr_res,
cmap='viridis',
vmin=None,
vmax=None,
title=None,
cb_title=None,
fp=None):

fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1],
projection=ccrs.LambertConformal(),
frameon=False)
ax.patch.set_visible(False)
ax.set_extent([-120, -74, 22, 50], ccrs.Geodetic())

shapename = 'admin_1_states_provinces_lakes'
states_shp = shpreader.natural_earth(
resolution='110m', category='cultural', name=shapename)
ax.add_geometries(
shpreader.Reader(states_shp).geometries(),
ccrs.PlateCarree(), facecolor='w', edgecolor='gray')

cm = xr_res.plot(transform=ccrs.PlateCarree(),
zorder=10,
add_colorbar=False,
cmap=cmap,
vmin=vmin,
vmax=vmax,
subplot_kws={"projection": ccrs.LambertConformal(
central_longitude=-95, central_latitude=45)})

cb = plt.colorbar(cm, shrink=0.5)
cb.set_label(cb_title)
ax.set_title(title)

if fp is not None:
plt.savefig(fp, dpi=600)

return fig, ax
4 changes: 1 addition & 3 deletions pvdeg/standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ def standoff(

res = {'x': x,
'T98_0': T98_0,
'T98_inf': T98_inf,
'latitude': meta['latitude'],
'longitude': meta['longitude']}
'T98_inf': T98_inf}

df_res = pd.DataFrame.from_dict(res, orient='index').T

Expand Down
7 changes: 4 additions & 3 deletions pvdeg/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def ini_h5_geospatial(fps):

ds = xr.merge(dss)
ds = xr.decode_cf(ds)

# Rechunk time axis
ds = ds.chunk(chunks={'time': -1, 'gid': ds.chunks['gid']})

weather_ds = ds

return weather_ds, meta_df
Expand Down Expand Up @@ -308,9 +312,6 @@ def get_NSRDB_fnames(satellite, names, NREL_HPC = False, **_):
hpc_fp = '/nrel/nsrdb/'
hsds = True

if type(names) in [int, float]:
nsrdb_fp = os.path.join(hpc_fp, sat_map[satellite], '*_{}.h5'.format(int(names)))

if type(names) in [int, float]:
nsrdb_fp = os.path.join(hpc_fp, sat_map[satellite], '*_{}.h5'.format(int(names)))
nsrdb_fnames = glob.glob(nsrdb_fp)
Expand Down
Loading

0 comments on commit db6d586

Please sign in to comment.