Beispiel #1
0
 def area_coverage(self, area_of_interest):
     """Get the ratio of coverage (between 0 and 1) of the pass with the area
     of interest.
     """
     try:
         area_boundary = area_of_interest.poly
     except AttributeError:
         area_boundary = AreaDefBoundary(area_of_interest,
                                         frequency=500)
         area_boundary = area_boundary.contour_poly
     inter = self.boundary.contour_poly.intersection(area_boundary)
     if inter is None:
         return 0
     return inter.area() / area_boundary.area()
Beispiel #2
0
def get_area_slices(data_area, area_to_cover):
    """Compute the slice to read from an *area* based on an *area_to_cover*."""

    if data_area.proj_dict['proj'] != 'geos':
        raise NotImplementedError('Only geos supported')

    # Intersection only required for two different projections
    if area_to_cover.proj_dict['proj'] == data_area.proj_dict['proj']:
        LOGGER.debug('Projections for data and slice areas are'
                     ' identical: {}'.format(area_to_cover.proj_dict['proj']))
        # Get xy coordinates
        llx, lly, urx, ury = area_to_cover.area_extent
        x, y = data_area.get_xy_from_proj_coords([llx, urx], [lly, ury])

        return slice(x[0], x[1] + 1), slice(y[1], y[0] + 1)

    from trollsched.boundary import AreaDefBoundary, Boundary

    data_boundary = Boundary(*get_geostationary_bounding_box(data_area))

    area_boundary = AreaDefBoundary(area_to_cover, 100)
    intersection = data_boundary.contour_poly.intersection(
        area_boundary.contour_poly)

    x, y = data_area.get_xy_from_lonlat(np.rad2deg(intersection.lon),
                                        np.rad2deg(intersection.lat))

    return slice(min(x), max(x) + 1), slice(min(y), max(y) + 1)
Beispiel #3
0
def get_area_slices(data_area, area_to_cover):
    """This function computes the slice to read from an *area* based on an
     *area_to_cover*.
     """
    from trollsched.boundary import AreaDefBoundary, Boundary

    if data_area.proj_dict['proj'] != 'geos':
        raise NotImplementedError('Only geos supported')

    data_boundary = Boundary(*get_geostationary_bounding_box(data_area))

    area_boundary = AreaDefBoundary(area_to_cover, 100)

    # from trollsched.satpass import Mapper
    # import matplotlib.pyplot as plt
    # with Mapper() as mapper:
    #     data_boundary.draw(mapper, 'g+-')
    #     area_boundary.draw(mapper, 'b+-')
    #     res = area_boundary.contour_poly.intersection(
    #         data_boundary.contour_poly)
    #     res.draw(mapper, 'r+-')
    # plt.show()

    intersection = data_boundary.contour_poly.intersection(
        area_boundary.contour_poly)

    x, y = data_area.get_xy_from_lonlat(np.rad2deg(intersection.lon),
                                        np.rad2deg(intersection.lat))

    return slice(min(x), max(x) + 1), slice(min(y), max(y) + 1)
Beispiel #4
0
def coverage(scene, area):

    shapes = set()
    for channel in scene.channels:
        if channel.is_loaded():
            shapes.add(channel.shape)

    coverages = []

    from trollsched.satpass import Mapper

    for shape in shapes:

        datas = []
        areas = []
        for channel in scene.channels:
            if channel.is_loaded() and channel.shape == shape:
                datas.append(channel.data)
                areas.append(channel.area)

        disk_polys = [
            poly.contour_poly
            for poly in get_polygons(datas, areas[0], frequency=100)
        ]

        area_poly = AreaDefBoundary(area, frequency=100).contour_poly

        inter_area = 0

        for poly in disk_polys:
            inter = poly.intersection(area_poly)
            if inter is not None:
                inter_area += inter.area()

        coverages.append(inter_area / area_poly.area())
    try:
        return min(*coverages)
    except TypeError:
        return coverages[0]
