Skip to content

Commit 5f00ec4

Browse files
committed
Merge branch 'development' into Documentation
2 parents 87d744f + 2aa7332 commit 5f00ec4

16 files changed

+644
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pvdeg.geospatial.plot\_sparse\_analysis\_land
2+
=============================================
3+
4+
.. currentmodule:: pvdeg.geospatial
5+
6+
.. autofunction:: plot_sparse_analysis_land

docs/source/_autosummary/pvdeg.geospatial.rst

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pvdeg.geospatial
3434
pvdeg.geospatial.plot_Europe
3535
pvdeg.geospatial.plot_USA
3636
pvdeg.geospatial.plot_sparse_analysis
37+
pvdeg.geospatial.plot_sparse_analysis_land
3738
pvdeg.geospatial.start_dask
3839
pvdeg.geospatial.template_parameters
3940
pvdeg.geospatial.zero_template
@@ -157,6 +158,13 @@ pvdeg.geospatial
157158
.. minigallery:: pvdeg.geospatial.plot_sparse_analysis
158159
:add-heading:
159160

161+
.. autofunction:: plot_sparse_analysis_land
162+
163+
.. _sphx_glr_backref_pvdeg.geospatial.plot_sparse_analysis_land:
164+
165+
.. minigallery:: pvdeg.geospatial.plot_sparse_analysis_land
166+
:add-heading:
167+
160168
.. autofunction:: start_dask
161169

162170
.. _sphx_glr_backref_pvdeg.geospatial.start_dask:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pvdeg.utilities.display\_json
2+
=============================
3+
4+
.. currentmodule:: pvdeg.utilities
5+
6+
.. autofunction:: display_json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pvdeg.utilities.linear\_normalize
2+
=================================
3+
4+
.. currentmodule:: pvdeg.utilities
5+
6+
.. autofunction:: linear_normalize
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pvdeg.utilities.merge\_sparse
2+
=============================
3+
4+
.. currentmodule:: pvdeg.utilities
5+
6+
.. autofunction:: merge_sparse
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pvdeg.utilities.read\_material
2+
==============================
3+
4+
.. currentmodule:: pvdeg.utilities
5+
6+
.. autofunction:: read_material

docs/source/_autosummary/pvdeg.utilities.rst

+40
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ pvdeg.utilities
2121

2222
pvdeg.utilities.compare_templates
2323
pvdeg.utilities.convert_tmy
24+
pvdeg.utilities.display_json
2425
pvdeg.utilities.fix_metadata
2526
pvdeg.utilities.geospatial_from_csv
2627
pvdeg.utilities.get_kinetics
2728
pvdeg.utilities.get_state_bbox
2829
pvdeg.utilities.gid_downsampling
30+
pvdeg.utilities.linear_normalize
31+
pvdeg.utilities.merge_sparse
2932
pvdeg.utilities.meta_as_dict
3033
pvdeg.utilities.new_id
3134
pvdeg.utilities.nrel_kestrel_check
3235
pvdeg.utilities.quantile_df
36+
pvdeg.utilities.read_material
3337
pvdeg.utilities.remove_scenario_filetrees
3438
pvdeg.utilities.restore_gids
39+
pvdeg.utilities.search_json
3540
pvdeg.utilities.strip_normalize_tmy
3641
pvdeg.utilities.tilt_azimuth_scan
3742
pvdeg.utilities.ts_gid_df
@@ -65,6 +70,13 @@ pvdeg.utilities
6570
.. minigallery:: pvdeg.utilities.convert_tmy
6671
:add-heading:
6772

73+
.. autofunction:: display_json
74+
75+
.. _sphx_glr_backref_pvdeg.utilities.display_json:
76+
77+
.. minigallery:: pvdeg.utilities.display_json
78+
:add-heading:
79+
6880
.. autofunction:: fix_metadata
6981

7082
.. _sphx_glr_backref_pvdeg.utilities.fix_metadata:
@@ -100,6 +112,20 @@ pvdeg.utilities
100112
.. minigallery:: pvdeg.utilities.gid_downsampling
101113
:add-heading:
102114

