Question
Part 1 - wave.py First we will practice some file I/O (/0 or 10 is short for Input/Output). Starting with file input. In wave.py, write
Part 1 - wave.py First we will practice some file I/O (\"\\/0\" or \"10\" is short for \"Input/Output\"). Starting with file input. In wave.py, write the function read_parameters o The function has one parameter that takes in the relative path to a data file The data files are given in the data folder of this repo. The files have multiple lines, but are two numbers separated by TAB characters ('\\t') o Read in the data and return as a list of tuples of two numbers Add a properly formatted and descriptive doc -string to the function definition o Test this part with test_read_parameters.py Add the main method to the wave.py that # name o Properly use the if _main__.'. construct o Define a variable for the particular file path . We will be using short.csv for this lab, but your code should work for additional files in the future! o Calls read parameters and accepts the return value o Prints the values using nicely formatted strings Define a header with Amplitude\" and \"Frequency as labels - Center formatted numbers under these in order Use four decimal places for both The output should match what is in text file, but be formatted . Git usage o Follow good coding practice by coding incrementally and committing frequently At least 4 commits is reasonable suggested commit points In wave.py, write get_time_vector o This function takes two parameters, end time and number of time steps name the variables as you wish, but something professional and fitting style guide o Returns a list of length equal to the number of time steps + 1 starting a 0 and ending at the designated end time . For example, given ending time of 10, and two time steps, you return [0.0, 5.0, 10.0] o Add a call to this method from your main method and print return value a Test with a few different values, and reasonable number of (eg 5 to 10 time steps) - Test with test_time_vector.py Commit and push appropriately during development and make a commit after this is working In wave.py, write get wave function o Takes two parameters a tuple of two floats, and a list for time vector o Returns three lists: angles, sine, and scaled wave . angles list is the angle in radians corresponding to each time - product of the second element of the tuple (e.g. frequency) for each time - For example, given the values (1.5, 0.5), (0.0, 5.0, 1.0) as input - the angles list is [0.0, 2.5, 5.0] in radians - sine wave list is the calculation of the sine of each angle in angle list Use math.sin - So given (1.5, 0.5), (0.0, 5.0, 10.01 as input to get wave. - you would return approximately [0.0, 0.598, +0.959, for the sine wave list angles list is the angle in radians corresponding to each time . product of the second element of the tuple (e.g. frequency) for each time . For example, given the values (1.5, 0.5), (0.0, 5.0, 10.0] as input the angles list is [0.0, 2.5, 5.a) in radians sine wave list is the calculation of the sine of each angle in angle list Use math.sin . So given (1.5, 0.5), (0.0, 5.0, 10.0) as input to get_wave. - you would retum approximately (0.0, 0.598,-0.959, ) for the sine wave list scaled wave list is the product of the amplitude (first element of tuple) and sine of each angle in angle list . So given (1.5, 0.5), (0.0, 5.0, 10.0) as input to get_wave - you would retum approximately (0.0, 0.898, 1.438, ] for the scaled wave list o Call the function from your main method using your time vector from above using the amplitude, frequency) tuple of (1.5, 0.5) print the time, angle, and wave values for each time in time vector Test with test_get_wave.py Write methods to do some sine wave magic for us, while we practice file I/0, loops and lists, and Matplotliblib Read the entire README first! (It's called README for a reason.) You are expected to code incrementally, test, and commit regularly. You are expected to make significant progress during lab, so don't \"spin your wheels\" too long if you are stuck. limport matplotlib import os import csv import numpy as py I The function read_parameters takes the data in the short.csv file and turn them into tuple with two numbers each. IIIIII MD 1 README.md X te plot_waves.py X te wave.py short.csv .8105694691387022 1.5707963267948966 -0.09006327434874468 4.71238898038469 0.03242277876554809 7.853981633974483 2 3 4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started