# Path: gprMax/exceptions.py
# class CmdInputError(ValueError):
#     """Handles errors in user specified commands. Subclasses the ValueError class."""
# 
#     def __init__(self, message, *args):
# 
#         self.message = message
#         super(CmdInputError, self).__init__(message, *args)
#         print(Fore.RED)
# 
# Path: gprMax/receivers.py
# class Rx(object):
#     """Receiver output points."""
# 
#     allowableoutputs = ['Ex', 'Ey', 'Ez', 'Hx', 'Hy', 'Hz', 'Ix', 'Iy', 'Iz']
#     gpu_allowableoutputs = allowableoutputs[:-3]
#     defaultoutputs = allowableoutputs[:-3]
# 
#     def __init__(self):
# 
#         self.ID = None
#         self.outputs = OrderedDict()
#         self.xcoord = None
#         self.ycoord = None
#         self.zcoord = None
#         self.xcoordorigin = None
#         self.ycoordorigin = None
#         self.zcoordorigin = None
# 
# Path: gprMax/utilities.py
# def fft_power(waveform, dt):
#     """Calculate a FFT of the given waveform of amplitude values;
#         converted to decibels and shifted so that maximum power is 0dB
# 
#     Args:
#         waveform (ndarray): time domain waveform
#         dt (float): time step
# 
#     Returns:
#         freqs (ndarray): frequency bins
#         power (ndarray): power
#     """
# 
#     # Calculate magnitude of frequency spectra of waveform (ignore warning from taking a log of any zero values)
#     with np.errstate(divide='ignore'):
#         power = 10 * np.log10(np.abs(np.fft.fft(waveform))**2)
# 
#     # Replace any NaNs or Infs from zero division
#     power[np.invert(np.isfinite(power))] = 0
# 
#     # Frequency bins
#     freqs = np.fft.fftfreq(power.size, d=dt)
# 
#     # Shift powers so that frequency with maximum power is at zero decibels
#     power -= np.amax(power)
# 
#     return freqs, power


import argparse
import os
import sys
import h5py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from gprMax.exceptions import CmdInputError
from gprMax.receivers import Rx
from gprMax.utilities import fft_power
                elif output == 'Ix':
                    ax = plt.subplot(gs[0, 2])
                    ax.plot(time, outputdata, 'b', lw=2, label=outputtext)
                    ax.set_ylabel(outputtext + ', current [A]')
                elif output == 'Iy':
                    ax = plt.subplot(gs[1, 2])
                    ax.plot(time, outputdata, 'b', lw=2, label=outputtext)
                    ax.set_ylabel(outputtext + ', current [A]')
                elif output == 'Iz':
                    ax = plt.subplot(gs[2, 2])
                    ax.plot(time, outputdata, 'b', lw=2, label=outputtext)
                    ax.set_ylabel(outputtext + ', current [A]')
            for ax in fig.axes:
                ax.set_xlim([0, np.amax(time)])
                ax.grid(which='both', axis='both', linestyle='-.')

        # Save a PDF/PNG of the figure
        # fig.savefig(os.path.splitext(os.path.abspath(filename))[0] + '_rx' + str(rx) + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
        # fig.savefig(os.path.splitext(os.path.abspath(filename))[0] + '_rx' + str(rx) + '.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)

    f.close()

    return plt


if __name__ == "__main__":

    # Parse command line arguments
    parser = argparse.ArgumentParser(description='Plots electric and magnetic fields and currents from all receiver points in the given output file. Each receiver point is plotted in a new figure window.', usage='cd gprMax; python -m tools.plot_Ascan outputfile')
    parser.add_argument('outputfile', help='name of output file including path')

# Path: gprMax/exceptions.py
# class CmdInputError(ValueError):
#     """Handles errors in user specified commands. Subclasses the ValueError class."""
# 
#     def __init__(self, message, *args):
# 
#         self.message = message
#         super(CmdInputError, self).__init__(message, *args)
#         print(Fore.RED)
# 
# Path: gprMax/receivers.py
# class Rx(object):
#     """Receiver output points."""
# 
#     allowableoutputs = ['Ex', 'Ey', 'Ez', 'Hx', 'Hy', 'Hz', 'Ix', 'Iy', 'Iz']
#     gpu_allowableoutputs = allowableoutputs[:-3]
#     defaultoutputs = allowableoutputs[:-3]
# 
#     def __init__(self):
# 
#         self.ID = None
#         self.outputs = OrderedDict()
#         self.xcoord = None
#         self.ycoord = None
#         self.zcoord = None
#         self.xcoordorigin = None
#         self.ycoordorigin = None
#         self.zcoordorigin = None
# 
# Path: gprMax/utilities.py
# def fft_power(waveform, dt):
#     """Calculate a FFT of the given waveform of amplitude values;
#         converted to decibels and shifted so that maximum power is 0dB
# 
#     Args:
#         waveform (ndarray): time domain waveform
#         dt (float): time step
# 
#     Returns:
#         freqs (ndarray): frequency bins
#         power (ndarray): power
#     """
# 
#     # Calculate magnitude of frequency spectra of waveform (ignore warning from taking a log of any zero values)
#     with np.errstate(divide='ignore'):
#         power = 10 * np.log10(np.abs(np.fft.fft(waveform))**2)
# 
#     # Replace any NaNs or Infs from zero division
#     power[np.invert(np.isfinite(power))] = 0
# 
#     # Frequency bins
#     freqs = np.fft.fftfreq(power.size, d=dt)
# 
#     # Shift powers so that frequency with maximum power is at zero decibels
#     power -= np.amax(power)
# 
#     return freqs, power


# Path: tools/plot_Ascan.py
import argparse
import os
import sys
import h5py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from gprMax.exceptions import CmdInputError
from gprMax.receivers import Rx
from gprMax.utilities import fft_power

                elif output == 'Ix':
                    ax = plt.subplot(gs[0, 2])
                    ax.plot(time, outputdata, 'b', lw=2, label=outputtext)
                    ax.set_ylabel(outputtext + ', current [A]')
                elif output == 'Iy':
                    ax = plt.subplot(gs[1, 2])
                    ax.plot(time, outputdata, 'b', lw=2, label=outputtext)
                    ax.set_ylabel(outputtext + ', current [A]')
                elif output == 'Iz':
                    ax = plt.subplot(gs[2, 2])
                    ax.plot(time, outputdata, 'b', lw=2, label=outputtext)
                    ax.set_ylabel(outputtext + ', current [A]')
            for ax in fig.axes:
                ax.set_xlim([0, np.amax(time)])
                ax.grid(which='both', axis='both', linestyle='-.')

        # Save a PDF/PNG of the figure
        # fig.savefig(os.path.splitext(os.path.abspath(filename))[0] + '_rx' + str(rx) + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
        # fig.savefig(os.path.splitext(os.path.abspath(filename))[0] + '_rx' + str(rx) + '.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)

    f.close()

    return plt


if __name__ == "__main__":

    # Parse command line arguments
    parser = argparse.ArgumentParser(description='Plots electric and magnetic fields and currents from all receiver points in the given output file. Each receiver point is plotted in a new figure window.', usage='cd gprMax; python -m tools.plot_Ascan outputfile')
    parser.add_argument('outputfile', help='name of output file including path')

    parser.add_argument('--outputs', help='outputs to be plotted', default=Rx.defaultoutputs, choices=['Ex', 'Ey', 'Ez', 'Hx', 'Hy', 'Hz', 'Ix', 'Iy', 'Iz', 'Ex-', 'Ey-', 'Ez-', 'Hx-', 'Hy-', 'Hz-', 'Ix-', 'Iy-', 'Iz-'], nargs='+')