115+
.. autofunction:: linear_normalize
116+
117+
.. _sphx_glr_backref_pvdeg.utilities.linear_normalize:
118+
119+
.. minigallery:: pvdeg.utilities.linear_normalize
120+
:add-heading:
121+
122+
.. autofunction:: merge_sparse
123+
124+
.. _sphx_glr_backref_pvdeg.utilities.merge_sparse:
125+
126+
.. minigallery:: pvdeg.utilities.merge_sparse
127+
:add-heading:
128+
103129
.. autofunction:: meta_as_dict
104130

105131
.. _sphx_glr_backref_pvdeg.utilities.meta_as_dict:
@@ -128,6 +154,13 @@ pvdeg.utilities
128154
.. minigallery:: pvdeg.utilities.quantile_df
129155
:add-heading:
130156

157+
.. autofunction:: read_material
158+
159+
.. _sphx_glr_backref_pvdeg.utilities.read_material:
160+
161+
.. minigallery:: pvdeg.utilities.read_material
162+
:add-heading:
163+
131164
.. autofunction:: remove_scenario_filetrees
132165

133166
.. _sphx_glr_backref_pvdeg.utilities.remove_scenario_filetrees:
@@ -142,6 +175,13 @@ pvdeg.utilities
142175
.. minigallery:: pvdeg.utilities.restore_gids
143176
:add-heading:
144177

178+
.. autofunction:: search_json
179+
180+
.. _sphx_glr_backref_pvdeg.utilities.search_json:
181+
182+
.. minigallery:: pvdeg.utilities.search_json
183+
:add-heading:
184+
145185
.. autofunction:: strip_normalize_tmy
146186

147187
.. _sphx_glr_backref_pvdeg.utilities.strip_normalize_tmy:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pvdeg.utilities.search\_json
2+
============================
3+
4+
.. currentmodule:: pvdeg.utilities
5+
6+
.. autofunction:: search_json

docs/source/whatsnew/index.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ What's New
44
==========
55
PVDegradationTools (pvdeg) change log:
66

7-
7+
.. include:: releases/v0.4.3.rst
8+
.. include:: releases/v0.4.2.rst
89
.. include:: releases/v0.4.1.rst
910
.. include:: releases/v0.4.0.rst
1011
.. include:: releases/v0.3.3.rst

docs/source/whatsnew/releases/v0.4.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Tests
1313
Contributors
1414
~~~~~~~~~~~~
1515
* Martin Springer (:ghuser:`martin-springer`)
16-
* Aidan Wesley (:ghuser:`AidanWesley``)
16+
* Aidan Wesley (:ghuser:`AidanWesley``)
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
v0.4.3 (2024-10-10)
2+
===================
3+
4+
Enhancements
5+
------------
6+
Suite of utility functions to facilitate accessing material parameter json files.
7+
8+
* ``pvdeg.utilities.read_material`` creates a public api to replace the private ``pvdeg.untility._read_material`` function (to be deprecated soon)
9+
* ``pvdeg.utilities.search_json`` to search jsons and identify keys for desired materials.
10+
* ``pvdeg.utilities.display_json`` to view 2 level jsons in Jupyter Notebooks using HTML.
11+
12+
Contributors
13+
-----------
14+
* Tobin Ford (:ghuser:`tobin-ford`)

