0

I need to find the hourly sun angle (angle at which the sun strikes the Earth) for a particular position (latitude, longitude) for a given day in Belgium. I used sunAngle() from "oce" package for 31 July 2020. t is the hourly vector starting a 00:00:00 of that day until 00:00:00 of August 1.

lat = 50.879700 long = 4.700712 t0 <- as.POSIXct(paste("2020-07-31", "00:00:00"), tz="") t <- seq(from=t0, to=t0+86400, by="60 min") a <- sunAngle(t, lat, long) 

The result is:

a[["altitude"]] [1] -60.225122 -49.174321 -36.305296 -22.665730 -8.661004 5.521092 19.768803 [8] 33.983602 48.017946 61.503752 72.978661 75.957727 66.875621 53.924237 [15] 40.050031 25.882692 11.628080 -2.604935 -16.717790 -30.567994 -43.875928 [22] -55.964635 -64.970966 -66.929191 -60.402859` 

However, this output can not be correct as it means that the sun rises at 4 am and sets at 5 pm, which is impossible for a summer day in Belgium.

Any idea of what is wrong?

1 Answer 1

1

sunAngle args are longitude, latitude:

Usage: sunAngle(t, longitude = 0, latitude = 0, useRefraction = FALSE) 

You called sunAngle(t, lat, long) which is the wrong way round, and R doesn't know what your variables are named, it matches them with the args of sunAngle by position.

Either name them, in which case you can do them any way round, or do them unnamed in the right order:

a <- data.frame(sunAngle(t, latitude=lat, longitude=long)) a <- data.frame(sunAngle(t, long, lat)) 

should work. I don't know personally know daylight hours in July in Belgium but this does return longer daylight hours (sunset ~19:30 UTC?)

1
  • Indeed, I inverted the latitude and longitude, by placing them in the right order it worked! tz = "" refers to the local timezone of your computer, as I am in Belgium it gives me the right output (sunset 22h) but tz ="CEST" should be used if the code is ran from another time zone. Thank you! Commented Dec 4, 2021 at 18:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.