Name | sunposition JSON |
Version |
1.2.1
JSON |
| download |
home_page | None |
Summary | Compute the sun's observed position based on Reda & Adreas's 2004 paper "Solar position algorithm for solar radiation applications" |
upload_time | 2025-02-03 06:27:18 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | None |
keywords |
astronomy
solar
sun
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# sunposition
## Description
`sunposition` is a python module for computing the sun's position based on the algorithms from "Solar position algorithm for solar radiation applications" by Ibrahim Reda and Afshin Anreas, Solar Energy (2004).
The algorithm calculates "the solar zenith and azimuth angles in the period from the year −2000 to 6000, with uncertainties of ±0.0003°".
See http://dx.doi.org/10.1016/j.solener.2003.12.003 for more information.
In this code, the latitude and longitude are positive for North and East, respectively.
The azimuth angle is 0 at North and positive towards the east.
The zenith angle is 0 at vertical and positive towards the horizon.
The code is hosted at https://github.com/s-bear/sun-position
The module is a single python file `sunposition.py` and may be used as a command-line utility or imported into a script.
The module depends only on [NumPy](https://numpy.org) but can optionally use [Numba](https://numba.pydata.org/) and [SciPy](https://scipy.org) for performance improvements.
## Installation
`sunposition` is hosted at [https://pypi.org/project/sunposition/](https://pypi.org/project/sunposition/) and may be installed using `pip`:
```
$ pip install sunposition
```
## Example usage on the command line
```
$ sunposition --help
usage: sunposition [-h] [--version] [--citation] [-t TIME] [-lat LATITUDE] [-lon LONGITUDE] [-e ELEVATION] [-T TEMPERATURE] [-p PRESSURE] [-a ATMOS_REFRACT] [-dt DT] [-r] [--csv] [--jit]
Compute sun position parameters given the time and location
options:
-h, --help show this help message and exit
--version show program's version number and exit
--citation Print citation information
-t TIME, --time TIME "now" or date and time in ISO8601 format or a (UTC) POSIX timestamp
-lat LATITUDE, --latitude LATITUDE
observer latitude, in decimal degrees, positive for north
-lon LONGITUDE, --longitude LONGITUDE
observer longitude, in decimal degrees, positive for east
-e ELEVATION, --elevation ELEVATION
observer elevation, in meters
-T TEMPERATURE, --temperature TEMPERATURE
temperature, in degrees celcius
-p PRESSURE, --pressure PRESSURE
atmospheric pressure, in millibar
-a ATMOS_REFRACT, --atmos_refract ATMOS_REFRACT
Atmospheric refraction at sunrise and sunset, in degrees. Omit to compute automatically, spa.c uses 0.5667
-dt DT difference between earth's rotation time (TT) and universal time (UT1)
-r, --radians Output in radians instead of degrees
--csv Comma separated values (time,dt,lat,lon,elev,temp,pressure,az,zen,RA,dec,H)
--jit Enable Numba acceleration (likely to cause slowdown for a single computation!)
$ sunposition
Computing sun position at T = 2025-02-03T05:13:53.608472Z + 0.0 s
Lat, Lon, Elev = 51.48 deg, 0.0 deg, 0 m
T, P = 14.6 C, 1013.0 mbar
Results:
Azimuth, zenith = 88.915691 deg, 112.077238 deg
RA, dec, H = 317.087980 deg, -16.448005 deg, -104.973487 deg
$ sunposition -t "1953-05-29 05:45:00" -lat 27.9881 -lon 86.9253 -e 8848
Computing sun position at T = 1953-05-29T05:45:00Z + 0.0 s
Lat, Lon, Elev = 27.9881 deg, 86.9253 deg, 8848.0 m
T, P = 14.6 C, 1013.0 mbar
Results:
Azimuth, zenith = 137.735174 deg, 8.480987 deg
RA, dec, H = 65.760501 deg, 21.576785 deg, 353.875172 deg
```
An example test file is provided at https://raw.githubusercontent.com/s-bear/sun-position/master/sunposition_test.txt
## Example usage in a script
```python
import numpy as np
import matplotlib.pyplot as plt
# When imported as a module, sunposition will use numba.jit if available
# This may negatively impact performance if few positions are being computed
# For a rough guideline, on the author's machine:
# jit: 5.5 seconds + 35 microseconds per computation
# no-jit 1.4 milliseconds per computation
# break-even: ~4000 computations
# There are several methods to disable jit:
# 1. If numba.config.DISABLE_JIT or the environment variable NUMBA_DISABLE_JIT
# are set *before* sunposition is imported, jit will be disabled by default.
# 2. After sunposition is imported, use
# sunposition.disable_jit()
# or
# sunposition.enable_jit(False)
# 3. Pass `jit=False` as a keyword argument to the function
import sunposition
#evaluate on a 2 degree grid
lon = np.linspace(-180,180,181)
lat = np.linspace(-90,90,91)
LON, LAT = np.meshgrid(lon,lat)
# time_to_datetime64(t) converts a string to a numpy.datetime64 timestamp,
# with microsecond resolution.
# t may be 'now', which returns the current time using time.time(),
# or an ISO-8601 formatted date & time, e.g. '2024-04-08T11:09:34-07:00'
now = sunposition.time_to_datetime64('now')
az,zen = sunposition.sunpos(now,LAT,LON,0)[:2] #discard RA, dec, H
#convert zenith to elevation
elev = 90 - zen
#convert azimuth to vectors
u, v = np.cos((90-az)*np.pi/180), np.sin((90-az)*np.pi/180)
#plot
fig, ax = plt.subplots(figsize=(6,3),layout='constrained')
img = ax.imshow(elev,cmap=plt.cm.CMRmap,origin='lower',vmin=-90,vmax=90,extent=(-181,181,-91,91))
s = slice(5,-1,5) # equivalent to 5:-1:5
ax.quiver(lon[s],lat[s],u[s,s],v[s,s],pivot='mid',scale_units='xy')
ax.contour(lon,lat,elev,[0])
ax.set_aspect('equal')
ax.set_xticks(np.arange(-180,181,45))
ax.set_yticks(np.arange(-90,91,45))
ax.set_xlabel('Longitude (deg)')
ax.set_ylabel('Latitude (deg)')
cb = plt.colorbar(img,ax=ax,shrink=0.8,pad=0.03)
cb.set_label('Sun Elevation (deg)')
#display plot
plt.show() #unnecessary in interactive sessions
```
## Running Tests
The tests are written using `pytest`, with the test environment controlled by [`Hatch`](https://hatch.pypa.io/latest/).
Run `hatch test` in the `sunposition` source directory to run the test suite. Use `hatch test --all` to run the tests
on the Python versions specified in `pyproject.toml` test matrix.
## Citations
Ibrahim Reda and Afshin Andreas, "Solar position algorithm for solar radiation applications," Solar Energy, Volume 76, Issue 5, 2004, Pages 577-589, ISSN 0038-092X, [doi: 10.1016/j.solener.2003.12.003](https://dx.doi.org/10.1016/j.solener.2003.12.003).
Keywords: Global solar irradiance; Solar zenith angle; Solar azimuth angle; VSOP87 theory; Universal time; ΔUT1
Ibrahim Reda and Afshin Andreas, “Corrigendum to ‘Solar position algorithm for solar radiation applications’ [Solar Energy 76 (2004) 577–589],” Solar Energy, vol. 81, no. 6, p. 838, Jun. 2007, [doi: 10.1016/j.solener.2007.01.003](https://dx.doi.org/10.1016/j.solener.2007.01.003).
Cassio Neri and Lorenz Schneider, “Euclidean affine functions and their application to calendar algorithms,” Software: Practice and Experience, vol. 53, no. 4, pp. 937–970, Apr. 2023, [doi: 10.1002/spe.3172](https://dx.doi.org/10.1002/spe.3172).
# LICENSE
Copyright (c) 2025 Samuel Bear Powell, samuel.powell@uq.edu.au
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Raw data
{
"_id": null,
"home_page": null,
"name": "sunposition",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "astronomy, solar, sun",
"author": null,
"author_email": "Samuel Powell <samuel.powell@uq.edu.au>",
"download_url": "https://files.pythonhosted.org/packages/32/8d/694f3bdd6a0ad4efd64f023b924b8451fd52c807e9fa5940de80231e67ba/sunposition-1.2.1.tar.gz",
"platform": null,
"description": "# sunposition\n\n## Description\n\n`sunposition` is a python module for computing the sun's position based on the algorithms from \"Solar position algorithm for solar radiation applications\" by Ibrahim Reda and Afshin Anreas, Solar Energy (2004).\nThe algorithm calculates \"the solar zenith and azimuth angles in the period from the year \u22122000 to 6000, with uncertainties of \u00b10.0003\u00b0\".\nSee http://dx.doi.org/10.1016/j.solener.2003.12.003 for more information.\n\nIn this code, the latitude and longitude are positive for North and East, respectively.\nThe azimuth angle is 0 at North and positive towards the east.\nThe zenith angle is 0 at vertical and positive towards the horizon.\n\nThe code is hosted at https://github.com/s-bear/sun-position\n\nThe module is a single python file `sunposition.py` and may be used as a command-line utility or imported into a script.\nThe module depends only on [NumPy](https://numpy.org) but can optionally use [Numba](https://numba.pydata.org/) and [SciPy](https://scipy.org) for performance improvements.\n\n## Installation\n\n`sunposition` is hosted at [https://pypi.org/project/sunposition/](https://pypi.org/project/sunposition/) and may be installed using `pip`:\n\n```\n$ pip install sunposition\n```\n\n## Example usage on the command line\n\n```\n$ sunposition --help\nusage: sunposition [-h] [--version] [--citation] [-t TIME] [-lat LATITUDE] [-lon LONGITUDE] [-e ELEVATION] [-T TEMPERATURE] [-p PRESSURE] [-a ATMOS_REFRACT] [-dt DT] [-r] [--csv] [--jit]\n\nCompute sun position parameters given the time and location\n\noptions:\n -h, --help show this help message and exit\n --version show program's version number and exit\n --citation Print citation information\n -t TIME, --time TIME \"now\" or date and time in ISO8601 format or a (UTC) POSIX timestamp\n -lat LATITUDE, --latitude LATITUDE\n observer latitude, in decimal degrees, positive for north\n -lon LONGITUDE, --longitude LONGITUDE\n observer longitude, in decimal degrees, positive for east\n -e ELEVATION, --elevation ELEVATION\n observer elevation, in meters\n -T TEMPERATURE, --temperature TEMPERATURE\n temperature, in degrees celcius\n -p PRESSURE, --pressure PRESSURE\n atmospheric pressure, in millibar\n -a ATMOS_REFRACT, --atmos_refract ATMOS_REFRACT\n Atmospheric refraction at sunrise and sunset, in degrees. Omit to compute automatically, spa.c uses 0.5667\n -dt DT difference between earth's rotation time (TT) and universal time (UT1)\n -r, --radians Output in radians instead of degrees\n --csv Comma separated values (time,dt,lat,lon,elev,temp,pressure,az,zen,RA,dec,H)\n --jit Enable Numba acceleration (likely to cause slowdown for a single computation!)\n\n$ sunposition\nComputing sun position at T = 2025-02-03T05:13:53.608472Z + 0.0 s\nLat, Lon, Elev = 51.48 deg, 0.0 deg, 0 m\nT, P = 14.6 C, 1013.0 mbar\nResults:\nAzimuth, zenith = 88.915691 deg, 112.077238 deg\nRA, dec, H = 317.087980 deg, -16.448005 deg, -104.973487 deg\n\n$ sunposition -t \"1953-05-29 05:45:00\" -lat 27.9881 -lon 86.9253 -e 8848\nComputing sun position at T = 1953-05-29T05:45:00Z + 0.0 s\nLat, Lon, Elev = 27.9881 deg, 86.9253 deg, 8848.0 m\nT, P = 14.6 C, 1013.0 mbar\nResults:\nAzimuth, zenith = 137.735174 deg, 8.480987 deg\nRA, dec, H = 65.760501 deg, 21.576785 deg, 353.875172 deg\n```\n\nAn example test file is provided at https://raw.githubusercontent.com/s-bear/sun-position/master/sunposition_test.txt\n\n## Example usage in a script\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\n# When imported as a module, sunposition will use numba.jit if available\n# This may negatively impact performance if few positions are being computed\n# For a rough guideline, on the author's machine:\n# jit: 5.5 seconds + 35 microseconds per computation\n# no-jit 1.4 milliseconds per computation\n# break-even: ~4000 computations\n# There are several methods to disable jit:\n# 1. If numba.config.DISABLE_JIT or the environment variable NUMBA_DISABLE_JIT\n# are set *before* sunposition is imported, jit will be disabled by default.\n# 2. After sunposition is imported, use\n# sunposition.disable_jit()\n# or\n# sunposition.enable_jit(False)\n# 3. Pass `jit=False` as a keyword argument to the function\nimport sunposition\n\n#evaluate on a 2 degree grid\nlon = np.linspace(-180,180,181)\nlat = np.linspace(-90,90,91)\nLON, LAT = np.meshgrid(lon,lat)\n# time_to_datetime64(t) converts a string to a numpy.datetime64 timestamp,\n# with microsecond resolution. \n# t may be 'now', which returns the current time using time.time(),\n# or an ISO-8601 formatted date & time, e.g. '2024-04-08T11:09:34-07:00'\nnow = sunposition.time_to_datetime64('now')\naz,zen = sunposition.sunpos(now,LAT,LON,0)[:2] #discard RA, dec, H\n#convert zenith to elevation\nelev = 90 - zen\n#convert azimuth to vectors\nu, v = np.cos((90-az)*np.pi/180), np.sin((90-az)*np.pi/180)\n#plot\nfig, ax = plt.subplots(figsize=(6,3),layout='constrained')\nimg = ax.imshow(elev,cmap=plt.cm.CMRmap,origin='lower',vmin=-90,vmax=90,extent=(-181,181,-91,91))\ns = slice(5,-1,5) # equivalent to 5:-1:5\nax.quiver(lon[s],lat[s],u[s,s],v[s,s],pivot='mid',scale_units='xy')\nax.contour(lon,lat,elev,[0])\nax.set_aspect('equal')\nax.set_xticks(np.arange(-180,181,45))\nax.set_yticks(np.arange(-90,91,45))\nax.set_xlabel('Longitude (deg)')\nax.set_ylabel('Latitude (deg)')\ncb = plt.colorbar(img,ax=ax,shrink=0.8,pad=0.03)\ncb.set_label('Sun Elevation (deg)')\n#display plot\nplt.show() #unnecessary in interactive sessions\n\n```\n\n## Running Tests\nThe tests are written using `pytest`, with the test environment controlled by [`Hatch`](https://hatch.pypa.io/latest/).\nRun `hatch test` in the `sunposition` source directory to run the test suite. Use `hatch test --all` to run the tests\non the Python versions specified in `pyproject.toml` test matrix.\n\n## Citations\nIbrahim Reda and Afshin Andreas, \"Solar position algorithm for solar radiation applications,\" Solar Energy, Volume 76, Issue 5, 2004, Pages 577-589, ISSN 0038-092X, [doi: 10.1016/j.solener.2003.12.003](https://dx.doi.org/10.1016/j.solener.2003.12.003).\nKeywords: Global solar irradiance; Solar zenith angle; Solar azimuth angle; VSOP87 theory; Universal time; \u0394UT1\n\nIbrahim Reda and Afshin Andreas, \u201cCorrigendum to \u2018Solar position algorithm for solar radiation applications\u2019 [Solar Energy 76 (2004) 577\u2013589],\u201d Solar Energy, vol. 81, no. 6, p. 838, Jun. 2007, [doi: 10.1016/j.solener.2007.01.003](https://dx.doi.org/10.1016/j.solener.2007.01.003).\n\nCassio Neri and Lorenz Schneider, \u201cEuclidean affine functions and their application to calendar algorithms,\u201d Software: Practice and Experience, vol. 53, no. 4, pp. 937\u2013970, Apr. 2023, [doi: 10.1002/spe.3172](https://dx.doi.org/10.1002/spe.3172).\n\n \n# LICENSE\n\nCopyright (c) 2025 Samuel Bear Powell, samuel.powell@uq.edu.au\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
"bugtrack_url": null,
"license": null,
"summary": "Compute the sun's observed position based on Reda & Adreas's 2004 paper \"Solar position algorithm for solar radiation applications\"",
"version": "1.2.1",
"project_urls": {
"Homepage": "https://github.com/s-bear/sun-position"
},
"split_keywords": [
"astronomy",
" solar",
" sun"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "fe9b75a03efa3dcbe13299529cb1cf3d8ee353fa4240dd5fdb89c85056315f50",
"md5": "8e79751d88997960fc9c8055c7430e27",
"sha256": "bfe7d71020d8a0df1566ecd88ed0b7b4caffd4dfccd945bb22244ebdb5f8fc58"
},
"downloads": -1,
"filename": "sunposition-1.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8e79751d88997960fc9c8055c7430e27",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 23334,
"upload_time": "2025-02-03T06:27:16",
"upload_time_iso_8601": "2025-02-03T06:27:16.666195Z",
"url": "https://files.pythonhosted.org/packages/fe/9b/75a03efa3dcbe13299529cb1cf3d8ee353fa4240dd5fdb89c85056315f50/sunposition-1.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "328d694f3bdd6a0ad4efd64f023b924b8451fd52c807e9fa5940de80231e67ba",
"md5": "2896f0fe029c3915cf9b1ef775363ec8",
"sha256": "3ba3dec7082245167db903fa405cf22619a12a1c994044e59c7be08ddeb09790"
},
"downloads": -1,
"filename": "sunposition-1.2.1.tar.gz",
"has_sig": false,
"md5_digest": "2896f0fe029c3915cf9b1ef775363ec8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 22989,
"upload_time": "2025-02-03T06:27:18",
"upload_time_iso_8601": "2025-02-03T06:27:18.280633Z",
"url": "https://files.pythonhosted.org/packages/32/8d/694f3bdd6a0ad4efd64f023b924b8451fd52c807e9fa5940de80231e67ba/sunposition-1.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-03 06:27:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "s-bear",
"github_project": "sun-position",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "sunposition"
}