Pkg.add(url = "https://github.com/AleMorales/Sky.jl.git")
Sky.jl
The package Sky provides a function to calculate the solar radiation on a horizontal surface (for clear skies) as a function of latitude, day of year and time of the day and for different wavebands. In addition, it can generate light sources as required by the VPL package to simulate the light distribution in a 3D scene.
Installation
The package Sky is not in the Julia registry. To install it, you can use the following command:
Usage
Solar radiation
Use the clear_sky
function to calculate the solar radiation on a horizontal plane as a function of day of year, latitude (in radians) and the relative solar time of the day (f = 0
is sunrise, f = 1
is sunset). The function returns the total solar radiation in W/m² as well as direct and diffuse components. For example:
using Sky
= 52.0*π/180.0 # latitude in radians
lat = 182
DOY = 0.5 # solar noon
f = clear_sky(lat = lat, DOY = DOY, f = f) # W/m2 Ig, Idir, Idif
The values Ig
, Idir
and Idif
are the total, direct and diffuse solar radiation in W/m². The function waveband_conversion
can be used to convert these values to specfic wavebands (UV, PAR, NIR, blue, green or red) as well as converting from W/m² to umol/m²/s, assuming particular spectra for direct and diffuse solar radiation. For example:
= waveband_conversion(Itype = :direct, waveband = :PAR, mode = :flux)
f_PAR_dir = f_PAR_dir*Idir # PAR in umol/m²/s
Idir_PAR = waveband_conversion(Itype = :diffuse, waveband = :PAR, mode = :flux)
f_PAR_dif = f_PAR_dif*Idif # PAR in umol/m²/s Idif_PAR
Light sources for ray tracing
Once the direct and diffuse solar radiation in the relevant wavebands and units have been calculated, the function sky
can be used to generate the light sources required by VPL to simulate the light distribution in a 3D scene. For example, a simple horizontal tile (representing soil) in VPL may be created as follows:
using VPL
= Rectangle(length = 2.0, width = 1.0)
r rotatey!(r, -π/2) # To put it in the XY plane
translate!(r, Vec(0.0, 0.5, 0.0))
render(r)
A 3D scene requires adding optical properties (e.g., a black material property) and linking these to the mesh (for complicated scenes see VPL documentation for examples):
= [Black()]
materials = [1,1]
ids = RTScene(mesh = r, ids = ids, materials = materials) scene
If we want to compute the amount of solar radiation absorbed by this tile, we need to create a series of light sources. The function sky
can be used for that purpose:
= sky(scene,
sources = Idir_PAR, # Direct solar radiation from above
Idir = 1_000_000, # Number of rays for direct solar radiation
nrays_dir = Idif_PAR, # Diffuse solar radiation from above
Idif = 10_000_000, # Total number of rays for diffuse solar radiation
nrays_dif = StandardSky, # Angular distribution of solar radiation
sky_model = equal_solid_angles, # Discretization of the sky dome
dome_method = 9, # Number of discretization steps in the zenith angle
ntheta = 12) # Number of discretization steps in the azimuth angle nphi
The function takes the scene as input to ensure that light sources scale with the scene. Direct solar radiation is represented by a single directiona light source that will emmit a number of rays given by nrays_dir
. Diffuse solar radiation is represented by a hemispherical dome of directional light sources that will emmit a total of nrays_dif
rays. The angular distribution of the diffuse solar radiation and the discretization of the sky dome can be modified via dome_method, sky_model
, ntheta
and nphi
. See API documentation and VPL documentation for details.
Once the light sources are created, a ray tracing object can be generated combining all the elements above:
= RTSettings(parallel = true)
settings = RayTracer(scene, sources, settings = settings); rtobj
And the ray tracing can be performed by calling the trace!
function:
trace!(rtobj);
As expected, the amount of solar radiation absorbed by the tile equals the total in the scene (Ig
):
1].power[1]/area(r) ≈ Idir_PAR + Idif_PAR materials[
See VPL documentation for more details and tutorials on ray tracing simulations
Roadmap for future dfevelopment
The package is still under development. The following features are planned:
Calculate fraction of direct and diffuse radiation from measurements of actual solar radiation.
Calculate the solar radiation on a tilted surface.
Allow for a different orientation of the 3D scene from VPL.
More advanced algorithms for solar radiation and spectrum (e.g., SOLPOS, Bird).