Skip to main content

python implementation of NOAA's Solar Position Calculators

Project description

Python implementation of NOAA’s Solar Position Calculators

NOAA has the calculation details at their website at Solar Calculation Details

pysunNOAA is based on the spreadsheet NOAA_Solar_Calculations_day.xls . All the calculation cells in row 2 of the spreadsheet are implemented in pysunNOAA. This is a work in progress. But it is fully usable at this point

Here is what it can do:

import datetime
from pysunnoaa import noaa

latitude = 40 # Latitude (+ to N)
longitude = -105 # Longitude (+ to E)
timezone = -6 # Time Zone (+ to E)
thedatetime = datetime.datetime(2010, 6, 21, 9, 54)

altitude, azimuth = noaa.sunposition(
latitude, longitude, timezone, thedatetime, atm_corr=True
)

print(f"{altitude=}, {azimuth=}")

>> altitude=47.36178497432497, azimuth=98.30691558695895

The above calculation is corrected for atmospheric diffraction. We can also do the calculation without the correction for atmospheric diffraction by setting atm_corr=False:

altitude, azimuth = noaa.sunposition(
    latitude, longitude, timezone, thedatetime, atm_corr=False
)
print(f"{altitude=}, {azimuth=}")

>> altitude=47.346932081680364, azimuth=98.30691558695895

Let us take a look at generating multiple sun positions for a time series. First we have to generate the time series:

thedates = noaa.datetimerange(
    datetime.datetime(2024, 6, 21, 10), # start
    datetime.datetime(2024, 6, 21, 11), # stop
    minutes=10 # step
) # The arguments are similar to python's range.
  # It returns a generator
for thedate in thedates:
    print(thedate)

2024-06-21 10:00:00
2024-06-21 10:10:00
2024-06-21 10:20:00
2024-06-21 10:30:00
2024-06-21 10:40:00
2024-06-21 10:50:00

So let us generate the sun positions for this time series:

thedates = noaa.datetimerange(
    datetime.datetime(2024, 6, 21, 10),
    datetime.datetime(2024, 6, 21, 11),
    minutes=10
)

positions = noaa.sunpositions(latitude, longitude, timezone, thedates, atm_corr=False)
for altitude, azimuth in positions:
    print(f"{altitude=}, {azimuth=}")

altitude=48.44972994443188, azimuth=99.43756106034147
altitude=50.33276597510335, azimuth=101.44934328356527
altitude=52.20206053830976, azimuth=103.57347468902549
altitude=54.05415607848319, azimuth=105.82830623146941
altitude=55.88497413825557, azimuth=108.23537482765607
altitude=57.689656999063025, azimuth=110.82001062044083

Let us print this again:

for altitude, azimuth in positions:
    print(f"{altitude=}, {azimuth=}")

WHAT !!! Why did it not print anything ??

Both noaa.datetimerange and noaa.sunpositions are generators. Once you loop through the generator, the values are exhausted (or emptied). To get the values again you will need to call the functions again:

thedates = noaa.datetimerange(
    datetime.datetime(2024, 6, 21, 10),
    datetime.datetime(2024, 6, 21, 11),
    minutes=10
)

positions = noaa.sunpositions(latitude, longitude, timezone, thedates, atm_corr=False)
for altitude, azimuth in positions:
    print(f"{altitude=}, {azimuth=}")

altitude=48.44972994443188, azimuth=99.43756106034147
altitude=50.33276597510335, azimuth=101.44934328356527
altitude=52.20206053830976, azimuth=103.57347468902549
altitude=54.05415607848319, azimuth=105.82830623146941
altitude=55.88497413825557, azimuth=108.23537482765607
altitude=57.689656999063025, azimuth=110.82001062044083

That’s all for now.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysunnoaa-0.1.7.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

pysunnoaa-0.1.7-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file pysunnoaa-0.1.7.tar.gz.

File metadata

  • Download URL: pysunnoaa-0.1.7.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.3 Darwin/23.2.0

File hashes

Hashes for pysunnoaa-0.1.7.tar.gz
Algorithm Hash digest
SHA256 90463e79b8c6aed817ed8535cf749743842dbcc4b20227c86d28b9f53f3ab427
MD5 ca4dc5b1596f02a93c5c6cfbd7fb6f0d
BLAKE2b-256 eedf5fb4e522f0ca85c2d9117e5859269c083a220d8bcfce0b0068cd71e6c4ef

See more details on using hashes here.

File details

Details for the file pysunnoaa-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: pysunnoaa-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.3 Darwin/23.2.0

File hashes

Hashes for pysunnoaa-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2aecbfc0a34dfd5a732eb121c3354a68004f00cb126fb744d1fdc277036c7cfb
MD5 08a9116ff5516850761c6a929abeb5d7
BLAKE2b-256 86f24d2bc696327a04643f430e540245a76bdfff5e9875d493ccb5a42c971c5b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page