예제 #1
0
 def getSitesContext(self):
     """
     :returns:
        SitesContext object.
     """
     sctx = SitesContext()
     sctx.vs30 = self._Vs30.getData().copy()
     sctx.z1pt0 = self._Z1Pt0
     sctx.z2pt5 = self._Z2Pt5
     sctx.backarc = self._backarc  # zoneconfig might have this info
     if self._vs30measured_grid is None:  # If we don't know, then use false
         sctx.vs30measured = np.zeros_like(sctx.vs30, dtype=bool)
     else:
         sctx.vs30measured = self._vs30measured_grid
     sctx.lons = self._lons
     sctx.lats = self._lats
     return sctx
예제 #2
0
파일: sites.py 프로젝트: jnf0910/shakemap
 def getSitesContext(self):
     """
     :returns:
        SitesContext object.
     """
     sctx = SitesContext()
     sctx.vs30 = self._Vs30.getData().copy()
     sctx.z1pt0 = self._Z1Pt0
     sctx.z2pt5 = self._Z2Pt5
     sctx.backarc = self._backarc  # zoneconfig might have this info
     if self._vs30measured_grid is None:  # If we don't know, then use false
         sctx.vs30measured = np.zeros_like(
             sctx.vs30, dtype=bool)
     else:
         sctx.vs30measured = self._vs30measured_grid
     sctx.lons = self._lons
     sctx.lats = self._lats
     return sctx
예제 #3
0
    def sampleFromSites(self, lats, lons, vs30measured_grid=None):
        """
        Create a SitesContext object by sampling the current Sites object.

        :param lats:
            Sequence of latitudes.
        :param lons:
            Sequence of longitudes.
        :param vs30measured_grid:
            Sequence of booleans of the same shape as lats/lons indicating 
            whether the vs30 values are measured or inferred.
        :returns:
            SitesContext object where data are sampled from the current Sites
            object.
        :raises ShakeMapException:
             When lat/lon input sequences do not share dimensionality.
        """
        lats = np.array(lats)
        lons = np.array(lons)
        latshape = lats.shape
        lonshape = lons.shape
        if latshape != lonshape:
            msg = 'Input lat/lon arrays must have the same dimensions'
            raise ShakeMapException(msg)

        site = SitesContext()
        # use default vs30 if outside grid
        site.vs30 = self._Vs30.getValue(lats, lons, default=self._defaultVs30)
        site.lats = lats
        site.lons = lons
        site.z1pt0 = _calculate_z1p0(site.vs30)
        site.z2pt5 = _calculate_z2p5(site.z1pt0)
        if vs30measured_grid is None:  # If we don't know, then use false
            site.vs30measured = np.zeros_like(lons, dtype=bool)
        else:
            site.vs30measured = vs30measured_grid
        site.backarc = self._backarc

        return site
예제 #4
0
파일: sites.py 프로젝트: jnf0910/shakemap
    def sampleFromSites(self, lats, lons, vs30measured_grid=None):
        """
        Create a SitesContext object by sampling the current Sites object.

        :param lats:
            Sequence of latitudes.
        :param lons:
            Sequence of longitudes.
        :param vs30measured_grid:
            Sequence of booleans of the same shape as lats/lons indicating 
            whether the vs30 values are measured or inferred.
        :returns:
            SitesContext object where data are sampled from the current Sites
            object.
        :raises ShakeMapException:
             When lat/lon input sequences do not share dimensionality.
        """
        lats = np.array(lats)
        lons = np.array(lons)
        latshape = lats.shape
        lonshape = lons.shape
        if latshape != lonshape:
            msg = 'Input lat/lon arrays must have the same dimensions'
            raise ShakeMapException(msg)

        site = SitesContext()
        # use default vs30 if outside grid
        site.vs30 = self._Vs30.getValue(lats, lons, default=self._defaultVs30)
        site.lats = lats
        site.lons = lons
        site.z1pt0 = _calculate_z1p0(site.vs30)
        site.z2pt5 = _calculate_z2p5(site.z1pt0)
        if vs30measured_grid is None:  # If we don't know, then use false
            site.vs30measured = np.zeros_like(lons, dtype=bool)
        else:
            site.vs30measured = vs30measured_grid
        site.backarc = self._backarc

        return site
