Skip to content
Snippets Groups Projects
Commit 2d6a021f authored by cprutean's avatar cprutean
Browse files

Update file Checkpoint4.ipynb

parent 3d5115a9
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:d5db6b1d tags: %% Cell type:markdown id:d5db6b1d tags:
## Checkpoint 4 ## Checkpoint 4
### Aim ![ch4.png](ch4.png)
To write a Python program to read in data from a text file in a specified format, perform some simple processing and display the output using pyplot. ***“In the middle of the journey of our life I found myself within a dark woods where the straight way was lost.”***
― Dante Alighieri, Inferno
From a computing viewpoint this checkpoint demonstrates how to read data from a text file into suitable lists, perform some processing on these lists and then graphically display the results. Attempting to finish the course by jumping directly to the checkpoints may seem like a good idea, until it isn't. To get back on track, you may want to return to the [Week 4 tasklist](../WeeklyTasks/Week4.ipynb).
### Dataset
The voltage and current in an electronic circuit are sampled at a rate of 25kHz and the sampled data are written to a text file with the following format:
- The first three lines are comments detailing the equipment used and are not useful for plotting, these lines start with the "#" character.
- The following (several hundred) lines contain the data in the two floats separated by a " , ". The first data entry being voltage and the second the current.
### Task
The computing task is to write a Python program to read in data from the supplied file for voltage, V(t), and current, I(t), and to plot, via pyplot, the log power, being, p(t)=log(V(t)I(t)) where log is natural log to base e.
Your program should:
- Prompt for the filename to be read.
- Read in the required data from sample.txt file and display p(t) over the supplied range of t with suitable titles and axis labels.
- You must use a function of the form logpower(voltage,current) to form the p(t), and a main() program.
### Background
To successfully complete this checkpoint you should read carefully [Parsing Input](../CourseNotes/ParsingInput.ipynb).
### Input files
For this checkpoint there are 2 input files with which to test, and then run your code.
These are [short.txt](short.txt) for testing and [sample.txt](sample.txt) for the real run.
Both of these are in the current folder, so they can be read in and executed upon directly here. ***Be very careful not to WRITE into these files, as you may lose the measured data and will have to go to great lengths to recover it!***
### Checkpoint
- Test your program with both files, and make sure for each that the output is correcly displayed.
- You should prompt the user for the filename to use.
- Call a demonstrator, show them your code, and run your program for the two different datasets.
### Assessment
To pass this checkpoint:
- The programme works correctly for both input files.
- The programme uses a function of the form logpower(voltage,current) to form the p(t), and has a main() function.
- The program is well structured and laid out.
- It has sensible variable names that make clear their purpose.
The output graph has correct title and labels.
>Think carefully about what you are reading from the file and what you want to plot. Also, to deal with the comment line, remember that comment lines start with a ```#``` which you can test for. Look up on the web what the string function ```str.startswith()``` does, it may be useful!
### Next steps
Once you have completed this checkpoint, please continue with the [Week4](../WeeklyTasks/Week4.ipynb) tasklist.
%% Cell type:code id:c3ccaba4 tags: %% Cell type:code id:c3ccaba4 tags:
``` python ``` python
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment