Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

Log in or register to post/reply in the forum.

Sun Shine Hours calculation

rgupta65 Nov 30, 2011 03:02 AM

Hi ,
Pl help me to calculate the daily sunshine hours..

I having CR1000 datalogger and CMP11 pyranometer sensor to measure Global horizontal irradiance, installed at my solar PV site.

and i want to calculate Sunshine hours (Sun rise to sun set) on daily basis.

Pl rply asap.

Thanks in advance

R Gupta

kirving Nov 30, 2011 07:22 PM

I have an aproximate algorithm that could maybe be used for this, and could post it or a link to it if interested. We use it to calculate the angle of the sun above/below the horizon, to avoid taking CC640 pictures when it's probably too dark out.

If you google or otherwise investigate the 'equation of time' you'll find it to be quite complex; our simplified version ignores some details, but is probably within a few minutes of the correct times.

rgupta65 Dec 1, 2011 03:59 AM

Hi, it would be great if you can send me your Algorithm.

kirving Dec 1, 2011 04:20 PM

The algorithm for CR1000 or similar loggers uses several constants, public or dim variables, aliases, and a subroutine. It assumes the logger is set to local standard time, with no daylight-savings adjustment. The calc_SunElev() procedure puts its result in the sun_elevation variable, after calculating the local 'solar hour' and the Earth's declination (tilt) based on the day of year.

    const LATITUDE = 68.80
    const LONGITUDE = -151.54
    const TZ_HOURS = -9

  public solar_hour
  public declination
  public sun_elevation

  dim Time(9)
  '' note: RealTime(Time()) must be run to update alias values!
  '' Time(): 1:year, 2:month, 3:day, 4:hour, 5:minute, 6:second,
  ''         7:microsecond, 8:day_of_week, 9:day_of_year
  alias Time(4) = thisHour
  alias Time(5) = thisMinute
  alias Time(9) = thisDayOfYear

  sub calc_SunElev()
    '' update Time aliases thisHour, thisMinute, thisDayOfYear:
    '' algorithm assumes logger clock on standard time, not DST
    '' calculate solar hour, correcting for timezone and longitude:
    solar_hour = thisHour + (thisMinute/60) + (LONGITUDE/15 - TZ_HOURS)
    '' calculate declination, the earth's tilt
    declination = -23.45 * cos( TWOPI * (thisDayOfYear + 10) / 365 )
    '' calculate "elevation", the angle of the sun above the horizon:
    sun_elevation = (LATITUDE - 90) * cos(solar_hour * 15 * TWOPI / 360) + declination
  endsub ' calc_SunElev

I hope this might be helpful.

rainyday Aug 27, 2015 04:05 PM

The algorithm above looks useful, but I wonder if anyone has gone further?

For public information purposes (rather than for being able to define results to the nth degree of accuracy), I'd like to be able to calculate, log and disseminate daily sunshine hours. The ideas developed at http://www.elyweather.co.uk/Sunshine1.aspx look very useful.

The code in the lines above from 2011 allow sun elevation to be calculated. I have a CR1000 data logger with a SP1110 pyranometer (i.e. installed horizontally and therefore recording total intensity not direct irradiance).

I'd like to be able to use the above code (or something similar) to calculate the theoretical max for every 15 mins, taking into account the horizontal installation, then compare with the average solar radiation in W/m2 for each 15-min period. I would have thought that a % threshold could be used, e.g. if measured >=50% or 60% of theoretical, then accumulate 0.25 hrs of sunshine for that logging interval; find total at end of day; log and report accordingly.

Would anyone have some program code which they could share for such purposes?

GaryTRoberts Aug 27, 2015 06:35 PM

You can also do it using the SolarPosition() instruction:

Const ALTITUDE = 1488
Const LATITUDE = 41.76590632436906
Const LONGITUDE = 111.85510575771332
Const TIME_ZONE = 7

Public panel_temperature_c
Public voltage_information(4)
Public is_daylight As Boolean
Public solar_information(5)
Alias solar_information(1) = solar_azimuth
Alias solar_information(2) = sun_elevation
Alias solar_information(3) = hour_angle
Alias solar_information(4) = declination
Alias solar_information(5) = air_mass
Public time(9)
Alias time(1) = year
Alias time(2) = month
Alias time(3) = day_of_month
Alias time(4) = hour
Alias time(5) = minute
Alias time(6) = second
Alias time(7) = micro_second
Alias time(8) = day_of_week
Alias time(9) = day_of_year

'Main Program
Scan(1, Sec, 0, 0)
PanelTemp(panel_temperature_c , _60Hz)

SolarPosition(solar_information(), time(), (-TIME_ZONE * 3600), LATITUDE, LONGITUDE, ALTITUDE, -1, panel_temperature_c)

If(sun_elevation > 0) Then
is_daylight = True
is_daylight = False

You might have to adjust the threshold of the of the is_daylight If statement to account for mountains, etc. But it should work as well as the methods mentioned above. This would help determine if a image should be taken or not. It won't give the total sun hours for the day.

* Last updated by: GaryTRoberts on 8/27/2015 @ 12:44 PM *

aps Aug 28, 2015 08:57 AM

As mentioned above the meteorological definition of "sunshine hours" is not simply the time from sunrise to sunset. Strictly speaking it is the total time that the direct beam component of the sun exceeds 120 W/m^2.

Estimating this from a pyranometer will always be an approximation as it does not measure the direct beam component alone, but the WMO does accept an approximation technique (similar to that mentioned by "rainday") for reported data.

The broad principles our discussed in one of our old technical notes and also here:


That manufacturer will provide you with their own version of the algorithm and I believe have an implementation in CRBasic (there is a link in their tech note to request a copy).

It is likely their program can be simplified using the newish solar position instruction mentioned above, which is a step towards working out the maximum solar radiation you might expect.

rainyday Aug 30, 2015 09:06 PM

Many thanks for the code.

It is worth noting that this code will require OS 28.02, which is a recent release at this time.

Kind regards.

maurixio Nov 5, 2015 03:46 PM

kirving : what value has the variable TWOPI in your code?

kirving Nov 5, 2015 04:22 PM

I overlooked that in the listing above, but it's just a constant with the value of 2*pi, roughly 6.28..., but it can be defined as:

const TWOPI = 4 * atn2(1,0)

* Last updated by: kirving on 11/5/2015 @ 9:23 AM *

Jawaid84 Nov 9, 2021 04:46 PM

can anyone tell me how to save sun rise and sun set time in daily record table

 i am using CS301 Pyranometer along woth CR1000x Datalogger

there is no option for this shortcut software

Log in or register to post/reply in the forum.