Exemple #1
0
    def test_segfault_after_error_handling(self):
        """
        Many functions in evalresp call `error_return()` which uses longjmp()
        to jump to some previously set state.

        ObsPy calls some evalresp functions directly so evalresp cannot call
        setjmp(). In that case longjmp() jumps to an undefined location, most
        likely resulting in a segfault.

        This test tests a workaround for this issue.

        As long as it does not segfault the test is doing alright.
        """
        filename = os.path.join(self.data_dir,
                                "TM.SKLT..BHZ_faulty_response.xml")
        inv = read_inventory(filename)

        t_samp = 0.05
        nfft = 256

        with CatchOutput():
            self.assertRaises(
                ValueError,
                inv[0][0][0].response.get_evalresp_response,
                t_samp,
                nfft,
                output="DISP")
Exemple #2
0
    def test_segfault_after_error_handling(self):
        """
        Many functions in evalresp call `error_return()` which uses longjmp()
        to jump to some previously set state.

        ObsPy calls some evalresp functions directly so evalresp cannot call
        setjmp(). In that case longjmp() jumps to an undefined location, most
        likely resulting in a segfault.

        This test tests a workaround for this issue.

        As long as it does not segfault the test is doing alright.
        """
        filename = os.path.join(self.data_dir,
                                "TM.SKLT..BHZ_faulty_response.xml")
        inv = read_inventory(filename)

        t_samp = 0.05
        nfft = 256

        with CatchOutput():
            self.assertRaises(ValueError,
                              inv[0][0][0].response.get_evalresp_response,
                              t_samp,
                              nfft,
                              output="DISP")
Exemple #3
0
    def test_evalresp_with_output_from_seed(self):
        """
        The StationXML file has been converted to SEED with the help of a tool
        provided by IRIS:

        https://seiscode.iris.washington.edu/projects/stationxml-converter
        """
        t_samp = 0.05
        nfft = 16384

        # Test for different output units.
        units = ["DISP", "VEL", "ACC"]
        filenames = ["IRIS_single_channel_with_response", "XM.05", "AU.MEEK"]

        for filename in filenames:
            xml_filename = os.path.join(self.data_dir,
                                        filename + os.path.extsep + "xml")
            seed_filename = os.path.join(self.data_dir,
                                         filename + os.path.extsep + "seed")

            p = Parser(seed_filename)

            # older systems don't like an end date in the year 2599
            t_ = UTCDateTime(2030, 1, 1)
            if p.blockettes[50][0].end_effective_date > t_:
                p.blockettes[50][0].end_effective_date = None
            if p.blockettes[52][0].end_date > t_:
                p.blockettes[52][0].end_date = None

            resp_filename = p.getRESP()[0][-1]

            inv = read_inventory(xml_filename)

            network = inv[0].code
            station = inv[0][0].code
            location = inv[0][0][0].location_code
            channel = inv[0][0][0].code
            date = inv[0][0][0].start_date

            for unit in units:
                resp_filename.seek(0, 0)

                seed_response, seed_freq = evalresp(t_samp,
                                                    nfft,
                                                    resp_filename,
                                                    date=date,
                                                    station=station,
                                                    channel=channel,
                                                    network=network,
                                                    locid=location,
                                                    units=unit,
                                                    freq=True)

                xml_response, xml_freq = \
                    inv[0][0][0].response.get_evalresp_response(t_samp, nfft,
                                                                output=unit)

                self.assertTrue(np.allclose(seed_freq, xml_freq, rtol=1E-5))
                self.assertTrue(
                    np.allclose(seed_response, xml_response, rtol=1E-5))
Exemple #4
0
 def test_response_plot(self):
     """
     Tests the response plot.
     """
     cha = read_inventory()[0][0][0]
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("ignore")
         with ImageComparison(self.image_dir, "channel_response.png") as ic:
             rcParams['savefig.dpi'] = 72
             cha.plot(0.005, outfile=ic.name)
Exemple #5
0
 def test_response_plot(self):
     """
     Tests the response plot.
     """
     cha = read_inventory()[0][0][0]
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("ignore")
         with ImageComparison(self.image_dir, "channel_response.png") as ic:
             rcParams['savefig.dpi'] = 72
             cha.plot(0.005, outfile=ic.name)
Exemple #6
0
    def test_evalresp_with_output_from_seed(self):
        """
        The StationXML file has been converted to SEED with the help of a tool
        provided by IRIS:

        https://seiscode.iris.washington.edu/projects/stationxml-converter
        """
        t_samp = 0.05
        nfft = 16384

        # Test for different output units.
        units = ["DISP", "VEL", "ACC"]
        filenames = ["IRIS_single_channel_with_response", "XM.05", "AU.MEEK"]

        for filename in filenames:
            xml_filename = os.path.join(self.data_dir,
                                        filename + os.path.extsep + "xml")
            seed_filename = os.path.join(self.data_dir,
                                         filename + os.path.extsep + "seed")

            p = Parser(seed_filename)

            # older systems don't like an end date in the year 2599
            t_ = UTCDateTime(2030, 1, 1)
            if p.blockettes[50][0].end_effective_date > t_:
                p.blockettes[50][0].end_effective_date = None
            if p.blockettes[52][0].end_date > t_:
                p.blockettes[52][0].end_date = None

            resp_filename = p.getRESP()[0][-1]

            inv = read_inventory(xml_filename)

            network = inv[0].code
            station = inv[0][0].code
            location = inv[0][0][0].location_code
            channel = inv[0][0][0].code
            date = inv[0][0][0].start_date

            for unit in units:
                resp_filename.seek(0, 0)

                seed_response, seed_freq = evalresp(
                    t_samp, nfft, resp_filename, date=date, station=station,
                    channel=channel, network=network, locid=location,
                    units=unit, freq=True)

                xml_response, xml_freq = \
                    inv[0][0][0].response.get_evalresp_response(t_samp, nfft,
                                                                output=unit)

                self.assertTrue(np.allclose(seed_freq, xml_freq, rtol=1E-5))
                self.assertTrue(np.allclose(seed_response, xml_response,
                                            rtol=1E-5))
Exemple #7
0
 def test_response_plot(self):
     """
     Tests the response plot.
     """
     resp = read_inventory()[0][0][0].response
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("ignore")
         with ImageComparison(self.image_dir, "response_response.png") \
                 as ic:
             rcParams['savefig.dpi'] = 72
             resp.plot(0.001, output="VEL", start_stage=1, end_stage=3,
                       outfile=ic.name)
Exemple #8
0
 def test_response_plot(self):
     """
     Tests the response plot.
     """
     resp = read_inventory()[0][0][0].response
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("ignore")
         with ImageComparison(self.image_dir, "response_response.png") \
                 as ic:
             rcParams['savefig.dpi'] = 72
             resp.plot(0.001,
                       output="VEL",
                       start_stage=1,
                       end_stage=3,
                       outfile=ic.name)
Exemple #9
0
    def test_response_plot(self):
        """
        Tests the response plot.
        """
        # Bug in matplotlib 1.4.0 - 1.4.2:
        # See https://github.com/matplotlib/matplotlib/issues/4012
        reltol = 1.0
        if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 4, 2]:
            reltol = 2.0

        sta = read_inventory()[0][0]
        with warnings.catch_warnings(record=True):
            warnings.simplefilter("ignore")
            with ImageComparison(self.image_dir, "station_response.png", reltol=reltol) as ic:
                rcParams["savefig.dpi"] = 72
                sta.plot(0.05, channel="*[NE]", outfile=ic.name)
Exemple #10
0
    def test_response_plot(self):
        """
        Tests the response plot.
        """
        # Bug in matplotlib 1.4.0 - 1.4.2:
        # See https://github.com/matplotlib/matplotlib/issues/4012
        reltol = 1.0
        if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 4, 2]:
            reltol = 2.0

        sta = read_inventory()[0][0]
        with warnings.catch_warnings(record=True):
            warnings.simplefilter("ignore")
            with ImageComparison(self.image_dir, "station_response.png",
                                 reltol=reltol) as ic:
                rcParams['savefig.dpi'] = 72
                sta.plot(0.05, channel="*[NE]", outfile=ic.name)
