How to use the pyresample.geometry.AreaDefinition function in pyresample

To help you get started, we’ve selected a few pyresample examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytroll / satpy / test / test_pp_core.py View on Github external
def unpatch_geometry():
    """Unpatching the geometry module.
    """
    geometry.AreaDefinition = geometry.OldAreaDefinition
    delattr(geometry, "OldAreaDefinition")
    geometry.SwathDefinition = geometry.OldSwathDefinition
    delattr(geometry, "OldSwathDefinition")
github pytroll / satpy / mpop / test_projector.py View on Github external
def fake_parse_area_file(filename, area):
        """Fake function.
        """
        del filename
        if area == "raise" or not isinstance(area, str):
            raise utils.AreaNotFound("This area is not to be found")
        else:
            return [geometry.AreaDefinition(area)]
github pytroll / pyresample / test / test_image.py View on Github external
import numpy

from pyresample import image, geometry, grid, utils

def mask(f):
    f.mask = True
    return f

def tmp(f):
    f.tmp = True
    return f


class Test(unittest.TestCase):

    area_def = geometry.AreaDefinition('areaD', 'Europe (3km, HRV, VTC)', 'areaD', 
                                   {'a': '6378144.0',
                                    'b': '6356759.0',
                                    'lat_0': '50.00',
                                    'lat_ts': '50.00',
                                    'lon_0': '8.00',
                                    'proj': 'stere'}, 
                                    800,
                                    800,
                                    [-1370912.72,
                                     -909968.64000000001,
                                     1029087.28,
                                     1490031.3600000001])

    msg_area = geometry.AreaDefinition('msg_full', 'Full globe MSG image 0 degrees', 
                                   'msg_full',
                                   {'a': '6378169.0',
github pytroll / pyresample / pyresample / utils / rasterio.py View on Github external
a, b, c, d, e, f, _, _, _ = dataset.transform
    if not (b == d == 0):
        raise ValueError('Rotated rasters are not supported at this time.')

    if proj_dict is None:
        crs = dataset.crs
        if crs is not None:
            proj_dict = dataset.crs.to_dict()
        else:
            raise ValueError('The source raster is not gereferenced, please provide the value of proj_dict')

        if proj_id is None:
            proj_id = crs.wkt.split('"')[1]

    area_def = AreaDefinition(area_id, name, proj_id, proj_dict,
                              dataset.width, dataset.height, dataset.bounds)
    return area_def
github pytroll / satpy / satpy / satin / nc_reader.py View on Github external
y__ *= proj4_dict["h"]

                x_pixel_size = abs((np.diff(x__)).mean())
                y_pixel_size = abs((np.diff(y__)).mean())

                llx = x__[0] - x_pixel_size / 2.0
                lly = y__[-1] - y_pixel_size / 2.0
                urx = x__[-1] + x_pixel_size / 2.0
                ury = y__[0] + y_pixel_size / 2.0

                area_extent = (llx, lly, urx, ury)

                try:
                    # create the pyresample areadef
                    from pyresample.geometry import AreaDefinition
                    area = AreaDefinition("myareaid", "myareaname",
                                          "myprojid", proj4_dict,
                                          len(x__), len(y__),
                                          area_extent)

                except ImportError:
                    LOG.warning("Pyresample not found, "
                                "cannot load area descrition")
                processed |= set([area_var_name, x_name, y_name])
                LOG.debug("Grid mapping found and used.")
            except AttributeError:
                LOG.debug("No grid mapping found.")
                
            try:
                area_var = getattr(var,"coordinates")
                coordinates_vars = area_var.split(" ")
                lons = None
github pytroll / pyresample / pyresample / geometry.py View on Github external
if axis == 0:
        same_size = area1.width == area2.width
    else:
        raise NotImplementedError('Only vertical contatenation is supported.')
    if different_items or not same_size:
        raise IncompatibleAreas("Can't concatenate area definitions with "
                                "different projections: "
                                "{0} and {1}".format(area1, area2))

    if axis == 0:
        area_extent = combine_area_extents_vertical(area1, area2)
        x_size = int(area1.width)
        y_size = int(area1.height + area2.height)
    else:
        raise NotImplementedError('Only vertical contatenation is supported.')
    return AreaDefinition(area1.area_id, area1.description, area1.proj_id,
                          area1.proj_dict, x_size, y_size,
                          area_extent)
github pytroll / pyresample / pyresample / area_config.py View on Github external
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)
github jmozmoz / cloudmap / cloudmap / geo_jma.py View on Github external
"""

        from pyresample import image, geometry
        from .satellites import pc

        self.load_image()

        x_size = self.data.shape[1]
        y_size = self.data.shape[0]
        proj_dict = {'a': '6378137.0', 'b': '6356752.3',
                     'lon_0': self.longitude,
                     'h': '35785831.0', 'proj': 'geos'}
        self.extent = 5568742.4 * 0.964
        area_extent = (-self.extent, -self.extent,
                       self.extent, self.extent)
        area = geometry.AreaDefinition('geo', 'geostat', 'geo',
                                       proj_dict, x_size,
                                       y_size, area_extent)
        dataIC = image.ImageContainerQuick(self.data, area)

        dataResampled = dataIC.resample(pc(self.outwidth,
                                           self.outheight))
        dataResampledImage = self.rescale(dataResampled.image_data)
        dataResampledImage = self.polar_clouds(dataResampledImage)
        weight = self.get_weight()

        self.logger.debug("image max: %r" % np.max(dataResampledImage))

        result = np.array([dataResampledImage, weight])
        return result
github pytroll / pyresample / pyresample / geometry.py View on Github external
def copy(self, **override_kwargs):
        """Make a copy of the current area.

        This replaces the current values with anything in *override_kwargs*.
        """
        kwargs = {'area_id': self.area_id,
                  'description': self.description,
                  'proj_id': self.proj_id,
                  'projection': self.proj_dict,
                  'width': self.width,
                  'height': self.height,
                  'area_extent': self.area_extent,
                  'rotation': self.rotation}
        kwargs.update(override_kwargs)
        return AreaDefinition(**kwargs)
github pytroll / satpy / satpy / readers / scmi.py View on Github external
def get_area_def(self, key):
        """Get the area definition of the data at hand."""
        # FIXME: Can't we pass dataset info to the get_area_def?
        projection = self._get_cf_grid_mapping_var()
        proj_dict = self._get_proj_specific_params(projection)
        area_extent = self._calc_extents(proj_dict)
        area_name = '{}_{}'.format(self.sensor, proj_dict['proj'])
        return geometry.AreaDefinition(
            area_name,
            "SCMI file area",
            area_name,
            proj_dict,
            self.ncols,
            self.nlines,
            np.asarray(area_extent))