Skip to content

Instantly share code, notes, and snippets.

@kandersolar
Created November 1, 2021 18:47
Show Gist options
  • Select an option

  • Save kandersolar/4c780640585881b01f82768c5bac5b51 to your computer and use it in GitHub Desktop.

Select an option

Save kandersolar/4c780640585881b01f82768c5bac5b51 to your computer and use it in GitHub Desktop.
Notebook to reproduce a pvfactors issue when surface_tilt is exactly zero
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "3132ef64-b0f0-477e-b96f-6e1a125cdf0e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pvlib 0.8.1\n",
"pvfactors 1.5.1\n"
]
}
],
"source": [
"import pvlib\n",
"import pvfactors\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"for pkg in [pvlib, pvfactors]:\n",
" print(pkg.__name__, pkg.__version__)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "571b4a69-2656-4b72-a0ef-39164e72ba7e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\users\\kanderso\\software\\anaconda3\\envs\\work-scratch\\lib\\site-packages\\pvfactors\\geometry\\base.py:349: ShapelyDeprecationWarning: Setting custom attributes on geometry objects is deprecated, and will raise an AttributeError in Shapely 2.0\n",
" self.list_surfaces = list_surfaces\n",
"c:\\users\\kanderso\\software\\anaconda3\\envs\\work-scratch\\lib\\site-packages\\pvfactors\\geometry\\base.py:350: ShapelyDeprecationWarning: Setting custom attributes on geometry objects is deprecated, and will raise an AttributeError in Shapely 2.0\n",
" self.shaded = self._get_shading(shaded)\n",
"c:\\users\\kanderso\\software\\anaconda3\\envs\\work-scratch\\lib\\site-packages\\pvfactors\\geometry\\base.py:351: ShapelyDeprecationWarning: Setting custom attributes on geometry objects is deprecated, and will raise an AttributeError in Shapely 2.0\n",
" self.is_collinear = is_collinear(list_surfaces)\n",
"c:\\users\\kanderso\\software\\anaconda3\\envs\\work-scratch\\lib\\site-packages\\pvfactors\\geometry\\base.py:352: ShapelyDeprecationWarning: Setting custom attributes on geometry objects is deprecated, and will raise an AttributeError in Shapely 2.0\n",
" self.param_names = param_names\n",
"c:\\users\\kanderso\\software\\anaconda3\\envs\\work-scratch\\lib\\site-packages\\pvfactors\\geometry\\base.py:937: ShapelyDeprecationWarning: Setting custom attributes on geometry objects is deprecated, and will raise an AttributeError in Shapely 2.0\n",
" self.list_segments = tuple(list_segments)\n",
"c:\\users\\kanderso\\software\\anaconda3\\envs\\work-scratch\\lib\\site-packages\\pvfactors\\geometry\\base.py:938: ShapelyDeprecationWarning: Setting custom attributes on geometry objects is deprecated, and will raise an AttributeError in Shapely 2.0\n",
" self._all_surfaces = None\n"
]
}
],
"source": [
"# Import pvfactors functions for timeseries calculations.\n",
"from pvfactors.run import run_timeseries_engine\n",
"\n",
"def run_pvfactors(surface_tilt):\n",
"\n",
" timestamps = pd.to_datetime(['2019-06-01 10:00']).tz_localize('Etc/GMT+5')\n",
" solar_azimuth = np.array([135])\n",
" solar_zenith = np.array([45])\n",
" dni = np.array([200])\n",
" dhi = np.array([400])\n",
" albedo = 0.2\n",
"\n",
" pvarray_parameters = {\n",
" 'n_pvrows': 3,\n",
" 'axis_azimuth': 180,\n",
" 'pvrow_height': 2,\n",
" 'pvrow_width': 1,\n",
" 'gcr': 0.4\n",
" }\n",
"\n",
" irradiance_model_params = { # defaults from pvlib.bifacial.pvfactors_timeseries\n",
" 'rho_front': 0.03,\n",
" 'rho_back': 0.05,\n",
" 'horizon_band_angle': 15\n",
" }\n",
"\n",
" def fn_build_report(pvarray):\n",
" pvrow = pvarray.ts_pvrows[1]\n",
" irradiance = {\n",
" 'total_inc_back': pvrow.back.get_param_weighted('qinc'),\n",
" 'total_inc_front': pvrow.front.get_param_weighted('qinc'),\n",
" 'total_abs_back': pvrow.back.get_param_weighted('qabs'),\n",
" 'total_abs_front': pvrow.front.get_param_weighted('qabs'),\n",
" }\n",
" return irradiance, pvarray.ts_vf_aoi_matrix\n",
"\n",
" surface_tilt = np.array([surface_tilt])\n",
" surface_azimuth = np.array([90])\n",
"\n",
" irrad, ts_vf_aoi_matrix = run_timeseries_engine(\n",
" fn_build_report, pvarray_parameters,\n",
" timestamps, dni, dhi, solar_zenith, solar_azimuth,\n",
" surface_tilt, surface_azimuth, albedo,\n",
" irradiance_model_params=irradiance_model_params)\n",
" return irrad, ts_vf_aoi_matrix\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "7dd39e20-1d36-4cbc-abeb-63beb920087a",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\users\\kanderso\\software\\anaconda3\\envs\\work-scratch\\lib\\site-packages\\pvfactors\\geometry\\pvground.py:121: RuntimeWarning: divide by zero encountered in true_divide\n",
" dx = (y1s_pvrow - y_ground) / np.tan(rotation_vec)\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>total_inc_back</th>\n",
" <th>total_inc_front</th>\n",
" <th>total_abs_back</th>\n",
" <th>total_abs_front</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>254.512852</td>\n",
" <td>702.081332</td>\n",
" <td>241.787209</td>\n",
" <td>681.018892</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_inc_back total_inc_front total_abs_back total_abs_front\n",
"0 254.512852 702.081332 241.787209 681.018892"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"irrad, vf_matrix = run_pvfactors(0.0)\n",
"pd.DataFrame(irrad)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e75791dc-65f0-4a4a-b0d2-0727a6cb2bb2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-0.6823207602002184"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.min(vf_matrix)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "63115242-0648-4e0d-88ba-96d5bb7455dd",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>total_inc_back</th>\n",
" <th>total_inc_front</th>\n",
" <th>total_abs_back</th>\n",
" <th>total_abs_front</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>76.187245</td>\n",
" <td>541.424948</td>\n",
" <td>72.377883</td>\n",
" <td>525.1822</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" total_inc_back total_inc_front total_abs_back total_abs_front\n",
"0 76.187245 541.424948 72.377883 525.1822"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"irrad, vf_matrix = run_pvfactors(0.001)\n",
"pd.DataFrame(irrad)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4a455230-e7e1-4ebd-ae13-515aa17fbebd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.0"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.min(vf_matrix)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment