Exemplo n.º 1
0
def create_config(conf='conf.json', tutorial=False, less_data=False):
    """Create JSON config file and download tutorial data if requested"""
    shutil.copyfile(resource_filename('yam', 'conf_example.json'), conf)
    temp_dir = os.path.join(tempfile.gettempdir(), 'yam_example_data')
    template = os.path.join(temp_dir, 'example_data')
    station_template = os.path.join(temp_dir, 'example_inventory')
    try:
        num_files = (len([name for name in os.listdir(template)]),
                     len([name for name in os.listdir(station_template)]))
    except FileNotFoundError:
        num_files = (0, 0)
    if tutorial and (num_files[0] <
                     (9 if less_data else 54) or num_files[1] < 3):
        print('Download example data from Geofon')
        from obspy import UTCDateTime as UTC
        from obspy.clients.fdsn.mass_downloader import (GlobalDomain,
                                                        Restrictions,
                                                        MassDownloader)
        domain = GlobalDomain()
        restrictions = Restrictions(
            starttime=UTC('2010-02-04' if less_data else '2010-02-01'),
            endtime=UTC('2010-02-06' if less_data else '2010-02-15'),
            network='CX',
            station='PATCX',
            location=None,
            channel_priorities=["BH[ZN]"],
            chunklength_in_sec=86400,
            reject_channels_with_gaps=False,
            minimum_length=0.5)
        mdl = MassDownloader(providers=['GFZ'])
        kw = dict(threads_per_client=1, download_chunk_size_in_mb=200)
        mdl.download(domain, restrictions, template, station_template, **kw)
        restrictions.station = 'PB06'
        if not less_data:
            restrictions.endtime = UTC('2010-02-12')
        mdl.download(domain, restrictions, template, station_template, **kw)
        restrictions.station = 'PB01'
        restrictions.endtime = UTC('2010-02-04 08:00:00')
        restrictions.channel_priorities = ["BHZ"]
        mdl.download(domain, restrictions, template, station_template, **kw)
        if not less_data:
            restrictions.starttime = UTC('2010-02-08 00:00:00')
            restrictions.endtime = UTC('2010-02-09 23:55:00')
            restrictions.channel_priorities = ["BHZ"]
            mdl.download(domain, restrictions, template, station_template,
                         **kw)
    if tutorial:
        dest_dir = os.path.dirname(conf)
        dest_dir_data = os.path.join(dest_dir, 'example_data')
        dest_dir_inv = os.path.join(dest_dir, 'example_inventory')
        if not os.path.exists(dest_dir_data):
            if less_data:
                ignore = shutil.ignore_patterns('*2010020[123]T000000Z__*',
                                                '*2010020[6-9]T000000Z__*',
                                                '*2010021?T000000Z__*')
            else:
                ignore = None
            shutil.copytree(template, dest_dir_data, ignore=ignore)
        if not os.path.exists(dest_dir_inv):
            shutil.copytree(station_template, dest_dir_inv)
Exemplo n.º 2
0
 def __init__(self,
              network,
              station,
              location,
              channel,
              starttime,
              endtime,
              chunklength_in_sec=None,
              overlap_in_sec=0,
              groupby='{network}.{station}.{channel}'):
     """
     Restrictions to download mseed 
     
     Parameters:
     -----------
     network: str
         Select one or more network codes. 
         Multiple codes are comma-separated (e.g. "IU,TA"). 
         Wildcards are allowed.
     station: str
         Select one or more SEED station codes. 
         Multiple codes are comma-separated (e.g. "ANMO,PFO"). 
         Wildcards are allowed.
     location: str
         Select one or more SEED location identifiers. 
         Multiple identifiers are comma-separated (e.g. "00,01"). 
         Wildcards are allowed.
     channel: str
         Select one or more SEED channel codes. 
         Multiple codes are comma-separated (e.g. "BHZ,HHZ").
     starttime: obspy.UTCDateTime
         Limit results to time series samples on or 
         after the specified start time.
     endtime: obspy.UTCDateTime
         Limit results to time series samples on or 
         before the specified end time.
     chunklength_in_sec: None or int
         The length of one chunk in seconds. 
         If set, the time between starttime and endtime will be divided 
         into segments of chunklength_in_sec seconds.
     overlap_in_sec: None or int
         For more than one chunk, each segment will have overlapping seconds
     groupby: str
         Download group traces together which have the same metadata given by this parameter. 
         The parameter should name the corresponding keys of the stats object, e.g. '{network}.{station}'. 
         This parameter can take the value 'id' which groups the traces by SEED id.
     """
     Restrictions.__init__(self,
                           network=network,
                           station=station,
                           location=location,
                           channel=channel,
                           starttime=starttime,
                           endtime=endtime,
                           chunklength_in_sec=chunklength_in_sec)
     self.overlap_in_sec = overlap_in_sec
     self.groupby = groupby
Exemplo n.º 3
0
 def _download_kemmerer(self):
     """ downloads both stations and waveforms """
     for station in ["M17A", "M18A"]:
         domain = RectangularDomain(
             minlatitude=40.0,
             maxlatitude=43.0,
             minlongitude=-111.0,
             maxlongitude=-110.0,
         )
         restrictions = Restrictions(
             starttime=obspy.UTCDateTime("2009-04-01T00:00:00"),
             endtime=obspy.UTCDateTime("2009-04-04T00:00:00"),
             chunklength_in_sec=3600,
             network="TA",
             channel="BH?",
             station=station,
             reject_channels_with_gaps=False,
             minimum_length=0.0,
             minimum_interstation_distance_in_m=10.0,
         )
         MassDownloader(providers=[self._download_client]).download(
             domain,
             restrictions,
             mseed_storage=str(self.waveform_path),
             stationxml_storage=str(self.station_path),
         )
Exemplo n.º 4
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.º 5
0
def _download_cont(nw, starttime, endtime):
    '''
    Download data for each network
    Return:
        None
    '''
    print(f'======Download data for network {nw}: {starttime} - {endtime}======')
    restrictions = Restrictions(
        starttime = starttime,
        endtime = endtime,
        chunklength_in_sec = para["Station Info"].getint("chunksize", 1) * 24 * 60 * 60,
        network = nw,
        station = para["Station Info"].get("station", "*"),
        channel_priorities = para["Station Info"].get("channelpri", "*").split(","),
        reject_channels_with_gaps = False,
        minimum_length = 0.0,
        minimum_interstation_distance_in_m = 100.0)

    mdl = MassDownloader(providers=["IRIS"])
    mdl.download(
        domain, 
        restrictions, 
        mseed_storage = para["DEFAULT"].get("projdir") + "/waveform/{station}/{network}.{station}.{location}.{channel}__{starttime}__{endtime}.mseed", 
        stationxml_storage = para["DEFAULT"].get("projdir") + "/station/{network}.{station}.xml")

    return
Exemplo n.º 6
0
def download_noise_windows(yr=2021, mnth=3, day=4, tod='morning'):

    morning = [UTCDateTime(yr, mnth, day, 6), UTCDateTime(yr, mnth, day, 9)]

    afternoon = [
        UTCDateTime(yr, mnth, day, 12),
        UTCDateTime(yr, mnth, day, 15)
    ]

    evening = [UTCDateTime(yr, mnth, day, 18), UTCDateTime(yr, mnth, day, 21)]

    night = [
        UTCDateTime(yr, mnth, day, 22, 30),
        UTCDateTime(yr, mnth, day + 1, 1, 30)
    ]

    restrictions = Restrictions(
        starttime=morning[0],
        endtime=morning[1],
        chunklength_in_sec=46,
        network=ntwk_query[2],
        station="USC",
        location="",
        channel="?N?",
        reject_channels_with_gaps=False,
        minimum_length=0.0,
    )
