Skip to content

A go package with info related to the sun movement

License

Notifications You must be signed in to change notification settings

KarlsMaranjs/gosolar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gosolar

A Go package with info related to the sun movement

Calculations made by this package are done using NOAA's methods. You can find more information on their website:

Solar calculations details

PDF version

This is still a WIP. Feel free to open PRs, fork and contribute

Usage

You should use the method Calculator() to return a SolarCalculation object that will provide access to all the other methods in the module.

package main

import (
	"fmt"
	"log"
	"github.com/karlsmaranjs/gosolar"
)

func main() {
	latitude := 35.0               // float Degrees
	longitude := -80.37486         // float Degrees
	date := "2023-06-16"           // string "YYYY-MM-DD"
	dayTime := 0.64                // float time of the day/24. 12:00:00 PM = 0.5
	timeZone := "America/New_York" // string Timezone ID

	sun, err := gosolar.Calculator(latitude, longitude, dayTime, timeZone, date)
	if err != nil {
		log.Fatalf("Error calculating sun info: %v", err)
	}
	// Returns the solar declination
	declination := sun.SolarDeclination()

	// Returns the incidence angle on a surface tilted 35 degrees from the ground and pointing south
	tiltedAngle := sun.IncidenceOnTiltedSurface(35, 180)

	fmt.Sprintf("declination: %f, Incidence on roof: %f", declination, tiltedAngle)
}

Please notice that Calculator() expects a valid string as a timeZone e.g. "America/New_York". This allows to determine the current offset for that timeZone including daylight saving time (DST). Calculator() then will determine the timezone offset using TimeZoneOffset() and use this value (float64) to initialize a SolarCalculation object.

Disclaimer

This library is not associated in any way, shape or form with NOAA

About

A go package with info related to the sun movement

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages