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 get_border_lonlats(geo_def): """Get the border x- and y-coordinates.""" if geo_def.proj_dict['proj'] == 'geos': lon_b, lat_b = get_geostationary_bounding_box(geo_def, 3600) else: lons, lats = geo_def.get_boundary_lonlats() lon_b = np.concatenate((lons.side1, lons.side2, lons.side3, lons.side4)) lat_b = np.concatenate((lats.side1, lats.side2, lats.side3, lats.side4)) return lon_b, lat_b
def boundary_for_area(area_def: PRGeometry) -> Boundary: """Create Boundary object representing the provided area.""" if not FIXED_PR and isinstance(area_def, SwathDefinition): # TODO: Persist lon/lats if requested lons, lats = area_def.get_bbox_lonlats() freq = int(area_def.shape[0] * 0.05) if hasattr(lons[0], "compute") and da is not None: lons, lats = da.compute(lons, lats) lons = [lon_side.astype(np.float64) for lon_side in lons] lats = [lat_side.astype(np.float64) for lat_side in lats] adp = AreaBoundary(*zip(lons, lats)) adp.decimate(freq) elif getattr(area_def, "is_geostationary", False): adp = Boundary( *get_geostationary_bounding_box(area_def, nb_points=100)) else: freq_fraction = 0.05 if isinstance(area_def, SwathDefinition) else 0.30 adp = AreaDefBoundary(area_def, frequency=int(area_def.shape[0] * freq_fraction)) return adp
def _get_sunlight_coverage(area_def, start_time, sza_threshold=90, overpass=None): """Get the sunlight coverage of *area_def* at *start_time* as a value between 0 and 1.""" if isinstance(area_def, SwathDefinition): lons, lats = area_def.get_lonlats() freq = int(lons.shape[-1] * 0.10) lons, lats = da.compute(lons[::freq, ::freq], lats[::freq, ::freq]) adp = Boundary(lons.ravel(), lats.ravel()).contour_poly elif area_def.is_geostationary: 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)) < sza_threshold: return 1.0 else: return 0.0 else: daylight_area = daylight.area() total_area = adp.area() return daylight_area / total_area