Exemplo n.º 7
0
def download_data(cat, downloaded=True):

    import obspy
    from obspy.clients.fdsn.mass_downloader import CircularDomain, \
        Restrictions, MassDownloader

    if downloaded == False:
        # First, define a domain.
        domain = CircularDomain(latitude=cat[0].origins[0].latitude,
                                longitude=cat[0].origins[0].longitude,
                                minradius=0.25,
                                maxradius=5.0)

        # Second, define some additional restrictions.
        restrictions = Restrictions(
            starttime=cat[0].origins[0].time - 0.5 * 60,
            endtime=cat[0].origins[0].time + 5 * 60,
            minimum_interstation_distance_in_m=100E3,
            channel="BHZ",
        )

        # If you leave the providers empty it will loop through
        # all data centers it knows.
        # It will prefer data from the first providers.
        mdl = MassDownloader(providers=["SCEDC", "NCEDC", "IRIS"])

        # Finally launch it.
        mdl.download(domain,
                     restrictions,
                     mseed_storage="waveforms",
                     stationxml_storage="stations")
    else:
        print('Data has been downloaded')
Exemplo n.º 8
0
    def download_data(self, event, providers=None):
        """
        """
        event = self.comm.events.get(event)

        from obspy.clients.fdsn.mass_downloader import MassDownloader, \
            Restrictions, GlobalDomain

        proj = self.comm.project

        if isinstance(proj.domain, lasif.domain.GlobalDomain):
            domain = GlobalDomain()
        else:
            domain = self._get_spherical_section_domain(proj.domain)

        event_time = event["origin_time"]
        ds = proj.config["download_settings"]
        starttime = event_time - ds["seconds_before_event"]
        endtime = event_time + ds["seconds_after_event"]

        mseed_storage = os.path.join(proj.paths["data"], event["event_name"],
                                     "raw")

        # Attempt to get StationXML data for a very long time span. This has
        # the nice side effect that StationXML files will mostly be shared
        # between events.
        restrictions = Restrictions(
            starttime=starttime,
            endtime=endtime,
            # Go back 10 years.
            station_starttime=starttime - 86400 * 365.25 * 10,
            # Advance 10 years.
            station_endtime=endtime + 86400 * 365.25 * 10,
            network=None, station=None, location=None, channel=None,
            minimum_interstation_distance_in_m=ds[
                "interstation_distance_in_m"],
            reject_channels_with_gaps=True,
            minimum_length=0.95,
            location_priorities=ds["location_priorities"],
            channel_priorities=ds["channel_priorities"])

        stationxml_storage = self._get_stationxml_storage_fct(starttime,
                                                              endtime)

        # Also log to file for reasons of provenance and debugging.
        logger = logging.getLogger("obspy.clients.fdsn.mass_downloader")
        fh = logging.FileHandler(
            self.comm.project.get_log_file("DOWNLOADS", event["event_name"]))
        fh.setLevel(logging.INFO)
        FORMAT = "[%(asctime)s] - %(name)s - %(levelname)s: %(message)s"
        formatter = logging.Formatter(FORMAT)
        fh.setFormatter(formatter)
        logger.addHandler(fh)

        dlh = MassDownloader(providers=providers)
        dlh.download(domain=domain, restrictions=restrictions,
                     mseed_storage=mseed_storage,
                     stationxml_storage=stationxml_storage)
def download_data(starttime,
                  endtime,
                  waveform_dir,
                  station_dir,
                  networks=None,
                  channels=None,
                  providers=None,
                  minimum_length=0.95):
    # Rectangular domain containing parts of southern Germany.
    domain = RectangularDomain(minlatitude=-90,
                               maxlatitude=90,
                               minlongitude=-180,
                               maxlongitude=180)

    if isinstance(channels, list):
        channel = ",".join(channels)
    elif channels == "None" or channels is None:
        channel = None
    else:
        raise ValueError("Unknown channels: {}".format(channels))

    if isinstance(networks, list):
        network = ",".join(networks)
    elif networks == "None" or networks is None:
        network = None
    else:
        raise ValueError("Unknown networks: {}".format(networks))

    print("network: ", network)
    print("channel: ", channel)

    # Set download restrictions
    restrictions = Restrictions(starttime=starttime,
                                endtime=endtime,
                                reject_channels_with_gaps=False,
                                minimum_length=minimum_length,
                                station=None,
                                network=network,
                                channel=channel,
                                location_priorities=["", "00", "10"],
                                channel_priorities=["BH[ZNE12]", "HH[ZNE12]"])

    if (providers is None) or (providers == "None"):
        mdl = MassDownloader()
    else:
        mdl = MassDownloader(providers=providers)

    mdl.download(domain,
                 restrictions,
                 mseed_storage=waveform_dir,
                 stationxml_storage=station_dir)
Exemplo n.º 10
0
def _get_w(bg, st, station_dic, end_t, mdl, domain, output_dir, n_days,
           channel_list):

    next_month = bg + datetime.timedelta(n_days)
    nt = station_dic[str(st)]['network']
    save_dir = os.path.join(output_dir, st)
    save_dir2 = os.path.join(output_dir + "xml", st)

    while next_month <= end_t:
        if len(channel_list) == 0:
            restrictions = Restrictions(starttime=bg,
                                        endtime=next_month,
                                        network=nt,
                                        station=st,
                                        reject_channels_with_gaps=False,
                                        minimum_length=0.0)
        else:
            restrictions = Restrictions(starttime=bg,
                                        endtime=next_month,
                                        network=nt,
                                        station=st,
                                        reject_channels_with_gaps=False,
                                        channel_priorities=channel_list,
                                        minimum_length=0.0)
        try:
            mdl.download(domain,
                         restrictions,
                         mseed_storage=save_dir,
                         stationxml_storage=save_dir2)
            print(f"** done with --> {st} -- {nt} -- {str(bg).split('T')[0]}")

        except Exception:
            print(f"!! failed downloading --> {st} -- {nt} !")
            pass
        time.sleep(np.random.randint(25, 30))
        bg = next_month
        next_month = bg + datetime.timedelta(n_days)
def descargar_datos(cat, radiomin, radiomax, start_time, end_time, dist_esta):
    nombre_evento = cat["region"].values[0]
    fecha_evento = cat["fecha_evento"].values[0]
    magnitud = cat["Mw_cmt"].values[0]
    nombre_evento = str(nombre_evento + " " + str(fecha_evento) + " " +
                        str(magnitud))  # + str(canal)
    lat_e = cat["lat_cmt"].values[0]
    lon_e = cat["lon_cmt"].values[0]
    time = cat["tiempo_cmt"].values[0]
    time = str(fecha_evento) + "T" + time
    time = UTCDateTime(time)
    depth = cat["depth_cmt"].values[0]
    client = Client("IRIS")
    domain = CircularDomain(latitude=lat_e,
                            longitude=lon_e,
                            minradius=radiomin,
                            maxradius=radiomax)
    mdl = MassDownloader(providers=["IRIS"])
    restrictions = Restrictions(starttime=time - start_time,
                                endtime=time + end_time,
                                chunklength_in_sec=86400,
                                location="00",
                                channel="BHZ",
                                reject_channels_with_gaps=True,
                                minimum_length=0.95,
                                minimum_interstation_distance_in_m=dist_esta,
                                sanitize=True)
    ruta = os.getcwd()
    rutas = "datos/"
    informacion = ruta + "/" + rutas + nombre_evento
    n_carpeta_w = nombre_evento + "/waveforms"
    n_carpeta_s = nombre_evento + "/stations"

    informacion = informacion.replace("/", "\\")
    try:
        os.mkdir(informacion)
        os.chdir(informacion)
        archivo = open("info.txt", "w")
        archivo.write(str(cat["id_evento"].values[0]) + "\n")
        archivo.close()
        os.chdir("..")
        mdl.download(domain,
                     restrictions,
                     mseed_storage=n_carpeta_w,
                     stationxml_storage=n_carpeta_s)
    except:
        return -100
Exemplo n.º 12
0
def download(eqname, t0, min_length=600):
    domain = GlobalDomain()

    restrictions = Restrictions(starttime=t0,endtime=t0+min_length,chunklength_in_sec=84600,network="*", station="*", location="", channel="BH*",
        reject_channels_with_gaps=True,minimum_length=0.0,minimum_interstation_distance_in_m=100.0)

    waveform_dir = "data/{}/waveforms".format(eqname)
    stationxml_dir = "data/{}/stations".format(eqname)
    makedir(waveform_dir)
    makedir(stationxml_dir)

    mdl = MassDownloader(providers=["http://eida.koeri.boun.edu.tr:8080"])
    # Kandilli FDSN matchtimeseries=True icin bos istasyon listesi donduruyor.
    mdl._initialized_clients["http://eida.koeri.boun.edu.tr:8080"].services["station"].pop("matchtimeseries")
    mdl.download(domain, restrictions,
                 mseed_storage=waveform_dir,
                 stationxml_storage=stationxml_dir)
def get_data(date, latitude, longitude):
    resp_files = '/Users/gsilveira/Documents/MadalenaMatias/dataless/resp/'
    from obspy.clients.fdsn.mass_downloader import RectangularDomain, \
        Restrictions, MassDownloader

    domain = RectangularDomain(
        minlatitude=-55.5,
        maxlatitude=latitude,  #66.7,
        minlongitude=-71.5,
        maxlongitude=longitude)

    restrictions = Restrictions(
        # Get data for a whole year.
        starttime=obspy.UTCDateTime(int(date[0]), int(date[1]), int(date[2]),
                                    int(date[3]), int(date[4]), int(date[5]),
                                    int(date[6])),
        endtime=obspy.UTCDateTime(2020, 10, 1),
        # Chunk it to have one file per day.
        chunklength_in_sec=3600000,
        # Considering the enormous amount of data associated with continuous
        # requests, you might want to limit the data based on SEED identifiers.
        # If the location code is specified, the location priority list is not
        # used; the same is true for the channel argument and priority list.
        network="GH",
        station="AKOS",
        location="*",
        channel="*",
        # The typical use case for such a data set are noise correlations where
        # gaps are dealt with at a later stage.
        reject_channels_with_gaps=False,
        # Same is true with the minimum length. All data might be useful.
        minimum_length=0.0,
        # Guard against the same station having different names.
        minimum_interstation_distance_in_m=100.0)

    # Restrict the number of providers if you know which serve the desired
    # data. If in doubt just don't specify - then all providers will be
    # queried.
    mdl = MassDownloader(providers=["IRIS"])
    mdl.download(
        domain,
        restrictions,
        mseed_storage=("../per_hour/{network}/Leslie/{station}/"
                       "{channel}.{location}.{starttime}.{endtime}.mseed"),
        stationxml_storage="stations")
Exemplo n.º 14
0
def download_global_data(starttime,
                         endtime,
                         waveform_dir,
                         stationxml_dir,
                         stations=None,
                         networks=None,
                         channels=None,
                         location_priorities=None,
                         channel_priorities=None,
                         minimum_length=0.95,
                         reject_channels_with_gaps=True,
                         providers=None):

    domain = GlobalDomain()

    station = list2str(stations)
    network = list2str(networks)
    channel = list2str(channels)

    print("network {}: | station: {} | channel: {} ".format(
        network, station, channel))

    time.sleep(2.0)

    # Set download restrictions
    restrictions = Restrictions(
        starttime=starttime,
        endtime=endtime,
        reject_channels_with_gaps=reject_channels_with_gaps,
        minimum_length=minimum_length,
        station=station,
        network=network,
        channel=channel,
        location_priorities=location_priorities,
        channel_priorities=channel_priorities)

    if (providers is None) or (providers == "None"):
        mdl = MassDownloader()
    else:
        mdl = MassDownloader(providers=providers)

    mdl.download(domain,
                 restrictions,
                 mseed_storage=waveform_dir,
                 stationxml_storage=stationxml_dir)
Exemplo n.º 15
0
def _download_event(eventtime, starttime, endtime):
    '''
    Download each event for all stations
    Return:
        None
    '''

    restrictions = Restrictions(
                        starttime = eventtime - starttime * 60,
                        endtime = eventtime + endtime * 60,
                        network = para["Station Info"].get("network", "*"),
                        station = para["Station Info"].get("station", "*"),
                        reject_channels_with_gaps = False,
                        minimum_length = 0.0,
                        channel_priorities = para["Station Info"].get("channelpri", "*").split(","))

    mdl = MassDownloader(providers=["IRIS"])
    mdl.download(
        domain, 
        restrictions, 
        mseed_storage = f'{para["DEFAULT"].get("projdir")}/waveform', 
        stationxml_storage = f'{para["DEFAULT"].get("projdir")}/station')
    return
Exemplo n.º 16
0
def download_event(event: str):
    d.mkdir(mseed := f'mseed/{event}')
    d.mkdir(xml := f'xml/{event}')
    
    # Event object
    e = read_events(f'events/{event}')[0]
    time = e.preferred_origin().time

    # call mass downloader
    restrictions = Restrictions(
        starttime=time - 600,
        endtime=time + 7800,
        reject_channels_with_gaps=True,
        minimum_length=0.95,
        channel_priorities=['BH[ZNE12]', 'HH[ZNE12]'],
        location_priorities=['', '00', '10']
    )

    MassDownloader().download(
        GlobalDomain(), restrictions,
        mseed_storage=d.abs(mseed),
        stationxml_storage=d.abs(xml)
    )
Exemplo n.º 17
0
def download_events(cat, yeartag="2005", firstid=1):
    """
    Download events to lower 48 with MassDownloader using
    events in obspy Catalog object cat.  Parameters for 
    station definitions are hard wired 
    """
    wf_storage = yeartag + "/{starttime}/{network}_{station}_{location}.mseed"
    site_storage = "site_" + yeartag + ".dir"
    mdl = MassDownloader()
    domain = RectangularDomain(minlatitude=20.0,
                               maxlatitude=54.0,
                               minlongitude=-135,
                               maxlongitude=-55)
    count_evid = 1
    for event in cat:
        if (count_evid >= firstid):
            t0 = time.time()
            o = event.preferred_origin()
            # Time attribute is already a UTCDateTime object
            origin_time = o.time
            restrictions = Restrictions(
                starttime=origin_time,
                endtime=origin_time + 3600.0,
                reject_channels_with_gaps=True,
                minimum_length=0.95,
                minimum_interstation_distance_in_m=100.0,
                channel_priorities=["BH[ZNE12]"],
                location_priorities=["", "00", "10", "01"])

            wf_storage = ("%s/event%d" % (yeartag, count_evid))
            mdl.download(domain,
                         restrictions,
                         mseed_storage=wf_storage,
                         stationxml_storage=site_storage)
            dt = time.time() - t0
            print("Event ", count_evid, " download time (s)=", dt)
        count_evid += 1
Exemplo n.º 18
0
    def generate_restrictions(
        self,
        starttime: obspy.core.utcdatetime.UTCDateTime,
        endtime: obspy.core.utcdatetime.UTCDateTime,
        ds: dict,
    ):
        """
        Create a restriction criterion for the mass downloader

        :param starttime: Start time of data request
        :type starttime: obspy.core.utcdatetime.UTCDateTime
        :param endtime: End time of data request
        :type endtime: obspy.core.utcdatetime.UTCDateTime
        :param ds: Dictionary of information
        :type ds: dict
        :return: Restrictions to download request
        """
        from obspy.clients.fdsn.mass_downloader import Restrictions

        return Restrictions(
            starttime=starttime,
            endtime=endtime,
            # Go back 1 day.
            station_starttime=starttime - 86400 * 1,
            # Advance 1 day.
            station_endtime=endtime + 86400 * 1,
            network=ds["networks"],
            station=None,
            location=None,
            channel=None,
            minimum_interstation_distance_in_m=ds[
                "interstation_distance_in_m"],
            reject_channels_with_gaps=True,
            minimum_length=0.95,
            location_priorities=ds["location_priorities"],
            channel_priorities=ds["channel_priorities"],
        )
Exemplo n.º 19
0
                        maxradius=r)

t1 = UTCDateTime(2021, 3, 2)
t2 = UTCDateTime(2021, 3, 5)

restrictions = Restrictions(
    # Get data for a whole year.
    starttime=t1,
    endtime=t2,

    # 1 day chunks
    chunklength_in_sec=86400,

    # If the location code is specified, the location priority list is not
    # used; the same is true for the channel argument and priority list.
    network=ntwk_query[2],
    station="USC",
    location="",
    channel="?N?",
    # The typical use case for such a data set are noise correlations where
    # gaps are dealt with at a later stage.
    reject_channels_with_gaps=False,
    # Same is true with the minimum length. All data might be useful.
    minimum_length=0.0,
    # Guard against the same station having different names.
    #minimum_interstation_distance_in_m=100.0
)

mdl = "tmp"
download = False

if download:
Exemplo n.º 20
0
                           minlatitude=statLat_min, maxlatitude=statLat_max)

restrictions = Restrictions(
    # Get data from 5 minutes before the event to one hour after the
    # event. This defines the temporal bounds of the waveform data.
    starttime=origin_time - seconds_before,
    endtime=origin_time + seconds_after,
    #    station = 'BGAR',
    network=network,
    # You might not want to deal with gaps in the data. If this setting is
    # True, any trace with a gap/overlap will be discarded.
    reject_channels_with_gaps=True,
    # And you might only want waveforms that have data for at least 95 % of
    # the requested time span. Any trace that is shorter than 95 % of the
    # desired total duration will be discarded.
    minimum_length=0.95,
    # No two stations should be closer than 10 km to each other. This is
    # useful to for example filter out stations that are part of different
    # networks but at the same physical station. Settings this option to
    # zero or None will disable that filtering.
    minimum_interstation_distance_in_m=0,
    # Only HH or BH channels. If a station has HH channels, those will be
    # downloaded, otherwise the BH. Nothing will be downloaded if it has
    # neither. You can add more/less patterns if you like.
    channel_priorities=channel_priorities,
    #    channel_priorities=["HG[NE]", "HG[NE]"],
    # Location codes are arbitrary and there is no rule as to which
    # location is best. Same logic as for the previous setting.
    location_priorities=["", "00", "10"])

# No specified providers will result in all known ones being queried.
Exemplo n.º 21
0
def downloadwav(
    phase: str, min_epid: float, max_epid: float, model: TauPyModel,
    event_cat: Catalog, tz: float, ta: float, statloc: str,
    rawloc: str, clients: list, evtfile: str, network: str = None,
    station: str = None, saveasdf: bool = False,
    log_fh: logging.FileHandler = None, loglvl: int = logging.WARNING,
        verbose: bool = False, fast_redownload: bool = False):
    """
    Downloads the waveforms for all events in the catalogue
     for a circular domain around the epicentre with defined epicentral
     distances from Clients defined in clients. Also Station
     xmls for corresponding stations are downloaded.

    Parameters
    ----------
    phase : string
        Arrival phase to be used. P, S, SKS, or ScS.
    min_epid : float
        Minimal epicentral distance to be downloaded.
    max_epid : float
        Maxmimal epicentral distance to be downloaded.
    model : obspy.taup.TauPyModel
        1D velocity model to calculate arrival.
    event_cat : Obspy event catalog
        Catalog containing all events, for which waveforms should be
        downloaded.
    tz : int
        time window before first arrival to download (seconds)
    ta : int
        time window after first arrival to download (seconds)
    statloc : string
        Directory containing the station xmls.
    rawloc : string
        Directory containing the raw seismograms.
    clients : list
        List of FDSN servers. See obspy.Client documentation for acronyms.
    network : string or list, optional
        Network restrictions. Only download from these networks, wildcards
        allowed. The default is None.
    station : string or list, optional
        Only allowed if network != None. Station restrictions.
        Only download from these stations, wildcards are allowed.
        The default is None.
    saveasdf : bool, optional
        Save the dataset as Adaptable Seismic Data Format (asdf; recommended).
        Else, one will be left with .mseeds.
    log_fh : logging.FileHandler, optional
        file handler to be used for the massdownloader logger.
    loglvl : int, optional
        Use this logging level.
    verbose: Bool, optional
        Set True, when experiencing issues with download. Output of
        obspy MassDownloader will be logged in download.log.

    Returns
    -------
    None

    """

    # needed to check whether data is already in the asdf
    global asdfsave
    asdfsave = saveasdf

    # Calculate the min and max theoretical arrival time after event time
    # according to minimum and maximum epicentral distance
    min_time = model.get_travel_times(source_depth_in_km=500,
                                      distance_in_degree=min_epid,
                                      phase_list=[phase])[0].time

    max_time = model.get_travel_times(source_depth_in_km=0.001,
                                      distance_in_degree=max_epid,
                                      phase_list=[phase])[0].time

    mdl = MassDownloader(providers=clients)

    ###########
    # logging for the download
    fdsn_mass_logger = logging.getLogger("obspy.clients.fdsn.mass_downloader")
    fdsn_mass_logger.setLevel(loglvl)

    # # Create handler to the log
    if log_fh is None:
        fh = logging.FileHandler(os.path.join('logs', 'download.log'))
        fh.setLevel(logging.INFO)
        fh.setLevel(loglvl)
        # Create Formatter
        fmt = logging.Formatter(
            fmt='%(asctime)s - %(levelname)s - %(message)s')
        fh.setFormatter(fmt)
    else:
        fh = log_fh

    fdsn_mass_logger.addHandler(fh)

    ####
    # Loop over each event
    global event
    for ii, event in enumerate(tqdm(event_cat)):
        # fetch event-data
        origin_time = event.origins[0].time
        ot_fiss = UTCDateTime(origin_time).format_fissures()
        fdsn_mass_logger.info('Downloading event: '+ot_fiss)
        evtlat = event.origins[0].latitude
        evtlon = event.origins[0].longitude

        # Download location
        ot_loc = UTCDateTime(origin_time, precision=-1).format_fissures()[:-6]
        evtlat_loc = str(roundhalf(evtlat))
        evtlon_loc = str(roundhalf(evtlon))
        tmp.folder = os.path.join(
            rawloc, '%s_%s_%s' % (ot_loc, evtlat_loc, evtlon_loc))

        # create folder for each event
        os.makedirs(tmp.folder, exist_ok=True)

        # Circular domain around the epicenter. This module also offers
        # rectangular and global domains. More complex domains can be
        # defined by inheriting from the Domain class.

        domain = CircularDomain(latitude=evtlat, longitude=evtlon,
                                minradius=min_epid, maxradius=max_epid)

        restrictions = Restrictions(
            # Get data from sufficient time before earliest arrival
            # and after the latest arrival
            # Note: All the traces will still have the same length
            starttime=origin_time + min_time - tz,
            endtime=origin_time + max_time + ta,
            network=network, station=station,
            # You might not want to deal with gaps in the data.
            # If this setting is
            # True, any trace with a gap/overlap will be discarded.
            # This will delete streams with several traces!
            reject_channels_with_gaps=False,
            # And you might only want waveforms that have data for at least 95%
            # of the requested time span. Any trace that is shorter than 95% of
            # the desired total duration will be discarded.
            minimum_length=0.95,  # For 1.00 it will always delete the waveform
            # No two stations should be closer than 1 km to each other. This is
            # useful to for example filter out stations that are part of
            # different networks but at the same physical station. Settings
            # this option to zero or None will disable that filtering.
            # Guard against the same station having different names.
            minimum_interstation_distance_in_m=100.0,
            # Only HH or BH channels. If a station has BH channels, those will
            # be downloaded, otherwise the HH. Nothing will be downloaded if it
            # has neither.
            channel_priorities=["BH[ZNE12]", "HH[ZNE12]"],
            # Location codes are arbitrary and there is no rule as to which
            # location is best. Same logic as for the previous setting.
            # location_priorities=["", "00", "10"],
            sanitize=False
            # discards all mseeds for which no station information is available
            # I changed it too False because else it will redownload over and
            # over and slow down the script
        )

        # The data will be downloaded to the ``./waveforms/`` and
        # ``./stations/`` folders with automatically chosen file names.
        incomplete = True
        while incomplete:
            try:
                mdl.download(
                    domain, restrictions,
                    mseed_storage=get_mseed_storage,
                    stationxml_storage=statloc,
                    threads_per_client=3, download_chunk_size_in_mb=50)
                incomplete = False
            except IncompleteRead:
                continue  # Just retry for poor connection
            except Exception:
                incomplete = False  # Any other error: continue

        # 2021.02.15 Here, we write everything to asdf
        if saveasdf:
            writeraw(event, tmp.folder, statloc, verbose, True)
            # If that works, we will be deleting the cached mseeds here
            try:
                shutil.rmtree(tmp.folder)
            except FileNotFoundError:
                # This does not make much sense, but for some reason it occurs
                # even if the folder exists? However, we will not want the
                # whole process to stop because of this
                pass
        if fast_redownload:
            event_cat[ii:].write(evtfile, format="QUAKEML")

    if not saveasdf:
        download_full_inventory(statloc, clients)
    tmp.folder = "finished"  # removes the restriction for preprocess.py
Exemplo n.º 22
0
    def download_surf(self, datadir, commontime = True, fskip=True, chanrank=['LH', 'BH', 'HH'],\
            channels='ZNE', vmax = 8.0, vmin=.5, verbose=False, start_date=None, end_date=None, skipinv=True, threads_per_client = 3,\
            providers  = None, blon = 0.05, blat = 0.05):
        """request Rayleigh wave data from 
        ====================================================================================================================
        ::: input parameters :::
        lon0, lat0      - center of array. If specified, all waveform will have the same starttime and endtime
        min/maxDelta    - minimum/maximum epicentral distance, in degree
        channel         - Channel code, e.g. 'BHZ'.
                            Last character (i.e. component) can be a wildcard (‘?’ or ‘*’) to fetch Z, N and E component.
        vmin, vmax      - minimum/maximum velocity for surface wave window
        =====================================================================================================================
        """
        if providers is None:
            providers = ['BGR', 'ETH', 'GFZ', 'ICGC', 'INGV', 'IPGP',\
                'IRIS', 'KNMI', 'KOERI', 'LMU', 'NCEDC', 'NIEP', 'NOA', 'ODC', 'ORFEUS',\
                'RASPISHAKE', 'RESIF', 'SCEDC', 'TEXNET', 'USP']
        self.get_limits_lonlat()
        minlongitude = self.minlon
        maxlongitude = self.maxlon
        if minlongitude > 180.:
            minlongitude -= 360.
        if maxlongitude > 180.:
            maxlongitude -= 360.
        lon0 = (minlongitude + maxlongitude) / 2.
        lat0 = (self.minlat + self.maxlat) / 2.
        domain = RectangularDomain(minlatitude=self.minlat - blat,
                                   maxlatitude=self.maxlat + blat,
                                   minlongitude=minlongitude - blon,
                                   maxlongitude=maxlongitude + blon)
        try:
            print(self.cat)
        except AttributeError:
            self.copy_catalog()
        try:
            stime4down = obspy.core.utcdatetime.UTCDateTime(start_date)
        except:
            stime4down = obspy.UTCDateTime(0)
        try:
            etime4down = obspy.core.utcdatetime.UTCDateTime(end_date)
        except:
            etime4down = obspy.UTCDateTime()
        mdl = MassDownloader(providers=providers)
        chantype_list = []
        for chantype in chanrank:
            chantype_list.append('%s[%s]' % (chantype, channels))
        channel_priorities = tuple(chantype_list)
        t1 = time.time()
        # loop over events
        for event in self.cat:
            pmag = event.preferred_magnitude()
            try:
                magnitude = pmag.mag
                evdp = porigin.depth / 1000.
            except:
                pass
            try:
                Mtype = pmag.magnitude_type
                event_descrip = event.event_descriptions[
                    0].text + ', ' + event.event_descriptions[0].type
                porigin = event.preferred_origin()
                otime = porigin.time
                timestr = otime.isoformat()
                evlo = porigin.longitude
                evla = porigin.latitude
            except:
                pass
            if otime < stime4down or otime > etime4down:
                continue
            if commontime:
                dist, az, baz = obspy.geodetics.gps2dist_azimuth(
                    evla, evlo, lat0, lon0)  # distance is in m
                dist = dist / 1000.
                starttime = otime + dist / vmax
                endtime = otime + dist / vmin
            oyear = otime.year
            omonth = otime.month
            oday = otime.day
            ohour = otime.hour
            omin = otime.minute
            osec = otime.second
            label = '%d_%s_%d_%d_%d_%d' % (oyear, mondict[omonth], oday, ohour,
                                           omin, osec)
            eventdir = datadir + '/' + label
            if not os.path.isdir(eventdir):
                os.makedirs(eventdir)
            event_logfname = eventdir + '/download.log'
            if fskip and os.path.isfile(event_logfname):
                continue
            stationxml_storage = "%s/{network}/{station}.xml" % eventdir
            if commontime:
                restrictions = Restrictions(
                    # starttime and endtime
                    starttime=starttime,
                    endtime=endtime,
                    # You might not want to deal with gaps in the data.
                    reject_channels_with_gaps=True,
                    # And you might only want waveforms that have data for at least
                    # 95 % of the requested time span.
                    minimum_length=0.95,
                    # No two stations should be closer than 10 km to each other.
                    minimum_interstation_distance_in_m=10E3,
                    # Only HH or BH channels. If a station has HH channels,
                    # those will be downloaded, otherwise the BH. Nothing will be
                    # downloaded if it has neither.
                    channel_priorities=channel_priorities,
                    sanitize=True)
                mseed_storage = eventdir
                # # # mseed_storage   = ("%s/{network}/{station}/{channel}.{location}.%s.mseed" %(datadir, label) )
                mdl.download(domain,
                             restrictions,
                             mseed_storage=mseed_storage,
                             stationxml_storage=stationxml_storage,
                             threads_per_client=threads_per_client)
            else:
                # loop over stations
                Nsta = 0
                for network in self.inv:
                    for station in network:
                        netcode = network.code
                        stacode = station.code
                        staid = netcode + '.' + stacode
                        with warnings.catch_warnings():
                            warnings.simplefilter("ignore")
                            st_date = station.start_date
                            ed_date = station.end_date
                        if skipinv and (otime < st_date or otime > ed_date):
                            continue
                        stlo = station.longitude
                        stla = station.latitude
                        dist, az, baz = obspy.geodetics.gps2dist_azimuth(
                            evla, evlo, stla, stlo)  # distance is in m
                        dist = dist / 1000.
                        starttime = otime + dist / vmax
                        endtime = otime + dist / vmin

                        restrictions = Restrictions(
                            network=netcode,
                            station=stacode,
                            # starttime and endtime
                            starttime=starttime,
                            endtime=endtime,
                            # You might not want to deal with gaps in the data.
                            reject_channels_with_gaps=True,
                            # And you might only want waveforms that have data for at least
                            # 95 % of the requested time span.
                            minimum_length=0.95,
                            # No two stations should be closer than 10 km to each other.
                            minimum_interstation_distance_in_m=10E3,
                            # Only HH or BH channels. If a station has HH channels,
                            # those will be downloaded, otherwise the BH. Nothing will be
                            # downloaded if it has neither.
                            channel_priorities=channel_priorities,
                            sanitize=True)
                        mseed_storage = eventdir
                        # mseed_storage   = ("%s/{network}/{station}/{channel}.{location}.%s.mseed" %(datadir, label) )
                        mdl.download(domain,
                                     restrictions,
                                     mseed_storage=mseed_storage,
                                     stationxml_storage=stationxml_storage,
                                     threads_per_client=threads_per_client)
                        Nsta += 1
            print('--- [RAYLEIGH DATA DOWNLOAD] Event: %s %s' %
                  (otime.isoformat(), event_descrip))
            with open(event_logfname, 'w') as fid:
                fid.writelines('evlo: %g, evla: %g\n' % (evlo, evla))
                if commontime:
                    fid.writelines('distance: %g km\n' % dist)
                fid.writelines('DONE\n')
        return
Exemplo n.º 23
0
    def GetData(self,stationdirpath='stations',datadirpath='waveforms',req_type='continuous',\
     chunklength=86400,tracelen=20000, vmodel='ak135'):
        '''Call obspy mass downloader to get waveform data. Chunklength refers to the trace length option
		for a continuous download, tracelen is for an event-based request'''

        #Currently set up to download one day worth of data in the continuous mode, 2000 seconds
        #in the event-based mode

        self.stationdirpath = stationdirpath
        self.datadirpath = datadirpath

        from obspy.clients.fdsn.mass_downloader import RectangularDomain, CircularDomain,\
        Restrictions, MassDownloader

        if req_type == 'continuous':

            #Get data from all stations within this domain

            domain = RectangularDomain(minlatitude=self.minlatitude,maxlatitude=self.maxlatitude,\
             minlongitude=self.minlongitude,maxlongitude=self.maxlongitude)

            #Download data in daily segements - may want to change

            restrictions = Restrictions(\
                                    starttime=self.starttime,endtime=self.endtime,\
                                    chunklength_in_sec=chunklength,\
                                    channel=self.channel,station=self.station,location="",\
                                    reject_channels_with_gaps=False,\
                                    minimum_length=0.0,minimum_interstation_distance_in_m=100.0)

            #Call mass downloader to get the waveform information

            mdl = MassDownloader(providers=[self.clientname])

            mdl.download(domain,
                         restrictions,
                         mseed_storage=datadirpath,
                         stationxml_storage=stationdirpath)

        elif req_type == 'event':

            if self.quake_cat == None:

                print(
                    "Stop: Must call fetchEvents first to get event catalog to download from"
                )
                sys.exit(1)

            #Add option for non-continuous download - event/station pairing for example

            #Ger data for all stations in this domain

            domain = RectangularDomain(minlatitude=self.minlatitude,maxlatitude=self.maxlatitude,\
             minlongitude=self.minlongitude,maxlongitude=self.maxlongitude)

            for event in self.quake_cat:
                cnt = 0.
                print("Downloading data for event %s" % event)

                #For each event, download the waveforms at all stations requested

                origin_time = event.origins[0].time

                vel_model = TauPyModel(model=vmodel)

                #case where we only want to download data for some station-event pairs'
                stations_to_exclude = []

                if self.station_autoselect_flag == True:

                    stations_to_download = []
                    evlat = event.origins[0].latitude
                    evlon = event.origins[0].longitude

                    #EK changes added 04/2019
                    evdep = event.origins[0].depth

                    for network in self.inventory:

                        for station in network:

                            stlat = station.latitude
                            stlon = station.longitude

                            #EK 04/2019
                            #this downloads data within Short Wave Window (SWW), a cone under the station bounded by an angle, here we chose 45 deg
                            #calculate distance between eq and station and azimuth

                            ddeg = locations2degrees(evlat, evlon, stlat,
                                                     stlon)
                            distance_m, az, baz = gps2dist_azimuth(
                                evlat, evlon, stlat, stlon)

                            #calculate proxy for incident angle

                            theta = np.arctan2(distance_m, evdep)

                            if theta <= np.pi / 4:

                                #find if station has needed arrival

                                arrivals = vel_model.get_travel_times(
                                    source_depth_in_km=evdep / 1000.,
                                    distance_in_degree=ddeg,
                                    phase_list=["s", "S"])
                                if len(arrivals) > 0:

                                    #get stations you want to download

                                    stations_to_download.append(station.code)
                                    print(station.code,
                                          'angle = %.2f' % np.rad2deg(theta))
                                    print(arrivals)
                                    cnt = cnt + 1
                                else:
                                    stations_to_exclude.append(station.code)
                            else:

                                if station.code not in stations_to_exclude:
                                    stations_to_exclude.append(station.code)

                    print(
                        "\n-------------\n%g event-station pairs found in SWW\n-------------\n"
                        % cnt)
                    print(
                        "\n-------------\nSelecting just the following stations for download\n-------------\n"
                    )
                    print(stations_to_download)

                    #this approach doesn't work, use exclude_stations flag later
                    #restrictions = Restrictions(starttime=origin_time,endtime=origin_time + tracelen,\
                    #reject_channels_with_gaps=False, minimum_length=0.95, minimum_interstation_distance_in_m=10E3,\
                    #channel=self.channel,location="",network=self.network,station=stations_to_download)

                #case where we have single network

                if self.network:

                    restrictions = Restrictions(starttime=origin_time,endtime=origin_time + tracelen,\
                     reject_channels_with_gaps=False, minimum_length=0.95, minimum_interstation_distance_in_m=10E3,\
                     channel=self.channel,location="",network=self.network,exclude_stations=stations_to_exclude)

                #Case where we want all networks within a region (assumes that we also want all stations unless we have built
                # a stations to exclude list)

                else:

                    restrictions = Restrictions(starttime=origin_time,endtime=origin_time + tracelen,\
                     reject_channels_with_gaps=False, minimum_length=0.95, minimum_interstation_distance_in_m=10E3,\
                     channel=self.channel,exclude_stations=stations_to_exclude)

                mdl = MassDownloader(providers=[self.clientname])

                mdl.download(domain, restrictions, mseed_storage=datadirpath,\
                 stationxml_storage=stationdirpath)
Exemplo n.º 24
0
def get_mass_data(network,
                  starttime,
                  endtime,
                  outdir='.',
                  lat=0,
                  lon=0,
                  minrad=0,
                  maxrad=180,
                  providers=['IRIS']):
    """
    Use obspy's massdownloader to download lots of data, stores as day-long \
    miniseed files using IRIS DMC naming conventions.

    :type network: str
    :param network: Network code
    :type starttime: UTCDateTime
    :param starttime: Time to begin donloading from, will use the date
    :type endtime: UTCDateTime
    :param endtime: Time to end download, will use the date
    :type outdir: str
    :param outdir: Path to write to, will write in Y????/R???.01 directories \
        within this head directory.
    :type lat: float
    :param lat: Origin latitude
    :type lon: float
    :param lon: Origin longitude
    :type minrad: float
    :param minrad: Minumum radius in degrees for stations from lat/lon.
    :type maxrad: float
    :param maxrad: Maximum radius in degrees for stations from lat/lon
    :type providers: list
    :param providers: List of providers to query.  Default is IRIS. Can parse \
        an empty list and will query all providers, but slow.

    .. note:: Currently selects data using a circular domain, default is \
        set to entire globe so that a whole network can be downloaded. \
        Options left in function to allow repurposing.
    """
    def get_mseed_storage(network, station, location, channel, starttime,
                          endtime):
        """Function to define the naming for the stored file.

        .. note:: Can only have these arguments.  As such this needs to be a \
            function defined within the other function to have access to the \
            outdir variable.
        """
        import os
        # Returning True means that neither the data nor the StationXML file
        # will be downloaded.
        # If a string is returned the file will be saved in that location.
        path = os.path.join(
            outdir, "%s/%s.%s.%s.%s.%s" %
            (starttime.strftime('Y%Y/R%j.01'), network, station, location,
             channel, starttime.strftime('%Y.%j')))
        if os.path.exists(path):
            return True
        return path

    import obspy
    from obspy.clients.fdsn.mass_downloader import CircularDomain, \
        Restrictions, MassDownloader

    domain = CircularDomain(latitude=lat,
                            longitude=lon,
                            minradius=minrad,
                            maxradius=maxrad)

    restrictions = Restrictions(
        # Get data for a whole year.
        starttime=starttime,
        endtime=endtime,
        # Chunk it to have one file per day.
        chunklength_in_sec=86400,
        # Considering the enormous amount of data associated with continuous
        # requests, you might want to limit the data based on SEED identifiers.
        # If the location code is specified, the location priority list is not
        # used; the same is true for the channel argument and priority list.
        network=network,
        station="NA390",
        location="*",
        channel="H*",
        # The typical use case for such a data set are noise correlations where
        # gaps are dealt with at a later stage.
        reject_channels_with_gaps=False,
        # Same is true with the minimum length. All data might be useful.
        minimum_length=0.0,
        # Guard against the same station having different names.
        minimum_interstation_distance_in_m=0.0,
        # Do not sanitize downloads, currently a bug
        sanitize=False,
        location_priorities=("", "01", "00", "EP", "S1", "S3", "02", "10",
                             "09", "08", "03", "04", "06", "07", "05", "20",
                             "T0", "2C", "40", "50"))

    # Restrict the number of providers if you know which serve the desired
    # data. If in doubt just don't specify - then all providers will be
    # queried.
    mdl = MassDownloader(providers=providers)
    mseed_storage = get_mseed_storage
    #  + "/{station}.{network}.{location}.{channel}.{starttime}")
    mdl.download(domain,
                 restrictions,
                 mseed_storage=mseed_storage,
                 stationxml_storage="stations",
                 threads_per_client=5)
Exemplo n.º 25
0
def download(evtime,sec_before,sec_after,lon,lat,minrad,maxrad,provider=["IRIS"],OUT='./'):
    '''
    #example input
    evtime='2000-01-01T06:58:39.780Z'
    sec_before=120
    sec_after=600
    lon=120
    lat=24
    minrad=0
    maxrad=10
    provider=["IRIS"]
    OUT='./TESTDL'
    download(evtime,sec_before,sec_after,lon,lat,minrad,maxrad,provider,OUT)
    '''
    yyyy,mm,dd,HH,MM,SS,NS=cattime2normal(evtime) 
    origin_time = obspy.UTCDateTime(yyyy,mm,dd,HH,MM,SS,NS)
    domain = CircularDomain(latitude=lat, longitude=lon,
                        minradius=minrad, maxradius=maxrad)
    
    
    #domain = RectangularDomain(minlatitude=34.452, maxlatitude=38.72, minlongitude=-123.201, maxlongitude=-118.015)
    
    
    restrictions = Restrictions(
    # Get data from 5 minutes before the event to one hour after the
    # event. This defines the temporal bounds of the waveform data.
    starttime=origin_time - sec_before,
    endtime=origin_time + sec_after,
    # You might not want to deal with gaps in the data. If this setting is
    # True, any trace with a gap/overlap will be discarded.
    reject_channels_with_gaps=True,
    # And you might only want waveforms that have data for at least 95 % of
    # the requested time span. Any trace that is shorter than 95 % of the
    # desired total duration will be discarded.
    minimum_length=0.9,
    # No two stations should be closer than 10 km to each other. This is
    # useful to for example filter out stations that are part of different
    # networks but at the same physical station. Settings this option to
    # zero or None will disable that filtering.
    minimum_interstation_distance_in_m=10E1,
    # Only HH or BH channels. If a station has HH channels, those will be
    # downloaded, otherwise the BH. Nothing will be downloaded if it has
    # neither. You can add more/less patterns if you like.
    #channel_priorities=["HH[ZNE]", "BH[ZNE]"],
    #channel_priorities=["BH[ZNE]"],
    #channel_priorities=["BH[ZNE]"],
    #channel_priorities=["BHZ","HNZ"],
    #channel_priorities=["BHZ"],
    #channel_priorities=["HNZ"],
    channel_priorities=["BHZ","HHZ"],
    #channel_priorities=["HN[ZNE]"],
    # Location codes are arbitrary and there is no rule as to which
    # location is best. Same logic as for the previous setting.
    location_priorities=["", "00", "10","100"])
    
    # No specified providers will result in all known ones being queried.
    #mdl = MassDownloader(providers=provider)
    mdl = MassDownloader(providers=["IRIS"])
    # The data will be downloaded to the ``./waveforms/`` and ``./stations/``
    # folders with automatically chosen file names.
    outstr=evtime.split('T')[0].replace('-','')+str(HH).zfill(2)+str(MM).zfill(2)+str(SS).zfill(2) #save dir as evid
    outmsdir=OUT+'/'+outstr+"/waveforms"
    outstadir=OUT+'/'+outstr+"/stations"
    
    mdl.download(domain, restrictions,threads_per_client=20, mseed_storage=outmsdir,stationxml_storage=outstadir)
    return(outmsdir,outstadir)
Exemplo n.º 26
0
def data_request(cmt_filename, param_path):

    # Request config_file
    request_param_path = os.path.join(param_path,
                                      "RequestParams/RequestParams.yml")

    # Read the parameter file
    rCparams = smart_read_yaml(request_param_path, mpi_mode=is_mpi_env())

    # Earthquake and Station parameters
    cmt_dir = os.path.dirname(cmt_filename)
    station_dir = os.path.join(cmt_dir, "station_data")

    # Get STATIONS file from CMT directory
    stationsfile = os.path.join(station_dir, "STATIONS")

    # Observed output dir
    obsd_dir = os.path.join(cmt_dir, "seismograms", "obs")

    # CMT parameter input
    cmt = CMTSource.from_CMTSOLUTION_file(cmt_filename)
    duration = rCparams['duration']
    starttime_offset = rCparams['starttime_offset']

    starttime = cmt.origin_time + starttime_offset
    endtime = starttime + duration

    # Get station_list from station_file in database entry
    stations = read_station_file(stationsfile)

    # Create list of networks to download from
    networks = list(set([station[0] for station in stations]))
    network_string = ",".join(networks)

    # Set domain containing all locations
    # Rectangular domain containing parts of southern Germany.
    domain = RectangularDomain(minlatitude=-90,
                               maxlatitude=90,
                               minlongitude=-180,
                               maxlongitude=180)

    # Set download restrictions
    restrictions = Restrictions(
        starttime=starttime,
        endtime=endtime,
        reject_channels_with_gaps=False,
        minimum_length=float(rCparams['minimum_length']),
        # Trace needs to be almost full length
        network=network_string,  # Only certain networks
        channel=",".join(rCparams['channels']),
        location=",".join(rCparams['locations']))

    # No specified providers will result in all known ones being queried.
    providers = ["IRIS"]
    mdl = MassDownloader(providers=providers)
    # The data will be downloaded to the ``./waveforms/`` and ``./stations/``
    # folders with automatically chosen file n
    stationxml_storage = os.path.join(station_dir)
    waveform_storage = os.path.join(obsd_dir)
    logger.info("MSEEDs: %s" % waveform_storage)
    logger.info("XMLs: %s" % stationxml_storage)

    mdl.download(domain,
                 restrictions,
                 mseed_storage=waveform_storage,
                 stationxml_storage=stationxml_storage)
