-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solar position calculation #1440
Comments
pvlib python's |
@wholmgren Awesome! It never occurred to me to search for this already existing, but I should have checked out pvlib. Thanks for pointing us that way. |
I'm assuming you're looking for things like the azimuth/elevation of the sun from a given Lat/Lon/elevation? If so, I'd highly recommend Skyfield /// add'l homepage It uses SPICE kernels from the JPL for ephem data - and it's super simple: import skyfield.api as sapi
#Read about BSP SPICE Kernels
#Automatically downloads from the JPL/NASA
#see: https://naif.jpl.nasa.gov/naif/tutorials.html
ephem = sapi.load('de421.bsp')
timescale = sapi.load.timescale()
tsnow = timescale.now()
earth = ephem['earth']
sun = ephem['sun']
waikiki=sapi.Topos(latitude_degrees=21.281194, longitude_degrees=-157.837911, elevation_m=1)
me_at_waikiki = earth + waikiki
#(yes, making a location on earth is really as easy as adding the earth to the Topos() object!)
sunpos = me_at_waikiki.at(tsnow).observe(sun)
sunpos.apparent().altaz()
#or any number of things... Check out the documentation -- it really explains it well! (There's also astropy and poliastro but they are probably a bit overboard for your application 😁) |
I stumbled upon this issue researching a matplotlib deprecation issue in the Meteogram example https://unidata.github.io/MetPy/latest/examples/meteogram_metpy.html The weewx weather station software uses the ephem Python package. Works great. |
I've used Astropy for this purpose in the past. |
|
FWIW we created a pvlib asv benchmarker in the time since this issue first came up. The solar position functions are relatively well covered, but pvlib does not wrap skyfield so we can't say anything about that comparison. One thing to keep in mind is that pvlib's functions, like many other libraries, are tailored to time series at a specific location. Occasionally people from the weather/climate community will come to pvlib and want to run simulations over grids. See this SO post for example. That means they have to hack at the lower level functions or they need to loop over each grid point. I think metpy could do a great service by reimplementing a good enough algorithm in a vectorized way that supported both spatial and temporal dimensions. A working definition of good enough: pvlib analytical, NAM/GFS algorithm, WRF ~3.5 algorithm < good enough <? NREL algorithm, WRF ~3.6+ < astropy, pyephem, skyfield (~approximate for WRF versions because I don't remember exactly when the more accurate solar position algorithm was copied from the WRF Solar fork to the main WRF code base)
|
+1 for paying attention to vectorizing as suggested by @wholmgren. The (related) example below, adapted from the
which gives Naively calculating the offset for 360 longitudes takes 12 seconds:
|
Including some kind of solar position calculator would be useful to a variety of calculations, including wet bulb globe temperate (WBGT #1374 ) and plotting theoretical solar radiation curves for meteograms (#208 ).
I'm dumping a bunch of open tabs I have from a brief investigation, where of course there are many ways to go about this:
The text was updated successfully, but these errors were encountered: