def _get_swathsegment(filelist, time_start, time_end=None, area=None): """ Return only the granule files for the time interval or area. """ if area is not None: from trollsched.spherical import SphPolygon from trollsched.boundary import AreaBoundary lons, lats = area.get_boundary_lonlats() area_boundary = AreaBoundary( (lons.side1, lats.side1), (lons.side2, lats.side2), (lons.side3, lats.side3), (lons.side4, lats.side4)) area_boundary.decimate(500) contour_poly = area_boundary.contour_poly segment_files = [] for filename in filelist: timetup = _get_times_from_npp(filename) # Search for multiple granules using an area if area is not None: md = NPPMetaData(filename) md.read() coords = np.vstack(md.get_ring_lonlats()) poly = SphPolygon(np.deg2rad(coords)) if poly.intersection(contour_poly) is not None: segment_files.append(filename) continue # Search for single granule using time start if time_end is None: if time_start >= timetup[0] and time_start <= timetup[1]: segment_files.append(filename) continue # search for multiple granules else: # check that granule start time is inside interval if timetup[0] >= time_start and timetup[0] <= time_end: segment_files.append(filename) continue # check that granule end time is inside interval if timetup[1] >= time_start and timetup[1] <= time_end: segment_files.append(filename) continue segment_files.sort() return segment_files