Exemplo n.º 1
0
 def _download_crandall(self):
     """download waveform/station info for dataset."""
     bank = WaveBank(self.waveform_path)
     domain = CircularDomain(
         self.latitude,
         self.longitude,
         minradius=0,
         maxradius=kilometers2degrees(self.max_dist),
     )
     cat = obspy.read_events(str(self.source_path / "events.xml"))
     df = events_to_df(cat)
     for _, row in df.iterrows():
         starttime = row.time - self.time_before
         endtime = row.time + self.time_after
         restrictions = Restrictions(
             starttime=UTC(starttime),
             endtime=UTC(endtime),
             minimum_length=0.90,
             minimum_interstation_distance_in_m=100,
             channel_priorities=["HH[ZNE]", "BH[ZNE]"],
             location_priorities=["", "00", "01", "--"],
         )
         kwargs = dict(
             domain=domain,
             restrictions=restrictions,
             mseed_storage=str(self.waveform_path),
             stationxml_storage=str(self.station_path),
         )
         MassDownloader(providers=[self._download_client]).download(
             **kwargs)
         # ensure data have actually been downloaded
         bank.update_index()
         assert not bank.read_index(starttime=starttime,
                                    endtime=endtime).empty
Exemplo n.º 2
0
class WavebankWrapper(AnxcorDatabase):
    def __init__(self, directory):
        super().__init__()
        self.bank = WaveBank(
            directory, name_structure='{network}.{station}.{channel}.{time}')
        self.bank.update_index()

    def get_waveforms(self, **kwargs):
        stream = self.bank.get_waveforms(**kwargs)
        traces = []
        for trace in stream:
            data = trace.data[:-1]
            if isinstance(data, np.ma.MaskedArray):
                data = np.ma.filled(data, fill_value=np.nan)
            header = {
                'delta': trace.stats.delta,
                'station': trace.stats.station,
                'starttime': trace.stats.starttime,
                'channel': trace.stats.channel,
                'network': trace.stats.network
            }
            traces.append(Trace(data, header=header))
        return Stream(traces=traces)

    def get_stations(self):
        df = self.bank.get_availability_df()
        uptime = self.bank.get_uptime_df()

        def create_seed(row):
            network = row['network']
            station = row['station']
            return network + '.' + station

        df['seed'] = df.apply(lambda row: create_seed(row), axis=1)
        unique_stations = df['seed'].unique().tolist()
        return unique_stations
Exemplo n.º 3
0
 def continuous_sbank(self, download_data):
     """ return an sbank pointed at the temp_dir_path """
     sb = WaveBank(download_data)
     sb.update_index()
     return sb