a #e@s"ddlZddZGdddZdS)NcCs<d}t|jdD]}|t|d|tjf7}qt|S)Nr.)rangeshapenpsquarenewaxissqrt)arrZsum_sqir /webodm/app/api/hillshade.py_vector_magnitude sr c@s6eZdZdddZeddZdd d Zdd d Zd S) LightSource;-cCs||_||_dS)N)azdegaltdeg)selfrrr r r __init__szLightSource.__init__cCsRtd|j}t|j}tt|t|t|t|t|gS)z3The unit vector direction towards the light source.Z)rradiansrrarraycossin)razaltr r r directions zLightSource.direction?c Csj| }t||||\}}t|jdt|}| |d<| |d<d|d<|t|}|||S)a; Calculates the illumination intensity for a surface using the defined azimuth and elevation for the light source. This computes the normal vectors for the surface, and then passes them on to `shade_normals` Parameters ---------- elevation : array-like A 2d array (or equivalent) of the height values used to generate an illumination map vert_exag : number, optional The amount to exaggerate the elevation values by when calculating illumination. This can be used either to correct for differences in units between the x-y coordinate system and the elevation coordinate system (e.g. decimal degrees vs. meters) or to exaggerate or de-emphasize topographic effects. dx : number, optional The x-spacing (columns) of the input *elevation* grid. dy : number, optional The y-spacing (rows) of the input *elevation* grid. fraction : number, optional Increases or decreases the contrast of the hillshade. Values greater than one will cause intermediate values to move closer to full illumination or shadow (and clipping any values that move beyond 0 or 1). Note that this is not visually or mathematically the same as vertical exaggeration. Returns ------- intensity : ndarray A 2d array of illumination values between 0-1, where 0 is completely in shadow and 1 is completely illuminated. )).r).rr).)rgradientemptyrviewtyper shade_normals) rZ elevation vert_exagdxdyfractionZe_dyZe_dxnormalr r r hillshade)s%   zLightSource.hillshadecCsX||j}||}}||9}||dkrF||8}|||}t|dd}|S)a Calculates the illumination intensity for the normal vectors of a surface using the defined azimuth and elevation for the light source. Imagine an artificial sun placed at infinity in some azimuth and elevation position illuminating our surface. The parts of the surface that slope toward the sun should brighten while those sides facing away should become darker. Parameters ---------- fraction : number, optional Increases or decreases the contrast of the hillshade. Values greater than one will cause intermediate values to move closer to full illumination or shadow (and clipping any values that move beyond 0 or 1). Note that this is not visually or mathematically the same as vertical exaggeration. Returns ------- intensity : ndarray A 2d array of illumination values between 0-1, where 0 is completely in shadow and 1 is completely illuminated. gư>rr)dotrminmaxrclip)rZnormalsr) intensityiminimaxr r r r%\s   zLightSource.shade_normalsN)rr)rrrr)r)__name__ __module__ __qualname__rpropertyrr+r%r r r r rs   3r)numpyrr rr r r r s