# -*- coding: utf-8 -*-
"""
Created on Mon Sep 28 12:13:17 2020

@author: jbobowsk
"""

# This tutorial is used to demonstrate how to import data stored in a file
# into an array.

import numpy as np 
import matplotlib.pyplot as plt

# Import data.  Use 'np.loadtext()' to import the data contained in the file
# 'short - 085 - 10 MHz - 13.5 GHz - 00.txt'.  In this example, the file
# must be contained in the same folder as the Python script (*.py file).
shortData = np.loadtxt("short - 085 - 10 MHz - 13.5 GHz - 00.txt")

# The np.shape() function tells us that Python has imported the data as a
# matrix with 3201 rows and 3 columns.
print(np.shape(shortData))

# Here's another way to implement the shape function.
print(shortData.shape)

# Here's the matrix of imported data. 
print(shortData)

# In this next example, the file is in a folder called 'folder' that is 
# contained in the same folder as the Python script (*.py file).  This line 
# will only work for you if you create 'folder' and put the data file in it.
shortData = np.loadtxt("folder/short - 085 - 10 MHz - 13.5 GHz - 00.txt")

# It will work even is you use '\' instead of '/' in the file path.
shortData = np.loadtxt("folder\short - 085 - 10 MHz - 13.5 GHz - 00.txt")

# In this example, the entire path leading to the file is specified.  
# This line will not work for you because you won't have the same folder 
# structure that I have.  You'll have to make the appropriate edits.
shortData = np.loadtxt(\
 "G:/UBCO/2020-2021/Python/20200928/folder/short - 085 - 10 MHz - 13.5 GHz - 00.txt")

# To access the individual columns of data, use:
freq = shortData[:, 0]
real = shortData[:, 1]
imag = shortData[:, 2]
print(freq)

# Of course, we can do do mathematical operations on the data arrays.
# For example, here's the manitude of the complex data set ploted on a log-log scale.
mag = np.sqrt(real**2 + imag**2)
plt.loglog(freq, mag)