Exemplo n.º 27
0
starttime = UTCDateTime(2008, 1, 1)
endtime = UTCDateTime(2011, 1, 1)
ROOTDIR = "/run/media/seisman/Seagate Expansion Drive/DOWNLOADING/"
DATADIR = ROOTDIR + network

domain = RectangularDomain(minlatitude=18,
                           maxlatitude=54,
                           minlongitude=65,
                           maxlongitude=135)

restrictions = Restrictions(
    starttime=starttime,
    endtime=endtime,
    network=network,
    channel="BH?,SH?,LH?",
    chunklength_in_sec=86400,
    reject_channels_with_gaps=False,
    minimum_length=0.0,
    minimum_interstation_distance_in_m=50.0,
    location_priorities=['', '00', '10', '01', '*'],
)


def mseed_storage(network, station, location, channel, starttime, endtime):

    path = os.path.join(
        DATADIR, starttime.strftime("%Y%m%d"),
        "{}.{}.{}.{}.mseed".format(network, station, location, channel))

    if os.path.exists(path):
        return True
Exemplo n.º 28
0
    def retrieveData(self):
        """Retrieve data from many FDSN services, turn into StreamCollection.

        Args:
            event (dict):
                Best dictionary matching input event, fields as above
                in return of getMatchingEvents().

        Returns:
            StreamCollection: StreamCollection object.
        """
        # Bail out if FDSNFetcher not configured
        if 'FDSNFetcher' not in self.config['fetchers']:
            return
        rawdir = self.rawdir
        if self.rawdir is None:
            rawdir = tempfile.mkdtemp()
        else:
            if not os.path.isdir(rawdir):
                os.makedirs(rawdir)

        # use the mass downloader to retrieve data of interest from any FSDN
        # service.
        origin_time = UTCDateTime(self.time)

        # The Obspy mass downloader has it's own logger - grab that stream
        # and write it to our own log file
        ldict = logging.Logger.manager.loggerDict
        if OBSPY_LOGGER in ldict:
            root = logging.getLogger()
            fhandler = root.handlers[0]
            obspy_logger = logging.getLogger(OBSPY_LOGGER)
            obspy_stream_handler = obspy_logger.handlers[0]
            obspy_logger.removeHandler(obspy_stream_handler)
            obspy_logger.addHandler(fhandler)

        # Circular domain around the epicenter.
        domain = CircularDomain(latitude=self.lat,
                                longitude=self.lon,
                                minradius=0,
                                maxradius=self.radius)

        min_dist = self.minimum_interstation_distance_in_m
        restrictions = Restrictions(
            # Define the temporal bounds of the waveform data.
            starttime=origin_time - self.time_before,
            endtime=origin_time + self.time_after,
            network=self.network,
            station='*',
            location='*',
            location_priorities=['*'],
            reject_channels_with_gaps=self.reject_channels_with_gaps,
            # Any trace that is shorter than 95 % of the
            # desired total duration will be discarded.
            minimum_length=self.minimum_length,
            sanitize=self.sanitize,
            minimum_interstation_distance_in_m=min_dist,
            exclude_networks=self.exclude_networks,
            exclude_stations=self.exclude_stations,
            channel_priorities=self.channels)

        # For each of the providers, check if we have a username and password
        # provided in the config. If we do, initialize the client with the
        # username and password. Otherwise, use default initalization.
        client_list = []
        for provider_str in URL_MAPPINGS.keys():
            if provider_str == GEO_NET_ARCHIVE_KEY:
                dt = UTCDateTime.utcnow() - UTCDateTime(self.time)
                if dt < GEONET_ARCHIVE_DAYS:
                    provider_str = GEONET_REALTIME_URL
            try:
                fdsn_config = self.config['fetchers']['FDSNFetcher']
                if provider_str in fdsn_config:
                    client = Client(
                        provider_str,
                        user=fdsn_config[provider_str]['user'],
                        password=fdsn_config[provider_str]['password'])
                else:
                    client = Client(provider_str)
                client_list.append(client)
            # If the FDSN service is down, then an FDSNException is raised
            except FDSNException:
                logging.warning('Unable to initalize client %s' % provider_str)
            except KeyError:
                logging.warning('Unable to initalize client %s' % provider_str)

        if len(client_list):
            # Pass off the initalized clients to the Mass Downloader
            mdl = MassDownloader(providers=client_list)

            logging.info('Downloading new MiniSEED files...')
            # The data will be downloaded to the ``./waveforms/`` and
            # ``./stations/`` folders with automatically chosen file names.
            mdl.download(domain,
                         restrictions,
                         mseed_storage=rawdir,
                         stationxml_storage=rawdir)

            seed_files = glob.glob(os.path.join(rawdir, '*.mseed'))
            streams = []
            for seed_file in seed_files:
                try:
                    tstreams = read_obspy(seed_file, self.config)
                except BaseException as e:
                    tstreams = None
                    fmt = 'Could not read seed file %s - "%s"'
                    logging.info(fmt % (seed_file, str(e)))
                if tstreams is None:
                    continue
                else:
                    streams += tstreams

            stream_collection = StreamCollection(
                streams=streams, drop_non_free=self.drop_non_free)
            return stream_collection
Exemplo n.º 29
0
center = "IRIS"
domain = GlobalDomain()

#stations_list=["AXAS1","AXAS2","AXBA1","AXCC1","AXEC1","AXEC2","AXEC3","AXID1"]
stations_list = "AX*"
client = Client(center)

### Restrictions

restrictions = Restrictions(
    starttime=obspy.UTCDateTime(2015, 1, 1),
    endtime=obspy.UTCDateTime(2016, 1, 1),
    chunklength_in_sec=86400,
    network=network_code,
    station=stations_list,
    # The typical use case for such a data set are noise correlations where
    # gaps are dealt with at a later stage.
    reject_channels_with_gaps=False,
    # Same is true with the minimum length. All data might be useful.
    minimum_length=0.0,
    channel_priorities=["HH[ZNE]", "EH[ZNE]"],
    # Guard against the same station having different names.
    minimum_interstation_distance_in_m=0.0)

### Downlaod Data

mdl = MassDownloader(providers=[center])
mdl.download(domain,
             restrictions,
             mseed_storage="/home/baillard/waveforms/",
             stationxml_storage='/home/baillard/')
Exemplo n.º 30
0
domain = RectangularDomain(minlatitude=52.,
                           maxlatitude=72.5,
                           minlongitude=-172.,
                           maxlongitude=-122.)

restrictions = Restrictions(
    # Get data for a whole year.
    starttime=obspy.UTCDateTime(2017, 6, 11),
    endtime=obspy.UTCDateTime(2017, 6, 21),
    # Chunk it to have one file per day.
    chunklength_in_sec=86400,
    # Considering the enormous amount of data associated with continuous
    # requests, you might want to limit the data based on SEED identifiers.
    # If the location code is specified, the location priority list is not
    # used; the same is true for the channel argument and priority list.
    network="TA",
    station="H20K",
    location="",
    channel="LH?",
    # The typical use case for such a data set are noise correlations where
    # gaps are dealt with at a later stage.
    reject_channels_with_gaps=False,
    # Same is true with the minimum length. All data might be useful.
    minimum_length=0.0,
    # Guard against the same station having different names.
    minimum_interstation_distance_in_m=100.0)

mseed_storage = ("waveforms/{network}/{station}/"
                 "{channel}.{location}.{starttime}.{endtime}.mseed")
stationxml_storage = "stations/{network}/{station}.xml"
# Restrict the number of providers if you know which serve the desired