Exemple #11
0
    def test_response_plot(self):
        """
        Tests the response plot.
        """
        # Bug in matplotlib 1.4.0 - 1.4.2:
        # See https://github.com/matplotlib/matplotlib/issues/4012
        reltol = 1.0
        if [1, 4, 0] <= MATPLOTLIB_VERSION <= [1, 4, 2]:
            reltol = 2.0

        resp = read_inventory()[0][0][0].response
        with warnings.catch_warnings(record=True):
            warnings.simplefilter("ignore")
            with ImageComparison(self.image_dir, "response_response.png",
                                 reltol=reltol) as ic:
                rcParams['savefig.dpi'] = 72
                resp.plot(0.001, output="VEL", start_stage=1, end_stage=3,
                          outfile=ic.name)
            fnmatch.fnmatch(station_name, exclude_station_patterns):
        continue

    print "File %i of %i (%s)..." % (_i + 1, len(station_files), xml_file)

    # Find the corresponding SEED file.
    seed_file = os.path.join(
        seed,
        os.path.splitext(os.path.basename(xml_file))[0] + os.path.extsep +
        "seed")
    if not os.path.exists(seed_file):
        msg = "Could not find SEED file '%s'. Will be skipped" % seed_file
        print_warning(msg)
        continue

    inv = read_inventory(xml_file, format="stationxml")
    net_id = inv[0].code
    stat_id = inv[0][0].code

    # Loop over every channel.
    for channel in inv[0][0]:

        # Nothing to be done if it has no response.
        if not channel.response:
            print_info("No response found...")
            continue

        if channel.end_date:
            date = channel.start_date + 0.5 * (channel.end_date -
                                               channel.start_date)
        else:
            fnmatch.fnmatch(station_name, exclude_station_patterns):
        continue

    print "File %i of %i (%s)..." % (_i + 1, len(station_files), xml_file)

    # Find the corresponding SEED file.
    seed_file = os.path.join(
        seed,
        os.path.splitext(
            os.path.basename(xml_file))[0] + os.path.extsep + "seed")
    if not os.path.exists(seed_file):
        msg = "Could not find SEED file '%s'. Will be skipped" % seed_file
        print_warning(msg)
        continue

    inv = read_inventory(xml_file, format="stationxml")
    net_id = inv[0].code
    stat_id = inv[0][0].code

    # Loop over every channel.
    for channel in inv[0][0]:

        # Nothing to be done if it has no response.
        if not channel.response:
            print_info("No response found...")
            continue

        if channel.end_date:
            date = channel.start_date + 0.5 * (channel.end_date -
                                               channel.start_date)
        else:
Exemple #14
0
:copyright:
    Lion Krischer ([email protected]), 2014
:license:
    GNU Lesser General Public License, Version 3
    (http://www.gnu.org/copyleft/lesser.html)
"""
import colorama
from obspy.station import read_inventory
from obspy.fdsn import Client
import os

output_dir = "StationXML"

c = Client()

inv = read_inventory("./all_stations.xml")


def print_error(msg):
    print colorama.Fore.RED + msg + colorama.Fore.RESET


def print_ok(msg):
    print colorama.Fore.GREEN + msg + colorama.Fore.RESET


for network in inv.networks:
    for station in network.stations:
        output_filename = os.path.join(
            output_dir, "%s.%s.xml" % (network.code, station.code))
        if os.path.exists(output_filename):
:copyright:
    Lion Krischer ([email protected]), 2014
:license:
    GNU Lesser General Public License, Version 3
    (http://www.gnu.org/copyleft/lesser.html)
"""
import colorama
from obspy.station import read_inventory
from obspy.fdsn import Client
import os

output_dir = "StationXML"

c = Client()

inv = read_inventory("./all_stations.xml")


def print_error(msg):
    print colorama.Fore.RED + msg + colorama.Fore.RESET


def print_ok(msg):
    print colorama.Fore.GREEN + msg + colorama.Fore.RESET


for network in inv.networks:
    for station in network.stations:
        output_filename = os.path.join(output_dir, "%s.%s.xml" % (network.code, station.code))
        if os.path.exists(output_filename):
            continue