How to use the salem.lazy_property function in salem

To help you get started, we’ve selected a few salem 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 fmaussion / salem / salem / gis.py View on Github external
    @lazy_property
    def extent(self):
        """[left, right, bottom, top] boundaries of the grid in the grid's
        projection.

        The boundaries are the pixels leftmost, rightmost, lowermost and
        uppermost corners, meaning that they are independent from the grid's
        representation.
        """

        x = np.array([0, self.nx]) * self.dx + self.corner_grid.x0
        ypoint = [0, self.ny] if self.origin == 'lower-left' else [self.ny, 0]
        y = np.array(ypoint) * self.dy + self.corner_grid.y0

        return [x[0], x[1], y[0], y[1]]
github fmaussion / salem / salem / datasets.py View on Github external
    @lazy_property
    def _img(self):
        """Download the image."""
        if self.use_cache:
            return utils.joblib_read_img_url(self.googleurl.generate_url())
        else:
            from matplotlib.image import imread
            fd = urlopen(self.googleurl.generate_url())
            return imread(io.BytesIO(fd.read()))
github fmaussion / salem / salem / gis.py View on Github external
    @lazy_property
    def center_grid(self):
        """``salem.Grid`` instance representing the grid in center coordinates.
        """

        if self.pixel_ref == 'center':
            return self
        else:
            # shift the grid
            x0y0 = ((self.x0 + self.dx / 2.), (self.y0 + self.dy / 2.))
            args = dict(nxny=(self.nx, self.ny), dxdy=(self.dx, self.dy),
                        proj=self.proj, pixel_ref='center', x0y0=x0y0)
            return Grid(**args)
github fmaussion / salem / salem / gis.py View on Github external
    @lazy_property
    def ystagg_ll_coordinates(self):
        """Tuple of longitudes, latitudes of the Y staggered grid.

        (independent of the grid's cornered or centered representation.)
        """

        x, y = self.ystagg_xy_coordinates
        proj_out = check_crs('EPSG:4326')
        return transform_proj(self.proj, proj_out, x, y)
github fmaussion / salem / salem / gis.py View on Github external
    @lazy_property
    def pixcorner_ll_coordinates(self):
        """Tuple of longitudes, latitudes (dims: ny+1, nx+1) at the corners of
        the grid.

        Useful for graphics.Map essentially

        (independant of the grid's cornered or centered representation.)
        """

        x = self.corner_grid.x0 + np.arange(self.nx+1) * self.dx
        y = self.corner_grid.y0 + np.arange(self.ny+1) * self.dy
        x, y = np.meshgrid(x, y)
        proj_out = check_crs('EPSG:4326')
        return transform_proj(self.proj, proj_out, x, y)
github fmaussion / salem / salem / gis.py View on Github external
    @lazy_property
    def corner_grid(self):
        """``salem.Grid`` instance representing the grid in corner coordinates.
        """

        if self.pixel_ref == 'corner':
            return self
        else:
            # shift the grid
            x0y0 = ((self.x0 - self.dx / 2.), (self.y0 - self.dy / 2.))
            args = dict(nxny=(self.nx, self.ny), dxdy=(self.dx, self.dy),
                        proj=self.proj, pixel_ref='corner', x0y0=x0y0)
            return Grid(**args)
github fmaussion / salem / salem / gis.py View on Github external
    @lazy_property
    def xstagg_ll_coordinates(self):
        """Tuple of longitudes, latitudes of the X staggered grid.

        (independent of the grid's cornered or centered representation.)
        """

        x, y = self.xstagg_xy_coordinates
        proj_out = check_crs('EPSG:4326')
        return transform_proj(self.proj, proj_out, x, y)
github fmaussion / salem / salem / wrftools.py View on Github external
    @lazy_property
    def _factor(self):
        # easy would be to have time step as variable
        vars = self.nc.variables
        if 'XTIME' in vars:
            dt_minutes = vars['XTIME'][1] - vars['XTIME'][0]
        elif 'xtime' in vars:
            dt_minutes = vars['xtime'][1] - vars['xtime'][0]
        elif 'time' in vars:
            var = vars['time']
            nctime = num2date(var[0:2], var.units)
            dt_minutes = np.asarray(nctime[1] - nctime[0])
            dt_minutes = dt_minutes.astype('timedelta64[m]').astype(float)
        else:
            # ok, parse time
            time = []
            stimes = vars['Times'][0:2]
github fmaussion / salem / salem / gis.py View on Github external
    @lazy_property
    def ll_coordinates(self):
        """Tuple of longitudes, latitudes of the grid points.

        (dependent of the grid's cornered or centered representation.)
        """

        x, y = self.xy_coordinates
        proj_out = check_crs('EPSG:4326')

        return transform_proj(self.proj, proj_out, x, y)