def _get_sunlight_coverage(area_def, start_time, overpass=None): """Get the sunlight coverage of *area_def* at *start_time*.""" adp = AreaDefBoundary(area_def, frequency=100).contour_poly poly = get_twilight_poly(start_time) if overpass is not None: ovp = overpass.boundary.contour_poly cut_area_poly = adp.intersection(ovp) else: cut_area_poly = adp if cut_area_poly is None: if not adp._is_inside(ovp): return 0.0 else: # Should already have been taken care of in pyresample.spherical.intersection cut_area_poly = adp daylight = cut_area_poly.intersection(poly) if daylight is None: if sun_zenith_angle(start_time, *area_def.get_lonlat(0, 0)) < 90: return 1.0 else: return 0.0 else: daylight_area = daylight.area() total_area = adp.area() return daylight_area / total_area
def _get_sunlight_coverage(area_def, start_time, overpass=None): """Get the sunlight coverage of *area_def* at *start_time* as a value between 0 and 1.""" if area_def.proj_dict.get('proj') == 'geos': adp = Boundary(*get_geostationary_bounding_box( area_def, nb_points=100)).contour_poly else: adp = AreaDefBoundary(area_def, frequency=100).contour_poly poly = get_twilight_poly(start_time) if overpass is not None: ovp = overpass.boundary.contour_poly cut_area_poly = adp.intersection(ovp) else: cut_area_poly = adp if cut_area_poly is None: if not adp._is_inside(ovp): return 0.0 else: # Should already have been taken care of in pyresample.spherical.intersection cut_area_poly = adp daylight = cut_area_poly.intersection(poly) if daylight is None: if sun_zenith_angle(start_time, *area_def.get_lonlat(0, 0)) < 90: return 1.0 else: return 0.0 else: daylight_area = daylight.area() total_area = cut_area_poly.area() return daylight_area / total_area
def combine(p1, p2, area_of_interest): """Combine passes together. """ try: return combination[p1, p2] except KeyError: pass area = area_of_interest.poly.area() def pscore(poly, coeff=1): if poly is None: return 0 else: return poly.area() * coeff twi1 = get_twilight_poly(p1.uptime) twi2 = get_twilight_poly(p2.uptime) ip1, sip1 = p1.score.get(area_of_interest, (None, None)) if sip1 is None: ip1 = p1.boundary.contour_poly.intersection(area_of_interest.poly) # FIXME: ip1 or ip2 could be None if the pass is entirely inside the # area (or vice versa) if ip1 is None: return 0 ip1d = ip1.intersection(twi1) if ip1d is None: lon, lat = np.rad2deg(ip1.vertices[0, :]) theta = astronomy.cos_zen(p1.uptime, lon, lat) if np.sign(theta) > 0: ip1d = ip1 ip1n = None else: ip1n = ip1 else: twi1.invert() ip1n = ip1.intersection(twi1) twi1.invert() ns1 = pscore(ip1n, p1.satellite.score.night / area) ds1 = pscore(ip1d, p1.satellite.score.day / area) sip1 = ns1 + ds1 p1.score[area_of_interest] = (ip1, sip1) ip2, sip2 = p2.score.get(area_of_interest, (None, None)) if sip2 is None: ip2 = p2.boundary.contour_poly.intersection(area_of_interest.poly) if ip2 is None: return 0 ip2d = ip2.intersection(twi2) if ip2d is None: lon, lat = np.rad2deg(ip2.vertices[0, :]) theta = astronomy.cos_zen(p2.uptime, lon, lat) if np.sign(theta) > 0: ip2d = ip2 ip2n = None else: ip2n = ip2 else: twi2.invert() ip2n = ip2.intersection(twi2) twi2.invert() ns2 = pscore(ip2n, p2.satellite.score.night / area) ds2 = pscore(ip2d, p2.satellite.score.day / area) sip2 = ns2 + ds2 p2.score[area_of_interest] = (ip2, sip2) ip1p2 = ip1.intersection(ip2) if ip1p2 is None: sip1p2 = 0 else: ip1p2da = ip1p2.intersection(twi1) twi1.invert() ip1p2na = ip1p2.intersection(twi1) twi1.invert() ip1p2db = ip1p2.intersection(twi2) twi2.invert() ip1p2nb = ip1p2.intersection(twi2) twi2.invert() ns12a = pscore(ip1p2na, p1.satellite.score.night / area) ds12a = pscore(ip1p2da, p1.satellite.score.day / area) ns12b = pscore(ip1p2nb, p2.satellite.score.night / area) ds12b = pscore(ip1p2db, p2.satellite.score.day / area) sip1p2a = ns12a + ds12a sip1p2b = ns12b + ds12b sip1p2 = (sip1p2a + sip1p2b) / 2.0 if p2 > p1: tdiff = (p2.uptime - p1.uptime).seconds / 3600. else: tdiff = (p1.uptime - p2.uptime).seconds / 3600. res = fermia(tdiff) * (sip1 + sip2) - fermib(tdiff) * sip1p2 combination[p1, p2] = res return res
def combine(p1, p2, area_of_interest, scores): """Combine passes together. """ try: return combination[p1, p2] except KeyError: pass area = area_of_interest.poly.area() def pscore(poly, coeff=1): if poly is None: return 0 else: return poly.area() * coeff twi1 = get_twilight_poly(p1.uptime) twi2 = get_twilight_poly(p2.uptime) ip1, sip1 = p1.score.get(area_of_interest, (None, None)) if sip1 is None: ip1 = p1.boundary.contour_poly.intersection(area_of_interest.poly) # FIXME: ip1 or ip2 could be None if the pass is entirely inside the # area (or vice versa) if ip1 is None: return 0 ip1d = ip1.intersection(twi1) if ip1d is None: lon, lat = np.rad2deg(ip1.vertices[0, :]) theta = astronomy.cos_zen(p1.uptime, lon, lat) if np.sign(theta) > 0: ip1d = ip1 ip1n = None else: ip1n = ip1 else: twi1.invert() ip1n = ip1.intersection(twi1) twi1.invert() ns1 = pscore(ip1n, scores[p1.satellite][0] / area) ds1 = pscore(ip1d, scores[p1.satellite][1] / area) sip1 = ns1 + ds1 p1.score[area_of_interest] = (ip1, sip1) ip2, sip2 = p2.score.get(area_of_interest, (None, None)) if sip2 is None: ip2 = p2.boundary.contour_poly.intersection(area_of_interest.poly) if ip2 is None: return 0 ip2d = ip2.intersection(twi2) if ip2d is None: lon, lat = np.rad2deg(ip2.vertices[0, :]) theta = astronomy.cos_zen(p2.uptime, lon, lat) if np.sign(theta) > 0: ip2d = ip2 ip2n = None else: ip2n = ip2 else: twi2.invert() ip2n = ip2.intersection(twi2) twi2.invert() ns2 = pscore(ip2n, scores[p2.satellite][0] / area) ds2 = pscore(ip2d, scores[p2.satellite][1] / area) sip2 = ns2 + ds2 p2.score[area_of_interest] = (ip2, sip2) ip1p2 = ip1.intersection(ip2) if ip1p2 is None: sip1p2 = 0 else: ip1p2da = ip1p2.intersection(twi1) twi1.invert() ip1p2na = ip1p2.intersection(twi1) twi1.invert() ip1p2db = ip1p2.intersection(twi2) twi2.invert() ip1p2nb = ip1p2.intersection(twi2) twi2.invert() ns12a = pscore(ip1p2na, scores[p1.satellite][0] / area) ds12a = pscore(ip1p2da, scores[p1.satellite][1] / area) ns12b = pscore(ip1p2nb, scores[p2.satellite][0] / area) ds12b = pscore(ip1p2db, scores[p2.satellite][1] / area) sip1p2a = ns12a + ds12a sip1p2b = ns12b + ds12b sip1p2 = (sip1p2a + sip1p2b) / 2.0 if p2 > p1: tdiff = (p2.uptime - p1.uptime).seconds / 3600. else: tdiff = (p1.uptime - p2.uptime).seconds / 3600. res = fermia(tdiff) * (sip1 + sip2) - fermib(tdiff) * sip1p2 combination[p1, p2] = res return res