././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1736004678.6552424 pysolar-0.13/0000755000000000000240000000000000000000000011753 5ustar00rootstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/COPYING0000644000000000000240000010442600000000000013015 0ustar00rootstaff GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/MANIFEST.in0000644000000000000240000000001500000000000013505 0ustar00rootstaffinclude *.py ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1736004678.655125 pysolar-0.13/PKG-INFO0000644000000000000240000000052100000000000013046 0ustar00rootstaffMetadata-Version: 2.1 Name: pysolar Version: 0.13 Summary: Collection of Python libraries for simulating the irradiation of any point on earth by the sun Home-page: http://pysolar.org Author: Brandon Stafford Author-email: brandon@pingswept.org License: GNU General Public License (GPL) Platform: UNKNOWN License-File: COPYING UNKNOWN ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1736004678.653273 pysolar-0.13/pysolar/0000755000000000000240000000000000000000000013444 5ustar00rootstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/__init__.py0000644000000000000240000000030200000000000015550 0ustar00rootstafffrom . import \ constants, \ solartime as stime, \ radiation, \ util, \ solar, \ numeric def use_numpy(): numeric.use_numpy() def use_math(): numeric.use_math()././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/__init__.pyi0000644000000000000240000000004200000000000015722 0ustar00rootstaff# Stubs for pysolar (Python 3.6) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/constants.py0000644000000000000240000003077400000000000016045 0ustar00rootstaff# Copyright Brandon Stafford # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . """This file is consists of numerical constants for calculating corrections, such as the wiggling ("nutation") of the axis of the earth. It also includes functions for building dictionaries of polynomial functions for rapid calculation of corrections. Most of the constants come from a 2005 paper by Reda and Andreas: I. Reda and A. Andreas, "Solar Position Algorithm for Solar Radiation Applications," National Renewable Energy Laboratory, NREL/TP-560-34302, revised November 2005. http://www.osti.gov/bridge/servlets/purl/15003974-iP3z6k/native/15003974.PDF However, it seems that Reda and Andreas took the bulk of the constants (L0, etc.) from Pierre Bretagnon and Gerard Francou's Variations Seculaires des Orbites Planetaires, or VSOP87: http://en.wikipedia.org/wiki/Secular_variations_of_the_planetary_orbits#VSOP87 See also ftp://ftp.imcce.fr/pub/ephem/planets/vsop87/VSOP87D.ear """ aberration_coeffs = None def get_aberration_coeffs(): """This function builds a dictionary of polynomial functions from a list of coefficients, so that the functions can be called by name. This is used in calculating nutation. """ global aberration_coeffs if aberration_coeffs == None : aberration_coeffs = dict \ ( (name, (lambda a, b, c, d: lambda x: a + b * x + c * x ** 2 + (x ** 3) / d)(*coeffs)) for name, coeffs in ( ('ArgumentOfLatitudeOfMoon', (93.27191, 483202.017538, -0.0036825, 327270.0)), ('LongitudeOfAscendingNode', (125.04452, -1934.136261, 0.0020708, 450000.0)), ('MeanElongationOfMoon', (297.85036, 445267.111480, -0.0019142, 189474.0)), ('MeanAnomalyOfMoon', (134.96298, 477198.867398, 0.0086972, 56250.0)), ('MeanAnomalyOfSun', (357.52772, 35999.050340, -0.0001603, -300000.0)), ) ) #end if return \ aberration_coeffs #end get_aberration_coeffs earth_radius = 6378140.0 # meters earth_axis_inclination = 23.45 # degrees seconds_per_day = 86400 standard_pressure = 101325.00 # pascals standard_temperature = 288.15 # kelvin celsius_offset = 273.15 # subtract from kelvin to get deg C, add to deg C to get kelvin earth_temperature_lapse_rate = -0.0065 # change in temperature with height, kelvin/metre air_gas_constant = 8.31432 # N*m/s^2 earth_gravity = 9.80665 # m/s^2 or N/kg earth_atmosphere_molar_mass = 0.0289644 # kg/mol aberration_sin_terms = \ [ (0,0,0,0,1), (-2,0,0,2,2), (0,0,0,2,2), (0,0,0,0,2), (0,1,0,0,0), (0,0,1,0,0), (-2,1,0,2,2), (0,0,0,2,1), (0,0,1,2,2), (-2,-1,0,2,2), (-2,0,1,0,0), (-2,0,0,2,1), (0,0,-1,2,2), (2,0,0,0,0), (0,0,1,0,1), (2,0,-1,2,2), (0,0,-1,0,1), (0,0,1,2,1), (-2,0,2,0,0), (0,0,-2,2,1), (2,0,0,2,2), (0,0,2,2,2), (0,0,2,0,0), (-2,0,1,2,2), (0,0,0,2,0), (-2,0,0,2,0), (0,0,-1,2,1), (0,2,0,0,0), (2,0,-1,0,1), (-2,2,0,2,2), (0,1,0,0,1), (-2,0,1,0,1), (0,-1,0,0,1), (0,0,2,-2,0), (2,0,-1,2,1), (2,0,1,2,2), (0,1,0,2,2), (-2,1,1,0,0), (0,-1,0,2,2), (2,0,0,2,1), (2,0,1,0,0), (-2,0,2,2,2), (-2,0,1,2,1), (2,0,-2,0,1), (2,0,0,0,1), (0,-1,1,0,0), (-2,-1,0,2,1), (-2,0,0,0,1), (0,0,2,2,1), (-2,0,2,0,1), (-2,1,0,2,1), (0,0,1,-2,0), (-1,0,1,0,0), (-2,1,0,0,0), (1,0,0,0,0), (0,0,1,2,0), (0,0,-2,2,2), (-1,-1,1,0,0), (0,1,1,0,0), (0,-1,1,2,2), (2,-1,-1,2,2), (0,0,3,2,2), (2,-1,0,2,2), ] nutation_coefficients = \ [ (-171996,-174.2,92025,8.9), (-13187,-1.6,5736,-3.1), (-2274,-0.2,977,-0.5), (2062,0.2,-895,0.5), (1426,-3.4,54,-0.1), (712,0.1,-7,0), (-517,1.2,224,-0.6), (-386,-0.4,200,0), (-301,0,129,-0.1), (217,-0.5,-95,0.3), (-158,0,0,0), (129,0.1,-70,0), (123,0,-53,0), (63,0,0,0), (63,0.1,-33,0), (-59,0,26,0), (-58,-0.1,32,0), (-51,0,27,0), (48,0,0,0), (46,0,-24,0), (-38,0,16,0), (-31,0,13,0), (29,0,0,0), (29,0,-12,0), (26,0,0,0), (-22,0,0,0), (21,0,-10,0), (17,-0.1,0,0), (16,0,-8,0), (-16,0.1,7,0), (-15,0,9,0), (-13,0,7,0), (-12,0,6,0), (11,0,0,0), (-10,0,5,0), (-8,0,3,0), (7,0,-3,0), (-7,0,0,0), (-7,0,3,0), (-7,0,3,0), (6,0,0,0), (6,0,-3,0), (6,0,-3,0), (-6,0,3,0), (-6,0,3,0), (5,0,0,0), (-5,0,3,0), (-5,0,3,0), (-5,0,3,0), (4,0,0,0), (4,0,0,0), (4,0,0,0), (-4,0,0,0), (-4,0,0,0), (-4,0,0,0), (3,0,0,0), (-3,0,0,0), (-3,0,0,0), (-3,0,0,0), (-3,0,0,0), (-3,0,0,0), (-3,0,0,0), (-3,0,0,0), ] heliocentric_longitude_coeffs = \ [ [ # L0 (175347046.0,0,0), (3341656.0,4.6692568,6283.07585), (34894.0,4.6261,12566.1517), (3497.0,2.7441,5753.3849), (3418.0,2.8289,3.5231), (3136.0,3.6277,77713.7715), (2676.0,4.4181,7860.4194), (2343.0,6.1352,3930.2097), (1324.0,0.7425,11506.7698), (1273.0,2.0371,529.691), (1199.0,1.1096,1577.3435), (990,5.233,5884.927), (902,2.045,26.298), (857,3.508,398.149), (780,1.179,5223.694), (753,2.533,5507.553), (505,4.583,18849.228), (492,4.205,775.523), (357,2.92,0.067), (317,5.849,11790.629), (284,1.899,796.298), (271,0.315,10977.079), (243,0.345,5486.778), (206,4.806,2544.314), (205,1.869,5573.143), (202,2.458,6069.777), (156,0.833,213.299), (132,3.411,2942.463), (126,1.083,20.775), (115,0.645,0.98), (103,0.636,4694.003), (102,0.976,15720.839), (102,4.267,7.114), (99,6.21,2146.17), (98,0.68,155.42), (86,5.98,161000.69), (85,1.3,6275.96), (85,3.67,71430.7), (80,1.81,17260.15), (79,3.04,12036.46), (75,1.76,5088.63), (74,3.5,3154.69), (74,4.68,801.82), (70,0.83,9437.76), (62,3.98,8827.39), (61,1.82,7084.9), (57,2.78,6286.6), (56,4.39,14143.5), (56,3.47,6279.55), (52,0.19,12139.55), (52,1.33,1748.02), (51,0.28,5856.48), (49,0.49,1194.45), (41,5.37,8429.24), (41,2.4,19651.05), (39,6.17,10447.39), (37,6.04,10213.29), (37,2.57,1059.38), (36,1.71,2352.87), (36,1.78,6812.77), (33,0.59,17789.85), (30,0.44,83996.85), (30,2.74,1349.87), (25,3.16,4690.48) ], [ # L1 (628331966747.0,0,0), (206059.0,2.678235,6283.07585), (4303.0,2.6351,12566.1517), (425.0,1.59,3.523), (119.0,5.796,26.298), (109.0,2.966,1577.344), (93,2.59,18849.23), (72,1.14,529.69), (68,1.87,398.15), (67,4.41,5507.55), (59,2.89,5223.69), (56,2.17,155.42), (45,0.4,796.3), (36,0.47,775.52), (29,2.65,7.11), (21,5.34,0.98), (19,1.85,5486.78), (19,4.97,213.3), (17,2.99,6275.96), (16,0.03,2544.31), (16,1.43,2146.17), (15,1.21,10977.08), (12,2.83,1748.02), (12,3.26,5088.63), (12,5.27,1194.45), (12,2.08,4694), (11,0.77,553.57), (10,1.3,6286.6), (10,4.24,1349.87), (9,2.7,242.73), (9,5.64,951.72), (8,5.3,2352.87), (6,2.65,9437.76), (6,4.67,4690.48) ], [ # L2 (52919.0,0,0), (8720.0,1.0721,6283.0758), (309.0,0.867,12566.152), (27,0.05,3.52), (16,5.19,26.3), (16,3.68,155.42), (10,0.76,18849.23), (9,2.06,77713.77), (7,0.83,775.52), (5,4.66,1577.34), (4,1.03,7.11), (4,3.44,5573.14), (3,5.14,796.3), (3,6.05,5507.55), (3,1.19,242.73), (3,6.12,529.69), (3,0.31,398.15), (3,2.28,553.57), (2,4.38,5223.69), (2,3.75,0.98) ], [ # L3 (289.0,5.844,6283.076), (35,0,0), (17,5.49,12566.15), (3,5.2,155.42), (1,4.72,3.52), (1,5.3,18849.23), (1,5.97,242.73) ], [ # L4 (114.0,3.142,0), (8,4.13,6283.08), (1,3.84,12566.15) ], [ # L5 (1,3.14,0) ], ] heliocentric_latitude_coeffs = \ [ [ # B0 (280.0,3.199,84334.662), (102.0,5.422,5507.553), (80,3.88,5223.69), (44,3.7,2352.87), (32,4,1577.34) ], [ # B1 (9,3.9,5507.55), (6,1.73,5223.69) ], ] sun_earth_distance_coeffs = \ [ [ # R0 (100013989.0,0,0), (1670700.0,3.0984635,6283.07585), (13956.0,3.05525,12566.1517), (3084.0,5.1985,77713.7715), (1628.0,1.1739,5753.3849), (1576.0,2.8469,7860.4194), (925.0,5.453,11506.77), (542.0,4.564,3930.21), (472.0,3.661,5884.927), (346.0,0.964,5507.553), (329.0,5.9,5223.694), (307.0,0.299,5573.143), (243.0,4.273,11790.629), (212.0,5.847,1577.344), (186.0,5.022,10977.079), (175.0,3.012,18849.228), (110.0,5.055,5486.778), (98,0.89,6069.78), (86,5.69,15720.84), (86,1.27,161000.69), (65,0.27,17260.15), (63,0.92,529.69), (57,2.01,83996.85), (56,5.24,71430.7), (49,3.25,2544.31), (47,2.58,775.52), (45,5.54,9437.76), (43,6.01,6275.96), (39,5.36,4694), (38,2.39,8827.39), (37,0.83,19651.05), (37,4.9,12139.55), (36,1.67,12036.46), (35,1.84,2942.46), (33,0.24,7084.9), (32,0.18,5088.63), (32,1.78,398.15), (28,1.21,6286.6), (28,1.9,6279.55), (26,4.59,10447.39) ], [ # R1 (103019.0,1.10749,6283.07585), (1721.0,1.0644,12566.1517), (702.0,3.142,0), (32,1.02,18849.23), (31,2.84,5507.55), (25,1.32,5223.69), (18,1.42,1577.34), (10,5.91,10977.08), (9,1.42,6275.96), (9,0.27,5486.78) ], [ # R2 (4359.0,5.7846,6283.0758), (124.0,5.579,12566.152), (12,3.14,0), (9,3.63,77713.77), (6,1.87,5573.14), (3,5.47,18849.23) ], [ # R3 (145.0,4.273,6283.076), (7,3.92,12566.15), ], [ # R4 (4,2.56,6283.08) ], ] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/constants.pyi0000644000000000000240000000143100000000000016202 0ustar00rootstaff# Stubs for pysolar.constants (Python 3.6) from typing import Dict, List, Tuple aberration_coeffs: Dict[str,float] def get_aberration_coeffs() -> Dict[str,float]: ... earth_radius: float earth_axis_inclination: float seconds_per_day: int standard_pressure: float standard_temperature: float celsius_offset: float earth_temperature_lapse_rate: float air_gas_constant: float earth_gravity: float earth_atmosphere_molar_mass: float aberration_sin_terms: List[Tuple[float, float, float, float, float]] nutation_coefficients: List[Tuple[float, float, float, float]] heliocentric_longitude_coeffs: List[List[Tuple[float, float, float]]] heliocentric_latitude_coeffs: List[List[Tuple[float, float, float]]] sun_earth_distance_coeffs: List[List[Tuple[float, float, float]]] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/elevation.py0000644000000000000240000000573300000000000016014 0ustar00rootstaff# Copyright Sean T. Hammond # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . """Various elevation-related calculations """ import warnings from .constants import \ standard_pressure, \ standard_temperature, \ earth_temperature_lapse_rate, \ air_gas_constant, \ earth_gravity, \ earth_atmosphere_molar_mass def get_pressure_with_elevation(h, Ps=standard_pressure, Ts=standard_temperature, Tl=earth_temperature_lapse_rate, Hb=0.0, R=air_gas_constant, g=earth_gravity, M=earth_atmosphere_molar_mass): "This function returns an estimate of the pressure in pascals as a function of\n" \ " elevation above sea level.\n" \ "NOTES:\n" \ " * This equation is only accurate up to 11,000 meters\n" \ " * results might be odd for elevations below 0 (sea level), like Dead Sea.\n" \ "h=elevation relative to sea level (m)\n" \ "Ps= static pressure (pascals)\n" \ "Ts= temperature (kelvin)\n" \ "Tl= temperature lapse rate (kelvin/meter)\n" \ "Hb= height at the bottom of the layer\n" \ "R= universal gas constant for air\n" \ "g= gravitational acceleration\n" \ "M= Molar mass of atmosphere\n" \ "P = Ps * (Ts / ((Ts + Tl) * (h - Hb))) ^ ((g * M)/(R * Tl))\n" \ "returns pressure in pascals\n" if h > 11000.0 : warnings.warn \ ( "Elevation used exceeds the recommended maximum elevation for this function (11,000m)\n" ) #end if return \ Ps * (Ts / (Ts + Tl * (h - Hb))) ** ((g * M) / (R * Tl)) #end get_pressure_with_elevation def get_temperature_with_elevation(h, Ts=standard_temperature, Tl=earth_temperature_lapse_rate): "This function returns an estimate of temperature as a function above sea level.\n" \ "NOTES:\n" \ " * This equation is only accurate up to 11,000 meters\n" \ " * results might be odd for elevations below 0 (sea level), like Dead Sea.\n" \ "Ts= temperature (kelvin)\n" \ "Tl= temperature lapse rate (kelvin/meter)\n" \ "returns temp in kelvin\n" return \ Ts + h *Tl #end get_temperature_with_elevation def elevation_test(): print("Elevation(m) Pressure(Pa) Temperature(K)") h = 0 for _ in range(11): P = get_pressure_with_elevation(h) T = get_temperature_with_elevation(h) print("%i %i %i" % (h, P, T)) h += 1000 #end for #end elevation_test ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/elevation.pyi0000644000000000000240000000052100000000000016153 0ustar00rootstaff# Stubs for pysolar.elevation (Python 3.6) def get_pressure_with_elevation(h:float, Ps:float = ..., Ts:float = ..., Tl:float = ..., Hb:float = ..., R:float = ..., g:float = ..., M:float = ...) -> float: ... def get_temperature_with_elevation(h:float, Ts:float = ..., Tl:float = ...) -> float: ... def elevation_test() -> None: ... ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/numeric.py0000644000000000000240000001006600000000000015463 0ustar00rootstaff # Copyright François Steinmetz # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . """ Import math functions from either numpy (in order to vectorize operations) or builtins math module. By default, use numpy when available. To force builtins math module usage when numpy is available: import pysolar pysolar.use_math() """ from math import degrees, cos, sin, radians, tan, pi from math import acos, atan, asin, atan2, exp, e current_mod = 'math' def globals_import_from(module, name, name_as): """ Does "from import as " (globally) """ module = __import__(module, fromlist=[name]) globals()[name_as] = getattr(module, name) def where_math(condition, x, y): """ scalar version of numpy.where """ if condition: return x else: return y where = where_math def tm_yday_math(d): return d.utctimetuple().tm_yday tm_yday = tm_yday_math def tm_yday_numpy(d): dd = numpy.array(d, dtype='datetime64[D]') dy = numpy.array(d, dtype='datetime64[Y]') return (dd - dy).astype('int') + 1 def tm_hour_math(d): return d.utctimetuple().tm_hour tm_hour = tm_hour_math def tm_hour_numpy(d): dh = numpy.array(d, dtype='datetime64[h]') dd = numpy.array(d, dtype='datetime64[D]') return (dh - dd).astype('int') def tm_min_math(d): return d.utctimetuple().tm_min tm_min = tm_min_math def tm_min_numpy(d): dm = numpy.array(d, dtype='datetime64[m]') dh = numpy.array(d, dtype='datetime64[h]') return (dm - dh).astype('int') def use_numpy(): """ Import required functions/constants from numpy """ globals_import_from('numpy', 'degrees', 'degrees') globals_import_from('numpy', 'cos', 'cos') globals_import_from('numpy', 'sin', 'sin') globals_import_from('numpy', 'radians', 'radians') globals_import_from('numpy', 'tan', 'tan') globals_import_from('numpy', 'pi', 'pi') globals_import_from('numpy', 'arccos', 'acos') globals_import_from('numpy', 'arctan', 'atan') globals_import_from('numpy', 'arcsin', 'asin') globals_import_from('numpy', 'arctan2', 'atan2') globals_import_from('numpy', 'exp', 'exp') globals_import_from('numpy', 'e', 'e') globals_import_from('numpy', 'where', 'where') globals()['tm_yday'] = tm_yday_numpy globals()['tm_hour'] = tm_hour_numpy globals()['tm_min'] = tm_min_numpy globals()['current_mod'] = 'numpy' def use_math(): """ Import required functions/constants from builtins math module """ globals_import_from('math', 'degrees', 'degrees') globals_import_from('math', 'cos', 'cos') globals_import_from('math', 'sin', 'sin') globals_import_from('math', 'radians', 'radians') globals_import_from('math', 'tan', 'tan') globals_import_from('math', 'pi', 'pi') globals_import_from('math', 'acos', 'acos') globals_import_from('math', 'atan', 'atan') globals_import_from('math', 'asin', 'asin') globals_import_from('math', 'atan2', 'atan2') globals_import_from('math', 'exp', 'exp') globals_import_from('math', 'e', 'e') globals()['where'] = where globals()['tm_yday'] = tm_yday_math globals()['tm_hour'] = tm_hour_math globals()['tm_min'] = tm_min_math globals()['current_mod'] = 'math' try: import numpy use_numpy() except ImportError: pass ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/radiation.py0000644000000000000240000000340000000000000015765 0ustar00rootstaff# Copyright Brandon Stafford # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . """Calculate different kinds of radiation components via default values """ from . import numeric as math def get_air_mass_ratio(altitude_deg): # from Masters, p. 412 try : result = 1 / math.sin(math.radians(altitude_deg)) except ZeroDivisionError : result = float("inf") #end try return result #end get_air_mass_ratio def get_apparent_extraterrestrial_flux(day): # from Masters, p. 412 return 1160 + (75 * math.sin(2 * math.pi / 365 * (day - 275))) #end get_apparent_extraterrestrial def get_optical_depth(day): # from Masters, p. 412 return 0.174 + (0.035 * math.sin(2 * math.pi / 365 * (day - 100))) #end get_optical_depth def get_radiation_direct(when, altitude_deg): # from Masters, p. 412 is_daytime = (altitude_deg > 0) day = math.tm_yday(when) flux = get_apparent_extraterrestrial_flux(day) optical_depth = get_optical_depth(day) air_mass_ratio = get_air_mass_ratio(altitude_deg) return flux * math.exp(-1 * optical_depth * air_mass_ratio) * is_daytime #end get_radiation_direct ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/radiation.pyi0000644000000000000240000000050000000000000016134 0ustar00rootstaff# Stubs for pysolar.radiation (Python 3.6) import datetime def get_air_mass_ratio(altitude_deg:float) -> float: ... def get_apparent_extraterrestrial_flux(day:float) -> float: ... def get_optical_depth(day:float) -> float: ... def get_radiation_direct(when:datetime.datetime, altitude_deg:float) -> float: ... ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/rest.py0000644000000000000240000003513600000000000015003 0ustar00rootstaff# Copyright Brandon Stafford # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . # Disable linting as this is a work in progress # flake8: noqa from . import numeric as math from .constants import standard_pressure # single-scattering albedo used to calculate aerosol scattering transmittance; # not used for sky or ground albedo for backscattering estimate albedo = {} albedo["high-frequency"] = 0.92 albedo["low-frequency"] = 0.84 standard_pressure_millibars = standard_pressure / 100 un = 0.0003 # atm*cm, from [Gueymard 2008], p. 280 E0n = {"high-frequency": 635.4, # extra-atmospheric irradiance, 290-700 nm (UV and visible) "low-frequency": 709.7} # extra-atmospheric irradiance, 700-4000 nm (short infrared) def get_aerosol_forward_scatterance_factor(altitude_deg): Z = 90 - altitude_deg return 1 - math.e ** (-0.6931 - 1.8326 * math.cos(math.radians(Z))) def get_aerosol_optical_depth(turbidity_beta, effective_wavelength, turbidity_alpha): # returns tau_a return turbidity_beta * effective_wavelength ** -turbidity_alpha def get_aerosol_scattering_correction_factor(band, ma, tau_a): # returns F if band == "high-frequency": g0 = (3.715 + 0.368 * ma + 0.036294 * ma ** 2) / \ (1 + 0.0009391 * ma ** 2) g1 = (-0.164 - 0.72567 * ma + 0.20701 * ma ** 2) / \ (1 + 0.001901 * ma ** 2) g2 = (-0.052288 + 0.31902 * ma + 0.17871 * ma ** 2) / \ (1 + 0.0069592 * ma ** 2) return (g0 + g1 * tau_a) / (1 + g2 * tau_a) else: h0 = (3.4352 + 0.65267 * ma + 0.00034328 * ma ** 2) / \ (1 + 0.034388 * ma ** 1.5) h1 = (1.231 - 1.63853 * ma + 0.20667 * ma ** 2) / \ (1 + 0.1451 * ma ** 1.5) h2 = (0.8889 - 0.55063 * ma + 0.50152 * ma ** 2) / \ (1 + 0.14865 * ma ** 1.5) return (h0 + h1 * tau_a) / (1 + h2 * tau_a) def get_aerosol_transmittance(band, ma, tau_a): # returns Ta return math.exp(-ma * tau_a) def get_aerosol_scattering_transmittance(band, ma, tau_a): # returns Tas return math.exp(-ma * albedo[band] * tau_a) def get_backscattered_diffuse_broadband_irradiance(band, turbidity_alpha=1.3, turbidity_beta=0.6): return get_backscattered_diffuse_broadband_irradiance_by_band("high-frequency", turbidity_alpha, turbidity_beta) + get_backscattered_diffuse_broadband_irradiance_by_band("low-frequency", turbidity_alpha, turbidity_beta) def get_backscattered_diffuse_irradiance_by_band(band, Ebi, Edpi, turbidity_alpha=1.3, turbidity_beta=0.6): rhos = get_sky_albedo(band, turbidity_alpha, turbidity_beta) rhog = get_ground_albedo(band) Eddi = rhog * rhos * (Ebi + Edpi) / (1 - rhog * rhos) return Eddi def get_beam_broadband_irradiance(altitude_deg, pressure_millibars=standard_pressure_millibars, ozone_atm_cm=0.35, nitrogen_atm_cm=0.0002, precipitable_water_cm=5.0, turbidity_alpha=1.3, turbidity_beta=0.6): Z = 90 - altitude_deg Ebn = get_broadband_direct_normal_irradiance(altitude_deg, pressure_millibars, ozone_atm_cm, nitrogen_atm_cm, precipitable_water_cm, turbidity_alpha, turbidity_beta) return Ebn * math.cos(math.radians(Z)) def get_beam_irradiance_by_band(band, altitude_deg, pressure_millibars=standard_pressure_millibars, ozone_atm_cm=0.35, nitrogen_atm_cm=0.0002, precipitable_water_cm=5.0, turbidity_alpha=1.3, turbidity_beta=0.6): Z = 90 - altitude_deg Ebni = get_direct_normal_irradiance_by_band(band, altitude_deg, pressure_millibars, ozone_atm_cm, nitrogen_atm_cm, precipitable_water_cm, turbidity_alpha, turbidity_beta) return Ebni * math.cos(math.radians(Z)) def get_diffuse_broadband_irradiance(air_mass=1.66, turbidity_alpha=1.3, turbidity_beta=0.6): return get_diffuse_irradiance_by_band("high-frequency", air_mass, turbidity_alpha, turbidity_beta) + get_diffuse_irradiance_by_band("low-frequency", air_mass, turbidity_alpha, turbidity_beta) def get_diffuse_irradiance_by_band(band, air_mass=1.66, turbidity_alpha=1.3, turbidity_beta=0.6): Z = 90 - altitude_deg effective_wavelength = get_effective_aerosol_wavelength(band, turbidity_alpha) tau_a = get_aerosol_optical_depth( turbidity_beta, effective_wavelength, turbidity_alpha) ma = get_optical_mass_aerosol(altitude_deg) mo = get_optical_mass_ozone(altitude_deg) mR = get_optical_mass_rayleigh(altitude_deg, pressure_millibars) To = get_ozone_transmittance(band, mo) Tg = get_gas_transmittance(band, mR) Tn = get_nitrogen_transmittance(band, 1.66) Tw = get_water_vapor_transmittance(band, 1.66) TR = get_rayleigh_transmittance(band, mR) Ta = get_aerosol_transmittance(band, ma, tau_a) Tas = get_aerosol_scattering_transmittance(band, ma, tau_a) BR = get_rayleigh_extinction_forward_scattering_fraction(band, air_mass) Ba = get_aerosol_forward_scatterance_factor(altitude_deg) F = get_aerosol_scattering_correction_factor(band, ma, tau_a) Edpi = To * Tg * Tn * Tw * \ (BR * (1 - TR) * Ta ** 0.25 + Ba * F * TR * (1 - Tas ** 0.25)) * \ E0n[band] return Edpi def get_broadband_direct_normal_irradiance(altitude_deg, pressure_millibars=standard_pressure_millibars, ozone_atm_cm=0.35, nitrogen_atm_cm=0.0002, precipitable_water_cm=5.0, turbidity_alpha=1.3, turbidity_beta=0.6): high = get_direct_normal_irradiance_by_band("high-frequency", altitude_deg, pressure_millibars, ozone_atm_cm, nitrogen_atm_cm, precipitable_water_cm, turbidity_alpha, turbidity_beta) low = get_direct_normal_irradiance_by_band("low-frequency", altitude_deg, pressure_millibars, ozone_atm_cm, nitrogen_atm_cm, precipitable_water_cm, turbidity_alpha, turbidity_beta) return high + low def get_direct_normal_irradiance_by_band(band, altitude_deg, pressure_millibars=standard_pressure_millibars, ozone_atm_cm=0.35, nitrogen_atm_cm=0.0002, precipitable_water_cm=5.0, turbidity_alpha=1.3, turbidity_beta=0.6): ma = get_optical_mass_aerosol(altitude_deg) mo = get_optical_mass_ozone(altitude_deg) mR = get_optical_mass_rayleigh(altitude_deg, pressure_millibars) mRprime = mR * pressure_millibars / standard_pressure_millibars mw = get_optical_mass_water(altitude_deg) effective_wavelength = get_effective_aerosol_wavelength( band, ma, turbidity_alpha, turbidity_beta) tau_a = get_aerosol_optical_depth( turbidity_beta, effective_wavelength, turbidity_alpha) TR = get_rayleigh_transmittance(band, mRprime) Tg = get_gas_transmittance(band, mRprime) To = get_ozone_transmittance(band, mo, ozone_atm_cm) # is water_optical_mass really used for nitrogen calc? Tn = get_nitrogen_transmittance(band, mw, nitrogen_atm_cm) Tw = get_water_vapor_transmittance(band, mw, precipitable_water_cm) Ta = get_aerosol_transmittance(band, ma, tau_a) return E0n[band] * TR * Tg * To * Tn * Tw * Ta def get_effective_aerosol_wavelength(band, ma, turbidity_alpha, turbidity_beta): # This function has an error somewhere. It returns negative values sometimes, but wavelength should always be positive. ua = math.log(1 + ma * turbidity_beta) if band == "high-frequency": a1 = turbidity_alpha # just renaming to keep equations short d0 = 0.57664 - 0.024743 * a1 d1 = (0.093942 - 0.2269 * a1 + 0.12848 * a1 ** 2) / (1 + 0.6418 * a1) d2 = (-0.093819 + 0.36668 * a1 - 0.12775 * a1 ** 2) / \ (1 - 0.11651 * a1) d3 = a1 * (0.15232 - 0.087214 * a1 + 0.012664 * a1 ** 2) / \ (1 - 0.90454 * a1 + 0.26167 * a1 ** 2) return (d0 + d1 * ua + d2 * ua ** 2) / (1 + d3 * ua ** 2) else: a2 = turbidity_alpha e0 = (1.183 - 0.022989 * a2 + 0.020829 * a2 ** 2) / (1 + 0.11133 * a2) e1 = (-0.50003 - 0.18329 * a2 + 0.23835 * a2 ** 2) / (1 + 1.6756 * a2) e2 = (-0.50001 + 1.1414 * a2 + 0.0083589 * a2 ** 2) / (1 + 11.168 * a2) e3 = (-0.70003 - 0.73587 * a2 + 0.51509 * a2 ** 2) / (1 + 4.7665 * a2) return (e0 + e1 * ua + e2 * ua ** 2) / (1 + e3 * ua) def get_gas_transmittance(band, mRprime): if band == "high-frequency": return (1 + 0.95885 * mRprime + 0.012871 * mRprime ** 2) / (1 + 0.96321 * mRprime + 0.015455 * mRprime ** 2) else: return (1 + 0.27284 * mRprime - 0.00063699 * mRprime ** 2) / (1 + 0.30306 * mRprime) def get_global_broadband_irradiance(altitude_deg, pressure_millibars=standard_pressure_millibars, ozone_atm_cm=0.35, nitrogen_atm_cm=0.0002, precipitable_water_cm=5.0, turbidity_alpha=1.3, turbidity_beta=0.6): Eb_high = get_beam_irradiance_by_band("high-frequency", altitude_deg, pressure_millibars, ozone_atm_cm, nitrogen_atm_cm, precipitable_water_cm, turbidity_alpha, turbidity_beta) Eb_low = get_beam_irradiance_by_band("low-frequency", altitude_deg, pressure_millibars, ozone_atm_cm, nitrogen_atm_cm, precipitable_water_cm, turbidity_alpha, turbidity_beta) Edp_high = get_diffuse_irradiance_by_band("high-frequency", air_mass, turbidity_alpha, turbidity_beta) Edp_low = get_diffuse_irradiance_by_band("low-frequency", air_mass, turbidity_alpha, turbidity_beta) Edd_high = get_backscattered_diffuse_irradiance_by_band("high-frequency", Eb_high, Edp_high, turbidity_alpha, turbidity_beta) Edd_low = get_backscattered_diffuse_irradiance_by_band("low-frequency", Eb_low, Edp_low, turbidity_alpha, turbidity_beta) return Eb_high + Eb_low + Edp_high + Edp_low + Edd_high + Edd_low def get_ground_albedo(band): # This could probably be improved with [Gueymard, 1993: Mathematically integrable parameterization of clear-sky beam and global irradiances and its use in daily irradiation applications] # http://www.sciencedirect.com/science/article/pii/0038092X9390059W] return 0.150 # mean ground albedo from [Gueymard, 2008], Table 1 def get_nitrogen_transmittance(band, mw, nitrogen_atm_cm): if band == "high-frequency": g1 = (0.17499 + 41.654 * un - 2146.4 * un ** 2) / \ (1 + 22295.0 * un ** 2) g2 = un * (-1.2134 + 59.324 * un) / (1 + 8847.8 * un ** 2) g3 = (0.17499 + 61.658 * un + 9196.4 * un ** 2) / \ (1 + 74109.0 * un ** 2) return min(1, (1 + g1 * mw + g2 * mw ** 2) / (1 + g3 * mw)) else: return 1.0 # from Appendix B of [Gueymard, 2003] def get_optical_mass_rayleigh(altitude_deg, pressure_millibars): Z = 90 - altitude_deg Z_rad = math.radians(Z) return (pressure_millibars / standard_pressure_millibars) / ((math.cos(Z_rad) + 0.48353 * Z_rad ** 0.095846) / (96.741 - Z_rad) ** 1.754) def get_optical_mass_ozone(altitude_deg): # from Appendix B of [Gueymard, 2003] Z = 90 - altitude_deg Z_rad = math.radians(Z) return 1 / ((math.cos(Z_rad) + 1.0651 * Z_rad ** 0.6379) / (101.8 - Z_rad) ** 2.2694) def get_optical_mass_water(altitude_deg): # from Appendix B of [Gueymard, 2003] Z = 90 - altitude_deg Z_rad = math.radians(Z) return 1 / ((math.cos(Z_rad) + 0.10648 * Z_rad ** 0.11423) / (93.781 - Z_rad) ** 1.9203) def get_optical_mass_aerosol(altitude_deg): # from Appendix B of [Gueymard, 2003] Z = 90 - altitude_deg Z_rad = math.radians(Z) return 1 / ((math.cos(Z_rad) + 0.16851 * Z_rad ** 0.18198) / (95.318 - Z_rad) ** 1.9542) def get_ozone_transmittance(band, mo, uo): if band == "high-frequency": f1 = uo * (10.979 - 8.5421 * uo) / (1 + 2.0115 * uo + 40.189 * uo ** 2) f2 = uo * (-0.027589 - 0.005138 * uo) / \ (1 - 2.4857 * uo + 13.942 * uo ** 2) f3 = uo * (10.995 - 5.5001 * uo) / (1 + 1.6784 * uo + 42.406 * uo ** 2) return (1 + f1 * mo + f2 * mo ** 2) / (1 + f3 * mo) else: return 1.0 def get_rayleigh_extinction_forward_scattering_fraction(band, mR): # returns BR if band == "high-frequency": return 0.5 * (0.89013 - 0.049558 * mR + 0.000045721 * mR ** 2) else: return 0.5 def get_rayleigh_transmittance(band, mRprime): if band == "high-frequency": return (1 + 1.8169 * mRprime + 0.033454 * mRprime ** 2) / (1 + 2.063 * mRprime + 0.31978 * mRprime ** 2) else: return (1 - 0.010394 * mRprime) / (1 - 0.00011042 * mRprime ** 2) def get_sky_albedo(band, turbidity_alpha, turbidity_beta): if band == "high-frequency": a1 = turbidity_alpha # just renaming to keep equations short b1 = turbidity_beta rhos = (0.13363 + 0.00077358 * a1 + b1 * (0.37567 + 0.22946 * a1) / (1 - 0.10832 * a1)) / (1 + b1 * (0.84057 + 0.68683 * a1) / (1 - 0.08158 * a1)) else: a2 = turbidity_alpha # just renaming to keep equations short b2 = turbidity_beta rhos = (0.010191 + 0.00085547 * a2 + b2 * (0.14618 + 0.062758 * a2) / (1 - 0.19402 * a2)) / (1 + b2 * (0.58101 + 0.17426 * a2) / (1 - 0.17586 * a2)) return rhos def get_water_vapor_transmittance(band, mw, w): if band == "high-frequency": h = get_water_vapor_transmittance_coefficients(band, w) return (1 + h[1] * mw) / (1 + h[2] * mw) else: c = get_water_vapor_transmittance_coefficients(band, w) return (1 + c[1] * mw + c[2] * mw ** 2) / (1 + c[3] * mw + c[4] * mw ** 2) def get_water_vapor_transmittance_coefficients(band, w): if band == "high-frequency": h1 = w * (0.065445 + 0.00029901 * w) / (1 + 1.2728 * w) h2 = w * (0.065687 + 0.0013218 * w) / (1 + 1.2008 * w) return [float('NaN'), h1, h2] else: c1 = w * (19.566 - 1.6506 * w + 1.0672 * w ** 2) / \ (1 + 5.4248 * w + 1.6005 * w ** 2) c2 = w * (0.50158 - 0.14732 * w + 0.047584 * w ** 2) / \ (1 + 1.1811 * w + 1.0699 * w ** 2) c3 = w * (21.286 - 0.39232 * w + 1.2692 * w ** 2) / \ (1 + 4.8318 * w + 1.412 * w ** 2) c4 = w * (0.70992 - 0.23155 * w + 0.096514 * w ** 2) / \ (1 + 0.44907 * w + 0.75425 * w ** 2) return [float('NaN'), c1, c2, c3, c4] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/simulate.py0000644000000000000240000000531100000000000015641 0ustar00rootstaff# Copyright Brandon Stafford # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . """Support functions for horizon calculation """ from . import numeric as math import datetime from . import constants from . import radiation from . import solar def datetime_range(start_datetime, end_datetime, step_minutes): '''yields a sequence of datetimes evenly spaced apart by step_minutes.''' step = step_minutes * 60 span = end_datetime - start_datetime dt = datetime.timedelta(seconds = step) for n in range((span.days * constants.seconds_per_day + span.seconds) // step) : yield start_datetime + dt * n #end for #end datetime_range def simulate_span(latitude_deg, longitude_deg, horizon, start_datetime, end_datetime, step_minutes, elevation = 0, temperature = constants.standard_temperature, pressure = constants.standard_pressure): '''simulates the motion of the sun over a time span and location of your choosing. temperature in Kelvin and pressure in Pascal The start and end points are set by datetime objects, which can be created with the standard Python datetime module like this: import datetime start = datetime.datetime(2008, 12, 23, 23, 14, 0) ''' alt_zero = 380 for time in datetime_range(start_datetime, end_datetime, step_minutes) : alt = solar.get_altitude(latitude_deg, longitude_deg, time, elevation, temperature, pressure) azi = solar.get_azimuth(latitude_deg, longitude_deg, time, elevation) shade = horizon[round(azi)] if shade < alt_zero - round(alt_zero * math.sin(math.radians(alt))) : rad = 0 else : rad = radiation.get_radiation_direct(time, alt) #end if yield time, alt, azi, rad, shade #end for #end simulate_span # xs = shade.GetXShade(width, 120, azimuth_deg) # ys = shade.GetYShade(height, 120, altitude_deg) # shaded_area = xs * ys # shaded_percentage = shaded_area/area # import simulate, datetime; s = datetime.datetime(2008,1,1); e = datetime.datetime(2008,1,5); simulate.simulate_span(42.0, -70.0, s, e, 30) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/simulate.pyi0000644000000000000240000000115000000000000016007 0ustar00rootstaff# Stubs for pysolar.simulate (Python 3.6) import datetime from typing import Iterator, List, Tuple def datetime_range(start_datetime:datetime.datetime, end_datetime:datetime.datetime, step_minutes:float) -> Iterator[datetime.datetime]: ... def simulate_span(latitude_deg:float, longitude_deg:float, horizon:List[float], start_datetime:datetime.datetime, end_datetime:datetime.datetime, step_minutes:float, elevation:float = ..., temperature:float = ..., pressure:float = ...) -> Iterator[Tuple[datetime.datetime, float, float, float, float]]: ... # TODO unclear what horizon is, and never used in the code ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/solar.py0000644000000000000240000004455500000000000015153 0ustar00rootstaff# Copyright Brandon Stafford # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . """Solar geometry functions This module contains the most important functions for calculation of the position of the sun. """ from . import numeric as math import datetime from . import constants from . import solartime as stime from . import radiation from .tzinfo_check import check_aware_dt def solar_test(): latitude_deg = 42.364908 longitude_deg = -71.112828 d = datetime.datetime.now(tz=datetime.timezone.utc) thirty_minutes = datetime.timedelta(hours = 0.5) for _ in range(48): timestamp = d.ctime() altitude_deg = get_altitude(latitude_deg, longitude_deg, d) azimuth_deg = get_azimuth(latitude_deg, longitude_deg, d) power = radiation.get_radiation_direct(d, altitude_deg) if (altitude_deg > 0): print(timestamp, "UTC", altitude_deg, azimuth_deg, power) d = d + thirty_minutes def equation_of_time(day): "returns the number of minutes to add to mean solar time to get actual solar time." b = 2 * math.pi / 364.0 * (day - 81) return 9.87 * math.sin(2 * b) - 7.53 * math.cos(b) - 1.5 * math.sin(b) def get_aberration_correction(sun_earth_distance): # sun-earth distance is in astronomical units return -20.4898/(3600.0 * sun_earth_distance) @check_aware_dt('when') def get_topocentric_position(latitude_deg, longitude_deg, when, elevation = 0): '''Common calculations for altitude and azimuth''' # location-dependent calculations projected_radial_distance = get_projected_radial_distance(elevation, latitude_deg) projected_axial_distance = get_projected_axial_distance(elevation, latitude_deg) # time-dependent calculations jd = stime.get_julian_solar_day(when) jde = stime.get_julian_ephemeris_day(when) jce = stime.get_julian_ephemeris_century(jde) jme = stime.get_julian_ephemeris_millennium(jce) geocentric_latitude = get_geocentric_latitude(jme) geocentric_longitude = get_geocentric_longitude(jme) sun_earth_distance = get_sun_earth_distance(jme) aberration_correction = get_aberration_correction(sun_earth_distance) equatorial_horizontal_parallax = get_equatorial_horizontal_parallax(sun_earth_distance) nutation = get_nutation(jce) apparent_sidereal_time = get_apparent_sidereal_time(jd, jme, nutation) true_ecliptic_obliquity = get_true_ecliptic_obliquity(jme, nutation) # calculations dependent on location and time apparent_sun_longitude = get_apparent_sun_longitude(geocentric_longitude, nutation, aberration_correction) geocentric_sun_right_ascension = get_geocentric_sun_right_ascension(apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude) geocentric_sun_declination = get_geocentric_sun_declination(apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude) local_hour_angle = get_local_hour_angle(apparent_sidereal_time, longitude_deg, geocentric_sun_right_ascension) parallax_sun_right_ascension = get_parallax_sun_right_ascension(projected_radial_distance, equatorial_horizontal_parallax, local_hour_angle, geocentric_sun_declination) topocentric_local_hour_angle = get_topocentric_local_hour_angle(local_hour_angle, parallax_sun_right_ascension) topocentric_sun_declination = get_topocentric_sun_declination(geocentric_sun_declination, projected_axial_distance, equatorial_horizontal_parallax, parallax_sun_right_ascension, local_hour_angle) return topocentric_sun_declination, topocentric_local_hour_angle @check_aware_dt('when') def get_position(latitude_deg, longitude_deg, when, elevation=0, temperature = constants.standard_temperature, pressure = constants.standard_pressure): ''' Given location, time and atmospheric conditions temperature in Kelvin and pressure in Pascal returns (azimuth, altitude) of sun in degrees. Same as a combination of get_azimuth and get_altitude ''' topocentric_sun_declination, topocentric_local_hour_angle = \ get_topocentric_position(latitude_deg, longitude_deg, when, elevation) topocentric_elevation_angle = \ get_topocentric_elevation_angle(latitude_deg, topocentric_sun_declination, topocentric_local_hour_angle) refraction_correction = get_refraction_correction(pressure, temperature, topocentric_elevation_angle) altitude_deg = topocentric_elevation_angle + refraction_correction azimuth_deg = get_topocentric_azimuth_angle(topocentric_local_hour_angle, latitude_deg, topocentric_sun_declination) return azimuth_deg, altitude_deg @check_aware_dt('when') def get_altitude(latitude_deg, longitude_deg, when, elevation = 0, temperature = constants.standard_temperature, pressure = constants.standard_pressure): '''See also the faster, but less accurate, get_altitude_fast() temperature in Kelvin and pressure in Pascal ''' topocentric_sun_declination, topocentric_local_hour_angle = \ get_topocentric_position(latitude_deg, longitude_deg, when, elevation) topocentric_elevation_angle = get_topocentric_elevation_angle(latitude_deg, topocentric_sun_declination, topocentric_local_hour_angle) refraction_correction = get_refraction_correction(pressure, temperature, topocentric_elevation_angle) return topocentric_elevation_angle + refraction_correction @check_aware_dt('when') def get_altitude_fast(latitude_deg, longitude_deg, when): # expect 19 degrees for solar.get_altitude(42.364908,-71.112828,datetime.datetime(2007, 2, 18, 20, 13, 1, 130320)) day = math.tm_yday(when) declination_rad = math.radians(get_declination(day)) latitude_rad = math.radians(latitude_deg) hour_angle = get_hour_angle(when, longitude_deg) first_term = math.cos(latitude_rad) * math.cos(declination_rad) * math.cos(math.radians(hour_angle)) second_term = math.sin(latitude_rad) * math.sin(declination_rad) return math.degrees(math.asin(first_term + second_term)) def get_apparent_sidereal_time(jd, jme, nutation): return get_mean_sidereal_time(jd) + nutation['longitude'] * math.cos(get_true_ecliptic_obliquity(jme, nutation)) def get_apparent_sun_longitude(geocentric_longitude, nutation, ab_correction): return geocentric_longitude + nutation['longitude'] + ab_correction @check_aware_dt('when') def get_azimuth(latitude_deg, longitude_deg, when, elevation = 0): topocentric_sun_declination, topocentric_local_hour_angle = \ get_topocentric_position(latitude_deg, longitude_deg, when, elevation) azimuth = get_topocentric_azimuth_angle(topocentric_local_hour_angle, latitude_deg, topocentric_sun_declination) return azimuth def get_azimuth_fast(latitude_deg, longitude_deg, when): # expect 230 degrees for solar.get_azimuth(42.364908,-71.112828,datetime.datetime(2007, 2, 18, 20, 18, 0, 0)) day = math.tm_yday(when) declination_rad = math.radians(get_declination(day)) latitude_rad = math.radians(latitude_deg) hour_angle_rad = math.radians(get_hour_angle(when, longitude_deg)) altitude_rad = math.radians(get_altitude_fast(latitude_deg, longitude_deg, when)) azimuth_rad = math.asin(-math.cos(declination_rad) * math.sin(hour_angle_rad) / math.cos(altitude_rad)) return math.where(math.cos(hour_angle_rad) * math.tan(latitude_rad) >= math.tan(declination_rad), (180 - math.degrees(azimuth_rad)), math.degrees(azimuth_rad) + 360 * (azimuth_rad < 0) ) def get_coeff(jme, coeffs): "computes a polynomial with time-varying coefficients from the given constant" \ " coefficients array and the current Julian millennium." result = 0.0 x = 1.0 for line in coeffs : c = 0.0 for l in line : c += l[0] * math.cos(l[1] + l[2] * jme) #end for result += c * x x *= jme #end for return \ result #end get_coeff def get_declination(day): '''The declination of the sun is the angle between Earth's equatorial plane and a line between the Earth and the sun. The declination of the sun varies between 23.45 degrees and -23.45 degrees, hitting zero on the equinoxes and peaking on the solstices. ''' return constants.earth_axis_inclination * math.sin((2 * math.pi / 365.0) * (day - 81)) def get_equatorial_horizontal_parallax(sun_earth_distance): return 8.794 / (3600 / sun_earth_distance) def get_flattened_latitude(latitude): latitude_rad = math.radians(latitude) return math.degrees(math.atan(0.99664719 * math.tan(latitude_rad))) # Geocentric functions calculate angles relative to the center of the earth. def get_geocentric_latitude(jme): return -1 * get_heliocentric_latitude(jme) def get_geocentric_longitude(jme): return (get_heliocentric_longitude(jme) + 180) % 360 def get_geocentric_sun_declination(apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude): apparent_sun_longitude_rad = math.radians(apparent_sun_longitude) true_ecliptic_obliquity_rad = math.radians(true_ecliptic_obliquity) geocentric_latitude_rad = math.radians(geocentric_latitude) a = math.sin(geocentric_latitude_rad) * math.cos(true_ecliptic_obliquity_rad) b = math.cos(geocentric_latitude_rad) * math.sin(true_ecliptic_obliquity_rad) * math.sin(apparent_sun_longitude_rad) delta = math.asin(a + b) return math.degrees(delta) def get_geocentric_sun_right_ascension(apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude): apparent_sun_longitude_rad = math.radians(apparent_sun_longitude) true_ecliptic_obliquity_rad = math.radians(true_ecliptic_obliquity) geocentric_latitude_rad = math.radians(geocentric_latitude) a = math.sin(apparent_sun_longitude_rad) * math.cos(true_ecliptic_obliquity_rad) b = math.tan(geocentric_latitude_rad) * math.sin(true_ecliptic_obliquity_rad) c = math.cos(apparent_sun_longitude_rad) alpha = math.atan2((a - b), c) return math.degrees(alpha) % 360 # Heliocentric functions calculate angles relative to the center of the sun. def get_heliocentric_latitude(jme): return math.degrees(get_coeff(jme, constants.heliocentric_latitude_coeffs) / 1e8) def get_heliocentric_longitude(jme): return math.degrees(get_coeff(jme, constants.heliocentric_longitude_coeffs) / 1e8) % 360 @check_aware_dt('when') def get_hour_angle(when, longitude_deg): solar_time = get_solar_time(longitude_deg, when) return 15.0 * (solar_time - 12.0) def get_incidence_angle(topocentric_zenith_angle, slope, slope_orientation, topocentric_azimuth_angle): tza_rad = math.radians(topocentric_zenith_angle) slope_rad = math.radians(slope) so_rad = math.radians(slope_orientation) taa_rad = math.radians(topocentric_azimuth_angle) return math.degrees(math.acos(math.cos(tza_rad) * math.cos(slope_rad) + math.sin(slope_rad) * math.sin(tza_rad) * math.cos(taa_rad - math.pi - so_rad))) def get_local_hour_angle(apparent_sidereal_time, longitude, geocentric_sun_right_ascension): return (apparent_sidereal_time + longitude - geocentric_sun_right_ascension) % 360 def get_mean_sidereal_time(jd): # This function doesn't agree with Andreas and Reda as well as it should. Works to ~5 sig figs in current unit test jc = stime.get_julian_century(jd) sidereal_time = 280.46061837 + (360.98564736629 * (jd - 2451545.0)) + 0.000387933 * jc * jc * (1 - jc / 38710000) return sidereal_time % 360 def get_nutation(jce): abcd = constants.nutation_coefficients nutation_long = [] nutation_oblique = [] p = constants.get_aberration_coeffs() x = list \ ( p[k](jce) for k in ( # order is important 'MeanElongationOfMoon', 'MeanAnomalyOfSun', 'MeanAnomalyOfMoon', 'ArgumentOfLatitudeOfMoon', 'LongitudeOfAscendingNode', ) ) y = constants.aberration_sin_terms for i in range(len(abcd)): sigmaxy = 0.0 for j in range(len(x)): sigmaxy += x[j] * y[i][j] #end for nutation_long.append((abcd[i][0] + (abcd[i][1] * jce)) * math.sin(math.radians(sigmaxy))) nutation_oblique.append((abcd[i][2] + (abcd[i][3] * jce)) * math.cos(math.radians(sigmaxy))) # 36000000 scales from 0.0001 arcseconds to degrees nutation = {'longitude' : sum(nutation_long)/36000000.0, 'obliquity' : sum(nutation_oblique)/36000000.0} return nutation #end get_nutation def get_parallax_sun_right_ascension(projected_radial_distance, equatorial_horizontal_parallax, local_hour_angle, geocentric_sun_declination): prd = projected_radial_distance ehp_rad = math.radians(equatorial_horizontal_parallax) lha_rad = math.radians(local_hour_angle) gsd_rad = math.radians(geocentric_sun_declination) a = -1 * prd * math.sin(ehp_rad) * math.sin(lha_rad) b = math.cos(gsd_rad) - prd * math.sin(ehp_rad) * math.cos(lha_rad) parallax = math.atan2(a, b) return math.degrees(parallax) def get_projected_radial_distance(elevation, latitude): flattened_latitude_rad = math.radians(get_flattened_latitude(latitude)) latitude_rad = math.radians(latitude) return math.cos(flattened_latitude_rad) + (elevation * math.cos(latitude_rad) / constants.earth_radius) def get_projected_axial_distance(elevation, latitude): flattened_latitude_rad = math.radians(get_flattened_latitude(latitude)) latitude_rad = math.radians(latitude) return 0.99664719 * math.sin(flattened_latitude_rad) + (elevation * math.sin(latitude_rad) / constants.earth_radius) def get_sun_earth_distance(jme): return get_coeff(jme, constants.sun_earth_distance_coeffs) / 1e8 def get_refraction_correction(pressure, temperature, topocentric_elevation_angle): #function and default values according to original NREL SPA C code #http://www.nrel.gov/midc/spa/ sun_radius = 0.26667 atmos_refract = 0.5667 tea = topocentric_elevation_angle # Approximation only valid if sun is not well below horizon # This approximation could be improved; see history at https://github.com/pingswept/pysolar/pull/23 # Better method could come from Auer and Standish [2000]: # http://iopscience.iop.org/1538-3881/119/5/2472/pdf/1538-3881_119_5_2472.pdf a = pressure * 2.830 * 1.02 b = 1010.0 * temperature * 60.0 * math.tan(math.radians(tea + (10.3/(tea + 5.11)))) del_e = math.where(tea >= -1.0*(sun_radius + atmos_refract), a / b, 0.) return del_e @check_aware_dt('when') def get_solar_time(longitude_deg, when): "returns solar time in hours for the specified longitude and time," \ " accurate only to the nearest minute." return \ ( (math.tm_hour(when) * 60 + math.tm_min(when) + 4 * longitude_deg + equation_of_time(math.tm_yday(when))) / 60 ) # Topocentric functions calculate angles relative to a location on the surface of the earth. def get_topocentric_azimuth_angle(topocentric_local_hour_angle, latitude, topocentric_sun_declination): """West is negative, East is positive, Masters p. 395""" tlha_rad = math.radians(topocentric_local_hour_angle) latitude_rad = math.radians(latitude) tsd_rad = math.radians(topocentric_sun_declination) a = math.sin(tlha_rad) b = math.cos(tlha_rad) * math.sin(latitude_rad) - math.tan(tsd_rad) * math.cos(latitude_rad) return (180.0 + math.degrees(math.atan2(a, b))) % 360 def get_topocentric_elevation_angle(latitude, topocentric_sun_declination, topocentric_local_hour_angle): latitude_rad = math.radians(latitude) tsd_rad = math.radians(topocentric_sun_declination) tlha_rad = math.radians(topocentric_local_hour_angle) return math.degrees(math.asin((math.sin(latitude_rad) * math.sin(tsd_rad)) + math.cos(latitude_rad) * math.cos(tsd_rad) * math.cos(tlha_rad))) def get_topocentric_local_hour_angle(local_hour_angle, parallax_sun_right_ascension): return local_hour_angle - parallax_sun_right_ascension def get_topocentric_sun_declination(geocentric_sun_declination, projected_axial_distance, equatorial_horizontal_parallax, parallax_sun_right_ascension, local_hour_angle): gsd_rad = math.radians(geocentric_sun_declination) pad = projected_axial_distance ehp_rad = math.radians(equatorial_horizontal_parallax) psra_rad = math.radians(parallax_sun_right_ascension) lha_rad = math.radians(local_hour_angle) a = (math.sin(gsd_rad) - pad * math.sin(ehp_rad)) * math.cos(psra_rad) b = math.cos(gsd_rad) - (pad * math.sin(ehp_rad) * math.cos(lha_rad)) return math.degrees(math.atan2(a, b)) def get_topocentric_sun_right_ascension(projected_radial_distance, equatorial_horizontal_parallax, local_hour_angle, apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude): gsd = get_geocentric_sun_declination(apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude) psra = get_parallax_sun_right_ascension(projected_radial_distance, equatorial_horizontal_parallax, local_hour_angle, gsd) gsra = get_geocentric_sun_right_ascension(apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude) return psra + gsra def get_topocentric_zenith_angle(latitude, topocentric_sun_declination, topocentric_local_hour_angle, pressure, temperature): tea = get_topocentric_elevation_angle(latitude, topocentric_sun_declination, topocentric_local_hour_angle) return 90 - tea - get_refraction_correction(pressure, temperature, tea) def get_true_ecliptic_obliquity(jme, nutation): u = jme/10.0 mean_obliquity = 84381.448 - (4680.93 * u) - (1.55 * u ** 2) + (1999.25 * u ** 3) \ - (51.38 * u ** 4) -(249.67 * u ** 5) - (39.05 * u ** 6) + (7.12 * u ** 7) \ + (27.87 * u ** 8) + (5.79 * u ** 9) + (2.45 * u ** 10) return (mean_obliquity / 3600.0) + nutation['obliquity'] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/solar.pyi0000644000000000000240000000760200000000000015314 0ustar00rootstaff# Stubs for pysolar.solar (Python 3.6) import datetime from typing import List, Tuple def solar_test() -> None: ... def equation_of_time(day:int) -> float: ... def get_aberration_correction(sun_earth_distance:float) -> float: ... def get_altitude(latitude_deg:float, longitude_deg:float, when:datetime.datetime, elevation:float = ..., temperature:float = ..., pressure:float = ...) -> float: ... def get_altitude_fast(latitude_deg:float, longitude_deg:float, when:datetime.datetime) -> float: ... def get_apparent_sidereal_time(jd:float, jme:float, nutation_float) -> float: ... def get_apparent_sun_longitude(geocentric_longitude:float, nutation:float, ab_correction:float) -> float: ... def get_azimuth(latitude_deg:float, longitude_deg:float, when:datetime.datetime, elevation:float = ...) -> float: ... def get_azimuth_fast(latitude_deg:float, longitude_deg:float, when:datetime.datetime) -> float: ... def get_coeff(jme:float, coeffs:List[List[float]]) -> float: ... def get_declination(day:int) -> float: ... def get_equatorial_horizontal_parallax(sun_earth_distance:float) -> float: ... def get_flattened_latitude(latitude:float) -> float: ... def get_geocentric_latitude(jme:float) -> float: ... def get_geocentric_longitude(jme:float) -> float: ... def get_geocentric_sun_declination(apparent_sun_longitude:float, true_ecliptic_obliquity:float, geocentric_latitude:float) -> float: ... def get_geocentric_sun_right_ascension(apparent_sun_longitude:float, true_ecliptic_obliquity:float, geocentric_latitude:float) -> float: ... def get_heliocentric_latitude(jme:float) -> float: ... def get_heliocentric_longitude(jme:float) -> float: ... def get_hour_angle(when:datetime.datetime, longitude_deg:float) -> float: ... def get_incidence_angle(topocentric_zenith_angle:float, slope:float, slope_orientation:float, topocentric_azimuth_angle:float) -> float: ... def get_local_hour_angle(apparent_sidereal_time:float, longitude:float, geocentric_sun_right_ascension:float) -> float: ... def get_mean_sidereal_time(jd:float) -> float: ... def get_nutation(jce:float) -> float: ... def get_parallax_sun_right_ascension(projected_radial_distance:float, equatorial_horizontal_parallax:float, local_hour_angle:float, geocentric_sun_declination:float) -> float: ... def get_position(latitude_deg:float, longitude_deg:float, when:datetime.datetime, elevation:float = ..., temperature:float = ..., pressure:float = ...) -> Tuple[float, float]: ... def get_projected_radial_distance(elevation:float, latitude:float) -> float: ... def get_projected_axial_distance(elevation:float, latitude:float) -> float: ... def get_sun_earth_distance(jme:float) -> float: ... def get_refraction_correction(pressure:float, temperature:float, topocentric_elevation_angle:float) -> float: ... def get_solar_time(longitude_deg:float, when:datetime.datetime) -> float: ... def get_topocentric_azimuth_angle(topocentric_local_hour_angle:float, latitude:float, topocentric_sun_declination:float) -> float: ... def get_topocentric_elevation_angle(latitude:float, topocentric_sun_declination:float, topocentric_local_hour_angle:float) -> float: ... def get_topocentric_local_hour_angle(local_hour_angle:float, parallax_sun_right_ascension:float) -> float: ... def get_topocentric_sun_declination(geocentric_sun_declination:float, projected_axial_distance:float, equatorial_horizontal_parallax:float, parallax_sun_right_ascension:float, local_hour_angle:float) -> float: ... def get_topocentric_sun_right_ascension(projected_radial_distance:float, equatorial_horizontal_parallax:float, local_hour_angle:float, apparent_sun_longitude:float, true_ecliptic_obliquity:float, geocentric_latitude:float) -> float: ... def get_topocentric_zenith_angle(latitude:float, topocentric_sun_declination:float, topocentric_local_hour_angle:float, pressure:float, temperature:float) -> float: ... def get_true_ecliptic_obliquity(jme:float, nutation:float) -> float: ... ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1736004030.0 pysolar-0.13/pysolar/solartime.py0000644000000000000240000005011100000000000016013 0ustar00rootstaff# Copyright Brandon Stafford # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . """This file contains functions related to time conversion. """ import warnings import sys import datetime import time from .constants import \ seconds_per_day from pysolar.tzinfo_check import check_aware_dt julian_day_offset = 1721425 - 0.5 # add to datetime.datetime.toordinal() to get Julian day number gregorian_day_offset = 719163 # number of days to add to datetime.datetime.timestamp() / seconds_per_day to agree with datetime.datetime.toordinal() tt_offset = 32.184 # seconds to add to TAI to get TT #+ # Table of leap-seconds (to date) taken from Wikipedia # . #- leap_seconds_base_year = 1972 leap_seconds_adjustments = \ [ # two entries per year starting from 1972, first for 23:59:59 June 30, # second for 23:59:59 December 31. +1 indicates that 23:59:60 follows, # -1 indicates that 23:59:59 does not exist, not that the latter has ever occurred. # source: https://www.nist.gov/pml/time-and-frequency-division/atomic-standards/leap-second-and-ut1-utc-information (+1, +1), # 1972 (0, +1), # 1973 (0, +1), # 1974 (0, +1), # 1975 (0, +1), # 1976 (0, +1), # 1977 (0, +1), # 1978 (0, +1), # 1979 (0, 0), # 1980 (+1, 0), # 1981 (+1, 0), # 1982 (+1, 0), # 1983 (0, 0), # 1984 (+1, 0), # 1985 (0, 0), # 1986 (0, +1), # 1987 (0, 0), # 1988 (0, +1), # 1989 (0, +1), # 1990 (0, 0), # 1991 (+1, 0), # 1992 (+1, 0), # 1993 (+1, 0), # 1994 (0, +1), # 1995 (0, 0), # 1996 (+1, 0), # 1997 (0, +1), # 1998 (0, 0), # 1999 (0, 0), # 2000 (0, 0), # 2001 (0, 0), # 2002 (0, 0), # 2003 (0, 0), # 2004 (0, +1), # 2005 (0, 0), # 2006 (0, 0), # 2007 (0, +1), # 2008 (0, 0), # 2009 (0, 0), # 2010 (0, 0), # 2011 (+1, 0), # 2012 (0, 0), # 2013 (0, 0), # 2014 (+1, 0), # 2015 (0, +1), # 2016 (0, 0), # 2017 (0, 0), # 2018 (0, 0), # 2019 (0, 0), # 2020 (0, 0), # 2021 (0, 0), # 2022 (0, 0), # 2023 (0, 0), # 2024 (0, 0), # 2025 ] @check_aware_dt('when') def get_leap_seconds(when) : "returns adjustment to be added to UTC at the specified datetime to produce TAI." when = when.utctimetuple() adj = 10 # as decreed from 1972 year = leap_seconds_base_year while True : if year > when.tm_year : break if year - leap_seconds_base_year >= len(leap_seconds_adjustments) : if ( when.tm_year - leap_seconds_base_year > len(leap_seconds_adjustments) or when.tm_year - leap_seconds_base_year == len(leap_seconds_adjustments) and when.tm_mon > 6 ) : warnings.warn \ ( "Leap seconds for year %d are not available for the installed version of pysolar" % (leap_seconds_base_year + len(leap_seconds_adjustments) - 1) ) #end if break #end if entry = leap_seconds_adjustments[year - leap_seconds_base_year] if year == when.tm_year : if when.tm_mon > 6 : adj += entry[0] #end if break #end if adj += entry[0] + entry[1] year += 1 #end while return \ adj #end get_leap_seconds # table of values to add to UT1 to get TT (to date), generated by util/get_delta_t script delta_t_base_year = 1973 delta_t_base_month = 2 delta_t = \ [ [ # 1973 43.4724, # 2 43.5648, # 3 43.6737, # 4 43.7782, # 5 43.8763, # 6 43.9562, # 7 44.0315, # 8 44.1132, # 9 44.1982, # 10 44.2952, # 11 44.3936, # 12 ], [ # 1974 44.4841, # 1 44.5646, # 2 44.6425, # 3 44.7386, # 4 44.8370, # 5 44.9302, # 6 44.9986, # 7 45.0584, # 8 45.1284, # 9 45.2064, # 10 45.2980, # 11 45.3897, # 12 ], [ # 1975 45.4761, # 1 45.5633, # 2 45.6450, # 3 45.7375, # 4 45.8284, # 5 45.9133, # 6 45.9820, # 7 46.0408, # 8 46.1067, # 9 46.1825, # 10 46.2789, # 11 46.3713, # 12 ], [ # 1976 46.4567, # 1 46.5445, # 2 46.6311, # 3 46.7302, # 4 46.8284, # 5 46.9247, # 6 46.9970, # 7 47.0709, # 8 47.1451, # 9 47.2362, # 10 47.3413, # 11 47.4319, # 12 ], [ # 1977 47.5214, # 1 47.6049, # 2 47.6837, # 3 47.7781, # 4 47.8771, # 5 47.9687, # 6 48.0348, # 7 48.0942, # 8 48.1608, # 9 48.2460, # 10 48.3439, # 11 48.4355, # 12 ], [ # 1978 48.5344, # 1 48.6325, # 2 48.7294, # 3 48.8365, # 4 48.9353, # 5 49.0319, # 6 49.1013, # 7 49.1591, # 8 49.2286, # 9 49.3070, # 10 49.4018, # 11 49.4945, # 12 ], [ # 1979 49.5862, # 1 49.6805, # 2 49.7602, # 3 49.8556, # 4 49.9489, # 5 50.0347, # 6 50.1019, # 7 50.1622, # 8 50.2260, # 9 50.2968, # 10 50.3831, # 11 50.4599, # 12 ], [ # 1980 50.5387, # 1 50.6161, # 2 50.6866, # 3 50.7658, # 4 50.8454, # 5 50.9187, # 6 50.9761, # 7 51.0278, # 8 51.0843, # 9 51.1538, # 10 51.2319, # 11 51.3063, # 12 ], [ # 1981 51.3808, # 1 51.4526, # 2 51.5160, # 3 51.5985, # 4 51.6809, # 5 51.7573, # 6 51.8133, # 7 51.8532, # 8 51.9014, # 9 51.9603, # 10 52.0328, # 11 52.0985, # 12 ], [ # 1982 52.1668, # 1 52.2316, # 2 52.2938, # 3 52.3680, # 4 52.4465, # 5 52.5180, # 6 52.5752, # 7 52.6178, # 8 52.6668, # 9 52.7340, # 10 52.8056, # 11 52.8792, # 12 ], [ # 1983 52.9565, # 1 53.0445, # 2 53.1268, # 3 53.2197, # 4 53.3024, # 5 53.3747, # 6 53.4335, # 7 53.4778, # 8 53.5300, # 9 53.5845, # 10 53.6523, # 11 53.7256, # 12 ], [ # 1984 53.7882, # 1 53.8367, # 2 53.8830, # 3 53.9443, # 4 54.0042, # 5 54.0536, # 6 54.0856, # 7 54.1084, # 8 54.1463, # 9 54.1914, # 10 54.2452, # 11 54.2958, # 12 ], [ # 1985 54.3427, # 1 54.3911, # 2 54.4320, # 3 54.4898, # 4 54.5456, # 5 54.5977, # 6 54.6355, # 7 54.6532, # 8 54.6776, # 9 54.7174, # 10 54.7741, # 11 54.8253, # 12 ], [ # 1986 54.8713, # 1 54.9161, # 2 54.9581, # 3 54.9997, # 4 55.0476, # 5 55.0912, # 6 55.1132, # 7 55.1328, # 8 55.1532, # 9 55.1898, # 10 55.2416, # 11 55.2838, # 12 ], [ # 1987 55.3222, # 1 55.3613, # 2 55.4063, # 3 55.4629, # 4 55.5111, # 5 55.5524, # 6 55.5812, # 7 55.6004, # 8 55.6262, # 9 55.6656, # 10 55.7168, # 11 55.7698, # 12 ], [ # 1988 55.8197, # 1 55.8615, # 2 55.9130, # 3 55.9663, # 4 56.0220, # 5 56.0700, # 6 56.0939, # 7 56.1105, # 8 56.1314, # 9 56.1611, # 10 56.2068, # 11 56.2583, # 12 ], [ # 1989 56.3000, # 1 56.3399, # 2 56.3790, # 3 56.4283, # 4 56.4804, # 5 56.5352, # 6 56.5697, # 7 56.5983, # 8 56.6328, # 9 56.6739, # 10 56.7332, # 11 56.7972, # 12 ], [ # 1990 56.8553, # 1 56.9111, # 2 56.9755, # 3 57.0471, # 4 57.1136, # 5 57.1738, # 6 57.2226, # 7 57.2597, # 8 57.3073, # 9 57.3643, # 10 57.4334, # 11 57.5016, # 12 ], [ # 1991 57.5653, # 1 57.6333, # 2 57.6973, # 3 57.7711, # 4 57.8407, # 5 57.9058, # 6 57.9576, # 7 57.9975, # 8 58.0426, # 9 58.1043, # 10 58.1679, # 11 58.2389, # 12 ], [ # 1992 58.3092, # 1 58.3833, # 2 58.4537, # 3 58.5401, # 4 58.6228, # 5 58.6917, # 6 58.7410, # 7 58.7836, # 8 58.8406, # 9 58.8986, # 10 58.9714, # 11 59.0438, # 12 ], [ # 1993 59.1218, # 1 59.2003, # 2 59.2747, # 3 59.3574, # 4 59.4434, # 5 59.5242, # 6 59.5850, # 7 59.6344, # 8 59.6928, # 9 59.7588, # 10 59.8386, # 11 59.9111, # 12 ], [ # 1994 59.9845, # 1 60.0564, # 2 60.1231, # 3 60.2042, # 4 60.2804, # 5 60.3530, # 6 60.4012, # 7 60.4440, # 8 60.4900, # 9 60.5578, # 10 60.6324, # 11 60.7059, # 12 ], [ # 1995 60.7853, # 1 60.8664, # 2 60.9387, # 3 61.0277, # 4 61.1103, # 5 61.1870, # 6 61.2454, # 7 61.2881, # 8 61.3378, # 9 61.4036, # 10 61.4760, # 11 61.5525, # 12 ], [ # 1996 61.6287, # 1 61.6846, # 2 61.7433, # 3 61.8132, # 4 61.8823, # 5 61.9497, # 6 61.9969, # 7 62.0343, # 8 62.0714, # 9 62.1202, # 10 62.1810, # 11 62.2382, # 12 ], [ # 1997 62.2950, # 1 62.3506, # 2 62.3995, # 3 62.4754, # 4 62.5463, # 5 62.6136, # 6 62.6571, # 7 62.6942, # 8 62.7383, # 9 62.7926, # 10 62.8567, # 11 62.9146, # 12 ], [ # 1998 62.9659, # 1 63.0217, # 2 63.0807, # 3 63.1462, # 4 63.2053, # 5 63.2599, # 6 63.2844, # 7 63.2961, # 8 63.3126, # 9 63.3422, # 10 63.3871, # 11 63.4339, # 12 ], [ # 1999 63.4673, # 1 63.4979, # 2 63.5319, # 3 63.5679, # 4 63.6104, # 5 63.6444, # 6 63.6642, # 7 63.6739, # 8 63.6926, # 9 63.7147, # 10 63.7518, # 11 63.7927, # 12 ], [ # 2000 63.8285, # 1 63.8557, # 2 63.8804, # 3 63.9075, # 4 63.9393, # 5 63.9691, # 6 63.9799, # 7 63.9833, # 8 63.9938, # 9 64.0093, # 10 64.0400, # 11 64.0670, # 12 ], [ # 2001 64.0908, # 1 64.1068, # 2 64.1282, # 3 64.1584, # 4 64.1833, # 5 64.2094, # 6 64.2117, # 7 64.2073, # 8 64.2116, # 9 64.2223, # 10 64.2500, # 11 64.2761, # 12 ], [ # 2002 64.2998, # 1 64.3192, # 2 64.3450, # 3 64.3735, # 4 64.3943, # 5 64.4151, # 6 64.4132, # 7 64.4118, # 8 64.4097, # 9 64.4168, # 10 64.4329, # 11 64.4511, # 12 ], [ # 2003 64.4734, # 1 64.4893, # 2 64.5053, # 3 64.5269, # 4 64.5471, # 5 64.5597, # 6 64.5512, # 7 64.5371, # 8 64.5359, # 9 64.5415, # 10 64.5544, # 11 64.5654, # 12 ], [ # 2004 64.5736, # 1 64.5891, # 2 64.6015, # 3 64.6176, # 4 64.6374, # 5 64.6549, # 6 64.6530, # 7 64.6379, # 8 64.6372, # 9 64.6400, # 10 64.6543, # 11 64.6723, # 12 ], [ # 2005 64.6876, # 1 64.7052, # 2 64.7313, # 3 64.7575, # 4 64.7811, # 5 64.8001, # 6 64.7995, # 7 64.7876, # 8 64.7831, # 9 64.7921, # 10 64.8096, # 11 64.8311, # 12 ], [ # 2006 64.8452, # 1 64.8597, # 2 64.8850, # 3 64.9175, # 4 64.9480, # 5 64.9794, # 6 64.9895, # 7 65.0028, # 8 65.0138, # 9 65.0371, # 10 65.0773, # 11 65.1122, # 12 ], [ # 2007 65.1464, # 1 65.1833, # 2 65.2145, # 3 65.2494, # 4 65.2921, # 5 65.3279, # 6 65.3413, # 7 65.3452, # 8 65.3496, # 9 65.3711, # 10 65.3972, # 11 65.4296, # 12 ], [ # 2008 65.4573, # 1 65.4868, # 2 65.5152, # 3 65.5450, # 4 65.5781, # 5 65.6127, # 6 65.6288, # 7 65.6370, # 8 65.6493, # 9 65.6760, # 10 65.7097, # 11 65.7461, # 12 ], [ # 2009 65.7768, # 1 65.8025, # 2 65.8237, # 3 65.8595, # 4 65.8973, # 5 65.9323, # 6 65.9509, # 7 65.9534, # 8 65.9628, # 9 65.9839, # 10 66.0147, # 11 66.0420, # 12 ], [ # 2010 66.0699, # 1 66.0961, # 2 66.1310, # 3 66.1683, # 4 66.2072, # 5 66.2356, # 6 66.2409, # 7 66.2335, # 8 66.2349, # 9 66.2441, # 10 66.2751, # 11 66.3054, # 12 ], [ # 2011 66.3246, # 1 66.3406, # 2 66.3624, # 3 66.3957, # 4 66.4289, # 5 66.4619, # 6 66.4749, # 7 66.4751, # 8 66.4829, # 9 66.5056, # 10 66.5383, # 11 66.5706, # 12 ], [ # 2012 66.6030, # 1 66.6340, # 2 66.6569, # 3 66.6925, # 4 66.7289, # 5 66.7579, # 6 66.7708, # 7 66.7740, # 8 66.7846, # 9 66.8103, # 10 66.8400, # 11 66.8779, # 12 ], [ # 2013 66.9069, # 1 66.9443, # 2 66.9763, # 3 67.0258, # 4 67.0716, # 5 67.1100, # 6 67.1266, # 7 67.1331, # 8 67.1458, # 9 67.1718, # 10 67.2091, # 11 67.2460, # 12 ], [ # 2014 67.2810, # 1 67.3136, # 2 67.3457, # 3 67.3890, # 4 ], ] # delta_t @check_aware_dt('when') def get_delta_t(when) : "returns a suitable value for delta_t for the given datetime." when = when.utctimetuple() year, month = when.tm_year, when.tm_mon if year < delta_t_base_year : year = delta_t_base_year month = 1 elif year == delta_t_base_year : month = max(0, month - delta_t_base_month) + 1 elif year >= delta_t_base_year + len(delta_t) : year = delta_t_base_year + len(delta_t) - 1 #end if if year == delta_t_base_year + len(delta_t) - 1 : month = min(month, len(delta_t[year - delta_t_base_year])) #end if return \ delta_t[year - delta_t_base_year][month - 1] # don't bother doing any fancy interpolation #end get_delta_t @check_aware_dt('when') def get_julian_solar_day(when): "returns the UT Julian day number (including fraction of a day) corresponding to" \ " the specified date/time. This version assumes the proleptic Gregorian calendar;" \ " trying to adjust for pre-Gregorian dates/times seems pointless when the changeover" \ " happened over such wildly varying times in different regions." return \ ( (when.timestamp() + get_leap_seconds(when) + tt_offset - get_delta_t(when)) / seconds_per_day + gregorian_day_offset + julian_day_offset ) #end get_julian_solar_day @check_aware_dt('when') def get_julian_ephemeris_day(when) : "returns the TT Julian day number (including fraction of a day) corresponding to" \ " the specified date/time. This version assumes the proleptic Gregorian calendar;" \ " trying to adjust for pre-Gregorian dates/times seems pointless when the changeover" \ " happened over such wildly varying times in different regions." return \ ( (when.timestamp() + get_leap_seconds(when) + tt_offset) / seconds_per_day + gregorian_day_offset + julian_day_offset ) #end get_julian_ephemeris_day def get_julian_century(julian_day): return (julian_day - 2451545.0) / 36525.0 def get_julian_ephemeris_century(julian_ephemeris_day): return (julian_ephemeris_day - 2451545.0) / 36525.0 def get_julian_ephemeris_millennium(julian_ephemeris_century): return (julian_ephemeris_century / 10.0) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/solartime.pyi0000644000000000000240000000141500000000000016167 0ustar00rootstaff# Stubs for pysolar.time (Python 3.6) import datetime from typing import List, Tuple julian_day_offset: float gregorian_day_offset: int tt_offset: float leap_seconds_base_year: int leap_seconds_adjustments: List[Tuple[float,float]] def get_leap_seconds(when:datetime.datetime) -> int: ... delta_t_base_year: int delta_t_base_month: int delta_t: List[List[float]] def get_delta_t(when:datetime.datetime) -> float: ... def get_julian_solar_day(when:datetime.datetime) -> float: ... def get_julian_ephemeris_day(when:datetime.datetime) -> float: ... def get_julian_century(julian_day:float) -> float: ... def get_julian_ephemeris_century(julian_ephemeris_day:float) -> float: ... def get_julian_ephemeris_millennium(julian_ephemeris_century) -> float: ... ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/tzinfo_check.py0000644000000000000240000000616400000000000016473 0ustar00rootstafffrom functools import wraps import inspect class NoTimeZoneInfoError(ValueError): def __init__(self, argname, dt, *args): self.argname = argname self.dt = dt super().__init__(*args) def __str__(self): return """datetime value '{dt}' given for arg '{argname}' \ should be made timezone-aware. You have to specify the 'tzinfo' attribute of \ 'datetime.datetime' objects.""".format(dt=self.dt, argname=self.argname) def check_aware_dt(*argnames): """Returns a decorator that makes sure that all the arguments in 'argnames', are 'datetime.datetime' objects with a non-null tzinfo attribute Parameters ---------- argnames : List[str] list of names from the arguments of function 'func' (the decorated function) that are supposed to only accept as values 'datetime.datetime' objects with a non-null tzinfo attribute Returns ------- checker : function decorator that makes sure that every argument of the decorated function that is in 'argnames' is given only 'datetime.datetime' objects with non-null tzinfo attribute as values""" def checker(func): """Decorator (see above in the `Returns` section) Parameters ---------- func : function decorated function every argument of 'func' that is in argnames will only accept tz-aware 'datetime' objects Returns ------- func_with_check : function decorated function, basically the same function as 'func', with the check for tz-awareness performed before execution""" @wraps(func) def func_with_check(*args, **kwargs): """Decorated function ; will be, apart from the check, completely identical to the 'func' function We search for 'argnames' values in args and kwargs Parameters ---------- args : list list of positional arguments that are supposedly passed to the 'func' function kwargs : dict dict of keyword arguments that are supposedly passed to the 'func' function Returns ------- func(*args, **kwargs) we return the very same result that would have been returned by the 'func' function alone we just checked the values of args from argnames before""" for argname in argnames: # first checking if argname is a valid arg name full = inspect.getfullargspec(func) if (argname in full.args or argname in full.kwonlyargs): # getting value given for argname try: dt = args[full.args.index(argname)] except (IndexError, ValueError): dt = kwargs[argname] # checking if dt is timezone-aware if not hasattr(dt, 'shape'): # don't raise Exception if dt is an array (assumed of datetime64) if not hasattr(dt, 'tzinfo'): raise ValueError( "Expected a 'datetime.datetime' object \ for arg '%s', got %s instead" % (argname, dt)) if dt.tzinfo is None: raise NoTimeZoneInfoError(argname, dt) return func(*args, **kwargs) return func_with_check return checker ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/util.py0000644000000000000240000006203700000000000015003 0ustar00rootstaff# -*- coding: utf-8 -*- # Copyright Brandon Stafford # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . """Additional support functions for solar geometry, astronomy, radiation correlation :Original author: Simeon Nwaogaidu :Contact: SimeonObinna.Nwaogaidu AT lahmeyer DOT de :Additional author: Holger Zebner :Contact: holger.zebner AT lahmeyer DOT de :Additional author: Brandon Stafford """ from datetime import \ datetime, \ timedelta from . import numeric as math from . import solar, constants from .tzinfo_check import check_aware_dt # Some default constants AM_default = 2.0 # Default air mass is 2.0 TL_default = 1.0 # Default Linke turbidity factor is 1.0 SC_default = 1367.0 # Solar constant in W/m^2 is 1367.0. Note that this value could vary by +/-4 W/m^2 TY_default = 365 # Total year number from 1 to 365 days elevation_default = 0.0 # Default elevation is 0.0 # Useful equations for analysis @check_aware_dt('when') def get_sunrise_sunset_transit(latitude_deg, longitude_deg, when): """This function calculates the astronomical sunrise, sunset and sun transit times in local time. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. when : datetime.datetime date and time in any valid timezone, answers will be for same day in same timezone. Returns ------- sunrise_time_dt : datetime.datetime Sunrise time in local time. sunset_time_dt : datetime.datetime Sunset time in local time. transit_time_dt: Sun transit time in local time. References ---------- .. [1] http://www.skypowerinternational.com/uploads/documents/7.1415.01.121_cm121_bed-anleitung_engl.pdf .. [2] http://pysolar.org/ .. [3] https://www.esrl.noaa.gov/gmd/grad/solcalc/solareqns.PDF .. [4] https://www.sciencedirect.com/science/article/pii/S0038092X11004592 .. [5] https://iris.unipa.it/retrieve/handle/10447/55143/28818/Articolo.pdf Examples -------- >>> lat = 50.111512 >>> lon = 8.680506 >>> timezone_local = dateutil.tz.gettz('Europe/Berlin') >>> now = datetime.now(timezone_local) >>> sr, ss, tr = sb.get_sunrise_sunset_transit(lat, lon, now) >>> print('sunrise: ', sr) >>> print('sunset:', ss) >>> print('transit:', tr) """ utc_offset = when.utcoffset() if utc_offset != None : utc_offset = utc_offset.total_seconds() else : utc_offset = 0 #end if day = when.timetuple().tm_yday # Day of the year SHA = utc_offset / 3600 * 15.0 - longitude_deg # Solar hour angle TT = 2 * math.pi * day / 366 decl = \ ( 0.322003 - 22.971 * math.cos(TT) - 0.357898 * math.cos(2 * TT) - 0.14398 * math.cos(3 * TT) + 3.94638 * math.sin(TT) + 0.019334 * math.sin(2 * TT) + 0.05928 * math.sin(3 * TT) ) # solar declination in degrees TT = math.radians(279.134 + 0.985647 * day) # Time adjustment angle time_adst = \ ( ( 5.0323 - 100.976 * math.sin(TT) + 595.275 * math.sin(2 * TT) + 3.6858 * math.sin(3 * TT) - 12.47 * math.sin(4 * TT) - 430.847 * math.cos(TT) + 12.5024 * math.cos(2 * TT) + 18.25 * math.cos(3 * TT) ) / 3600 ) # Time adjustment in hours TON = 12 + SHA / 15.0 - time_adst # Time of noon ha = \ ( math.acos( math.cos(math.radians(90.833)) / ( math.cos(math.radians(latitude_deg)) * math.cos(math.radians(decl)) ) - math.tan(math.radians(latitude_deg)) * math.tan(math.radians(decl)) ) * (12 / math.pi) ) same_day = datetime(year = when.year, month = when.month, day = when.day, tzinfo = when.tzinfo) sunrise_time = same_day + timedelta(hours = TON - ha) sunset_time = same_day + timedelta(hours = TON + ha) transit_time = same_day + timedelta(hours = TON) return sunrise_time, sunset_time, transit_time @check_aware_dt('when') def get_sunrise_sunset(latitude_deg, longitude_deg, when): "Wrapper for get_sunrise_sunset_transit that returns just the sunrise and the sunset time." return \ get_sunrise_sunset_transit(latitude_deg, longitude_deg, when)[0:2] @check_aware_dt('when') def get_sunrise_time(latitude_deg, longitude_deg, when): "Wrapper for get_sunrise_sunset_transit that returns just the sunrise time." return \ get_sunrise_sunset_transit(latitude_deg, longitude_deg, when)[0] @check_aware_dt('when') def get_sunset_time(latitude_deg, longitude_deg, when): "Wrapper for get_sunrise_sunset_transit that returns just the sunset time." return \ get_sunrise_sunset_transit(latitude_deg, longitude_deg, when)[1] @check_aware_dt('when') def get_transit_time(latitude_deg, longitude_deg, when): "Wrapper for get_sunrise_sunset_transit that returns just the transit time." return \ get_sunrise_sunset_transit(latitude_deg, longitude_deg, when)[2] @check_aware_dt('when') def mean_earth_sun_distance(when): """Mean Earth-Sun distance is the arithmetical mean of the maximum and minimum distances between a planet (Earth) and the object about which it revolves (Sun). However, the function is used to calculate the Mean earth sun distance. Parameters ---------- when : datetime.datetime date/time for which to do the calculation Returns ------- KD : float Mean earth sun distance References ---------- .. [1] http://sunbird.jrc.it/pvgis/solres/solmod3.htm#clear-sky%20radiation .. [2] R. aguiar and et al, "The ESRA user guidebook, vol. 2. database", models and exploitation software-Solar radiation models, p.113 """ return 1 - 0.0335 * math.sin(2 * math.pi * (when.utctimetuple().tm_yday - 94)) / 365 @check_aware_dt('when') def extraterrestrial_irrad(latitude_deg, longitude_deg, when, SC=SC_default): """Equation calculates Extratrestrial radiation. Solar radiation incident outside the earth's atmosphere is called extraterrestrial radiation. On average the extraterrestrial irradiance is 1367 Watts/meter2 (W/m2). This value varies by + or - 3 percent as the earth orbits the sun. The earth's closest approach to the sun occurs around January 4th and it is furthest from the sun around July 5th. Parameters ---------- when : datetime.datetime date/time for which to do the calculation latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. SC : float The solar constant is the amount of incoming solar electromagnetic radiation per unit area, measured on the outer surface of Earth's atmosphere in a plane perpendicular to the rays.It is measured by satellite to be roughly 1366 watts per square meter (W/m^2) Returns ------- EXTR1 : float Extraterrestrial irradiation References ---------- .. [1] http://solardat.uoregon.edu/SolarRadiationBasics.html .. [2] Dr. J. Schumacher and et al,"INSEL LE(Integrated Simulation Environment Language)Block reference",p.68 """ day = when.utctimetuple().tm_yday ab = math.cos(2 * math.pi * (day - 1.0)/(365.0)) bc = math.sin(2 * math.pi * (day - 1.0)/(365.0)) cd = math.cos(2 * (2 * math.pi * (day - 1.0)/(365.0))) df = math.sin(2 * (2 * math.pi * (day - 1.0)/(365.0))) decl = math.radians(solar.get_declination(day)) ha = math.radians(solar.get_hour_angle(when, longitude_deg)) ZA = math.sin(math.radians(latitude_deg)) * math.sin(decl) + math.cos(math.radians(latitude_deg)) * math.cos(decl) * math.cos(ha) return SC * ZA * (1.00010 + 0.034221 * ab + 0.001280 * bc + 0.000719 * cd + 0.000077 * df) if ZA > 0 else 0.0 @check_aware_dt('when') def declination_degree(when, TY = TY_default): """The declination of the sun is the angle between Earth's equatorial plane and a line between the Earth and the sun. It varies between 23.45 degrees and -23.45 degrees, hitting zero on the equinoxes and peaking on the solstices. Parameters ---------- when : datetime.datetime date/time for which to do the calculation TY : float Total number of days in a year. eg. 365 days per year,(no leap days) Returns ------- DEC : float The declination of the Sun References ---------- .. [1] http://pysolar.org/ """ return constants.earth_axis_inclination * math.sin((2 * math.pi / (TY)) * ((when.utctimetuple().tm_yday) - 81)) @check_aware_dt('when') def solarelevation_function_clear(latitude_deg, longitude_deg, when, temperature = constants.standard_temperature, pressure = constants.standard_pressure, elevation = elevation_default): """Equation calculates Solar elevation function for clear sky type. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. when : datetime.datetime date/time for which to do the calculation temperature : float atmospheric temperature in kelvin pressure : float pressure in pascals elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. Returns ------- SOLALTC : float Solar elevation function clear sky References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ altitude = solar.get_altitude(latitude_deg, longitude_deg,when, elevation, temperature,pressure) return (0.038175 + (1.5458 * (math.sin(altitude))) + ((-0.59980) * (0.5 * (1 - math.cos(2 * (altitude)))))) @check_aware_dt('when') def solarelevation_function_overcast(latitude_deg, longitude_deg, when, elevation = elevation_default, temperature = constants.standard_temperature, pressure = constants.standard_pressure): """ The function calculates solar elevation function for overcast sky type. This associated hourly overcast radiation model is based on the estimation of the overcast sky transmittance with the sun directly overhead combined with the application of an over sky elavation function to estimate the overcast day global irradiation value at any solar elevation. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. when : datetime.datetime date/time for which to do the calculation elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. temperature : float atmospheric temperature in kelvin pressure : float pressure in pascals Returns ------- SOLALTO : float Solar elevation function overcast References ---------- .. [1] Prof. Peter Tregenza,"Solar radiation and daylight models", p.89. .. [2] Also accessible through Google Books: http://tinyurl.com/5kdbwu Tariq Muneer, "Solar Radiation and Daylight Models, Second Edition: For the Energy Efficient Design of Buildings" """ altitude = solar.get_altitude(latitude_deg, longitude_deg,when, elevation, temperature,pressure) return ((-0.0067133) + (0.78600 * (math.sin(altitude)))) + (0.22401 * (0.5 * (1 - math.cos(2 * altitude)))) def diffuse_transmittance(TL = TL_default): """Equation calculates the Diffuse_transmittance and the is the Theoretical Diffuse Irradiance on a horizontal surface when the sun is at the zenith. Parameters ---------- TL : float Linke turbidity factor Returns ------- DT : float diffuse_transmittance References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ return ((-21.657) + (41.752 * (TL)) + (0.51905 * (TL) * (TL))) @check_aware_dt('when') def diffuse_underclear(latitude_deg, longitude_deg, when, elevation = elevation_default, temperature = constants.standard_temperature, pressure = constants.standard_pressure, TL=TL_default): """Equation calculates diffuse radiation under clear sky conditions. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. when : datetime.datetime date/time for which to do the calculation elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. temperature : float atmospheric temperature in kelvin pressure : float pressure in pascals TL : float Linke turbidity factor Returns ------- DIFFC : float Diffuse Irradiation under clear sky References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ DT = ((-21.657) + (41.752 * (TL)) + (0.51905 * (TL) * (TL))) altitude = solar.get_altitude(latitude_deg, longitude_deg,when, elevation, temperature,pressure) return mean_earth_sun_distance(when) * DT * altitude @check_aware_dt('when') def diffuse_underovercast(latitude_deg, longitude_deg, when, elevation = elevation_default, temperature = constants.standard_temperature, pressure = constants.standard_pressure,TL=TL_default): """Function calculates the diffuse radiation under overcast conditions. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. when : datetime.datetime date/time for which to do the calculation elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. temperature : float atmospheric temperature in kelvin pressure : float pressure in pascals TL : float Linke turbidity factor Returns ------- DIFOC : float Diffuse Irradiation under overcast References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ DT = ((-21.657) + (41.752 * (TL)) + (0.51905 * (TL) * (TL))) DIFOC = ((mean_earth_sun_distance(when) )*(DT)*(solar.get_altitude(latitude_deg,longitude_deg, when, elevation, temperature, pressure))) return DIFOC @check_aware_dt('when') def direct_underclear(latitude_deg, longitude_deg, when, TY = TY_default, AM = AM_default, TL = TL_default, elevation = elevation_default, temperature = constants.standard_temperature, pressure = constants.standard_pressure): """Equation calculates direct radiation under clear sky conditions. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. when : datetime.datetime date/time for which to do the calculation TY : float Total number of days in a year. eg. 365 days per year,(no leap days) AM : float Air mass. An Air Mass is a measure of how far light travels through the Earth's atmosphere. One air mass, or AM1, is the thickness of the Earth's atmosphere. Air mass zero (AM0) describes solar irradiance in space, where it is unaffected by the atmosphere. The power density of AM1 light is about 1,000 W/m^2 TL : float Linke turbidity factor elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. temperature : float atmospheric temperature in kelvin pressure : float pressure in pascals Returns ------- DIRC : float Direct Irradiation under clear References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ KD = mean_earth_sun_distance(when) DEC = declination_degree(when,TY) DIRC = (1367 * KD * math.exp(-0.8662 * (AM) * (TL) * (DEC) ) * math.sin(solar.get_altitude(latitude_deg,longitude_deg, when,elevation , temperature , pressure ))) return DIRC @check_aware_dt('when') def global_irradiance_clear(latitude_deg, longitude_deg, when, TY = TY_default, AM = AM_default, TL = TL_default, elevation = elevation_default, temperature = constants.standard_temperature, pressure = constants.standard_pressure): """Equation calculates global irradiance under clear sky conditions. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. when : datetime.datetime date/time for which to do the calculation temperature : float atmospheric temperature in kelvin pressure : float pressure in pascals elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. TY : float Total number of days in a year. eg. 365 days per year,(no leap days) AM : float Air mass. An Air Mass is a measure of how far light travels through the Earth's atmosphere. One air mass, or AM1, is the thickness of the Earth's atmosphere. Air mass zero (AM0) describes solar irradiance in space, where it is unaffected by the atmosphere. The power density of AM1 light is about 1,000 W/m. TL : float Linke turbidity factor elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. Returns ------- ghic : float Global Irradiation under clear sky References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ DIRC = direct_underclear(latitude_deg, longitude_deg, when, TY, AM, TL, elevation, temperature = constants.standard_temperature, pressure = constants.standard_pressure) DIFFC = diffuse_underclear(latitude_deg, longitude_deg, when, elevation, temperature = constants.standard_temperature, pressure= constants.standard_pressure) ghic = (DIRC + DIFFC) return ghic @check_aware_dt('when') def global_irradiance_overcast(latitude_deg, longitude_deg, when, elevation = elevation_default, temperature = constants.standard_temperature, pressure = constants.standard_pressure): """Calculated Global is used to compare to the Diffuse under overcast conditions. Under overcast skies, global and diffuse are expected to be equal due to the absence of the beam component. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. when : datetime.datetime date/time for which to do the calculation elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. temperature : float atmospheric temperature in kelvin pressure : float pressure in pascals Returns ------- ghioc : float Global Irradiation under overcast sky References ---------- .. [1] S. Younes, R.Claywell and el al, "Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ ghioc = (572 * (solar.get_altitude(latitude_deg, longitude_deg, when, elevation , temperature , pressure ))) return ghioc def diffuse_ratio(DIFF_data, ghi_data): """Function calculates the Diffuse ratio. Parameters ---------- DIFF_data : array_like Diffuse horizontal irradiation data ghi_data : array_like global horizontal irradiation data array Returns ------- K : float diffuse_ratio References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ K = DIFF_data/ghi_data return K @check_aware_dt('when') def clear_index(ghi_data, latitude_deg, longitude_deg, when): """This calculates the clear index ratio. Parameters ---------- ghi_data : array_like global horizontal irradiation data array when : datetime.datetime date/time for which to do the calculation latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. Returns ------- KT : float Clear index ratio References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ EXTR1 = extraterrestrial_irrad(latitude_deg, longitude_deg, when) KT = (ghi_data / EXTR1) return KT ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/pysolar/util.pyi0000644000000000000240000000600000000000000015140 0ustar00rootstaff# Stubs for pysolar.util (Python 3.6) import datetime import numpy # https://stackoverflow.com/questions/21968643/what-is-a-scalar-in-numpy https://stackoverflow.com/questions/40378427/numpy-formal-definition-of-array-like-objects from typing import Tuple, Union AM_default: float TL_default: float SC_default: float TY_default: float elevation_default: float def get_sunrise_sunset_transit(latitude_deg:float, longitude_deg:float, when:datetime.datetime) -> Tuple[datetime.datetime, datetime.datetime, datetime.datetime]: ... def get_sunrise_sunset(latitude_deg:float, longitude_deg:float, when:datetime.datetime) -> Tuple[datetime.datetime, datetime.datetime]: ... def get_sunrise_time(latitude_deg:float, longitude_deg:float, when:datetime.datetime) -> datetime.datetime: ... def get_sunset_time(latitude_deg:float, longitude_deg:float, when:datetime.datetime) -> datetime.datetime: ... def get_transit_time(latitude_deg:float, longitude_deg:float, when:datetime.datetime) -> datetime.datetime: ... def mean_earth_sun_distance(when:datetime.datetime) -> float: ... def extraterrestrial_irrad(when:datetime.datetime, latitude_deg:float, longitude_deg:float, SC:float = ...) -> float: ... def declination_degree(when:datetime.datetime, TY:float = ...) -> float: ... def solarelevation_function_clear(latitude_deg:float, longitude_deg:float, when:datetime.datetime, temperature:float = ..., pressure:float = ..., elevation:float = ...) -> float: ... def solarelevation_function_overcast(latitude_deg:float, longitude_deg:float, when:datetime.datetime, elevation:float = ..., temperature:float = ..., pressure:float = ...) -> float: ... def diffuse_transmittance(TL:float = ...) -> float: ... def diffuse_underclear(latitude_deg:float, longitude_deg:float, when:datetime.datetime, elevation:float = ..., temperature:float = ..., pressure:float = ..., TL:float = ...) -> float: ... def diffuse_underovercast(latitude_deg:float, longitude_deg:float, when:datetime.datetime, elevation:float = ..., temperature:float = ..., pressure:float = ..., TL:float = ...) -> float: ... def direct_underclear(latitude_deg:float, longitude_deg:float, when:datetime.datetime, temperature:float = ..., pressure:float = ..., TY:float = ..., AM:float = ..., TL:float = ..., elevation:float = ...) -> float: ... def global_irradiance_clear(DIRC, DIFFC, latitude_deg:float, longitude_deg:float, when:datetime.datetime, temperature:float = ..., pressure:float = ..., TY:float = ..., AM:float = ..., TL:float = ..., elevation:float = ...) -> float: ... def global_irradiance_overcast(latitude_deg:float, longitude_deg:float, when:datetime.datetime, elevation:float = ..., temperature:float = ..., pressure:float = ...) -> float: ... def diffuse_ratio(DIFF_data:Union[numpy.array,numpy.ndarray,numpy.generic,float,int], ghi_data:Union[numpy.array,numpy.ndarray,numpy.generic,float,int]) -> float: ... def clear_index(ghi_data:Union[numpy.array,numpy.ndarray,numpy.generic,float,int], when:datetime.datetime, latitude_deg:float, longitude_deg:float) -> float: ... ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1736004678.653911 pysolar-0.13/pysolar.egg-info/0000755000000000000240000000000000000000000015136 5ustar00rootstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1736004678.0 pysolar-0.13/pysolar.egg-info/PKG-INFO0000644000000000000240000000052100000000000016231 0ustar00rootstaffMetadata-Version: 2.1 Name: pysolar Version: 0.13 Summary: Collection of Python libraries for simulating the irradiation of any point on earth by the sun Home-page: http://pysolar.org Author: Brandon Stafford Author-email: brandon@pingswept.org License: GNU General Public License (GPL) Platform: UNKNOWN License-File: COPYING UNKNOWN ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1736004678.0 pysolar-0.13/pysolar.egg-info/SOURCES.txt0000644000000000000240000000121600000000000017022 0ustar00rootstaffCOPYING MANIFEST.in setup.py pysolar/__init__.py pysolar/__init__.pyi pysolar/constants.py pysolar/constants.pyi pysolar/elevation.py pysolar/elevation.pyi pysolar/numeric.py pysolar/radiation.py pysolar/radiation.pyi pysolar/rest.py pysolar/simulate.py pysolar/simulate.pyi pysolar/solar.py pysolar/solar.pyi pysolar/solartime.py pysolar/solartime.pyi pysolar/tzinfo_check.py pysolar/util.py pysolar/util.pyi pysolar.egg-info/PKG-INFO pysolar.egg-info/SOURCES.txt pysolar.egg-info/dependency_links.txt pysolar.egg-info/requires.txt pysolar.egg-info/top_level.txt test/test_datetime_tzinfo.py test/test_hour_angle.py test/test_numpy.py test/test_solar.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1736004678.0 pysolar-0.13/pysolar.egg-info/dependency_links.txt0000644000000000000240000000000100000000000021204 0ustar00rootstaff ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1736004678.0 pysolar-0.13/pysolar.egg-info/requires.txt0000644000000000000240000000000600000000000017532 0ustar00rootstaffnumpy ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1736004678.0 pysolar-0.13/pysolar.egg-info/top_level.txt0000644000000000000240000000001000000000000017657 0ustar00rootstaffpysolar ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1736004678.6552975 pysolar-0.13/setup.cfg0000644000000000000240000000004600000000000013574 0ustar00rootstaff[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1736004067.0 pysolar-0.13/setup.py0000644000000000000240000000215000000000000013463 0ustar00rootstafffrom distutils.core import setup import setuptools classifiers = ['Development Status :: 5 - Production/Stable', 'Environment :: Console', 'Intended Audience :: Developers', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: GNU General Public License (GPL)', 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Atmospheric Science', 'Topic :: Scientific/Engineering :: Mathematics', 'Topic :: Software Development :: Libraries :: Python Modules', 'Programming Language :: Python :: 3'] setup(name='pysolar', version='0.13', description='Collection of Python libraries for simulating the irradiation of any point on earth by the sun', author='Brandon Stafford', author_email='brandon@pingswept.org', license = 'GNU General Public License (GPL)', url='http://pysolar.org', packages=['pysolar'], package_data = {"pysolar": ["*.pyi"]}, # *.py is included in any case install_requires = ['numpy'], ) ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1736004678.654814 pysolar-0.13/test/0000755000000000000240000000000000000000000012732 5ustar00rootstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/test/test_datetime_tzinfo.py0000644000000000000240000002750700000000000017543 0ustar00rootstaff# Copyright Brandon Stafford # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . """This test file makes sure that every function that requires 'datetime.datetime' objects as parameters receives only timezone-aware ones. """ from pysolar import solar from pysolar import solartime from pysolar import util import datetime import unittest from pysolar.tzinfo_check import NoTimeZoneInfoError import numpy as np class TestErrorTimeZoneIsNone(unittest.TestCase): unaware = datetime.datetime(2000, 1, 1) lat = 1.0 lon = 1.0 def test_solar_topocentric_position_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solar.get_topocentric_position(self.lat, self.lon, self.unaware) def test_solar_get_position_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solar.get_position(self.lat, self.lon, self.unaware) def test_solar_get_altitude_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solar.get_altitude(self.lat, self.lon, self.unaware) def test_solar_get_altitude_fast_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solar.get_altitude_fast(self.lat, self.lon, self.unaware) def test_solar_get_azimuth_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solar.get_azimuth(self.lat, self.lon, self.unaware) def test_solar_get_azimuth_fast_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solar.get_azimuth_fast(self.lat, self.lon, self.unaware) def test_solar_get_hour_angle_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solar.get_hour_angle(self.unaware, self.lon) def test_solar_get_solar_time_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solar.get_hour_angle(self.unaware, self.lon) def test_solartime_get_leap_seconds_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solartime.get_leap_seconds(self.unaware) def test_solartime_get_delta_t_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solartime.get_delta_t(self.unaware) def test_solartime_get_julian_solar_day_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solartime.get_julian_solar_day(self.unaware) def test_solartime_get_julian_ephemeris_day_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): solartime.get_julian_ephemeris_day(self.unaware) def test_util_get_sunrise_sunset_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.get_sunrise_sunset(self.lat, self.lon, self.unaware) def test_util_get_sunrise_time_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.get_sunrise_time(self.lat, self.lon, self.unaware) def test_util_get_sunset_time_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.get_sunset_time(self.lat, self.lon, self.unaware) def test_util_get_transit_time_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.get_transit_time(self.lat, self.lon, self.unaware) def test_util_mean_earth_sun_distance_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.mean_earth_sun_distance(self.unaware) def test_util_extraterrestrial_irrad_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.extraterrestrial_irrad(self.lat, self.lon, self.unaware) def test_util_declination_degree_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.declination_degree(self.unaware) def test_util_solarelevation_function_overcast_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.solarelevation_function_overcast(self.lat, self.lon, self.unaware) def test_util_diffuse_underclear_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.diffuse_underclear(self.lat, self.lon, self.unaware) def test_util_diffuse_underovercast_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.diffuse_underovercast(self.lat, self.lon, self.unaware) def test_util_direct_underclear_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.direct_underclear(self.lat, self.lon, self.unaware) def test_util_global_irradiance_clear_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.global_irradiance_clear(self.lat, self.lon, self.unaware) def test_util_global_irradiance_overcast_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): util.global_irradiance_overcast(self.lat, self.lon, self.unaware) def test_util_clear_index_raise_error(self): with self.assertRaises(NoTimeZoneInfoError): ghi_data = np.asarray([0, 0]) # Don't know what ghi_data is supposed to be util.clear_index(ghi_data, self.lat, self.lon, self.unaware) class TestTimeZoneNotNone(unittest.TestCase): aware = datetime.datetime(2000, 1, 1, tzinfo=datetime.timezone.utc) lat = 1.0 lon = 1.0 def test_solar_topocentric_position_no_error(self): try: solar.get_topocentric_position(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solar_get_position_no_error(self): try: solar.get_position(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solar_get_altitude_no_error(self): try: solar.get_altitude(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solar_get_altitude_fast_no_error(self): try: solar.get_altitude_fast(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solar_get_azimuth_no_error(self): try: solar.get_azimuth(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solar_get_azimuth_fast_no_error(self): try: solar.get_azimuth_fast(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solar_get_hour_angle_no_error(self): try: solar.get_hour_angle(self.aware, self.lon) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solar_get_solar_time_no_error(self): try: solar.get_hour_angle(self.aware, self.lon) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solartime_get_leap_seconds_no_error(self): try: solartime.get_leap_seconds(self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solartime_get_delta_t_no_error(self): try: solartime.get_delta_t(self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solartime_get_julian_solar_day_no_error(self): try: solartime.get_julian_solar_day(self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_solartime_get_julian_ephemeris_day_no_error(self): try: solartime.get_julian_ephemeris_day(self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_get_sunrise_sunset_no_error(self): try: util.get_sunrise_sunset(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_get_sunrise_time_no_error(self): try: util.get_sunrise_time(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_get_sunset_time_no_error(self): try: util.get_sunset_time(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_mean_earth_sun_distance_no_error(self): try: util.mean_earth_sun_distance(self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_extraterrestrial_irrad_no_error(self): try: util.extraterrestrial_irrad(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_declination_degree_no_error(self): try: util.declination_degree(self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_solarelevation_function_overcast_no_error(self): try: util.solarelevation_function_overcast(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_diffuse_underclear_no_error(self): try: util.diffuse_underclear(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_diffuse_underovercast_no_error(self): try: util.diffuse_underovercast(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_direct_underclear_no_error(self): try: util.direct_underclear(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_global_irradiance_clear_no_error(self): try: util.global_irradiance_clear(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_global_irradiance_overcast_no_error(self): try: util.global_irradiance_overcast(self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") def test_util_clear_index(self): try: ghi_data = np.asarray([0, 0]) # Don't know what ghi_data is supposed to be util.clear_index(ghi_data, self.lat, self.lon, self.aware) except NoTimeZoneInfoError: self.fail("""'NoTimeZoneInfoError' should not be raised \ as 'datetime' object is tz-aware.""") ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/test/test_hour_angle.py0000644000000000000240000000447000000000000016473 0ustar00rootstaff''' Created on Aug 13, 2015 @author: rene ''' import unittest import datetime from pysolar.solar import * from pysolar.solartime import * class Test(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def testHourAngle(self): ''' Example 1.6.1 from Book "Solar Engineering of Thermal Processes by Duffie and Beckman, fourth edition, Wiley 2013" hour angle should be -22.5. (-22.5 % 360.0 = 337.5) ''' tz = datetime.timezone(datetime.timedelta(hours=-6)) when = datetime.datetime(2008, 2, 13, 10, 42, tzinfo=tz) latitude_deg = 43.076342 longitude_deg = -89.384448 ''' Hour angle from get_hour_angle ''' ha = get_hour_angle(when, longitude_deg) '''Hour angle as in pysolar.solar.get_altitude''' # time-dependent calculations jd = get_julian_solar_day(when) jde = get_julian_ephemeris_day(when) jce = get_julian_ephemeris_century(jde) jme = get_julian_ephemeris_millennium(jce) geocentric_latitude = get_geocentric_latitude(jme) geocentric_longitude = get_geocentric_longitude(jme) sun_earth_distance = get_sun_earth_distance(jme) aberration_correction = get_aberration_correction(sun_earth_distance) nutation = get_nutation(jce) apparent_sidereal_time = get_apparent_sidereal_time(jd, jme, nutation) true_ecliptic_obliquity = get_true_ecliptic_obliquity(jme, nutation) # calculations dependent on location and time apparent_sun_longitude = get_apparent_sun_longitude( geocentric_longitude, nutation, aberration_correction) geocentric_sun_right_ascension = get_geocentric_sun_right_ascension( apparent_sun_longitude, true_ecliptic_obliquity, geocentric_latitude) local_hour_angle = get_local_hour_angle( apparent_sidereal_time, longitude_deg, geocentric_sun_right_ascension) reference_ha = -22.5 % 360.0 self.assertAlmostEqual(local_hour_angle % 360.0, ha % 360.0, places=0) self.assertAlmostEqual(reference_ha % 360.0, ha % 360.0, places=0) if __name__ == "__main__": #import sys;sys.argv = ['', 'Test.testName'] unittest.main() ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/test/test_numpy.py0000644000000000000240000000604500000000000015520 0ustar00rootstaffimport pysolar from pysolar import radiation, solar from pysolar import numeric as math import datetime import numpy as np from nose.tools import raises, assert_equal @raises(TypeError) def test_fail_with_math(): pysolar.use_math() lat = np.array([45., 40.]) lon = np.array([3., 4.]) time = datetime.datetime(2018, 5, 8, 12, 0, 0, tzinfo=datetime.timezone.utc) solar.get_altitude(lat, lon, time) def test_scalar_with_math(): pysolar.use_math() lat = 45. lon = 3. time = datetime.datetime(2018, 5, 8, 12, 0, 0, tzinfo=datetime.timezone.utc) print(solar.get_altitude(lat, lon, time)) print(solar.get_azimuth(lat, lon, time)) def test_scalar_with_numpy(): pysolar.use_numpy() lat = 50.63 lon = 3.05 time = datetime.datetime(2018, 5, 8, 12, 0, 0, tzinfo=datetime.timezone.utc) print(solar.get_altitude(lat, lon, time)) print(solar.get_azimuth(lat, lon, time)) def test_with_fixed_time(): """ get_altitude and get_azimuth, with scalar date """ pysolar.use_numpy() lat = np.array([45., 40.]) lon = np.array([3., 4.]) time = datetime.datetime(2018, 5, 8, 12, 0, 0, tzinfo=datetime.timezone.utc) print(solar.get_altitude(lat, lon, time)) print(solar.get_azimuth(lat, lon, time)) print(solar.get_altitude_fast(lat, lon, time)) print(solar.get_azimuth_fast(lat, lon, time)) def test_with_fixed_position(): """ get_altitude and get_azimuth, with scalar position """ pysolar.use_numpy() lat = 50. lon = 3. time = np.array(['2018-05-08T12:15:00', '2018-05-08T15:00:00'], dtype='datetime64') print(solar.get_altitude_fast(lat, lon, time)) print(solar.get_azimuth_fast(lat, lon, time)) def test_datetime_operations(): d0 = datetime.datetime(2018,5,8,12,0,0) d1 = np.array(d0) assert_equal(math.tm_yday_math(d0), math.tm_yday_numpy(d1)) assert_equal(math.tm_hour_math(d0), math.tm_hour_numpy(d1)) assert_equal(math.tm_min_math(d0), math.tm_min_numpy(d1)) def test_numpy(): """ get_altitude and get_azimuth, with lat, lon and date arrays """ pysolar.use_numpy() lat = np.array([45., 40.]) lon = np.array([3., 4.]) time = np.array(['2018-05-08T12:15:00', '2018-05-08T15:00:00'], dtype='datetime64') print(solar.get_altitude_fast(lat, lon, time)) print(solar.get_azimuth_fast(lat, lon, time)) def test_numpy_radiation(): """ get_radiation_direct with lat, lon, and date as arrays """ pysolar.use_numpy() lat = np.array([45., 40., 40.]) lon = np.array([3., 4., 3.]) time = np.array([ '2018-05-08T12:15:00', '2018-05-08T15:00:00', '2018-05-08T03:00:00', ], dtype='datetime64') altitude = solar.get_altitude_fast(lat, lon, time) rad_results = radiation.get_radiation_direct(time, altitude) assert rad_results[2] == 0 print(rad_results) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1735949444.0 pysolar-0.13/test/test_solar.py0000755000000000000240000002513100000000000015470 0ustar00rootstaff#!/usr/bin/python3 # Library for calculating location of the sun # Copyright Brandon Stafford # # This file is part of Pysolar. # # Pysolar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Pysolar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with Pysolar. If not, see . from pysolar import \ solar, \ constants, \ solartime as stime, \ elevation import datetime import unittest class TestSolar(unittest.TestCase): def setUp(self): self.d = datetime.datetime(2003, 10, 17, 19, 30, 30, tzinfo = datetime.timezone.utc) # only works with Python 3 self.d += datetime.timedelta(seconds = stime.get_delta_t(self.d) - stime.tt_offset - stime.get_leap_seconds(self.d)) # Reda & Andreas say that this time is in "Local Standard Time", which they # define as 7 hours behind UT (not UTC). Hence the adjustment to convert UT # to UTC. self.longitude = -105.1786 self.latitude = 39.742476 self.pressure = 82000.0 # pascals self.elevation = 1830.14 # meters self.temperature = 11.0 + constants.celsius_offset # kelvin self.slope = 30.0 # degrees self.slope_orientation = -10.0 # degrees east from south self.jd = stime.get_julian_solar_day(self.d) self.jc = stime.get_julian_century(self.jd) self.jde = stime.get_julian_ephemeris_day(self.d) self.jce = stime.get_julian_ephemeris_century(self.jde) self.jme = stime.get_julian_ephemeris_millennium(self.jce) self.geocentric_longitude = solar.get_geocentric_longitude(self.jme) self.geocentric_latitude = solar.get_geocentric_latitude(self.jme) self.nutation = solar.get_nutation(self.jce) self.sun_earth_distance = solar.get_sun_earth_distance(self.jme) self.true_ecliptic_obliquity = solar.get_true_ecliptic_obliquity(self.jme, self.nutation) self.aberration_correction = solar.get_aberration_correction(self.sun_earth_distance) self.apparent_sun_longitude = solar.get_apparent_sun_longitude(self.geocentric_longitude, self.nutation, self.aberration_correction) self.apparent_sidereal_time = solar.get_apparent_sidereal_time(self.jd, self.jme, self.nutation) self.geocentric_sun_right_ascension = solar.get_geocentric_sun_right_ascension(self.apparent_sun_longitude, self.true_ecliptic_obliquity, self.geocentric_latitude) self.geocentric_sun_declination = solar.get_geocentric_sun_declination(self.apparent_sun_longitude, self.true_ecliptic_obliquity, self.geocentric_latitude) self.local_hour_angle = solar.get_local_hour_angle(318.5119, self.longitude, self.geocentric_sun_right_ascension) #self.apparent_sidereal_time only correct to 5 sig figs, so override self.equatorial_horizontal_parallax = solar.get_equatorial_horizontal_parallax(self.sun_earth_distance) self.projected_radial_distance = solar.get_projected_radial_distance(self.elevation, self.latitude) self.projected_axial_distance = solar.get_projected_axial_distance(self.elevation, self.latitude) self.topocentric_sun_right_ascension = solar.get_topocentric_sun_right_ascension(self.projected_radial_distance, self.equatorial_horizontal_parallax, self.local_hour_angle, self.apparent_sun_longitude, self.true_ecliptic_obliquity, self.geocentric_latitude) self.parallax_sun_right_ascension = solar.get_parallax_sun_right_ascension(self.projected_radial_distance, self.equatorial_horizontal_parallax, self.local_hour_angle, self.geocentric_sun_declination) self.topocentric_sun_declination = solar.get_topocentric_sun_declination(self.geocentric_sun_declination, self.projected_axial_distance, self.equatorial_horizontal_parallax, self.parallax_sun_right_ascension, self.local_hour_angle) self.topocentric_local_hour_angle = solar.get_topocentric_local_hour_angle(self.local_hour_angle, self.parallax_sun_right_ascension) self.topocentric_zenith_angle = solar.get_topocentric_zenith_angle(self.latitude, self.topocentric_sun_declination, self.topocentric_local_hour_angle, self.pressure, self.temperature) self.topocentric_azimuth_angle = solar.get_topocentric_azimuth_angle(self.topocentric_local_hour_angle, self.latitude, self.topocentric_sun_declination) self.incidence_angle = solar.get_incidence_angle(self.topocentric_zenith_angle, self.slope, self.slope_orientation, self.topocentric_azimuth_angle) self.pressure_with_elevation = elevation.get_pressure_with_elevation(1567.7) self.temperature_with_elevation = elevation.get_temperature_with_elevation(1567.7) def test_get_julian_solar_day(self): self.assertAlmostEqual(2452930.312847, self.jd, 6) # value from Reda and Andreas (2005) def test_get_julian_ephemeris_day(self): self.assertAlmostEqual(2452930.3136, self.jde, 4) # value not validated def test_get_julian_century(self): self.assertAlmostEqual(0.03792779869191517, self.jc, 12) # value not validated def test_get_julian_ephemeris_millennium(self): self.assertAlmostEqual(0.0037927819143886397, self.jme, 12) # value not validated def test_get_geocentric_longitude(self): # self.assertAlmostEqual(204.0182635175, self.geocentric_longitude, 10) # value from Reda and Andreas (2005) self.assertAlmostEqual(204.0182635175, self.geocentric_longitude, 4) # above fails with more accurate Julian Ephemeris correction def test_get_geocentric_latitude(self): # self.assertAlmostEqual(0.0001011219, self.geocentric_latitude, 9) # value from Reda and Andreas (2005) self.assertAlmostEqual(0.0001011219, self.geocentric_latitude, 8) # above fails with more accurate Julian Ephemeris correction def test_get_nutation(self): self.assertAlmostEqual(0.00166657, self.nutation['obliquity'], 8) # value from Reda and Andreas (2005) self.assertAlmostEqual(-0.00399840, self.nutation['longitude'], 8) # value from Reda and Andreas (2005) def test_get_sun_earth_distance(self): self.assertAlmostEqual(0.9965421031, self.sun_earth_distance, 6) # value from Reda and Andreas (2005) def test_get_true_ecliptic_obliquity(self): self.assertAlmostEqual(23.440465, self.true_ecliptic_obliquity, 6) # value from Reda and Andreas (2005) def test_get_aberration_correction(self): self.assertAlmostEqual(-0.005711359, self.aberration_correction, 9) # value not validated def test_get_apparent_sun_longitude(self): # self.assertAlmostEqual(204.0085537528, self.apparent_sun_longitude, 10) # value from Reda and Andreas (2005) self.assertAlmostEqual(204.0085537528, self.apparent_sun_longitude, 4) # above fails with more accurate Julian Ephemeris correction def test_get_apparent_sidereal_time(self): self.assertAlmostEqual(318.5119, self.apparent_sidereal_time, 2) # value derived from Reda and Andreas (2005) def test_get_geocentric_sun_right_ascension(self): self.assertAlmostEqual(202.22741, self.geocentric_sun_right_ascension, 4) # value from Reda and Andreas (2005) def test_get_geocentric_sun_declination(self): self.assertAlmostEqual(-9.31434, self.geocentric_sun_declination, 4) # value from Reda and Andreas (2005) def test_get_local_hour_angle(self): self.assertAlmostEqual(11.105900, self.local_hour_angle, 4) # value from Reda and Andreas (2005) def test_get_projected_radial_distance(self): self.assertAlmostEqual(0.7702006, self.projected_radial_distance, 6) # value not validated def test_get_topocentric_sun_right_ascension(self): self.assertAlmostEqual(202.22741, self.topocentric_sun_right_ascension, 3) # value from Reda and Andreas (2005) def test_get_parallax_sun_right_ascension(self): self.assertAlmostEqual(-0.0003659912761437859, self.parallax_sun_right_ascension, 12) # value not validated def test_get_topocentric_sun_declination(self): self.assertAlmostEqual(-9.316179, self.topocentric_sun_declination, 3) # value from Reda and Andreas (2005) def test_get_topocentric_local_hour_angle(self): self.assertAlmostEqual(11.10629, self.topocentric_local_hour_angle, 4) # value from Reda and Andreas (2005) def test_get_topocentric_zenith_angle(self): self.assertAlmostEqual(50.11162, self.topocentric_zenith_angle, 3) # value from Reda and Andreas (2005) def test_get_topocentric_azimuth_angle(self): # self.assertAlmostEqual(194.34024, self.topocentric_azimuth_angle, 5) # value from Reda and Andreas (2005) self.assertAlmostEqual(194.34024, self.topocentric_azimuth_angle, 4) # above fails with more accurate Julian Ephemeris correction def test_get_incidence_angle(self): self.assertAlmostEqual(25.18700, self.incidence_angle, 3) # value from Reda and Andreas (2005) def testPressureWithElevation(self): self.assertAlmostEqual(83855.90228, self.pressure_with_elevation, 4) def testTemperatureWithElevation(self): self.assertAlmostEqual(277.9600, self.temperature_with_elevation, 4) class TestApi(unittest.TestCase): test_when = datetime.datetime(2016, 12, 19, 23, 0, 0, tzinfo=datetime.timezone.utc) def testGetPosition(self): az, al = solar.get_position(59.6365662,12.5350953, TestApi.test_when) self.assertAlmostEqual(az, 357.1431414) self.assertAlmostEqual(al, -53.7672217) az, al = solar.get_position(-43, 172, TestApi.test_when) self.assertAlmostEqual(az, 50.50035708) self.assertAlmostEqual(al, 63.0922036) # From Greenwich az, al = solar.get_position(51.4826, 0, TestApi.test_when) self.assertAlmostEqual(az, 333.04037976) self.assertAlmostEqual(al, -59.83724345) def testGetAltitude(self): al = solar.get_altitude(-43, 172, TestApi.test_when) self.assertAlmostEqual(al, 63.0922036) def testGetAzimuth(self): az = solar.get_azimuth(-43, 172, TestApi.test_when) self.assertAlmostEqual(az, 50.50035708) def testGetAltitudeFast(self): # location is in NZ, use relevant timezone day = datetime.datetime( 2016, 12, 19, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=12))) for hour in range(7, 19): when = day + datetime.timedelta(hours=hour) al = solar.get_altitude_fast(-43, 172, when) al_expected = solar.get_altitude(-43, 172, when) self.assertAlmostEqual(al, al_expected, delta=1) def testGetAzimuthFast(self): day = datetime.datetime( 2016, 12, 19, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=12))) for hour in range(7, 19): when = day + datetime.timedelta(hours=hour) az = solar.get_azimuth_fast(-43, 172, when) az_expected = solar.get_azimuth(-43, 172, when) self.assertAlmostEqual(az, az_expected, delta=1.5) if __name__ == "__main__": unittest.main(verbosity=2)