Skip to content

Commit c2ee663

Browse files
committed
add icosphere
1 parent 00afc37 commit c2ee663

File tree

4 files changed

+69
-103
lines changed

4 files changed

+69
-103
lines changed

example/notebooks/Sky luminance.ipynb

Lines changed: 40 additions & 66 deletions
Large diffs are not rendered by default.

src/alinea/astk/colormap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ def jet_colors(values, minval=None, maxval=None):
113113
if maxval is None:
114114
maxval = max(values)
115115
cmap = ColorMap()
116-
return map(lambda x: cmap(x, minval, maxval, 250., 20.), values)
116+
return list(map(lambda x: cmap(x, minval, maxval, 250., 20.), values))

src/alinea/astk/icosphere.py

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import math
2727
import numpy
2828
import warnings
29+
from alinea.astk.colormap import jet_colors
2930

3031
display_enable = True
3132
try:
@@ -34,6 +35,18 @@
3435
warnings.warn('PlantGL not installed: display is not enable!')
3536
display_enable = False
3637

38+
def sky_turtle(turtle_mesh, sky_sources):
39+
vertices, faces = turtle_mesh
40+
colors = jet_colors((lum for _,_,lum in sky_sources))
41+
scene = pgl.Scene()
42+
for i, face in enumerate(faces):
43+
vtx = [vertices[v] for v in face]
44+
idx = range(len(face))
45+
mat = pgl.Material(pgl.Color3(*colors[i]))
46+
shape = pgl.Shape(pgl.FaceSet(pointList=vtx, indexList=[idx]), mat)
47+
scene += shape
48+
return scene
49+
3750

3851
def display(vertices, faces, colors=None, view=True):
3952
"""3D display of a polyhedron with PlantGL
@@ -90,7 +103,7 @@ def spherical(points):
90103
x, y, z = zip(*proj)
91104
theta = numpy.arccos(z)
92105
phi = numpy.arctan2(y, x)
93-
return zip(theta, phi)
106+
return list(zip(theta, phi))
94107

95108

96109
def rotation_matrix(axis, theta):
@@ -396,21 +409,20 @@ def refine(level=0):
396409
return iter_triangle, iter_star
397410

398411

399-
def turtle_dome(refine_level=3):
412+
def turtle_mesh(min_faces=46):
400413
"""Generate faces of a dual icosphere polyhedron mapping the Z+ hemisphere
401414
402415
Args:
403-
refine_level (int): the level of refinement of the dual icosphere. By
404-
default 46 polygons are returned (refine_level=3).
405-
406-
For information, here are the number of faces obtained for the first ten
407-
refinement level: 0: 6, 1: 16, 2: 26, 3: 46, 4: 66, 5: 91, 6: 136,
408-
7: 196, 8: 251, 9: 341, 10: 406
416+
min_faces (int) : the minimal number of faces for the polyhedron
417+
The number of faces obtained for the first ten polyhedrons are:
418+
6, 16, 26, 46, 66, 91, 136, 196, 251, 341, 406
409419
410420
Returns:
411421
a list of vertices and a list of faces
412422
"""
413-
423+
sectors = [ 1, 6, 16, 26, 46, 66, 91, 136, 196, 251, 341, 406]
424+
refines = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
425+
refine_level = refines[numpy.searchsorted(sectors, min(max(sectors), min_faces))]
414426
vertices, faces = dual(*icosphere(*refine(refine_level)))
415427
# filter faces with centroids below horizontal plane
416428
centers = [centroid([vertices[p] for p in face]) for face in faces]
@@ -431,37 +443,17 @@ def turtle_dome(refine_level=3):
431443
return new_vertices, new_faces
432444

433445

434-
def turtle_sectors(nb_sectors=46):
435-
"""Generate faces of a dual icosphere polyhedron mapping the Z+ hemisphere
436-
437-
Args:
438-
refine_level (int): the level of refinement of the dual icosphere. By
439-
default 46 polygons are returned (refine_level=3).
440-
441-
For information, here are the number of faces obtained for the first ten
442-
refinement level: 0: 6, 1: 16, 2: 26, 3: 46, 4: 66, 5: 91, 6: 136,
443-
7: 196, 8: 251, 9: 341, 10: 406
444-
445-
Returns:
446-
a list of vertices and a list of faces
446+
def spherical_face_centers(turtle_mesh):
447+
""" Spherical coordinates of turtle mesh faces centers
447448
"""
448-
sectors = [ 1, 6, 16, 26, 46, 66, 91, 136, 196, 251, 341, 406]
449-
refines = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
450-
s2r = dict(zip(sectors,refines))
451-
452-
if nb_sectors not in s2r:
453-
print('Use a value of nb_sectors in the set ', sectors)
454-
455-
refine_level = s2r[nb_sectors]
456-
457-
vertices, faces = turtle_dome(refine_level)
449+
vertices, faces = turtle_mesh
458450

459451
# Compute the centroid of each face
460452
centers = [centroid([vertices[p] for p in face]) for face in faces]
461453

462-
elevations, azimuths = spherical(centers)
454+
zeniths, azimuths = zip(*spherical(centers))
463455

464-
return elevations, azimuths
456+
return list(zip(90-numpy.degrees(zeniths), numpy.degrees(azimuths)))
465457

466458

467459
def sample_faces(vertices, faces, iter=2, spheric=False):

src/alinea/astk/meteorology/sun_position.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def sun_position(dates=None, daydate=_day, latitude=_latitude,
6161
"""
6262

6363
if dates is None:
64-
dates = pandas.date_range(daydate, periods=24, freq='H')
64+
dates = pandas.date_range(daydate, periods=24, freq='h')
6565

6666
if dates.tz is None:
6767
times = dates.tz_localize(timezone)
@@ -93,7 +93,7 @@ def sun_extraradiation(dates=None, daydate=_day, solar_constant=1366.1,
9393
dates is not already localised.
9494
"""
9595
if dates is None:
96-
dates = pandas.date_range(daydate, periods=24, freq='H')
96+
dates = pandas.date_range(daydate, periods=24, freq='h')
9797

9898
if dates.tz is None:
9999
times = dates.tz_localize(timezone)

0 commit comments

Comments
 (0)