예제 #5
0
    def getSitesContext(self, lldict=None, rock_vs30=None):
        """
        Create a SitesContext object by sampling the current Sites object.

        Args:
            lldict: Either

                - None, in which case the SitesContext for the complete Sites
                  grid is returned, or
                - A location dictionary (elements are 'lats' and 'lons' and
                  each is a numpy array). Each element must have the same
                  shape. In this case the SitesContext for these locaitons is
                  returned.

            rock_vs30: Either

                - None, in which case the SitesContext will reflect the Vs30
                  grid in the Sites instance, or
                - A float for the rock Vs30 value, in which case the
                  SitesContext will be constructed for this constant Vs30
                  value.

        Returns:
            SitesContext object.

        Raises:
            ShakeLibException: When lat/lon input sequences do not share
                dimensionality.

        """  # noqa

        sctx = SitesContext()

        if lldict is not None:
            lats = lldict['lats']
            lons = lldict['lons']
            latshape = lats.shape
            lonshape = lons.shape
            if latshape != lonshape:
                msg = 'Input lat/lon arrays must have the same dimensions'
                raise ShakeLibException(msg)

            if rock_vs30 is not None:
                tmp = self._Vs30.getValue(
                    lats, lons, default=self._defaultVs30)
                sctx.vs30 = np.ones_like(tmp) * rock_vs30
            else:
                sctx.vs30 = self._Vs30.getValue(
                    lats, lons, default=self._defaultVs30)
            sctx.lats = lats
            sctx.lons = lons
        else:
            sctx.lats = self._lats.copy()
            sctx.lons = self._lons.copy()
            if rock_vs30 is not None:
                sctx.vs30 = np.full_like(self._Vs30.getData(), rock_vs30)
            else:
                sctx.vs30 = self._Vs30.getData().copy()

        sctx = Sites._addDepthParameters(sctx)

        # For ShakeMap purposes, vs30 measured is always Fales
        sctx.vs30measured = np.zeros_like(sctx.vs30, dtype=bool)

        # Backarc should be a numpy array
        if lldict is not None:
            backarcgrid = Grid2D(self._backarc, self._Vs30.getGeoDict())
            sctx.backarc = backarcgrid.getValue(lats, lons, default=False)
        else:
            sctx.backarc = self._backarc.copy()

        return sctx
예제 #6
0
파일: sites.py 프로젝트: ynthdhj/shakemap
    def getSitesContext(self, lldict=None, rock_vs30=None):
        """
        Create a SitesContext object by sampling the current Sites object.

        Args:
            lldict: Either

                - None, in which case the SitesContext for the complete Sites
                  grid is returned, or
                - A location dictionary (elements are 'lats' and 'lons' and
                  each is a numpy array). Each element must have the same
                  shape. In this case the SitesContext for these locaitons is
                  returned.

            rock_vs30: Either

                - None, in which case the SitesContext will reflect the Vs30
                  grid in the Sites instance, or
                - A float for the rock Vs30 value, in which case the
                  SitesContext will be constructed for this constant Vs30
                  value.

        Returns:
            SitesContext object.

        Raises:
            ShakeLibException: When lat/lon input sequences do not share
                dimensionality.

        """  # noqa

        sctx = SitesContext()

        if lldict is not None:
            lats = lldict['lats']
            lons = lldict['lons']
            latshape = lats.shape
            lonshape = lons.shape
            if latshape != lonshape:
                msg = 'Input lat/lon arrays must have the same dimensions'
                raise ShakeLibException(msg)

            if rock_vs30 is not None:
                tmp = self._Vs30.getValue(
                    lats, lons, default=self._defaultVs30)
                sctx.vs30 = np.ones_like(tmp) * rock_vs30
            else:
                sctx.vs30 = self._Vs30.getValue(
                    lats, lons, default=self._defaultVs30)
            sctx.lats = lats
            sctx.lons = lons
        else:
            sctx.lats = self._lats.copy()
            sctx.lons = self._lons.copy()
            if rock_vs30 is not None:
                sctx.vs30 = np.ones_like(self._Vs30.getData()) * rock_vs30
            else:
                sctx.vs30 = self._Vs30.getData().copy()

        sctx = Sites._addDepthParameters(sctx)

        # For ShakeMap purposes, vs30 measured is always Fales
        sctx.vs30measured = np.zeros_like(sctx.vs30, dtype=bool)

        # Backarc should be a numpy array
        if lldict is not None:
            backarcgrid = Grid2D(self._backarc, self._Vs30.getGeoDict())
            sctx.backarc = backarcgrid.getValue(lats, lons, default=False)
        else:
            sctx.backarc = self._backarc.copy()

        return sctx