Plot peak frequencies from text file.


In [1]:
%matplotlib inline
import matplotlib.pyplot as plt

In [2]:
import numpy as np
import pandas as pd

In [3]:
# REad dataframe.
file_path = '../data_in/Mdau_TE384_ANALYSIS_RESULTS.txt'
file_path = '../data_in/Ppip_TE384_ANALYSIS_RESULTS.txt'
#file_path = '../data_in/Myotis-Plecotus-Eptesicus_TE384_ANALYSIS_RESULTS.txt'

peak_df = pd.read_csv(file_path, sep="\t")
peak_df.head()


---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-3-6b1dee34b91f> in <module>
      4 #file_path = '../data_in/Myotis-Plecotus-Eptesicus_TE384_ANALYSIS_RESULTS.txt'
      5 
----> 6 peak_df = pd.read_csv(file_path, sep="\t")
      7 peak_df.head()

~/Desktop/dev/w_cloudedbats/cloudedbats_dsp/venv/lib/python3.6/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
    683         )
    684 
--> 685         return _read(filepath_or_buffer, kwds)
    686 
    687     parser_f.__name__ = name

~/Desktop/dev/w_cloudedbats/cloudedbats_dsp/venv/lib/python3.6/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
    455 
    456     # Create the parser.
--> 457     parser = TextFileReader(fp_or_buf, **kwds)
    458 
    459     if chunksize or iterator:

~/Desktop/dev/w_cloudedbats/cloudedbats_dsp/venv/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, f, engine, **kwds)
    893             self.options["has_index_names"] = kwds["has_index_names"]
    894 
--> 895         self._make_engine(self.engine)
    896 
    897     def close(self):

~/Desktop/dev/w_cloudedbats/cloudedbats_dsp/venv/lib/python3.6/site-packages/pandas/io/parsers.py in _make_engine(self, engine)
   1133     def _make_engine(self, engine="c"):
   1134         if engine == "c":
-> 1135             self._engine = CParserWrapper(self.f, **self.options)
   1136         else:
   1137             if engine == "python":

~/Desktop/dev/w_cloudedbats/cloudedbats_dsp/venv/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
   1915         kwds["usecols"] = self.usecols
   1916 
-> 1917         self._reader = parsers.TextReader(src, **kwds)
   1918         self.unnamed_cols = self._reader.unnamed_cols
   1919 

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: [Errno 2] File b'../data_in/Ppip_TE384_ANALYSIS_RESULTS.txt' does not exist: b'../data_in/Ppip_TE384_ANALYSIS_RESULTS.txt'

In [ ]:
# Calculate and add columns.
peak_df['frequency_khz'] = peak_df.frequency_hz / 1000
#absmin = abs(min(peak_df.amplitude_dbfs))
#print(absmin)
#peak_df['plot_size'] = (peak_df.amplitude_dbfs + absmin) **1.2
#peak_df.head()

In [ ]:
# Calculate time for compressed view, with no space between chirps. 
peak_df['time_compressed_s'] = [x*0.125/1000 for x in range(0, len(peak_df.index))]
peak_df.head()

In [ ]:
# Rename columns before plotting.
peak_df.rename(columns={'time_s': 'Time (s)', 
                        'frequency_khz': 'Frequency (kHz)', 
                        'amplitude_dbfs': 'Amplitude (dBFS)', 
                        'time_compressed_s': 'Compressed time (s)'}, inplace=True)

In [ ]:
# Plot two diagrams, normal and compressed time.
fig, (ax1, ax2) = plt.subplots(2,1,
                       figsize=(16, 5), 
                       dpi=150, 
                       #facecolor='w', 
                       #edgecolor='k',
                              )
# ax1.
peak_df.plot(kind='scatter',
             x='Time (s)',
             y='Frequency (kHz)',
             s=1,
             c='Amplitude (dBFS)',
             cmap=plt.get_cmap('Reds'),  #'YlOrRd'
             alpha=0.5,
             ax=ax1)
ax1.set_title('File: ' + file_path)
ax1.set_ylim((0,120))
ax1.minorticks_on()
ax1.grid(which='major', linestyle='-', linewidth='0.5', alpha=0.6)
ax1.grid(which='minor', linestyle='-', linewidth='0.5', alpha=0.3)
ax1.tick_params(which='both', top='off', left='off', right='off', bottom='off') 
# ax2.
peak_df.plot(kind='scatter',
             x='Compressed time (s)',
             y='Frequency (kHz)',
             s=1,
             c='Amplitude (dBFS)',
             cmap=plt.get_cmap('Reds'),  #'YlOrRd'
             alpha=0.5,
             ax=ax2)
ax2.set_ylim((0,120))
ax2.minorticks_on()
ax2.grid(which='major', linestyle='-', linewidth='0.5', alpha=0.6)
ax2.grid(which='minor', linestyle='-', linewidth='0.5', alpha=0.3)
ax2.tick_params(which='both', top='off', left='off', right='off', bottom='off') 

plt.tight_layout()
fig.savefig('test.png')
plt.show()

In [ ]: