Project 10 of 12, for Riya
Linear Algebra Lab
A linear algebra lab for Riya in two parts: a month of wind from the Archive's vane as arrows, for her wind print and for Neil's headwind and crosswind on the runway; then a real photograph of a lighthouse as a matrix, mirrored, turned and blurred like her filters, with a rotation matrix to finish.
Act 5 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- RiyaI'm making a print of January's wind, with an arrow for each day from the vane outside the Archive.
- YahyaThe old summary script averages the bearings and says January came from the south, when the vane pointed north all month.
- NeilAnd the flying field's runway points at forty degrees, so I'd like the headwind and the crosswind.
- PaulBearings go round in a circle and plain numbers don't, which is why you turn them into arrows.
- RiyaAfter that I want to do a photograph of a lighthouse as numbers, to see what my filters really do.
vane.csv has one row per day of January 2024: the date, the bearing the wind came from (degrees clockwise from north) and its speed in knots. load_vane and to_arrows are written: to_arrows gives one arrow per day, (east, north) in knots, pointing where the wind came from.
Write five functions that work on the arrows, with no loops:
to_bearings(arrows): the compass bearing of each arrow, from 0 up to 360.prevailing(arrows): the average wind,(bearing, speed): the direction and length of the mean arrow.steadiness(arrows): the mean arrow's length divided by the mean speed.angle_between(a, b): the angle between two arrows in degrees, from 0 to 180.along_and_across(arrows, heading): for a plane on that heading, one row per wind: the headwind (below 0 if the wind is behind) and the crosswind from the right (below 0 if it's from the left).
Then the second experiment, in lighthouse.py. lighthouse.csv is Riya's practice photograph, a real lighthouse in North Carolina, as a matrix: 64 rows of 48 brightnesses, 0 black to 255 white. load_image is written. Write seven more functions, each giving back a new array:
mirror(image): each row back to front.upside_down(image): the rows in reverse order.quarter_turn(image): turned a quarter turn clockwise.brighten(image, amount): every pixelamountbrighter, kept between 0 and 255.blur(image): each pixel the average of the 3 by 3 block around it, with the edge pixels repeated to fill the block.rotation(degrees): the 2 by 2 matrix that turns an arrowdegreesanticlockwise.turn_points(points, degrees): points, one(x, y)per row, turneddegreesanticlockwise about(0, 0), by multiplying by the rotation matrix with@.
January 2024: 31 days Average of the bearings: 197 degrees Prevailing wind: from 350 degrees at 11.4 knots Steadiness: 0.81 Biggest swing overnight: 120 degrees, 2024-01-28 to 2024-01-29 Runway 04: worst headwind 25.1 knots on 2024-01-26 Runway 04: worst crosswind 23.1 knots on 2024-01-15 Cape Lookout: 64 rows by 48 columns, brightness 0 to 229 Turned a quarter: 48 rows by 64 columns Brightened by 60: average 211.2, against 154.5 Blurred: brightness 8 to 226 House turned 30 degrees and back: True Roof, turned 90 degrees: [-12. 10.]
What you learn
What's in it
- Arrows, not bearings
- Two days of wind
- From a bearing to an arrow and back
- Due south
- The January vane
- How much lies along
- Dead ahead
- Many dot products at once
- The storm score
- How Paul would do it
- Fix Yahya's version
- Make the wind report
- A picture is a matrix
- A picture is a matrix
- A matrix that turns
- Half a turn
- Averaging the neighbours
- A bright corner
- Make the picture lab
- Ship it