def Ra(doy, lat): constant = (24 * 60.) / math.pi * 0.082 * invRelSolarDistance(doy) variable = (sunsetAngle(doy, lat) * pcr.scalar(pcr.sin(lat) * math.sin(solarDistance(doy))) + pcr.sin(sunsetAngle(doy, lat) * 180 / math.pi) * pcr.cos(lat) * math.cos(solarDistance(doy))) radiation = constant * variable return radiation * 0.408
def dayLength(doy,lat): """ daylength fraction of day """ lat = lat * pcr.scalar(math.pi) / 180.0 M_PI_2 = pcr.spatial(pcr.scalar(math.pi / 2.0)) dec = pcr.sin( (6.224111 + 0.017202 * doy) * 180. / math.pi) dec = pcr.scalar(0.39785 * pcr.sin ((4.868961 + .017203 * doy + 0.033446 * pcr.sin (dec* 180 / math.pi)) * 180 / math.pi)) dec = pcr.scalar(pcr.asin(dec)) lat = pcr.ifthenelse(pcr.abs(lat) > M_PI_2, (M_PI_2 - pcr.scalar(0.01)) * pcr.ifthenelse(lat > 0, pcr.scalar(1.0), pcr.scalar(-1.0)) ,lat ) arg = pcr.tan(dec ) * pcr.tan(lat * 180.0 / math.pi ) * -1.0 h = pcr.scalar( pcr.acos(arg ) ) h = h / 180. * math.pi h = pcr.ifthenelse(arg > 1.0, 0.0,h) # /* sun stays below horizon */ h = pcr.ifthenelse(arg < -1.0 ,math.pi,h) # /* sun stays above horizon */ return (h / math.pi)
def fractionXY(surface): #-returns the fraction of transport in the x- and y-directions # given a gradient in a surface aspect= pcr.aspect(surface) noAspect= pcr.nodirection(pcr.directional(aspect)) sinAspect= pcr.sin(aspect) cosAspect= pcr.cos(aspect) fracX= pcr.ifthenelse(noAspect,0.,sinAspect/(pcr.abs(sinAspect)+pcr.abs(cosAspect))) fracY= pcr.ifthenelse(noAspect,0.,cosAspect/(pcr.abs(sinAspect)+pcr.abs(cosAspect))) return fracX,fracY
def getArcDistancePCR(latA, lonA, latB, lonB, radius= 6371221.3): '''Computes the distance using PCRaster between two points, positioned by \ their geographic coordinates along the surface of a perfect sphere \ in units given by the radius used. Input variables include:\n - latA, latB: the latitude of the points considered in decimal degrees,\n - lonA, lonB: the longitude of the points considered in decimal degrees,\n - radius: the radius of the sphere in metres, set by default to \ that of Earth (6371221.3 m). ''' #-pad latitudes, longitudes #-convert all coordinates to radians pA= latA*deg2Rad; pB= latB*deg2Rad lA= lonA*deg2Rad; lB= lonB*deg2Rad dL= lB-lA; dP= pB-pA #-set arcDist default to zero and create mask of cells to be processed a= pcr.sin(0.5*dP)*pcr.sin(0.5*dP)+\ pcr.cos(pA)*pcr.cos(pB)*\ pcr.sin(0.5*dL)*pcr.sin(0.5*dL) arcDist= 2*pcr.scalar(pcr.atan(a**0.5/(1-a)**0.5)) arcDist*= radius #-return arcDist return arcDist