pvdeg/temperature.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def cell(
196196
Calculate the PV cell temperature using PVLIB
197197
Currently this only supports the SAPM temperature model.
198198
199-
Parameters:
199+
Parameters
200200
-----------
201201
weather_df : (pd.dataframe)
202202
Data Frame with minimum requirements of 'temp_air' and 'wind_speed'
@@ -304,7 +304,7 @@ def temperature(
304304
Calculate the PV cell or module temperature using PVLIB
305305
Current supports the following temperature models:
306306
307-
Parameters:
307+
Parameters
308308
-----------
309309
cell_or_mod : (str)
310310
choose to calculate the cell or module temperature. Use
@@ -347,12 +347,12 @@ def temperature(
347347
keyword argument dictionary used for the pvlib temperature model calculation.
348348
See https://pvlib-python.readthedocs.io/en/stable/reference/pv_modeling/temperature.html for more.
349349
350-
Return:
350+
Return
351351
-------
352352
temp_cell : pandas.DataFrame
353353
This is the temperature of the cell in a module at every time step.[°C]
354354
355-
References:
355+
References
356356
-----------
357357
R. Rabbani, M. Zeeshan, "Exploring the suitability of MERRA-2 reanalysis data for wind energy
358358
estimation, analysis of wind characteristics and energy potential assessment for selected

pvdeg/utilities.py

+145-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
from subprocess import run
1414
import cartopy.feature as cfeature
1515

16+
17+
# A mapping to simplify access to files stored in `pvdeg/data`
18+
pvdeg_datafiles = {
19+
"AApermeation": os.path.join(DATA_DIR, "AApermeation.json"),
20+
"H2Opermeation": os.path.join(DATA_DIR, "H2Opermeation.json"),
21+
"O2permeation": os.path.join(DATA_DIR, "O2permeation.json"),
22+
}
23+
24+
1625
def gid_downsampling(meta, n):
1726
"""
1827
Downsample the NSRDB GID grid by a factor of n
@@ -492,8 +501,7 @@ def convert_tmy(file_in, file_out="h5_from_tmy.h5"):
492501
)
493502

494503

495-
# previously: fname="materials.json"
496-
# add control over what parameters (O2, H2, AA)?
504+
### DEPRECATE ###
497505
def _read_material(name, fname="O2permeation.json"):
498506
"""
499507
read a material from materials.json and return the parameter dictionary
@@ -1337,4 +1345,138 @@ def merge_sparse(files: list[str])->xr.Dataset:
13371345
for var in ds.data_vars:
13381346
merged_ds[var].values[np.ix_(lat_inds, lon_inds)] = ds[var].values
13391347

1340-
return merged_ds
1348+
return merged_ds
1349+
1350+
def display_json(
1351+
pvdeg_file: str = None,
1352+
fp: str = None,
1353+
) -> None:
1354+
"""
1355+
Interactively view a 2 level JSON file in a JupyterNotebook
1356+
1357+
Parameters:
1358+
------------
1359+
pvdeg_file: str
1360+
keyword for material json file in `pvdeg/data`. Options:
1361+
>>> "AApermeation", "H2Opermeation", "O2permeation"
1362+
fp: str
1363+
file path to material parameters json with same schema as material parameters json files in `pvdeg/data`. `pvdeg_file` will override `fp` if both are provided.
1364+
"""
1365+
from IPython.display import display, HTML
1366+
1367+
if pvdeg_file:
1368+
try:
1369+
fp = pvdeg_datafiles[pvdeg_file]
1370+
except KeyError:
1371+
raise KeyError(f"{pvdeg_file} does not exist in pvdeg/data. Options are {pvdeg_datafiles.keys()}")
1372+
1373+
with open(fp, 'r') as file:
1374+
data = json.load(file)
1375+
1376+
def json_to_html(data):
1377+
json_str = json.dumps(data, indent=2)
1378+
for key in data.keys():
1379+
json_str = json_str.replace(f'"{key}":', f'<span style="color: plum;">"{key}":</span>')
1380+
1381+
indented_html = '<br>'.join([' ' * 4 + line for line in json_str.splitlines()])
1382+
return f'<pre style="color: white; background-color: black; padding: 10px; border-radius: 5px;">{indented_html}</pre>'
1383+
1384+
html = f'<h2 style="color: white;">JSON Output at fp: {fp}</h2><div>'
1385+
for key, value in data.items():
1386+
html += (
1387+
f'<div>'
1388+
f'<strong style="color: white;">{key}:</strong> '
1389+
f'<span onclick="this.nextElementSibling.style.display = this.nextElementSibling.style.display === \'none\' ? \'block\' : \'none\'" style="cursor: pointer; color: white;">&#9660;</span>'
1390+
f'<div style="display: none;">{json_to_html(value)}</div>'
1391+
f'</div>'
1392+
)
1393+
html += '</div>'
1394+
1395+
# Display the HTML
1396+
display(HTML(html))
1397+
1398+
1399+
def search_json(
1400+
pvdeg_file: str = None,
1401+
fp: str = None,
1402+
name_or_alias: str = None,
1403+
)-> str:
1404+
"""
1405+
Search through a 2 level JSON with arbitrary key names for subkeys with matching attributes of name or alias.
1406+
1407+
Parameters
1408+
------------
1409+
pvdeg_file: str
1410+
keyword for material json file in `pvdeg/data`. Options:
1411+
>>> "AApermeation", "H2Opermeation", "O2permeation"
1412+
fp: str
1413+
file path to material parameters json with same schema as material parameters json files in `pvdeg/data`. `pvdeg_file` will override `fp` if both are provided.
1414+
name_or_alias: str
1415+
searches for matching subkey value in either `name` or `alias` attributes. exits on the first matching instance.
1416+
1417+
Returns
1418+
---------
1419+
jsonkey: str
1420+
arbitrary key from json that owns the matching subattribute of `name` or `alias`.
1421+
"""
1422+
1423+
if pvdeg_file:
1424+
try:
1425+
fp = pvdeg_datafiles[pvdeg_file]
1426+
except KeyError:
1427+
raise KeyError(rf"{pvdeg_file} does not exist in pvdeg/data. Options are {pvdeg_datafiles.keys()}")
1428+
1429+
with open(fp, "r") as file:
1430+
data = json.load(file)
1431+
1432+
for key, subdict in data.items():
1433+
if "name" in subdict and "alias" in subdict:
1434+
if (subdict["name"] == name_or_alias or subdict["alias"] == name_or_alias):
1435+
return key
1436+
1437+
raise ValueError(rf"name_or_alias: {name_or_alias} not in JSON at {os.path(fp)}")
1438+
1439+
def read_material(
1440+
pvdeg_file: str = None,
1441+
fp: str = None,
1442+
key: str = None,
1443+
parameters: list[str] = None,
1444+
)-> dict:
1445+
"""
1446+
Read material parameters from a `pvdeg/data` file or JSON file path.
1447+
1448+
Parameters
1449+
-----------
1450+
pvdeg_file: str
1451+
keyword for material json file in `pvdeg/data`. Options:
1452+
>>> "AApermeation", "H2Opermeation", "O2permeation"
1453+
fp: str
1454+
file path to material parameters json with same schema as material parameters json files in `pvdeg/data`. `pvdeg_file` will override `fp` if both are provided.
1455+
key: str
1456+
key corresponding to specific material in the file. In the pvdeg files these have arbitrary names. Inspect the files or use `display_json` or `search_json` to identify the key for desired material.
1457+
parameters: list[str]
1458+
parameters to grab from the file at index key. If none, will grab all items at index key. the elements in parameters must match the keys in the json exactly or the output value for the specific key/parameter in the retunred dict will be `None`.
1459+
1460+
Returns
1461+
--------
1462+
material: dict
1463+
dictionary of material parameters from the seleted file at the index key.
1464+
"""
1465+
1466+
# these live in the `pvdeg/data` folder
1467+
if pvdeg_file:
1468+
try:
1469+
fp = pvdeg_datafiles[pvdeg_file]
1470+
except KeyError:
1471+
raise KeyError(f"{pvdeg_file} does not exist in pvdeg/data. Options are {pvdeg_datafiles.keys()}")
1472+
1473+
with open(fp, "r") as file:
1474+
data = json.load(file)
1475+
1476+
# take subdict from file
1477+
material_dict = data[key]
1478+
1479+
if parameters:
1480+
material_dict = {k: material_dict.get(k, None) for k in parameters}
1481+
1482+
return material_dict

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ docs = [
6767
"nbsphinx",
6868
"sphinx_toggleprompt",
6969
"pydata_sphinx_theme",
70+
"mistune==3.0.0",
7071
]
7172
test = [
7273
"pytest",

0 commit comments

Comments
 (0)