Name | solarenergy JSON |
Version |
0.1.9
JSON |
| download |
home_page | |
Summary | A Python module do simple modelling in the field of solar energy |
upload_time | 2023-11-05 15:09:48 |
maintainer | |
docs_url | None |
author | |
requires_python | |
license | EUPL 1.2 |
keywords |
solar energy
solar
energy
sun
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# SolarEnergy
![PyPI](https://img.shields.io/pypi/v/solarenergy?color=%230A0)
![PyPI - Downloads](https://img.shields.io/pypi/dm/solarenergy)
[![Code check](https://github.com/MarcvdSluys/SolarEnergy/actions/workflows/code-check.yml/badge.svg)](https://github.com/MarcvdSluys/SolarEnergy/actions/workflows/code-check.yml)
[![Documentation
Status](https://readthedocs.org/projects/solarenergy/badge/?version=latest)](https://solarenergy.readthedocs.io/en/latest/?badge=latest)
![PyPI - Licence](https://img.shields.io/pypi/l/solarenergy?color=%230A0)
A Python module to do simple modelling in the field of solar energy. The code is being developed by [Marc van
der Sluys](http://marc.vandersluys.nl) of the department of astrophysics of the Radboud University Nijmegen,
the Netherlands and the department of Sustainable energy of the HAN University of Applied Sciences in Arnhem,
the Netherlands, now at the Netherlands Institute for Nuclear and High-Energy Physics (Nikhef) and the
Institute for Gravitational and Subatomic Physics (GRASP) at Utrecht University in the Netherlands. The
SolarEnergy package can be used under the conditions of the EUPL 1.2 licence.
## Installation
This package can be installed using `pip install solarenergy`. This should automatically install the
dependency packages `numpy`, `pytz`, `astroconst` and `soltrack` (>=0.2.0) if they haven't been installed
already. If you are installing by hand, ensure that these packages are installed as well (if you're not using
a Python version older than 3.7, you will need to install `dataclasses` in addition).
## Code examples
### Code example for a numer or range (array, vector) of instances
In this mode, we prepare a list of datetimes (Pandas Series, DatetimeIndex, ndarrays of datetime64, ...) and
feed that to SolarEnergy at once, for better performance and easier use.
```python
"""Example Python script using the SolarEnergy module for a range of instances."""
# Location of my solar panels:
from solarenergy import d2r,r2d
geoLon = 5*d2r # Geographic longitude (>0 for eastern hemisphere; ° -> rad)
geoLat = 52*d2r # Geographic latitude (>0 for northern hemisphere; ° -> rad)
# Orientation of my solar panels:
spAz = -2*d2r # Azimuth ('wind direction') of my panels are facing. Note: South=0, W=90° (pi/2 rad) in the northern hemisphere! (rad)
spIncl = 28*d2r # Inclination of my panels w.r.t. the horizontal (rad)
import pandas as pd
dates = pd.date_range('2022-03-21', pd.to_datetime('2022-03-22'), freq='1h', tz='Europe/Amsterdam') # DatetimeIndex 0-24h
df = pd.DataFrame(data=dates, columns=['dtm']) # Create a Pandas DataFrame with the datetimes as first column
# Compute Sun positions (using SolTrack behind the scenes) and add them as three columns to the df:
import solarenergy as se
df['sunAz'],df['sunAlt'],df['sunDist'] = se.sun_position_from_datetime(geoLon,geoLat, df['dtm'])
df['I_ext'] = 1361.5 / df.sunDist**2 # Extraterrestrial radiation (at the top of the atmosphere; AM0)
df['AM'] = se.airmass(df.sunAlt) # Air mass for this Sun altitude
df['extFac'] = se.extinction_factor(df.AM) # Extinction factor at sea level for this airmass
df['DNI'] = df.I_ext / df.extFac # DNI for a clear sky
df['cosTheta'] = se.cos_angle_sun_panels(spAz,spIncl, df.sunAz,df.sunAlt) # cos of the angle with which Sun hits my panels
df['dirRad'] = df.DNI * df.cosTheta # Insolation of direct sunlight on my panels
df.sunAz *= r2d # Convert azimuth and ...
df.sunAlt *= r2d # ... altitude to degrees for printing
print(df[df.sunAlt > 0]) # Print the results for the hours where the Sun is above the horizon
```
### Code example for a single calculation
Note that in most cases, the vector option is preferred (see the [code example](#code-example) above, and see
[Performance](#performance) for details). The code example below is given for completeness.
```python
"""Example Python script using the SolarEnergy module for a single instance."""
# Location of my solar panels:
from solarenergy import d2r,r2d # Convert between radians and degrees
geoLon = 5*d2r # Geographic longitude (>0 for eastern hemisphere; ° -> rad)
geoLat = 52*d2r # Geographic latitude (>0 for northern hemisphere; ° -> rad)
# Orientation of my solar panels:
spAz = -2*d2r # Azimuth ('wind direction') of my panels are facing. Note: South=0, W=90° (pi/2 rad) in the northern hemisphere! (rad)
spIncl = 28*d2r # Inclination of my panels w.r.t. the horizontal (rad)
# An hour past noon local time on 1 March 2020:
myTZ = 'Europe/Amsterdam'
year = 2020
month = 3
day = 1
hour = 13
# Compute Sun position (uses SolTrack behind the scenes):
import solarenergy as se
sunAz,sunAlt,sunDist = se.sun_position_from_date_and_time(geoLon,geoLat, year,month,day, hour, timezone=myTZ)
I_ext = 1361.5 / sunDist**2 # Extraterrestrial radiation (at the top of the atmosphere; AM0)
AM = se.airmass(sunAlt) # Air mass for this Sun altitude
extFac = se.extinction_factor(AM) # Extinction factor at sea level for this airmass
cosTheta = se.cos_angle_sun_panels(spAz,spIncl, sunAz,sunAlt) # cos of the angle with which Sun hits my panels
DNI = I_ext / extFac # DNI for a clear sky
dirRad = DNI * cosTheta # Insolation of direct sunlight on my panels
# Print input and output:
import numpy as np
print("Location: %0.3lf E, %0.3lf N" % (geoLon*r2d, geoLat*r2d))
print("Date: %4d-%2.2d-%2.2d" % (year, month, day))
print("Time: %2d:00" % (hour))
print()
print("Sun azimuth: %7.3lf°" % (sunAz*r2d))
print("Sun altitude: %7.3lf°" % (sunAlt*r2d))
print("Sun distance: %7.4lf AU" % (sunDist))
print()
print("I_ext: %7.1lf W/m²" % (I_ext))
print()
print("Air mass: %7.3lf" % (AM))
print("Extinction factor: %7.3lf" % (extFac))
print("DNI: %7.1lf W/m²" % (DNI))
print()
print("Sun-panels angle: %7.1lf°" % (np.arccos(cosTheta)*r2d))
print("Direct insolation: %7.1lf W/m²" % (dirRad))
```
## Performance
SolarEnergy starts with the computation of the position of the Sun for a given instant (scalar) or for a
series of instances using an array or vector. The latter is faster than the former (for ~2 instances or more)
and may be easier to use in the majority of applications, depending on the problem given.
The table below shows the speed with which the position of the Sun is computed (in number of positions per
second) as a function of the size of the dataset. The runs were timed on a single hyperthreaded core capped
at 3.4GHz and the minimum time of 10 runs is displayed. The scalar runs scale linearly, the speed peaks
around 1<sup>5</sup>-1<sup>6</sup> elements for vectors. Timings below are for timezone-naive datetimes (and
hence UTC), if timezone-aware datetimes are used, the calculations take about 4.4 times longer(!)
| Mode | N<sub>calc</sub> | Time (s) | Speed (/s) |
|--------|------------------|----------|------------|
| scalar | 1e3 | 0.616 | 1623 |
| | | | |
| vector | 1 | 7.95e-4 | 1258 |
| vector | 1e1 | 8.79e-4 | 11,377 |
| vector | 1e2 | 0.001037 | 96,432 |
| vector | 1e3 | 0.00257 | 389,105 |
| vector | 1e4 | 0.0134 | 746,269 |
| vector | 1e5 | 0.0687 | 1,455,604 |
| vector | 1e6 | 0.667 | 1,499,250 |
| vector | 1e7 | 8.56 | 1,168,224 |
## SolarEnergy pages
* [Pypi](https://pypi.org/project/solarenergy/): SolarEnergy Python package
* [GitHub](https://github.com/MarcvdSluys/SolarEnergy): SolarEnergy source code
* [ReadTheDocs](https://solarenergy.readthedocs.io): SolarEnergy documentation
## Author and licence
* Author: Marc van der Sluys
* Contact: http://marc.vandersluys.nl
* Licence: [EUPL 1.2](https://www.eupl.eu/1.2/en/)
## References
* This Python code is adapted from the Fortran implementation in
[libTheSky](http://libthesky.sourceforge.net/), which contains many references.
* [Celestial mechanics in a nutshell (CMiaNS)](https://cmians.sourceforge.io/)
* [SolTrack](https://pypi.org/project/soltrack/): a free, fast and simple Python package to compute the position of the Sun, as well as its rise and set times.
Raw data
{
"_id": null,
"home_page": "",
"name": "solarenergy",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "solar energy,solar,energy,sun",
"author": "",
"author_email": "Marc van der Sluys <git@vandersluys.nl>",
"download_url": "https://files.pythonhosted.org/packages/f2/12/00e865c5953eebcfc2f53ceac1793cd0c8c0a5977cbf8fee811bbfb4c35f/solarenergy-0.1.9.tar.gz",
"platform": null,
"description": "# SolarEnergy\n\n![PyPI](https://img.shields.io/pypi/v/solarenergy?color=%230A0)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/solarenergy)\n[![Code check](https://github.com/MarcvdSluys/SolarEnergy/actions/workflows/code-check.yml/badge.svg)](https://github.com/MarcvdSluys/SolarEnergy/actions/workflows/code-check.yml)\n[![Documentation\nStatus](https://readthedocs.org/projects/solarenergy/badge/?version=latest)](https://solarenergy.readthedocs.io/en/latest/?badge=latest)\n![PyPI - Licence](https://img.shields.io/pypi/l/solarenergy?color=%230A0)\n\nA Python module to do simple modelling in the field of solar energy. The code is being developed by [Marc van\nder Sluys](http://marc.vandersluys.nl) of the department of astrophysics of the Radboud University Nijmegen,\nthe Netherlands and the department of Sustainable energy of the HAN University of Applied Sciences in Arnhem,\nthe Netherlands, now at the Netherlands Institute for Nuclear and High-Energy Physics (Nikhef) and the\nInstitute for Gravitational and Subatomic Physics (GRASP) at Utrecht University in the Netherlands. The\nSolarEnergy package can be used under the conditions of the EUPL 1.2 licence.\n\n\n## Installation\n\nThis package can be installed using `pip install solarenergy`. This should automatically install the\ndependency packages `numpy`, `pytz`, `astroconst` and `soltrack` (>=0.2.0) if they haven't been installed\nalready. If you are installing by hand, ensure that these packages are installed as well (if you're not using\na Python version older than 3.7, you will need to install `dataclasses` in addition).\n\n\n\n## Code examples\n\n### Code example for a numer or range (array, vector) of instances\n\nIn this mode, we prepare a list of datetimes (Pandas Series, DatetimeIndex, ndarrays of datetime64, ...) and\nfeed that to SolarEnergy at once, for better performance and easier use.\n\n```python\n\"\"\"Example Python script using the SolarEnergy module for a range of instances.\"\"\"\n\n# Location of my solar panels:\nfrom solarenergy import d2r,r2d\ngeoLon = 5*d2r # Geographic longitude (>0 for eastern hemisphere; \u00b0 -> rad)\ngeoLat = 52*d2r # Geographic latitude (>0 for northern hemisphere; \u00b0 -> rad)\n\n# Orientation of my solar panels:\nspAz = -2*d2r # Azimuth ('wind direction') of my panels are facing. Note: South=0, W=90\u00b0 (pi/2 rad) in the northern hemisphere! (rad)\nspIncl = 28*d2r # Inclination of my panels w.r.t. the horizontal (rad)\n\n\nimport pandas as pd\ndates = pd.date_range('2022-03-21', pd.to_datetime('2022-03-22'), freq='1h', tz='Europe/Amsterdam') # DatetimeIndex 0-24h\ndf = pd.DataFrame(data=dates, columns=['dtm']) # Create a Pandas DataFrame with the datetimes as first column\n\n# Compute Sun positions (using SolTrack behind the scenes) and add them as three columns to the df:\nimport solarenergy as se\ndf['sunAz'],df['sunAlt'],df['sunDist'] = se.sun_position_from_datetime(geoLon,geoLat, df['dtm'])\n\ndf['I_ext'] = 1361.5 / df.sunDist**2 # Extraterrestrial radiation (at the top of the atmosphere; AM0)\n\ndf['AM'] = se.airmass(df.sunAlt) # Air mass for this Sun altitude\ndf['extFac'] = se.extinction_factor(df.AM) # Extinction factor at sea level for this airmass\ndf['DNI'] = df.I_ext / df.extFac # DNI for a clear sky\n\ndf['cosTheta'] = se.cos_angle_sun_panels(spAz,spIncl, df.sunAz,df.sunAlt) # cos of the angle with which Sun hits my panels\ndf['dirRad'] = df.DNI * df.cosTheta # Insolation of direct sunlight on my panels\n\ndf.sunAz *= r2d # Convert azimuth and ...\ndf.sunAlt *= r2d # ... altitude to degrees for printing\n\nprint(df[df.sunAlt > 0]) # Print the results for the hours where the Sun is above the horizon\n```\n\n\n### Code example for a single calculation\n\nNote that in most cases, the vector option is preferred (see the [code example](#code-example) above, and see\n[Performance](#performance) for details). The code example below is given for completeness.\n\n```python\n\"\"\"Example Python script using the SolarEnergy module for a single instance.\"\"\"\n\n# Location of my solar panels:\nfrom solarenergy import d2r,r2d # Convert between radians and degrees\ngeoLon = 5*d2r # Geographic longitude (>0 for eastern hemisphere; \u00b0 -> rad)\ngeoLat = 52*d2r # Geographic latitude (>0 for northern hemisphere; \u00b0 -> rad)\n\n# Orientation of my solar panels:\nspAz = -2*d2r # Azimuth ('wind direction') of my panels are facing. Note: South=0, W=90\u00b0 (pi/2 rad) in the northern hemisphere! (rad)\nspIncl = 28*d2r # Inclination of my panels w.r.t. the horizontal (rad)\n\n# An hour past noon local time on 1 March 2020:\nmyTZ = 'Europe/Amsterdam'\nyear = 2020\nmonth = 3\nday = 1\nhour = 13\n\n\n# Compute Sun position (uses SolTrack behind the scenes):\nimport solarenergy as se\nsunAz,sunAlt,sunDist = se.sun_position_from_date_and_time(geoLon,geoLat, year,month,day, hour, timezone=myTZ)\n\nI_ext = 1361.5 / sunDist**2 # Extraterrestrial radiation (at the top of the atmosphere; AM0)\n\nAM = se.airmass(sunAlt) # Air mass for this Sun altitude\nextFac = se.extinction_factor(AM) # Extinction factor at sea level for this airmass\ncosTheta = se.cos_angle_sun_panels(spAz,spIncl, sunAz,sunAlt) # cos of the angle with which Sun hits my panels\n\nDNI = I_ext / extFac # DNI for a clear sky\ndirRad = DNI * cosTheta # Insolation of direct sunlight on my panels\n\n\n# Print input and output:\nimport numpy as np\nprint(\"Location: %0.3lf E, %0.3lf N\" % (geoLon*r2d, geoLat*r2d))\nprint(\"Date: %4d-%2.2d-%2.2d\" % (year, month, day))\nprint(\"Time: %2d:00\" % (hour))\nprint()\n\nprint(\"Sun azimuth: %7.3lf\u00b0\" % (sunAz*r2d))\nprint(\"Sun altitude: %7.3lf\u00b0\" % (sunAlt*r2d))\nprint(\"Sun distance: %7.4lf AU\" % (sunDist))\nprint()\n\nprint(\"I_ext: %7.1lf W/m\u00b2\" % (I_ext))\nprint()\n\nprint(\"Air mass: %7.3lf\" % (AM))\nprint(\"Extinction factor: %7.3lf\" % (extFac))\nprint(\"DNI: %7.1lf W/m\u00b2\" % (DNI))\nprint()\n\nprint(\"Sun-panels angle: %7.1lf\u00b0\" % (np.arccos(cosTheta)*r2d))\nprint(\"Direct insolation: %7.1lf W/m\u00b2\" % (dirRad))\n```\n\n## Performance\n\nSolarEnergy starts with the computation of the position of the Sun for a given instant (scalar) or for a\nseries of instances using an array or vector. The latter is faster than the former (for ~2 instances or more)\nand may be easier to use in the majority of applications, depending on the problem given.\n\nThe table below shows the speed with which the position of the Sun is computed (in number of positions per\nsecond) as a function of the size of the dataset. The runs were timed on a single hyperthreaded core capped\nat 3.4GHz and the minimum time of 10 runs is displayed. The scalar runs scale linearly, the speed peaks\naround 1<sup>5</sup>-1<sup>6</sup> elements for vectors. Timings below are for timezone-naive datetimes (and\nhence UTC), if timezone-aware datetimes are used, the calculations take about 4.4 times longer(!)\n\n| Mode | N<sub>calc</sub> | Time (s) | Speed (/s) |\n|--------|------------------|----------|------------|\n| scalar | 1e3 | 0.616 | 1623 |\n| | | | |\n| vector | 1 | 7.95e-4 | 1258 |\n| vector | 1e1 | 8.79e-4 | 11,377 |\n| vector | 1e2 | 0.001037 | 96,432 |\n| vector | 1e3 | 0.00257 | 389,105 |\n| vector | 1e4 | 0.0134 | 746,269 |\n| vector | 1e5 | 0.0687 | 1,455,604 |\n| vector | 1e6 | 0.667 | 1,499,250 |\n| vector | 1e7 | 8.56 | 1,168,224 |\n\n\n## SolarEnergy pages\n\n* [Pypi](https://pypi.org/project/solarenergy/): SolarEnergy Python package\n* [GitHub](https://github.com/MarcvdSluys/SolarEnergy): SolarEnergy source code\n* [ReadTheDocs](https://solarenergy.readthedocs.io): SolarEnergy documentation\n\n\n## Author and licence\n\n* Author: Marc van der Sluys\n* Contact: http://marc.vandersluys.nl\n* Licence: [EUPL 1.2](https://www.eupl.eu/1.2/en/)\n\n\n## References\n\n* This Python code is adapted from the Fortran implementation in\n [libTheSky](http://libthesky.sourceforge.net/), which contains many references.\n* [Celestial mechanics in a nutshell (CMiaNS)](https://cmians.sourceforge.io/)\n* [SolTrack](https://pypi.org/project/soltrack/): a free, fast and simple Python package to compute the position of the Sun, as well as its rise and set times.\n",
"bugtrack_url": null,
"license": "EUPL 1.2",
"summary": "A Python module do simple modelling in the field of solar energy",
"version": "0.1.9",
"project_urls": {
"GitHub": "https://github.com/MarcvdSluys/SolarEnergy",
"ReadTheDocs": "https://solarenergy.readthedocs.io"
},
"split_keywords": [
"solar energy",
"solar",
"energy",
"sun"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7664da82679867fa60fb24470fd7ff48c2c722179af64a5edd05ad4c0b423022",
"md5": "99c7e62759c831e56492358db8bad947",
"sha256": "8d66ee73efefe52b5e3fc70331d9130da525b4f7b93d4a779128d267d5bbc8ec"
},
"downloads": -1,
"filename": "solarenergy-0.1.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "99c7e62759c831e56492358db8bad947",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 25447,
"upload_time": "2023-11-05T15:09:46",
"upload_time_iso_8601": "2023-11-05T15:09:46.477122Z",
"url": "https://files.pythonhosted.org/packages/76/64/da82679867fa60fb24470fd7ff48c2c722179af64a5edd05ad4c0b423022/solarenergy-0.1.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f21200e865c5953eebcfc2f53ceac1793cd0c8c0a5977cbf8fee811bbfb4c35f",
"md5": "8d16705c80cec9cbf9e9e1f5f0c04abf",
"sha256": "47b7dc5a989a4bb9ed1bd1083255eb492c752d2653581e9ea4276ee677923202"
},
"downloads": -1,
"filename": "solarenergy-0.1.9.tar.gz",
"has_sig": false,
"md5_digest": "8d16705c80cec9cbf9e9e1f5f0c04abf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 29582,
"upload_time": "2023-11-05T15:09:48",
"upload_time_iso_8601": "2023-11-05T15:09:48.107808Z",
"url": "https://files.pythonhosted.org/packages/f2/12/00e865c5953eebcfc2f53ceac1793cd0c8c0a5977cbf8fee811bbfb4c35f/solarenergy-0.1.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-05 15:09:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MarcvdSluys",
"github_project": "SolarEnergy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "solarenergy"
}