def create_directory(self):
        """ create the directory with gaps in it """
        # get a dataframe of the gaps
        if self.gaps is not None:
            df = pd.DataFrame(self.gaps, columns=["start", "end"])
            df["start"] = df["start"].apply(lambda x: x.timestamp)
            df["end"] = df["end"].apply(lambda x: x.timestamp)
        else:
            df = pd.DataFrame(columns=["start", "end"])

        assert self.starttime and self.endtime, "needs defined times"
        for t1, t2 in make_time_chunks(self.starttime, self.endtime,
                                       self.duration, self.overlap):
            # figure out of this time lies in a gap
            gap = df[~((df.start >= t2) | (df.end <= t1))]
            if not gap.empty:
                try:
                    st = self.get_gap_stream(t1, t2, gap)
                except ValueError:
                    continue
            else:
                st = self.create_stream(t1, t2)
            finame = str(t1).split(".")[0].replace(":", "-") + ".mseed"
            path = join(self.path, finame)
            st.write(path, "mseed")
示例#2
0
    def yield_waveforms(
        self,
        starttime: UTCDateTime,
        endtime: UTCDateTime,
        duration: float,
        overlap: float,
    ) -> Stream:
        """
        Yield streams from starttime to endtime of a specified duration.

        Parameters
        ----------
        starttime
            The starting time of the streams
        endtime
            The stopping time of the streams
        duration
            The duration of each waveforms between starttime and endtime
        overlap
            The overlap between streams added to the end of the waveforms

        Yields
        -------
        Stream
        """
        time_chunks = make_time_chunks(starttime, endtime, duration, overlap)
        for t1, t2 in time_chunks:
            yield self.get_waveforms(starttime=t1, endtime=t2)
示例#3
0
    def yield_waveforms(
        self,
        network: Optional[str] = None,
        station: Optional[str] = None,
        location: Optional[str] = None,
        channel: Optional[str] = None,
        starttime: Optional[obspy.UTCDateTime] = None,
        endtime: Optional[obspy.UTCDateTime] = None,
        attach_response: bool = False,
        duration: float = 3600.0,
        overlap: Optional[float] = None,
    ) -> Stream:
        """
        Yield waveforms from the bank.

        Parameters
        ----------
        {get_waveforms_params}
        attach_response : bool
            If True attach the response to the waveforms using the stations
        duration : float
            The duration of the streams to yield. All channels selected
            channels will be included in the waveforms.
        overlap : float
            If duration is used, the amount of overlap in yielded streams,
            added to the end of the waveforms.


        Notes
        -----
        All string parameters can use posix style matching with * and ? chars.
        """
        # get times in float format
        starttime = to_datetime64(starttime, 0.0)
        endtime = to_datetime64(endtime, "2999-01-01")
        # read in the whole index df
        index = self.read_index(
            network=network,
            station=station,
            location=location,
            channel=channel,
            starttime=starttime,
            endtime=endtime,
        )
        # adjust start/end times
        starttime = max(starttime, index.starttime.min())
        endtime = min(endtime, index.endtime.max())
        # chunk time and iterate over chunks
        time_chunks = make_time_chunks(starttime, endtime, duration, overlap)
        for t1, t2 in time_chunks:
            t1, t2 = to_datetime64(t1), to_datetime64(t2)
            con1 = (index.starttime - self.buffer) > t2
            con2 = (index.endtime + self.buffer) < t1
            ind = index[~(con1 | con2)]
            if not len(ind):
                continue
            yield self._index2stream(ind, t1, t2, attach_response)
示例#4
0
    def build_archive(self, st, starttime=None, endtime=None):
        """
        Build the archive (don't use mass downloader for a little variety)
        """
        starttime = starttime or self.starttime
        endtime = endtime or self.endtime

        for utc1, utc2 in make_time_chunks(starttime, endtime, duration=3600):
            stt = st.copy()
            stt.trim(starttime=utc1, endtime=utc2)
            channels = {x.stats.channel for x in st}
            for channel in channels:
                ts = stt.select(channel=channel)
                if not len(ts):
                    continue
                stats = ts[0].stats
                net, sta = stats.network, stats.station
                loc, cha = stats.location, stats.channel
                utc_str = str(utc1).split(".")[0].replace(":", "-")
                end = utc_str + ".mseed"
                fpath = self.waveform_path / net / sta / loc / cha / end
                fpath.parent.mkdir(parents=True, exist_ok=True)
                ts.write(str(fpath), "mseed")
示例#5
0
    def yield_waveform_callable(
        self,
        starttime: UTCDateTime,
        endtime: UTCDateTime,
        duration: float,
        overlap: float,
    ) -> Callable[..., Stream]:
        """
        Yield callables that take no arguments and return a waveforms.

        This function is useful if you are distributing work to remote
        processes and want to avoid serializing the waveforms.

        Parameters
        ----------
        starttime
            The starting time of the streams
        endtime
            The stopping time of the streams
        duration
            The duration of each waveforms between starttime and endtime
        overlap
            The overlap between streams added to the end of the waveforms

        Yields
        -------
        Callable[..., Stream]
        """

        time_chunks = make_time_chunks(starttime, endtime, duration, overlap)
        for t1, t2 in time_chunks:

            def _func(starttime=t1, endtime=t2):
                return self.get_waveforms(starttime=starttime, endtime=endtime)

            yield _func
示例#6
0
 def time_tuple(self):
     tc = make_time_chunks(self.starttime, self.endtime, self.duration, self.overlap)
     return list(tc)