soltrack


Namesoltrack JSON
Version 0.2.5 PyPI version JSON
download
home_page
SummaryA free, fast and accurate Python package to compute the position of the Sun
upload_time2023-11-05 15:06:39
maintainer
docs_urlNone
author
requires_python
licenseEUPL 1.2
keywords astronomy ephemeris sun solar solar energy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SolTrack for Python

![PyPI](https://img.shields.io/pypi/v/soltrack?color=%230A0)
![PyPI - Downloads](https://img.shields.io/pypi/dm/soltrack)
[![Documentation
Status](https://readthedocs.org/projects/soltrack/badge/?version=latest)](https://soltrack.readthedocs.io/en/latest/?badge=latest)
![PyPI - Licence](https://img.shields.io/pypi/l/soltrack?color=%230A0)

A free, fast and simple Python package to compute the position of the Sun, as well as its rise and set times.
SolTrack was originally written in C/C++ by [Marc van der Sluys](http://marc.vandersluys.nl) of the department
of astrophysics of the Radboud University Nijmegen, the Netherlands and the Sustainable energy research group
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), and Paul van Kan of the Sustainable energy research group of the HAN
University of Applied Sciences in Arnhem, the Netherlands.  The code has now been translated to pure Python
and can be used under the conditions of the EUPL 1.2 licence.

SolTrack can perform up to 1.5 million position calculations per second on a single 3.4 GHz core of my laptop
(the [C version of SolTrack](http://soltrack.sourceforge.net/) is about twice as fast) with an accuracy of
0.0030 ± 0.0016°.


## Installation

This package can be installed using `pip install soltrack`.  This should automatically install the dependency
packages `numpy`, `pandas`, `astroconst` and `astrotool` if they haven't been installed already (if you're not
using a Python version older than 3.7, you will need to install `dataclasses` as well).  If you are installing
by hand, ensure that these packages are installed as well.


## Example use

### Update from v0.1.x to v0.2.0

The update from SolTrack v0.1.4 to v0.3.0 is **not backwards compatible**.  Most public members/variables and
methods/functions, as well as dummy arguments have been renamed in order to comply better with the Python
standards.  I have tried to put as much nuisance into a single update as possible (as opposed to in multiple
updates, rather than as opposed to as little nuisance as possible), so that this will hopefully not happen
again in the future.  For public methods, the obsolescent old name is kept as an alias, and warnings are
issued when used, instructing how to adapt your code.  In many cases a variable or function name `likeThis`
will have been replaced to one `like_this`, i.e. upper case replaced with an underscore and lower case.  See
the [documentation](https://soltrack.readthedocs.io) for more details.


### Code example for a number or range of datetimes

```python """Compute the position of the Sun and its rise and set times for a vector of instances."""

# Create a Pandas DatetimeIndex range every 20 days 1hour and 10 minutes, in my timezone:
import pandas as pd
dti = pd.date_range('2022-01-01 01:00', '2022-12-31 23:00', freq='20d1h10min', tz='Europe/Amsterdam')

# Set the geographic location to Arnhem, the Netherlands (we'll use degrees in SolTrack):
geo_lon =  5.950270  # Positive -> east of Greenwich (degrees)
geo_lat = 51.987380  # Positive -> northern hemisphere (degrees)


# Create a SolTrack instance and specify preferences:
from soltrack import SolTrack
st = SolTrack(geo_lon, geo_lat, use_degrees=True)  # Use default values for all but use_degrees
st.set_date_time(dti)  # Pass my dates and times to SolTrack
st.compute_position()  # Compute the Sun's position
st.compute_rise_set()  # Compute the rise and set times of the Sun


# Print some selected results as arrays and create chaos:
if st.lt is not None:  # If local time was used
    print('Local time:     ', *st.lt)  # Asterisk (*) unpacks the DTI
    
print('UTC:            ', *st.utc)
print('azimuth:        ', *st.azimuth)
print('altitude:       ', *st.altitude)
print('distance:       ', *st.distance)
print('riseTime:       ', *st.rise_time)
print('transTime:      ', *st.transit_time)
print('setTime:        ', *st.set_time)


# Store selected results in a Pandas DataFrame and print that in a more orderly fashion:
st.create_df(utc=True, jd=True, ecl=True, rts_pos=True)
with pd.option_context('display.max_columns',None, 'display.width',None):  # Want all columns
    print(st.df)
```

### Code example for a single instant

Note that in most cases, you should use the [vector option](#code-example-for-a-number-or-range-of-datetimes)
instead, as it is faster starting from calculations for two instances.  See the section
[Performance](#performance) for more details.  The code listing below is provided for completeness only.


```python
"""Example Python script to compute the position of the Sun and its rise and set times for a single instant
and demonstrate some other features."""

from soltrack import SolTrack
import datetime as dt
import pytz as tz

# Set the geographic location to Arnhem, the Netherlands:
geo_lon =  5.950270  # Positive -> east of Greenwich (degrees)
geo_lat = 51.987380  # Positive -> northern hemisphere (degrees)

st = SolTrack(geo_lon, geo_lat, use_degrees=True)  # Same as above, using default values for all but use_degrees.

# Set SolTrack date and time using separate (UTC!) year, month, day, hour, minute and second variables:
st.set_date_and_time(2023, 7, 16,  6, 2, 49.217348)  # Date: 2023-07-16, time: 06:02:49.217348 UTC

# Alternatively, use a (localised) datetime object:
cet     = tz.timezone('Europe/Amsterdam')
my_date = dt.datetime(2023, 7, 16,  8, 2, 49, 217348)  # Same as above, in local time for TZ=+2 (08:02:49.217348 LT)
my_date = cet.localize(my_date)
st.set_date_time(my_date)  # Set SolTrack date and time using a Python datetime object.

# Compute the Sun's position:
st.compute_position()

# Compute the rise and set times of the Sun:
st.compute_rise_set()


# Write results to standard output:
print("Location:   %0.3lf E, %0.3lf N"  % (st.geo_longitude, st.geo_latitude))
# print("Date/time:  %4d-%02d-%02d %02d:%02d:%09.6lf" % (st.year, st.month, st.day,  st.hour, st.minute, st.second))
print("Date/time:  %s"                  % my_date)
print("JD:         %0.11lf"             % (st.julian_day))
print()

print("Ecliptic longitude, latitude:        %10.6lf° %10.6lf°"     % (st.longitude, 0.0))  # Note: latitude is always 0 in this model
print("Distance:                            %10.6lf°"              % (st.distance))
print("Right ascension, declination:        %10.6lf° %10.6lf°"     % (st._right_ascension_uncorr, st._declination_uncorr))
print("Uncorrected altitude:                            %10.6lf°"  % (st._altitude_uncorr))
print("Corrected azimuth, altitude:         %10.6lf° %10.6lf°"     % (st.azimuth, st.altitude))
print("Corrected hour angle, declination:   %10.6lf° %10.6lf°"     % (st.hour_angle, st.declination))
print()

print("Rise time:      %s,    azimuth:   %11.5lf" % (*st.rise_time,     *st.rise_azimuth))
print("Transit time:   %s,    altitude:  %11.5lf" % (*st.transit_time,  *st.transit_altitude))
print("Set time:       %s,    azimuth:   %11.5lf" % (*st.set_time,      *st.set_azimuth))
print()


# Change the location whilst keeping the same SolTrack object:
st.set_location(geo_lon, -geo_lat)

# Compute the current position of the Sun for the new location:
st.now()
st.compute_position()

print("Location:   %0.3lf E, %0.3lf N"                         % (st.geo_longitude, st.geo_latitude))
print("Date (UT):  %4d-%02d-%02d"                              % (st.year, st.month, st.day))
print("Time (UT):  %02d:%02d:%09.6lf"                          % (st.hour, st.minute, st.second))
print("Corrected azimuth, altitude:         %10.6lf° %10.6lf°" % (st.azimuth, st.altitude))
```


### Code example for SolTrack v0.1.x (old)
```python
"""Example Python script to compute the position of the Sun and its rise and set times for a single instant."""

import soltrack as st

# Set preferences (all are False by default):
useDegrees             = True   # Input (geographic position) and output are in degrees
useNorthEqualsZero     = True   # Azimuth: 0 = South, pi/2 (90deg) = West  ->  0 = North, pi/2 (90deg) = East
computeRefrEquatorial  = True   # Compure refraction-corrected equatorial coordinates (Hour angle, declination)
computeDistance        = True   # Compute the distance to the Sun

# Set up geographical location (in degrees, since useDegrees=True) in a SolTrack Location dataclass object:
loc = st.Location(5.950270, 51.987380)  # longitude (>0: east of Greenwich),  latitude (>0: northern hemisphere)

# Set (UT!) date and time in a SolTrack Time dataclass object:
time = st.Time(2045, 7, 16,  6, 2, 49.217348)  # Date: 2045-07-16, time: 06:02:49.217348


# Compute positions - returns a st.Position object:
pos = st.computeSunPosition(loc, time, useDegrees, useNorthEqualsZero, computeRefrEquatorial, computeDistance)

# Compute rise and set times - returns a st.RiseSet object:
riseSet = st.computeSunRiseSet(loc, time, 0.0, useDegrees, useNorthEqualsZero)


# Write results to standard output:
print("Location:  %0.3lf E, %0.3lf N" % (loc.longitude, loc.latitude))
print("Date:      %4d %2d %2d" % (time.year, time.month, time.day))
print("Time:      %2d %2d %9.6lf" % (time.hour, time.minute, time.second))
print("JD:        %0.11lf" % (pos.julianDay))
print()

print("Ecliptic longitude, latitude:        %10.6lf° %10.6lf°" % (pos.longitude, 0.0))
print("Right ascension, declination:        %10.6lf° %10.6lf°" % (pos.rightAscension, pos.declination))
print("Uncorrected altitude:                            %10.6lf°" % (pos.altitude))
print("Corrected azimuth, altitude:         %10.6lf° %10.6lf°" % (pos.azimuthRefract, pos.altitudeRefract))
print("Corrected hour angle, declination:   %10.6lf° %10.6lf°" % (pos.hourAngleRefract, pos.declinationRefract))
print()

print("Rise time:      %11.5lf,    azimuth:   %11.5lf" % (riseSet.riseTime, riseSet.riseAzimuth))
print("Transit time:   %11.5lf,    altitude:  %11.5lf" % (riseSet.transitTime, riseSet.transitAltitude))
print("Set time:       %11.5lf,    azimuth:   %11.5lf" % (riseSet.setTime, riseSet.setAzimuth))
print()
```

## Performance

### Performance of position calculations for an array/vector or range of instants

From v0.2.0 on, SolTrack uses Pandas to allow the use of arrays or vectors of datetimes (Series,
DatetimeIndex, ndarrays of datetime64, ...).  This causes some overhead, which is relatively more significant
for small numbers.  SolTrack performs fastest (per position calculation and on my laptop) for about
10<sup>5</sup>-10<sup>6</sup> calculations:

| N<sub>calc</sub> (-) | Time (s) | Speed (/s) | Speed (millions/s) |
|----------------------|----------|------------|--------------------|
| 1e0                  | 0.00081  | 1.23e+03   | 0.001              |
| 1e1                  | 0.00080  | 1.25e+04   | 0.013              |
| 1e2                  | 0.00105  | 9.52e+04   | 0.095              |
| 1e3                  | 0.00256  | 3.91e+05   | 0.39               |
| 1e4                  | 0.0132   | 7.58e+05   | 0.76               |
| 1e5                  | 0.0688   | 1.45e+06   | 1.45               |
| 3e5                  | 0.1960   | 1.53e+06   | 1.53               |
| 1e6                  | 0.6660   | 1.50e+06   | 1.50               |
| 3e6                  | 2.068    | 1.45e+06   | 1.45               |
| 1e7                  | 8.691    | 1.15e+06   | 1.15               |

These benchmarks were done on a single CPU core, capped at 3.4GHz.  The cpu and core were always the same, and
the minimum of 10 benchmarks is listed.  Timezone-naive datetimes (representing UTC) were used; using
timezone-aware datetimes slows down the code by a factor of ~4.6 compared to the numbers in the table.


### Performance of calculations of rise, transit and set times

Benchmarks for rise, transit and set computations were performed in the same manner as above, but using
`return_datetimes=False` in the `st.compute_rise_set()` call, which returns rise, transit and set times in
decimal hours.  If instead datetimes are desired, the code becomes a factor of about 3.1 times slower.  The
use of `utc=True` has little effect, and using timezone-aware datetimes instead of timezone-naive ones adds
6.1% to the computational times listed below.

| N<sub>calc</sub> (-) | Time (s) | Speed (/s) |
|----------------------|----------|------------|
| 1                    | 0.0020   | 500.0      |
| 10                   | 0.0134   | 746.3      |
| 100                  | 0.1247   | 801.9      |
| 1000                 | 1.207    | 828.5      |
| 1e4                  | 12.00    | 833.3      |


### Performance of position calculation for a single instant

Because of the overhead of Pandas and datetime-like objects, SolTrack has actually slowed down by a factor of
~10.4 between versions 0.1.4 and 0.2.0 when doing single calculations.  I don't consider that a big issue,
since a single position calculation still takes less than a millisecond, so that the effect is not noticable
for humans.  It does become noticable for large numbers, but then arrays can be used, which make the code
~1000x faster.  In fact, the array version is faster starting from two iterations, so there is usually very
little reason to use the single-datetime option.

Single calculations can be made about 19% faster by providing datetimes in UTC and specifying `utc=True` in
the `st.set_date_time()` method.  The use of timezone-naive versus timezone-aware datetimes has little
influence on the performance for single calculations, and calculation times scale linearly when doing multiple
calls (since the must then be done in a Python loop).

For single datetimes, 1000 calculations take about 0.68 seconds on the single CPU core of my laptop capped at
3.4 GHz, and about 0.55 seconds with `utc=True`.


## SolTrack pages

* [Van der Sluys & Van Kan (2022)](https://arxiv.org/abs/2209.01557): SolTrack: a free, fast and accurate routine to
  compute the position of the Sun.  Scientific paper with all technical details.

* [Pypi](https://pypi.org/project/soltrack/): SolTrack Python package
* [GitHub](https://github.com/MarcvdSluys/SolTrack-Python): SolTrack Python source code
* [ReadTheDocs](https://soltrack.readthedocs.io/en/latest/): SolTrack Python documentation

* [SolTrack for C/C++](http://soltrack.sourceforge.net/) on SourceForge
* [SolTrack for Arduino](https://github.com/MarcvdSluys/SolTrack-Arduino) on GitHub


## Author and licence

* Author: Marc van der Sluys
* Contact: http://marc.vandersluys.nl
* Licence: [EUPL 1.2](https://www.eupl.eu/1.2/en/)


## See also

* [AstroConst](https://pypi.org/project/astroconst/): a Python package that provides astronomical constants.
* [AstroTool](https://pypi.org/project/astrotool/): a Python package for astronomical calculations in Python
  or on the command line.
* [elp-mpp02](https://pypi.org/project/elp-mpp02/): accurate Moon positions using the lunar solution ELP/MPP02
  in Python.
* [libTheSky](http://libthesky.sourceforge.net/): a Fortran library to compute the positions of celestial
  bodies (Sun, Moon, planets, stars, asteroids, comets) and events (e.g. lunar phases) with great accuracy.
* [SolarEnergy](https://pypi.org/project/solarenergy/): A Python module to do simple modelling in the field of
  solar energy.


## References

* [Van der Sluys & Van Kan (2022)](https://arxiv.org/abs/2209.01557): SolTrack: a free, fast and accurate routine to
  compute the position of the Sun.  Scientific paper with all technical details.

* [Celestial mechanics in a nutshell (CMiaNS)](https://cmians.sourceforge.io/): online living document.
* Meeus, [Astronomical algorithms](https://www.willbell.com/math/MC1.HTM), 2nd Ed.
* The C/C++ and Python codes have been adapted from the Fortran implementation in
  [libTheSky](http://libthesky.sourceforge.net/), which contains many references.


<sub>Copyright (c) 2019-2022 Marc van der Sluys</sub>

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "soltrack",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "astronomy,ephemeris,sun,solar,solar energy",
    "author": "",
    "author_email": "Marc van der Sluys <git@vandersluys.nl>",
    "download_url": "https://files.pythonhosted.org/packages/d0/fa/21f334d7ff2c2dc97d26fa8103034086f5c00541a8fbef00af7f10fdf8b5/soltrack-0.2.5.tar.gz",
    "platform": null,
    "description": "# SolTrack for Python\n\n![PyPI](https://img.shields.io/pypi/v/soltrack?color=%230A0)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/soltrack)\n[![Documentation\nStatus](https://readthedocs.org/projects/soltrack/badge/?version=latest)](https://soltrack.readthedocs.io/en/latest/?badge=latest)\n![PyPI - Licence](https://img.shields.io/pypi/l/soltrack?color=%230A0)\n\nA free, fast and simple Python package to compute the position of the Sun, as well as its rise and set times.\nSolTrack was originally written in C/C++ by [Marc van der Sluys](http://marc.vandersluys.nl) of the department\nof astrophysics of the Radboud University Nijmegen, the Netherlands and the Sustainable energy research group\nof the HAN University of Applied Sciences in Arnhem, the Netherlands (now at the Netherlands Institute for\nNuclear and High-Energy Physics (Nikhef) and the Institute for Gravitational and Subatomic Physics (GRASP) at\nUtrecht University in the Netherlands), and Paul van Kan of the Sustainable energy research group of the HAN\nUniversity of Applied Sciences in Arnhem, the Netherlands.  The code has now been translated to pure Python\nand can be used under the conditions of the EUPL 1.2 licence.\n\nSolTrack can perform up to 1.5 million position calculations per second on a single 3.4 GHz core of my laptop\n(the [C version of SolTrack](http://soltrack.sourceforge.net/) is about twice as fast) with an accuracy of\n0.0030 \u00b1 0.0016\u00b0.\n\n\n## Installation\n\nThis package can be installed using `pip install soltrack`.  This should automatically install the dependency\npackages `numpy`, `pandas`, `astroconst` and `astrotool` if they haven't been installed already (if you're not\nusing a Python version older than 3.7, you will need to install `dataclasses` as well).  If you are installing\nby hand, ensure that these packages are installed as well.\n\n\n## Example use\n\n### Update from v0.1.x to v0.2.0\n\nThe update from SolTrack v0.1.4 to v0.3.0 is **not backwards compatible**.  Most public members/variables and\nmethods/functions, as well as dummy arguments have been renamed in order to comply better with the Python\nstandards.  I have tried to put as much nuisance into a single update as possible (as opposed to in multiple\nupdates, rather than as opposed to as little nuisance as possible), so that this will hopefully not happen\nagain in the future.  For public methods, the obsolescent old name is kept as an alias, and warnings are\nissued when used, instructing how to adapt your code.  In many cases a variable or function name `likeThis`\nwill have been replaced to one `like_this`, i.e. upper case replaced with an underscore and lower case.  See\nthe [documentation](https://soltrack.readthedocs.io) for more details.\n\n\n### Code example for a number or range of datetimes\n\n```python \"\"\"Compute the position of the Sun and its rise and set times for a vector of instances.\"\"\"\n\n# Create a Pandas DatetimeIndex range every 20 days 1hour and 10 minutes, in my timezone:\nimport pandas as pd\ndti = pd.date_range('2022-01-01 01:00', '2022-12-31 23:00', freq='20d1h10min', tz='Europe/Amsterdam')\n\n# Set the geographic location to Arnhem, the Netherlands (we'll use degrees in SolTrack):\ngeo_lon =  5.950270  # Positive -> east of Greenwich (degrees)\ngeo_lat = 51.987380  # Positive -> northern hemisphere (degrees)\n\n\n# Create a SolTrack instance and specify preferences:\nfrom soltrack import SolTrack\nst = SolTrack(geo_lon, geo_lat, use_degrees=True)  # Use default values for all but use_degrees\nst.set_date_time(dti)  # Pass my dates and times to SolTrack\nst.compute_position()  # Compute the Sun's position\nst.compute_rise_set()  # Compute the rise and set times of the Sun\n\n\n# Print some selected results as arrays and create chaos:\nif st.lt is not None:  # If local time was used\n    print('Local time:     ', *st.lt)  # Asterisk (*) unpacks the DTI\n    \nprint('UTC:            ', *st.utc)\nprint('azimuth:        ', *st.azimuth)\nprint('altitude:       ', *st.altitude)\nprint('distance:       ', *st.distance)\nprint('riseTime:       ', *st.rise_time)\nprint('transTime:      ', *st.transit_time)\nprint('setTime:        ', *st.set_time)\n\n\n# Store selected results in a Pandas DataFrame and print that in a more orderly fashion:\nst.create_df(utc=True, jd=True, ecl=True, rts_pos=True)\nwith pd.option_context('display.max_columns',None, 'display.width',None):  # Want all columns\n    print(st.df)\n```\n\n### Code example for a single instant\n\nNote that in most cases, you should use the [vector option](#code-example-for-a-number-or-range-of-datetimes)\ninstead, as it is faster starting from calculations for two instances.  See the section\n[Performance](#performance) for more details.  The code listing below is provided for completeness only.\n\n\n```python\n\"\"\"Example Python script to compute the position of the Sun and its rise and set times for a single instant\nand demonstrate some other features.\"\"\"\n\nfrom soltrack import SolTrack\nimport datetime as dt\nimport pytz as tz\n\n# Set the geographic location to Arnhem, the Netherlands:\ngeo_lon =  5.950270  # Positive -> east of Greenwich (degrees)\ngeo_lat = 51.987380  # Positive -> northern hemisphere (degrees)\n\nst = SolTrack(geo_lon, geo_lat, use_degrees=True)  # Same as above, using default values for all but use_degrees.\n\n# Set SolTrack date and time using separate (UTC!) year, month, day, hour, minute and second variables:\nst.set_date_and_time(2023, 7, 16,  6, 2, 49.217348)  # Date: 2023-07-16, time: 06:02:49.217348 UTC\n\n# Alternatively, use a (localised) datetime object:\ncet     = tz.timezone('Europe/Amsterdam')\nmy_date = dt.datetime(2023, 7, 16,  8, 2, 49, 217348)  # Same as above, in local time for TZ=+2 (08:02:49.217348 LT)\nmy_date = cet.localize(my_date)\nst.set_date_time(my_date)  # Set SolTrack date and time using a Python datetime object.\n\n# Compute the Sun's position:\nst.compute_position()\n\n# Compute the rise and set times of the Sun:\nst.compute_rise_set()\n\n\n# Write results to standard output:\nprint(\"Location:   %0.3lf E, %0.3lf N\"  % (st.geo_longitude, st.geo_latitude))\n# print(\"Date/time:  %4d-%02d-%02d %02d:%02d:%09.6lf\" % (st.year, st.month, st.day,  st.hour, st.minute, st.second))\nprint(\"Date/time:  %s\"                  % my_date)\nprint(\"JD:         %0.11lf\"             % (st.julian_day))\nprint()\n\nprint(\"Ecliptic longitude, latitude:        %10.6lf\u00b0 %10.6lf\u00b0\"     % (st.longitude, 0.0))  # Note: latitude is always 0 in this model\nprint(\"Distance:                            %10.6lf\u00b0\"              % (st.distance))\nprint(\"Right ascension, declination:        %10.6lf\u00b0 %10.6lf\u00b0\"     % (st._right_ascension_uncorr, st._declination_uncorr))\nprint(\"Uncorrected altitude:                            %10.6lf\u00b0\"  % (st._altitude_uncorr))\nprint(\"Corrected azimuth, altitude:         %10.6lf\u00b0 %10.6lf\u00b0\"     % (st.azimuth, st.altitude))\nprint(\"Corrected hour angle, declination:   %10.6lf\u00b0 %10.6lf\u00b0\"     % (st.hour_angle, st.declination))\nprint()\n\nprint(\"Rise time:      %s,    azimuth:   %11.5lf\" % (*st.rise_time,     *st.rise_azimuth))\nprint(\"Transit time:   %s,    altitude:  %11.5lf\" % (*st.transit_time,  *st.transit_altitude))\nprint(\"Set time:       %s,    azimuth:   %11.5lf\" % (*st.set_time,      *st.set_azimuth))\nprint()\n\n\n# Change the location whilst keeping the same SolTrack object:\nst.set_location(geo_lon, -geo_lat)\n\n# Compute the current position of the Sun for the new location:\nst.now()\nst.compute_position()\n\nprint(\"Location:   %0.3lf E, %0.3lf N\"                         % (st.geo_longitude, st.geo_latitude))\nprint(\"Date (UT):  %4d-%02d-%02d\"                              % (st.year, st.month, st.day))\nprint(\"Time (UT):  %02d:%02d:%09.6lf\"                          % (st.hour, st.minute, st.second))\nprint(\"Corrected azimuth, altitude:         %10.6lf\u00b0 %10.6lf\u00b0\" % (st.azimuth, st.altitude))\n```\n\n\n### Code example for SolTrack v0.1.x (old)\n```python\n\"\"\"Example Python script to compute the position of the Sun and its rise and set times for a single instant.\"\"\"\n\nimport soltrack as st\n\n# Set preferences (all are False by default):\nuseDegrees             = True   # Input (geographic position) and output are in degrees\nuseNorthEqualsZero     = True   # Azimuth: 0 = South, pi/2 (90deg) = West  ->  0 = North, pi/2 (90deg) = East\ncomputeRefrEquatorial  = True   # Compure refraction-corrected equatorial coordinates (Hour angle, declination)\ncomputeDistance        = True   # Compute the distance to the Sun\n\n# Set up geographical location (in degrees, since useDegrees=True) in a SolTrack Location dataclass object:\nloc = st.Location(5.950270, 51.987380)  # longitude (>0: east of Greenwich),  latitude (>0: northern hemisphere)\n\n# Set (UT!) date and time in a SolTrack Time dataclass object:\ntime = st.Time(2045, 7, 16,  6, 2, 49.217348)  # Date: 2045-07-16, time: 06:02:49.217348\n\n\n# Compute positions - returns a st.Position object:\npos = st.computeSunPosition(loc, time, useDegrees, useNorthEqualsZero, computeRefrEquatorial, computeDistance)\n\n# Compute rise and set times - returns a st.RiseSet object:\nriseSet = st.computeSunRiseSet(loc, time, 0.0, useDegrees, useNorthEqualsZero)\n\n\n# Write results to standard output:\nprint(\"Location:  %0.3lf E, %0.3lf N\" % (loc.longitude, loc.latitude))\nprint(\"Date:      %4d %2d %2d\" % (time.year, time.month, time.day))\nprint(\"Time:      %2d %2d %9.6lf\" % (time.hour, time.minute, time.second))\nprint(\"JD:        %0.11lf\" % (pos.julianDay))\nprint()\n\nprint(\"Ecliptic longitude, latitude:        %10.6lf\u00b0 %10.6lf\u00b0\" % (pos.longitude, 0.0))\nprint(\"Right ascension, declination:        %10.6lf\u00b0 %10.6lf\u00b0\" % (pos.rightAscension, pos.declination))\nprint(\"Uncorrected altitude:                            %10.6lf\u00b0\" % (pos.altitude))\nprint(\"Corrected azimuth, altitude:         %10.6lf\u00b0 %10.6lf\u00b0\" % (pos.azimuthRefract, pos.altitudeRefract))\nprint(\"Corrected hour angle, declination:   %10.6lf\u00b0 %10.6lf\u00b0\" % (pos.hourAngleRefract, pos.declinationRefract))\nprint()\n\nprint(\"Rise time:      %11.5lf,    azimuth:   %11.5lf\" % (riseSet.riseTime, riseSet.riseAzimuth))\nprint(\"Transit time:   %11.5lf,    altitude:  %11.5lf\" % (riseSet.transitTime, riseSet.transitAltitude))\nprint(\"Set time:       %11.5lf,    azimuth:   %11.5lf\" % (riseSet.setTime, riseSet.setAzimuth))\nprint()\n```\n\n## Performance\n\n### Performance of position calculations for an array/vector or range of instants\n\nFrom v0.2.0 on, SolTrack uses Pandas to allow the use of arrays or vectors of datetimes (Series,\nDatetimeIndex, ndarrays of datetime64, ...).  This causes some overhead, which is relatively more significant\nfor small numbers.  SolTrack performs fastest (per position calculation and on my laptop) for about\n10<sup>5</sup>-10<sup>6</sup> calculations:\n\n| N<sub>calc</sub> (-) | Time (s) | Speed (/s) | Speed (millions/s) |\n|----------------------|----------|------------|--------------------|\n| 1e0                  | 0.00081  | 1.23e+03   | 0.001              |\n| 1e1                  | 0.00080  | 1.25e+04   | 0.013              |\n| 1e2                  | 0.00105  | 9.52e+04   | 0.095              |\n| 1e3                  | 0.00256  | 3.91e+05   | 0.39               |\n| 1e4                  | 0.0132   | 7.58e+05   | 0.76               |\n| 1e5                  | 0.0688   | 1.45e+06   | 1.45               |\n| 3e5                  | 0.1960   | 1.53e+06   | 1.53               |\n| 1e6                  | 0.6660   | 1.50e+06   | 1.50               |\n| 3e6                  | 2.068    | 1.45e+06   | 1.45               |\n| 1e7                  | 8.691    | 1.15e+06   | 1.15               |\n\nThese benchmarks were done on a single CPU core, capped at 3.4GHz.  The cpu and core were always the same, and\nthe minimum of 10 benchmarks is listed.  Timezone-naive datetimes (representing UTC) were used; using\ntimezone-aware datetimes slows down the code by a factor of ~4.6 compared to the numbers in the table.\n\n\n### Performance of calculations of rise, transit and set times\n\nBenchmarks for rise, transit and set computations were performed in the same manner as above, but using\n`return_datetimes=False` in the `st.compute_rise_set()` call, which returns rise, transit and set times in\ndecimal hours.  If instead datetimes are desired, the code becomes a factor of about 3.1 times slower.  The\nuse of `utc=True` has little effect, and using timezone-aware datetimes instead of timezone-naive ones adds\n6.1% to the computational times listed below.\n\n| N<sub>calc</sub> (-) | Time (s) | Speed (/s) |\n|----------------------|----------|------------|\n| 1                    | 0.0020   | 500.0      |\n| 10                   | 0.0134   | 746.3      |\n| 100                  | 0.1247   | 801.9      |\n| 1000                 | 1.207    | 828.5      |\n| 1e4                  | 12.00    | 833.3      |\n\n\n### Performance of position calculation for a single instant\n\nBecause of the overhead of Pandas and datetime-like objects, SolTrack has actually slowed down by a factor of\n~10.4 between versions 0.1.4 and 0.2.0 when doing single calculations.  I don't consider that a big issue,\nsince a single position calculation still takes less than a millisecond, so that the effect is not noticable\nfor humans.  It does become noticable for large numbers, but then arrays can be used, which make the code\n~1000x faster.  In fact, the array version is faster starting from two iterations, so there is usually very\nlittle reason to use the single-datetime option.\n\nSingle calculations can be made about 19% faster by providing datetimes in UTC and specifying `utc=True` in\nthe `st.set_date_time()` method.  The use of timezone-naive versus timezone-aware datetimes has little\ninfluence on the performance for single calculations, and calculation times scale linearly when doing multiple\ncalls (since the must then be done in a Python loop).\n\nFor single datetimes, 1000 calculations take about 0.68 seconds on the single CPU core of my laptop capped at\n3.4 GHz, and about 0.55 seconds with `utc=True`.\n\n\n## SolTrack pages\n\n* [Van der Sluys & Van Kan (2022)](https://arxiv.org/abs/2209.01557): SolTrack: a free, fast and accurate routine to\n  compute the position of the Sun.  Scientific paper with all technical details.\n\n* [Pypi](https://pypi.org/project/soltrack/): SolTrack Python package\n* [GitHub](https://github.com/MarcvdSluys/SolTrack-Python): SolTrack Python source code\n* [ReadTheDocs](https://soltrack.readthedocs.io/en/latest/): SolTrack Python documentation\n\n* [SolTrack for C/C++](http://soltrack.sourceforge.net/) on SourceForge\n* [SolTrack for Arduino](https://github.com/MarcvdSluys/SolTrack-Arduino) on GitHub\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## See also\n\n* [AstroConst](https://pypi.org/project/astroconst/): a Python package that provides astronomical constants.\n* [AstroTool](https://pypi.org/project/astrotool/): a Python package for astronomical calculations in Python\n  or on the command line.\n* [elp-mpp02](https://pypi.org/project/elp-mpp02/): accurate Moon positions using the lunar solution ELP/MPP02\n  in Python.\n* [libTheSky](http://libthesky.sourceforge.net/): a Fortran library to compute the positions of celestial\n  bodies (Sun, Moon, planets, stars, asteroids, comets) and events (e.g. lunar phases) with great accuracy.\n* [SolarEnergy](https://pypi.org/project/solarenergy/): A Python module to do simple modelling in the field of\n  solar energy.\n\n\n## References\n\n* [Van der Sluys & Van Kan (2022)](https://arxiv.org/abs/2209.01557): SolTrack: a free, fast and accurate routine to\n  compute the position of the Sun.  Scientific paper with all technical details.\n\n* [Celestial mechanics in a nutshell (CMiaNS)](https://cmians.sourceforge.io/): online living document.\n* Meeus, [Astronomical algorithms](https://www.willbell.com/math/MC1.HTM), 2nd Ed.\n* The C/C++ and Python codes have been adapted from the Fortran implementation in\n  [libTheSky](http://libthesky.sourceforge.net/), which contains many references.\n\n\n<sub>Copyright (c) 2019-2022 Marc van der Sluys</sub>\n",
    "bugtrack_url": null,
    "license": "EUPL 1.2",
    "summary": "A free, fast and accurate Python package to compute the position of the Sun",
    "version": "0.2.5",
    "project_urls": {
        "GitHub": "https://github.com/MarcvdSluys/SolTrack-Python/",
        "ReadTheDocs": "https://soltrack.readthedocs.io",
        "SourceForge": "https://soltrack.sourceforge.net"
    },
    "split_keywords": [
        "astronomy",
        "ephemeris",
        "sun",
        "solar",
        "solar energy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eb30c283e19c8b8b9881a37ac4cf41d83d6fe970228b460ebc1f2ca2d5bd6125",
                "md5": "aabdda74bb42935fec2b3cfbb2a3bd37",
                "sha256": "514fb5d56467495e60675c389f44ae5016ffa3ccc545a6bd63984a7f6684a0bc"
            },
            "downloads": -1,
            "filename": "soltrack-0.2.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aabdda74bb42935fec2b3cfbb2a3bd37",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 29070,
            "upload_time": "2023-11-05T15:06:38",
            "upload_time_iso_8601": "2023-11-05T15:06:38.109656Z",
            "url": "https://files.pythonhosted.org/packages/eb/30/c283e19c8b8b9881a37ac4cf41d83d6fe970228b460ebc1f2ca2d5bd6125/soltrack-0.2.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d0fa21f334d7ff2c2dc97d26fa8103034086f5c00541a8fbef00af7f10fdf8b5",
                "md5": "8a3c2dd24c15558624a74f05baf82499",
                "sha256": "49343aa7d811a3202036a580a9d458b2e2f1d02a3a630e575c04fed9c720a0ed"
            },
            "downloads": -1,
            "filename": "soltrack-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "8a3c2dd24c15558624a74f05baf82499",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 28287,
            "upload_time": "2023-11-05T15:06:39",
            "upload_time_iso_8601": "2023-11-05T15:06:39.898342Z",
            "url": "https://files.pythonhosted.org/packages/d0/fa/21f334d7ff2c2dc97d26fa8103034086f5c00541a8fbef00af7f10fdf8b5/soltrack-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-05 15:06:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MarcvdSluys",
    "github_project": "SolTrack-Python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "soltrack"
}
        
Elapsed time: 0.13175s