コード例 #1
0
ファイル: utils.py プロジェクト: loreclem/pyresample
def _parse_yaml_area_file(area_file_name, *regions):
    """Parse area information from a yaml area file.

    Args:
        area_file_name: filename, file-like object, yaml string, or list of
                        these.

    The result of loading multiple area files is the combination of all
    the files, using the first file as the "base", replacing things after
    that.
    """
    from pyresample.geometry import DynamicAreaDefinition
    area_dict = _read_yaml_area_file_content(area_file_name)
    area_list = regions or area_dict.keys()

    res = []

    for area_name in area_list:
        try:
            params = area_dict[area_name]
        except KeyError:
            raise AreaNotFound('Area "{0}" not found in file "{1}"'.format(
                area_name, area_file_name))
        description = params['description']
        projection = params['projection']
        optimize_projection = params.get('optimize_projection', False)
        try:
            xsize = params['shape']['width']
            ysize = params['shape']['height']
        except KeyError:
            xsize, ysize = None, None
        try:
            area_extent = (params['area_extent']['lower_left_xy'] +
                           params['area_extent']['upper_right_xy'])
        except KeyError:
            area_extent = None
        try:
            projection['units'] = params['area_extent']['units']
        except KeyError:
            pass
        try:
            rotation = params['rotation']
        except KeyError:
            rotation = 0
        area = DynamicAreaDefinition(area_name, description, projection, xsize,
                                     ysize, area_extent, optimize_projection,
                                     rotation)
        try:
            area = area.freeze()
        except (TypeError, AttributeError):
            pass

        res.append(area)
    return res
コード例 #2
0
def _make_area(area_id, description, proj_id, proj_dict, shape, area_extent,
               **kwargs):
    """Handles the creation of an area definition for create_area_def."""
    from pyresample.geometry import AreaDefinition
    from pyresample.geometry import DynamicAreaDefinition
    # Remove arguments that are only for DynamicAreaDefinition.
    optimize_projection = kwargs.pop('optimize_projection', False)
    resolution = kwargs.pop('resolution', None)
    # If enough data is provided, create an AreaDefinition. If only shape or area_extent are found, make a
    # DynamicAreaDefinition. If not enough information was provided, raise a ValueError.
    height, width = (None, None)
    if shape is not None:
        height, width = shape
    if None not in (area_extent, shape):
        return AreaDefinition(area_id, description, proj_id, proj_dict, width,
                              height, area_extent, **kwargs)

    return DynamicAreaDefinition(area_id=area_id,
                                 description=description,
                                 projection=proj_dict,
                                 width=width,
                                 height=height,
                                 area_extent=area_extent,
                                 rotation=kwargs.get('rotation'),
                                 resolution=resolution,
                                 optimize_projection=optimize_projection)
コード例 #3
0
ファイル: utils.py プロジェクト: wroberts4/Homework
def _make_area(area_id, name, proj_id, proj_dict, shape, area_extent,
               **kwargs):
    """Handles the actual creation of an area definition for from_params."""
    from pyresample.geometry import AreaDefinition
    from pyresample.geometry import DynamicAreaDefinition

    # Used for area definition to prevent indexing None.
    x_size, y_size = None, None
    if shape is not None:
        x_size, y_size = int(round(shape[1])), int(round(shape[0]))
        # Make sure shape is an integer.
        if not np.allclose([y_size, x_size], shape):
            raise ValueError(
                'Shape found or provided must be an integer: {0}'.format(
                    shape))
    # If enough data is provided, create an area_definition. If only shape or area_extent are found, make a
    # DynamicAreaDefinition. If not enough information was provided, raise a ValueError.
    if None not in (area_extent, shape):
        return AreaDefinition(area_id, name, proj_id, proj_dict, x_size,
                              y_size, area_extent, **kwargs)
    elif area_extent is not None or shape is not None:
        return DynamicAreaDefinition(area_id=area_id,
                                     description=name,
                                     proj_dict=proj_dict,
                                     x_size=x_size,
                                     y_size=y_size,
                                     area_extent=area_extent,
                                     rotation=kwargs.get('rotation'),
                                     optimize_projection=kwargs.get(
                                         'optimize_projection', False))
    raise ValueError(
        'Not enough information provided to create an area definition')
コード例 #4
0
ファイル: containers.py プロジェクト: wroberts4/polar2grid
 def to_satpy_area(self):
     from pyresample.geometry import AreaDefinition, DynamicAreaDefinition
     if self.is_static:
         xy_ll = self.ll_extent
         xy_ur = self.ur_extent
         return AreaDefinition(
             self["grid_name"],
             self["grid_name"],
             self["grid_name"],
             self.proj4_dict,
             self["width"],
             self["height"],
             area_extent=xy_ll + xy_ur,
         )
     return DynamicAreaDefinition(
         self["grid_name"],
         self["grid_name"],
         self.proj4_dict,
         self["width"],
         self["height"],
     )
コード例 #5
0
ファイル: containers.py プロジェクト: djhoese/polar2grid
    def to_satpy_area(self):
        from pyresample.geometry import AreaDefinition, DynamicAreaDefinition

        if self.is_static:
            xy_ll = self.ll_extent
            xy_ur = self.ur_extent
            return AreaDefinition(
                self["grid_name"],
                self["grid_name"],
                self["grid_name"],
                self.proj4_dict,
                self["width"],
                self["height"],
                area_extent=xy_ll + xy_ur,
            )
        kwargs = {}
        if self["cell_width"] is not None:
            kwargs["resolution"] = (self["cell_width"], self["cell_height"])
        return DynamicAreaDefinition(self["grid_name"], self["grid_name"],
                                     self.proj4_dict, self["width"],
                                     self["height"], **kwargs)