def test_sources(): light = light_sources(90, 0, 1) irr, (x,y,z) = light[0] numpy.testing.assert_array_equal([irr, x, y, z], [1, 0, 0, -1]) light = light_sources(1, 0, 1) irr, (x,y,z) = light[0] numpy.testing.assert_allclose([x, y, z], [-0.99, 0, -0.01], atol=0.01) # # Cardinal positions of elevation=45 deg sources when x+ = North # azimuth of input is from north, positive clockwise north, south, east, west = light_sources([45] * 4, [0, 180, 90, -90], [1] * 4) # North source has a X- look_at vector, South a X+ numpy.testing.assert_allclose(north[1], [-0.71, 0, -0.71], atol=0.01) numpy.testing.assert_allclose(south[1], [0.71, 0, -0.71], atol=0.01) # East source has Y+ look_at vector, west source a Y- numpy.testing.assert_allclose(east[1], [0, 0.71, -0.71], atol=0.01) numpy.testing.assert_allclose(west[1], [0, -0.71, -0.71], atol=0.01) # # Cardinal positions of elevation=45 deg sources when y+ = North # azimuth of input is from north, positive clockwise # orientation is from X+ to north, positive clockwise north, south, east, west = light_sources([45] * 4, [0, 180, 90, -90], [1] * 4, orientation=-90) # North source has a Y- look at vector, South a Y+ numpy.testing.assert_allclose(north[1], [0, -0.71, -0.71], atol=0.01) numpy.testing.assert_allclose(south[1], [0, 0.71, -0.71], atol=0.01) # East source has X- look_at vector, west source a X+ numpy.testing.assert_allclose(east[1], [-0.71, 0, -0.71], atol=0.01) numpy.testing.assert_allclose(west[1], [0.71, 0, -0.71], atol=0.01)
def illuminate(g, isolated=True, density=9, clear_sky=False, daydate=_daydate, longitude=_longitude, latitude=_latitude, altitude=_altitude, timezone=_timezone): """ Illuminate a plant Args: isolated : is the plant isolated or within a canopy ? clear_sky: use clear_sky (homogeneous sky is used otherwise) irradiance: (float) sum of horizontal irradiance of all sources. If None diffuse horizontal clear_sky irradiance are used for clear_sky type and 20% attenuated clear_sky global horizontal irradiances are used for soc and uoc types. dates: A pandas datetime index (as generated by pandas.date_range). If None, hourly values for daydate are used. daydate: (str) yyyy-mm-dd (not used if dates is not None). longitude: (float) in degrees latitude: (float) in degrees altitude: (float) in meter timezone:(str) the time zone (not used if dates are already localised) Returns: elevation (degrees), azimuth (degrees, from North positive clockwise), and horizontal irradiance of sources """ if not clear_sky: light = light_sources(*sky_sources()) else: sun, sky = sun_sky_sources(daydate=daydate, longitude=longitude, latitude=latitude, altitude=altitude, timezone=timezone, normalisation=1) light = light_sources(*sun) + light_sources(*sky) inter_row = 80 inter_plant = 1. / density / (inter_row / 100.) * 100 pattern = (-0.5 * inter_row, -0.5 * inter_plant, 0.5 * inter_row, 0.5 * inter_plant) cs = CaribuScene(g, light=light, pattern=pattern, scene_unit='cm') raw, agg = cs.run(direct=True, simplify=True, infinite=not isolated) return cs, raw, agg
def illuminate(scene, sky=None, sun=None, pattern=None): if sky is None and sun is None: sky = sky_sources() light = [] if sky is not None: light += light_sources(*sky) if sun is not None: light += light_sources(*sun) infinite = False if pattern is not None: infinite = True cs = CaribuScene(scene, light=light, scene_unit='cm', pattern=pattern) raw, agg = cs.run(direct=True, simplify=True, infinite=infinite) return cs, raw, agg
def get_turtle_light(current_PAR, sky_type='soc', turtle_sectors=46, add_sun=False, curent_date=None, longitude=_longitude, latitude=_latitude, altitude=_altitude, timezone=_timezone): """Sun + sky source using the 46 sector turtle sky discretisation Args: current_date: a naive datetime object sky_type:(str) type of sky luminance model. One of : 'soc' (standard overcast sky), 'uoc' (uniform overcast sky) 'clear_sky' (standard clear sky) turtle_sectors : (int) the minimal number of sectors to be used for discretising the sky hemisphere. Turtle discretisation will be one of 1, 6, 16 or 46 sectors longitude: (float) in degrees latitude: (float) in degrees altitude: (float) in meter timezone:(str) the time zone """ daydate = '2000-06-21' if curent_date is not None: daydate = curent_date.strftime('%Y-%m-%d') sun = [(), (), ()] f_sun = 0 if add_sun: sky_irr = sky_irradiances(daydate=daydate, longitude=longitude, latitude=latitude, altitude=altitude, timezone=timezone) f_sun = sun_fraction(sky_irr) sun = sun_sources(irradiance=f_sun * current_PAR, daydate=daydate, latitude=latitude, longitude=longitude, altitude=altitude, timezone=timezone) sky = sky_sources(sky_type=sky_type, irradiance=current_PAR * (1 - f_sun), turtle_sectors=turtle_sectors, daydate=daydate, longitude=longitude, latitude=latitude, altitude=altitude, timezone=timezone) return light_sources(*sky) + light_sources(*sun)
def illuminate(scene, light=None, pattern=None, scene_unit='cm', north=0): """Illuminate scene Args: scene: the scene (plantgl) light: lights. If None a vertical light is used pattern: the toric canopy pattern. If None, no pattern is used scene_unit: string indicating length unit in the scene (eg 'cm') north: the angle (deg, positive clockwise) from X+ to North (default: 0) Returns: """ infinite = False if pattern is not None: infinite = True if light is not None: light = light_sources(*light, orientation=north) cs = CaribuScene(scene, light=light, scene_unit=scene_unit, pattern=pattern) raw, agg = cs.run(direct=True, simplify=True, infinite=infinite) return cs, raw['Ei'], pandas.DataFrame(agg)
def illuminate(g, isolated=True): light = light_sources(*sky_sources()) # density =9 pl/m2 density = 9 inter_row = 80 inter_plant = 1. / density / (inter_row / 100.) * 100 pattern = (-0.5 * inter_row, -0.5 * inter_plant, 0.5 * inter_row, 0.5 * inter_plant) cs = CaribuScene(g, light=light, pattern=pattern, scene_unit='cm') raw, agg = cs.run(direct=True, simplify=True, infinite=not isolated) return cs, raw, agg