Package: daylight
daylight or libdaylight is a library which enables you to answer daylight related questions like:Irradiance - How bright is it outside, given a particular time and location?What is the time of sunrise/solarnoon/sunset, given a particular time and location?libdaylight is written in modern C++ with bindings to python usingpybind11.daylight's python bindings provide vectorized functions - allowing for efficient analysis when dealing with lots of queries. At the same, this allows daylight to play well with established data science tooling like numpy and pandas.The math used in this library is mostly based onNOAA's solar calculations, which were in turn based onAstronomical Algorithms, by Jean Meeus. Also thanks tothis Python implementationof these calculations by Michel Landers, which was a very useful reference while building this library.⚠️ Currently this library is only tested for basic use cases. For any scientific-grade use cases, or for cases where precise values are needed - this library is not extensively tested, yet. Any contributions from that aspect would be greatly appreciated.InstallationFromPyPI$pipinstalldaylightFrom source$pipinstallgit+https://github.com/adonmo/daylightNote: This requires cmake and pybind11 to be installed on your system. If you're having trouble with pybind11,try using a conda enviromentinstead.ExamplesThe examples directory contains a real world usage of this library atAdonmo- for its season and location independent brightness control mechanism:Click hereto read it.Usage (Python)importdatetimeimportpytzimportdaylightdefepoch(year,month,day,hour=0,minute=0,second=0,tz=pytz.UTC):returnint(tz.localize(datetime.datetime(year,month,day,hour,minute,second)).timestamp())tz=pytz.timezone("Asia/Kolkata")tz_offset=tz.utcoffset(datetime.datetime.utcnow()).total_seconds()/3600# Example with GPS coords for Hyderabad, India, in Indian timezone (IST)sun=daylight.Sunclock(17.3859,78.4867,tz_offset)# Know the daylight strength / ambient brightness level at a given time of day# Below call returns 0.882753920406182sun.irradiance(epoch(2020,5,21,14,10,35,tz))# Know the sunrise time for a given date# Returns unix timestamp for 5:42 AMsun.sunrise(epoch(2020,5,21,tz=tz))# Know the solar noon time for a given date# Returns unix timestamp for 12:12 PMsun.solar_noon(epoch(2020,5,21,tz=tz))# Know the sunset time for a given date# Returns unix timestamp for 18:42 PMsun.sunset(epoch(2020,5,21,tz=tz))# daylight's functions are vectorized as well - which means you can compute results# for multiple parameters efficiently, while playing well with libraries like numpy/pandas# Returns [-0.56570521  0.28650605]sun.irradiance([epoch(2020,5,21,3,0,0,tz),epoch(2020,5,21,7,0,0,tz),])Python API Reference and comparision with other libraries can be found on our docs:https://adonmo-daylight.readthedocs.io/en/latest/Usage (C)libdaylight can also be used in C through the provided C API.Here is an example code on how to do this:#include"daylight_c.h"#include<stdio.h>intmain(intargc,char*argv[]){structSunclock*s=newSunclock(17.3859,78.4867,5.5);time_tt_20200521141035=1590050435;doubleirradiance=Sunclock_irradiance(s,t_20200521141035);printf("%lf\n",irradiance);deleteSunclock(s);}Save the above file as main.c, and run the following commands to build and run it:Note: Make sure daylight isbuiltfirst before running these commands.$gcc-I/<path_to_daylight>/capi-cmain.c-omain.o
$g++-L/<path_to_daylight>/build/capimain.o-l:libdaylight_c-0.1.1.so-omain
$LD_LIBRARY_PATH=/<path_to_daylight>/build/capi./main0.882754API ReferencePython:https://adonmo-daylight.readthedocs.io/en/latest/reference.htmlC++:https://adonmo.github.io/daylight/Developmentlibdaylight uses theCMakebuild system.Building just the library$cmake-Bbuild-S.
$cmake--buildbuildThis builds a static library filelibdaylight.aIf you make any additional changes, you can just runcmake --build buildagain to get your changes reflected in the compiled outputs.Running tests$cmake-Bbuild/test-Stest$cmake--buildbuild/test
$./build/test/libdaylight-testsIf everything is working okay, you should see "All tests passed".libdaylight uses theCatch2library for its tests.Testing the python bindingsThere are no strict tests yet for the python bindings. However you can run an example script file, making this a sanity test at least.After building, from the tests/python directory, run:$pythontest.pyIf everything is working okay, you should see "All tests passed".Building docsPython (Sphinx)$pipinstallsphinxsphinx_rtd_themenumpynumpydoc
$cmake-Bbuild/docs-Sdocumentation
$cmake--buildbuild/docs
$cmake--buildbuild/docs--targetpydocsYou can then proceed to host the docs locally, for example onhttp://0.0.0.0:8000/$python-mhttp.server--directorydocumentation/python/_build/htmlC++ (Doxygen)$cmake-Bbuild/docs-Sdocumentation
$cmake--buildbuild/docs
$cmake--buildbuild/docs--targetcppdocsYou can then proceed to host the docs locally, for example onhttp://0.0.0.0:8000/$python-mhttp.server--directorybuild/docs/doxygen/htmlContributingIssues and pull requests are welcome.For proposing new features/improvements or reporting bugs,create an issue.Checkopen issuesfor viewing existing ideas, verify if it is already proposed/being worked upon.When implementing new features make sure to add relavant tests and documentation before sending pull requests.Related projectsPyEphem,pvlib-pythonandsolarpyare some libraries which have overlap with the type of problems this library solves.Comparision between them and this library can beread on our docs