CSC 223 - Python for Scientific Programming & Data Manipulation, Fall 2023, TuTh 4:30-5:45 PM, Old Main 159.

Assignment 2 Specification, code is due by end of October 19 via make turnitin on acad or mcgonagall.

Perform the following steps on acad or mcgonagall after logging into your account via putty or ssh:

cd                                    # places you into your login directory
mkdir Scripting              # all of your csc223 projects go into this directory
cd  ./Scripting                 # makes Scripting your current working directory, it probably already exists
cp  ~parson/Scripting/CSC223f23WAVEassn2.problem.zip  CSC223f23WAVEassn2.problem.zip
unzip  CSC223f23WAVEassn2.problem.zip    # unzips your working copy of the project directory
cd  ./CSC223f23WAVEassn2                            # your project working directory

Perform all test execution on mcgonagall to avoid any platform-dependent output differences.
All input and output data files in Assignment 2 are small and reside in your project directory.
Here are the files of interest in this project directory. There are a few you can ignore.

CSC223f23WAVEassn2.py  #
your work goes here, generating discrete waveform steps for trig & linear functions
CSC223f23WaveParams.csv     # input configuration data to
CSC223f23WAVEassn2.py
makefile                             # the Linux make utility uses this script to direct testing & data viz graphing actions
makelib                              # my library for the makefile
arfflib_3_3.py                     # my utility for manipulating typed CSV data as used in the Weka data mining toolset
plotcsv_1_3.py                 # a Python script that uses matplotlib and arfflib_3_3 to plot your output data graphs
makegraphs.sh                 # a bash shell script to run
plotcsv_1_3.py on columns of data in the output CSV files
reffiles                                # a subdirectory holding expected output reference files for test comparisons using diff
debug.sh
                            # bash script that performs individual tests on each waveform output data 1 at a time
README.txt                       # a documentation file showing important steps in output file CSC223f23WAVEassn2.csv
__pycache__                     # a subdirectory where Python stores compiled byte codes temporarily


After a successful make test there are these additional files.

$ ls -lrt        # After a run of the two Python scripts, files unrelated to symbolic links not shown.
...
-rw-r--r--. 1 parson domain users  2202 Sep 10 11:43 CSC223f23WAVEassn2.csv
-rw-r--r--. 1 parson domain users   910 Sep 10 11:43 CSC223f23WAVEassn2.txt
-rw-r--r--. 1 parson domain users     0 Sep 10 11:43 timestep.dif
-rw-r--r--. 1 parson domain users     0 Sep 10 11:43 triangle.dif
-rw-r--r--. 1 parson domain users     0 Sep 10 11:43 sine.dif
-rw-r--r--. 1 parson domain users     0 Sep 10 11:43 cos.dif
-rw-r--r--. 1 parson domain users     0 Sep 10 11:43 square.dif
-rw-r--r--. 1 parson domain users     0 Sep 10 11:43 pulse.dif
-rw-r--r--. 1 parson domain users     0 Sep 10 11:43 risingsaw.dif
-rw-r--r--. 1 parson domain users   333 Sep 10 11:43 tmpout.csv
-rw-r--r--. 1 parson domain users   333 Sep 10 11:43 tmpref.csv
-rw-r--r--. 1 parson domain users     0 Sep 10 11:43 fallingsaw.dif
-rw-r--r--. 1 parson domain users     0 Sep 10 11:43 CSC223f23WAVEassn2.txt.dif


Here are the configuration data in
CSC223f23WaveParams.csv. We will discuss this in class.

WaveType,Frequency,SampleRate,Duration,DutyCycle
triangle,1000.0,44100,1,0.25
sine,1000.0,44100,1,0.25
cos,1000.0,44100,1,0.25
square,1000.0,44100,1,0.25
pulse,1000.0,44100,1,0.25
risingsaw,1000.0,44100,1,0.25
fallingsaw,1000.0,44100,1,0.25

CSC223f23WAVEassn2.csv
is your output data and
CSC223f23WAVEassn2.txt is your statistical report.
The reffiles/ directory has my copy of these two files for comparing output to expected output.
The makefile compares your output files to the reffiles/ reference files automatically during make test.
When make test reports an error, any difference from the output to the reference output shows up in
    one or more of the .dif files. We will go over README.txt as it relates to expected output in class.

The handout code should test OK for timestep, sine, and risingsaw waveforms. Here is a successful test run.
$ make test
/bin/rm -f *.o *.class .jar core *.exe *.obj *.pyc __pycache__/*.pyc
/bin/rm -f junk* *.pyc *.png CSC223f23WAVEassn2.csv tmpout.csv tmpref.csv
/bin/rm -f *.tmp *.o *.dif *.out __pycache__/* CSC223f23WAVEassn2.txt
/bin/rm -f *.dif
/usr/local/bin/python3.7 CSC223f23WAVEassn2.py
# /usr/local/bin/python3.7 diffcsv.py CSC223f23WAVEassn2.csv  reffiles/CSC223f23WAVEassn2.csv
# diff --ignore-trailing-space --strip-trailing-cr --ignore-all-space CSC223f23WAVEassn2.csv reffiles/CSC223f23WAVEassn2.csv > CSC223f23WAVEassn2.dif
make debug
make[1]: Entering directory `/home/kutztown.edu/parson/private/csc223_fall2023/solutions/CSC223f23WAVEassn2'
bash debug.sh
column timestep is OK
column triangle is OK
column sine is OK
column cos is OK
column square is OK
column pulse is OK
column risingsaw is OK
column fallingsaw is OK
make[1]: Leaving directory `/home/kutztown.edu/parson/private/csc223_fall2023/solutions/CSC223f23WAVEassn2'
diff --ignore-trailing-space --strip-trailing-cr CSC223f23WAVEassn2.txt reffiles/CSC223f23WAVEassn2.txt > CSC223f23WAVEassn2.txt.dif

Here is what make graphs produces after a successful run. Signal levels range from -32767 to 32767.

CSC223f23WAVEassn2.png

For the handout code, triangle, cos, square, pulse, and fallingsaw are 0.
Running make graphs will create the graphs for columns in the output CSV file.
UPDATE 9/26: You will have to copy generated PNG files to your local machine using
WinSCP or FileZilla. KUIT has disabled read permission needed to access your acad PNGs
via a browser. Also, making graphs is optional. If make test works, you don't need the graphs.


$ make graphs
bash ./makegraphs.sh
mkdir: cannot create directory ‘/home/kutztown.edu/parson/public_html’: File exists
DEBUG X TYPE <class 'float'> 0.0
DEBUG FLIPPED genFile True
X is timestep Type is <class 'float'>
MEAN 22.0 MEDIAN 22.0 PSTDEV 12.987173159185437 MIN 0.0 MAX 44.0
Y is fallingsaw Type is <class 'float'>
DEBUG OUTPUT genFile is True
BROWSE https://acad.kutztown.edu/~parson/CSC223f23WAVEassn2.png
Use WinSCP or FileZilla to get at the OPTIONAL make graphs PNG files.

Use your work's graphs for visual detection of bugs and make clobber to remove all PNG files for storage recovery.

$ make clobber
/bin/rm -f *.o *.class .jar core *.exe *.obj *.pyc __pycache__/*.pyc
/bin/rm -f junk* *.pyc *.png CSC223f23WAVEassn2.csv tmpout.csv tmpref.csv
/bin/rm -f *.tmp *.o *.dif *.out __pycache__/* CSC223f23WAVEassn2.txt
/bin/rm -f *.dif
/bin/rm -f $HOME/public_html/CSC223f23*.png

There are some intentional asymmetries among waveforms in the generated data and the above graph.
The last discrete step of the sin, cos, and triangle waveforms is the same as their starting levels.
That would actually be the start of the next cycle of that waveform.
The square, pulse, risingsaw, and fallingsaw waveforms do not return to their starting levels.
I used this asymmetry for visual aesthetic reasons and to simplify the coding.
These timesteps in README.txt are critical in showing start, end, zero-crossing, and midway levels.

TS triangle sine cos square pulse risingsaw fallingsaw
0 -32767 -32767 32767 -32767 -32767 -32767 32767
11 0 0 0 -32767 -32767 -16384 16384
22 32767 32767 -32767 32767 -32767 0 0
33 0 0 0 32767 32767 16383 -16383
44 -32767 -32767 32767 32767 32767 32767 -32767


There are 45 timesteps in these data, 0 through 44, with levels varying from -32767 through 32767.
These are the levels used in 16-bit digital audio data, for example in WAV files.
My code for sin and risingsaw serve as examples for how to code the remaining functions.
We will go over the structure and STUDENT requirements of
CSC223f23WAVEassn2.py in class.

$ make STUDENT
grep 'STUDENT [0-9].*%' CSC223f23WAVEassn2.py
# STUDENT 1: 5% Complete documentation at top of CSC223f23WAVEassn2.py.
# STUDENT 2: 19% Write function genTri() to generate a triangle wave
# STUDENT 3: 19% Write function genCosine() to generate a cosine wave
# STUDENT 4: 19% Write function genSquare() to generate a square wave
# STUDENT 5: 19% Write function genPulse() to generate a pulse wave
# STUDENT 6: 19% Write function genFallSaw() to generate a falling sawtooth

If make test fails, look at the non-empty .dif files.

Finally, use make turnitin (NOT the turnin script) and hit Enter at the prompt. If you make changes after make turnitin,
just run it again to over-write the previous submission. That is due by end of 10/XX. I distribute grades via email, not D2L.

$ make turnitin
/bin/rm -f *.o *.class .jar core *.exe *.obj *.pyc __pycache__/*.pyc
/bin/rm -f junk* *.pyc *.png CSC223f23WAVEassn2.csv tmpout.csv tmpref.csv
/bin/rm -f *.tmp *.o *.dif *.out __pycache__/* CSC223f23WAVEassn2.txt
/bin/rm -f *.dif

Do you really want to send CSC223f23WAVEassn2 to Professor Parson?
Hit Enter to continue, control-C to abort.


/bin/bash -c "cd .. ; /bin/chmod 700 . ; \
/bin/tar cvf ./CSC223f23WAVEassn2_parson.tar CSC223f23WAVEassn2 ; \
/bin/gzip ./CSC223f23WAVEassn2_parson.tar ; \
/bin/chmod 666 ./CSC223f23WAVEassn2_parson.tar.gz ; \
/bin/mv ./CSC223f23WAVEassn2_parson.tar.gz ~parson/incoming"
CSC223f23WAVEassn2/
CSC223f23WAVEassn2/makelib
CSC223f23WAVEassn2/arfflib_3_3.py
CSC223f23WAVEassn2/__pycache__/
CSC223f23WAVEassn2/reffiles/
CSC223f23WAVEassn2/reffiles/CSC223f23WAVEassn2.txt
CSC223f23WAVEassn2/reffiles/CSC223f23WAVEassn2.csv
CSC223f23WAVEassn2/plotcsv_1_3.py
CSC223f23WAVEassn2/CSC223f23WaveParams.csv
CSC223f23WAVEassn2/debug.sh
CSC223f23WAVEassn2/README.txt
CSC223f23WAVEassn2/CSC223f23WAVEassn2.py
CSC223f23WAVEassn2/makegraphs.sh
CSC223f23WAVEassn2/makefile

ADDENDUM 10/4/2023 after yesterday's work session.

Running make graphs may not work and is not as useful as the following approach.

When you run make test, the waveform tests that say OK are completed.

bash debug.sh
column timestep is OK
column triangle has PROBLEMS
-rw-r--r--. 1 parson domain users 556 Oct 4 08:18 triangle.dif
column sine is OK
column cos has PROBLEMS
-rw-r--r--. 1 parson domain users 559 Oct 4 08:18 cos.dif
column square has PROBLEMS
-rw-r--r--. 1 parson domain users 576 Oct 4 08:18 square.dif
column pulse has PROBLEMS
-rw-r--r--. 1 parson domain users 587 Oct 4 08:18 pulse.dif
column risingsaw is OK
column fallingsaw has PROBLEMS
-rw-r--r--. 1 parson domain users 560 Oct 4 08:18 fallingsaw.dif
Check CSC223f23WAVEassn2.txt.dif as well.
make[1]: *** [debug] Error 1
make[1]: Leaving directory `/home/kutztown.edu/parson/Scripting/CSC223f23WAVEass
n2'
make: *** [CSC223f23WAVEassn2.csv] Error 2

When errors are reported, compare expected output in README.txt to CSC223f23WAVEassn2.csv.

README.txt has been formatted for reading by changing commas to TABs from a correct CSC223f23WAVEassn2.csv.
I added spaces around the one-quarter, halfway, and three-quarters timesteps to highlight midpoint crossings.

README.txt

TS triangle sine cos square pulse risingsaw fallingsaw
0 -32767 -32767 32767 -32767 -32767 -32767 32767
1 -29788 -32433 32433 -32767 -32767 -31278 31278
2 -26809 -31440 31440 -32767 -32767 -29788 29788
3 -23831 -29806 29806 -32767 -32767 -28299 28299
4 -20852 -27565 27565 -32767 -32767 -26809 26809
5 -17873 -24764 24764 -32767 -32767 -25320 25320
6 -14894 -21458 21458 -32767 -32767 -23831 23831
7 -11915 -17715 17715 -32767 -32767 -22341 22341
8 -8936 -13612 13612 -32767 -32767 -20852 20852
9 -5958 -9232 9232 -32767 -32767 -19362 19362
10 -2979 -4663 4663 -32767 -32767 -17873 17873

11 0 0 0 -32767 -32767 -16384 16384

12 2979 4663 -4663 -32767 -32767 -14894 14894
13 5958 9232 -9232 -32767 -32767 -13405 13405
14 8936 13612 -13612 -32767 -32767 -11915 11915
15 11915 17715 -17715 -32767 -32767 -10426 10426
16 14894 21458 -21458 -32767 -32767 -8936 8936
17 17873 24764 -24764 -32767 -32767 -7447 7447
18 20852 27565 -27565 -32767 -32767 -5958 5958
19 23831 29806 -29806 -32767 -32767 -4468 4468
20 26809 31440 -31440 -32767 -32767 -2979 2979
21 29788 32433 -32433 -32767 -32767 -1489 1489

22 32767 32767 -32767 32767 -32767 0 0

23 29788 32433 -32433 32767 -32767 1489 -1489
24 26809 31440 -31440 32767 -32767 2979 -2979
25 23831 29806 -29806 32767 -32767 4468 -4468
26 20852 27565 -27565 32767 -32767 5958 -5958
27 17873 24764 -24764 32767 -32767 7447 -7447
28 14894 21458 -21458 32767 -32767 8936 -8936
29 11915 17715 -17715 32767 -32767 10426 -10426
30 8936 13612 -13612 32767 -32767 11915 -11915
31 5958 9232 -9232 32767 -32767 13405 -13405
32 2979 4663 -4663 32767 -32767 14894 -14894

TS triangle sine cos square pulse risingsaw fallingsaw
33 0 0 0 32767 32767 16383 -16383

34 -2979 -4663 4663 32767 32767 17873 -17873
35 -5958 -9232 9232 32767 32767 19362 -19362
36 -8936 -13612 13612 32767 32767 20852 -20852
37 -11915 -17715 17715 32767 32767 22341 -22341
38 -14894 -21458 21458 32767 32767 23831 -23831
39 -17873 -24764 24764 32767 32767 25320 -25320
40 -20852 -27565 27565 32767 32767 26809 -26809
41 -23831 -29806 29806 32767 32767 28299 -28299
42 -26809 -31440 31440 32767 32767 29788 -29788
43 -29788 -32433 32433 32767 32767 31278 -31278
44 -32767 -32767 32767 32767 32767 32767 -32767


Here is
CSC223f23WAVEassn2.csv at the start of assignment:

timestep,triangle,sine,cos,square,pulse,risingsaw,fallingsaw
0,0,-32767,0,0,0,-32767,0
1,0,-32433,0,0,0,-31278,0
2,0,-31440,0,0,0,-29788,0
3,0,-29806,0,0,0,-28299,0
4,0,-27565,0,0,0,-26809,0
5,0,-24764,0,0,0,-25320,0
6,0,-21458,0,0,0,-23831,0
7,0,-17715,0,0,0,-22341,0
8,0,-13612,0,0,0,-20852,0
9,0,-9232,0,0,0,-19362,0
10,0,-4663,0,0,0,-17873,0
11,0,0,0,0,0,-16384,0
12,0,4663,0,0,0,-14894,0
13,0,9232,0,0,0,-13405,0
14,0,13612,0,0,0,-11915,0
15,0,17715,0,0,0,-10426,0
16,0,21458,0,0,0,-8936,0
17,0,24764,0,0,0,-7447,0
18,0,27565,0,0,0,-5958,0
19,0,29806,0,0,0,-4468,0
20,0,31440,0,0,0,-2979,0
21,0,32433,0,0,0,-1489,0
22,0,32767,0,0,0,0,0
23,0,32433,0,0,0,1489,0
24,0,31440,0,0,0,2979,0
25,0,29806,0,0,0,4468,0
26,0,27565,0,0,0,5958,0
27,0,24764,0,0,0,7447,0
28,0,21458,0,0,0,8936,0
29,0,17715,0,0,0,10426,0
30,0,13612,0,0,0,11915,0
31,0,9232,0,0,0,13405,0
32,0,4663,0,0,0,14894,0
33,0,0,0,0,0,16383,0
34,0,-4663,0,0,0,17873,0
35,0,-9232,0,0,0,19362,0
36,0,-13612,0,0,0,20852,0
37,0,-17715,0,0,0,22341,0
38,0,-21458,0,0,0,23831,0
39,0,-24764,0,0,0,25320,0
40,0,-27565,0,0,0,26809,0
41,0,-29806,0,0,0,28299,0
42,0,-31440,0,0,0,29788,0
43,0,-32433,0,0,0,31278,0
44,0,-32767,0,0,0,32767,0

You can see a tab-aligned view of xxx by typing this command line:
$ sed -e 's/,/\t/g' CSC223f23WAVEassn2.csv

timestep triangle sine cos square pulse risingsaw fallingsaw
0 0 -32767 0 0 0 -32767 0
1 0 -32433 0 0 0 -31278 0
2 0 -31440 0 0 0 -29788 0
3 0 -29806 0 0 0 -28299 0
4 0 -27565 0 0 0 -26809 0
5 0 -24764 0 0 0 -25320 0
6 0 -21458 0 0 0 -23831 0
7 0 -17715 0 0 0 -22341 0
8 0 -13612 0 0 0 -20852 0
9 0 -9232 0 0 0 -19362 0
10 0 -4663 0 0 0 -17873 0
11 0 0 0 0 0 -16384 0
12 0 4663 0 0 0 -14894 0
13 0 9232 0 0 0 -13405 0
14 0 13612 0 0 0 -11915 0
15 0 17715 0 0 0 -10426 0
16 0 21458 0 0 0 -8936 0
17 0 24764 0 0 0 -7447 0
18 0 27565 0 0 0 -5958 0
19 0 29806 0 0 0 -4468 0
20 0 31440 0 0 0 -2979 0
21 0 32433 0 0 0 -1489 0
22 0 32767 0 0 0 0 0
23 0 32433 0 0 0 1489 0
24 0 31440 0 0 0 2979 0
25 0 29806 0 0 0 4468 0
26 0 27565 0 0 0 5958 0
27 0 24764 0 0 0 7447 0
28 0 21458 0 0 0 8936 0
29 0 17715 0 0 0 10426 0
30 0 13612 0 0 0 11915 0
31 0 9232 0 0 0 13405 0
32 0 4663 0 0 0 14894 0
33 0 0 0 0 0 16383 0
34 0 -4663 0 0 0 17873 0
35 0 -9232 0 0 0 19362 0
36 0 -13612 0 0 0 20852 0
37 0 -17715 0 0 0 22341 0
38 0 -21458 0 0 0 23831 0
39 0 -24764 0 0 0 25320 0
40 0 -27565 0 0 0 26809 0
41 0 -29806 0 0 0 28299 0
42 0 -31440 0 0 0 29788 0
43 0 -32433 0 0 0 31278 0
44 0 -32767 0 0 0 32767 0


The Zoom video recording of October 3 goes over this approach to debugging.