Beispiel #5
0
def coverage(scene, area):

    shapes = set()
    for channel in scene.channels:
        if channel.is_loaded():
            shapes.add(channel.shape)

    coverages = []

    from trollsched.satpass import Mapper

    for shape in shapes:

        datas = []
        areas = []
        for channel in scene.channels:
            if channel.is_loaded() and channel.shape == shape:
                datas.append(channel.data)
                areas.append(channel.area)

        disk_polys = [poly.contour_poly
                      for poly
                      in get_polygons(datas, areas[0], frequency=100)]

        area_poly = AreaDefBoundary(area, frequency=100).contour_poly

        inter_area = 0

        for poly in disk_polys:
            inter = poly.intersection(area_poly)
            if inter is not None:
                inter_area += inter.area()

        coverages.append(inter_area / area_poly.area())
    try:
        return min(*coverages)
    except TypeError:
        return coverages[0]
Beispiel #6
0
def get_area_slices(data_area, area_to_cover):
    """Compute the slice to read from an *area* based on an *area_to_cover*."""
    from trollsched.boundary import AreaDefBoundary, Boundary

    if data_area.proj_dict['proj'] != 'geos':
        raise NotImplementedError('Only geos supported')

    data_boundary = Boundary(*get_geostationary_bounding_box(data_area))

    area_boundary = AreaDefBoundary(area_to_cover, 100)

    intersection = data_boundary.contour_poly.intersection(
        area_boundary.contour_poly)

    x, y = data_area.get_xy_from_lonlat(np.rad2deg(intersection.lon),
                                        np.rad2deg(intersection.lat))

    return slice(min(x), max(x) + 1), slice(min(y), max(y) + 1)
Beispiel #7
0
    def check_file_covers_area(file_handler, check_area):
        """Checks if the file covers the current area.

        If the file doesn't provide any bounding box information or 'area'
        was not provided in `filter_parameters`, the check returns True.
        """
        from trollsched.boundary import AreaDefBoundary, Boundary
        from satpy.resample import get_area_def
        try:
            gbb = Boundary(*file_handler.get_bounding_box())
        except NotImplementedError:
            pass
        else:
            abb = AreaDefBoundary(get_area_def(check_area), frequency=1000)

            intersection = gbb.contour_poly.intersection(abb.contour_poly)
            if not intersection:
                return False
        return True
Beispiel #8
0
    def select_files(self, base_dir=None, filenames=None, sensor=None):
        res = super(FileYAMLReader, self).select_files(base_dir, filenames,
                                                       sensor)

        # Organize filenames in to file types and create file handlers
        remaining_filenames = set(self.info['filenames'])
        for filetype, filetype_info in self.config['file_types'].items():
            filetype_cls = filetype_info['file_reader']
            patterns = filetype_info['file_patterns']
            file_handlers = []
            for pattern in patterns:
                used_filenames = set()

                levels = len(pattern.split('/'))
                # correct separator if needed
                pattern = os.path.join(*pattern.split('/'))

                for filename in remaining_filenames:
                    filebase = os.path.join(
                        *filename.split(os.path.sep)[-levels:])

                    if fnmatch(filebase, globify(pattern)):
                        # we know how to use this file (even if we may not use
                        # it later)
                        used_filenames.add(filename)
                        filename_info = parse(pattern, filebase)
                        file_handler = filetype_cls(filename, filename_info,
                                                    filetype_info)

                        # Only add this file handler if it is within the time
                        # we want
                        if self._start_time and file_handler.start_time < self._start_time:
                            continue
                        if self._end_time and file_handler.end_time > self._end_time:
                            continue

                        if self._area:
                            from trollsched.boundary import AreaDefBoundary, Boundary
                            from satpy.resample import get_area_def
                            try:
                                gbb = Boundary(
                                    *file_handler.get_bounding_box())
                            except NotImplementedError:
                                pass
                            else:
                                abb = AreaDefBoundary(get_area_def(self._area),
                                                      frequency=1000)

                                intersection = gbb.contour_poly.intersection(
                                    abb.contour_poly)
                                if not intersection:
                                    continue

                        file_handlers.append(file_handler)
                remaining_filenames -= used_filenames
            # Only create an entry in the file handlers dictionary if
            # we have those files
            if file_handlers:
                # Sort the file handlers by start time
                file_handlers.sort(key=lambda fh: fh.start_time)
                self.file_handlers[filetype] = file_handlers

        return res