def plot(self, min_freq, output="VEL", location="*", channel="*", time=None, starttime=None, endtime=None, axes=None, unwrap_phase=False, show=True, outfile=None): """ Show bode plot of instrument response of all (or a subset of) the station's channels. :type min_freq: float :param min_freq: Lowest frequency to plot. :type output: str :param output: Output units. One of: ``"DISP"`` displacement, output unit is meters ``"VEL"`` velocity, output unit is meters/second ``"ACC"`` acceleration, output unit is meters/second**2 :type location: str :param location: Only plot matching channels. Accepts UNIX style patterns and wildcards (e.g. ``"BH*"``, ``"BH?"``, ``"*Z"``, ``"[LB]HZ"``; see :func:`~fnmatch.fnmatch`) :type channel: str :param channel: Only plot matching channels. Accepts UNIX style patterns and wildcards (e.g. ``"BH*"``, ``"BH?"``, ``"*Z"``, ``"[LB]HZ"``; see :func:`~fnmatch.fnmatch`) :param time: Only show channels active at given point in time. :type starttime: :class:`~obspy.core.utcdatetime.UTCDateTime` :param starttime: Only show channels active at or after given point in time (i.e. channels ending before given time will not be shown). :type endtime: :class:`~obspy.core.utcdatetime.UTCDateTime` :param endtime: Only show channels active before or at given point in time (i.e. channels starting after given time will not be shown). :type axes: list of 2 :class:`matplotlib.axes.Axes` :param axes: List/tuple of two axes instances to plot the amplitude/phase spectrum into. If not specified, a new figure is opened. :type unwrap_phase: bool :param unwrap_phase: Set optional phase unwrapping using NumPy. :type show: bool :param show: Whether to show the figure after plotting or not. Can be used to do further customization of the plot before showing it. :type outfile: str :param outfile: Output file path to directly save the resulting image (e.g. ``"/tmp/image.png"``). Overrides the ``show`` option, image will not be displayed interactively. The given path/file name is also used to automatically determine the output format. Supported file formats depend on your matplotlib backend. Most backends support png, pdf, ps, eps and svg. Defaults to ``None``. .. rubric:: Basic Usage >>> from obspy import read_inventory >>> sta = read_inventory()[0][0] >>> sta.plot(0.001, output="VEL", channel="*Z") # doctest: +SKIP .. plot:: from obspy import read_inventory sta = read_inventory()[0][0] sta.plot(0.001, output="VEL", channel="*Z") """ import matplotlib.pyplot as plt if axes: ax1, ax2 = axes fig = ax1.figure else: fig = plt.figure() ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212, sharex=ax1) matching = self.select(location=location, channel=channel, time=time, starttime=starttime, endtime=endtime) for cha in matching.channels: try: cha.plot(min_freq=min_freq, output=output, axes=(ax1, ax2), label=".".join( (self.code, cha.location_code, cha.code)), unwrap_phase=unwrap_phase, show=False, outfile=None) except ZeroSamplingRate: msg = ("Skipping plot of channel with zero " "sampling rate:\n%s") warnings.warn(msg % str(cha), UserWarning) except ObsPyException as e: msg = "Skipping plot of channel (%s):\n%s" warnings.warn(msg % (str(e), str(cha)), UserWarning) # final adjustments to plot if we created the figure in here if not axes: from obspy.core.inventory.response import _adjust_bode_plot_figure _adjust_bode_plot_figure(fig, show=False) if outfile: fig.savefig(outfile) else: if show: plt.show() return fig
def plot_response(self, min_freq, output="VEL", network="*", station="*", location="*", channel="*", time=None, starttime=None, endtime=None, axes=None, unwrap_phase=False, show=True, outfile=None): """ Show bode plot of instrument response of all (or a subset of) the inventory's channels. :type min_freq: float :param min_freq: Lowest frequency to plot. :type output: str :param output: Output units. One of: * ``"DISP"`` -- displacement, output unit is meters; * ``"VEL"`` -- velocity, output unit is meters/second; or, * ``"ACC"`` -- acceleration, output unit is meters/second**2. :type network: str :param network: Only plot matching networks. Accepts UNIX style patterns and wildcards (e.g. ``"G*"``, ``"*[ER]"``; see :func:`~fnmatch.fnmatch`) :type station: str :param station: Only plot matching stations. Accepts UNIX style patterns and wildcards (e.g. ``"L44*"``, ``"L4?A"``, ``"[LM]44A"``; see :func:`~fnmatch.fnmatch`) :type location: str :param location: Only plot matching channels. Accepts UNIX style patterns and wildcards (e.g. ``"BH*"``, ``"BH?"``, ``"*Z"``, ``"[LB]HZ"``; see :func:`~fnmatch.fnmatch`) :type channel: str :param channel: Only plot matching channels. Accepts UNIX style patterns and wildcards (e.g. ``"BH*"``, ``"BH?"``, ``"*Z"``, ``"[LB]HZ"``; see :func:`~fnmatch.fnmatch`) :type time: :class:`~obspy.core.utcdatetime.UTCDateTime` :param time: Only regard networks/stations/channels active at given point in time. :type starttime: :class:`~obspy.core.utcdatetime.UTCDateTime` :param starttime: Only regard networks/stations/channels active at or after given point in time (i.e. networks ending before given time will not be shown). :type endtime: :class:`~obspy.core.utcdatetime.UTCDateTime` :param endtime: Only regard networks/stations/channels active before or at given point in time (i.e. networks starting after given time will not be shown). :type axes: list of 2 :class:`matplotlib.axes.Axes` :param axes: List/tuple of two axes instances to plot the amplitude/phase spectrum into. If not specified, a new figure is opened. :type unwrap_phase: bool :param unwrap_phase: Set optional phase unwrapping using NumPy. :type show: bool :param show: Whether to show the figure after plotting or not. Can be used to do further customization of the plot before showing it. :type outfile: str :param outfile: Output file path to directly save the resulting image (e.g. ``"/tmp/image.png"``). Overrides the ``show`` option, image will not be displayed interactively. The given path/file name is also used to automatically determine the output format. Supported file formats depend on your matplotlib backend. Most backends support png, pdf, ps, eps and svg. Defaults to ``None``. .. rubric:: Basic Usage >>> from obspy import read_inventory >>> inv = read_inventory() >>> inv.plot_response(0.001, station="RJOB") # doctest: +SKIP .. plot:: from obspy import read_inventory inv = read_inventory() inv.plot_response(0.001, station="RJOB") """ import matplotlib.pyplot as plt if axes: ax1, ax2 = axes fig = ax1.figure else: fig = plt.figure() ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212, sharex=ax1) matching = self.select(network=network, station=station, location=location, channel=channel, time=time, starttime=starttime, endtime=endtime) for net in matching.networks: for sta in net.stations: for cha in sta.channels: try: cha.plot(min_freq=min_freq, output=output, axes=(ax1, ax2), label=".".join((net.code, sta.code, cha.location_code, cha.code)), unwrap_phase=unwrap_phase, show=False, outfile=None) except ZeroSamplingRate: msg = ("Skipping plot of channel with zero " "sampling rate:\n%s") warnings.warn(msg % str(cha), UserWarning) except ObsPyException as e: msg = "Skipping plot of channel (%s):\n%s" warnings.warn(msg % (str(e), str(cha)), UserWarning) # final adjustments to plot if we created the figure in here if not axes: from obspy.core.inventory.response import _adjust_bode_plot_figure _adjust_bode_plot_figure(fig, show=False) if outfile: fig.savefig(outfile) else: if show: plt.show() return fig