-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore small wind direction changes with insignificant speed magnitu…
…de (#164) * Ignore small wind direction changes if insignificant speed * lceanup
- Loading branch information
Showing
4 changed files
with
131 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import styled from "@emotion/styled"; | ||
import { WindsAloftAltitude, WindsAloftHour } from "../../models/WindsAloft"; | ||
import Altitude from "./cells/Altitude"; | ||
import Temperature from "./cells/Temperature"; | ||
import WindDirection from "./cells/WindDirection"; | ||
import WindSpeed from "./cells/WindSpeed"; | ||
import { css } from "@emotion/react"; | ||
import { vectorDifferenceMagnitude } from "../../helpers/vector"; | ||
|
||
const DELTA_WINDSPEED_VECTOR_THRESHOLD_KPH = 10; | ||
|
||
const TableRow = styled.tr<{ opaque: boolean }>` | ||
${({ opaque }) => | ||
opaque && | ||
css` | ||
opacity: 0.5; | ||
`} | ||
`; | ||
|
||
interface RowProps { | ||
datum: WindsAloftAltitude; | ||
index: number; | ||
displayedRapData: WindsAloftAltitude[]; | ||
surfaceLevel: number; | ||
windsAloftHour: WindsAloftHour; | ||
} | ||
|
||
export default function Row({ | ||
datum, | ||
index, | ||
displayedRapData, | ||
surfaceLevel, | ||
windsAloftHour, | ||
}: RowProps) { | ||
function negativeAltitude(datum: WindsAloftAltitude): boolean { | ||
return !!(datum.altitudeInM - surfaceLevel < 0); | ||
} | ||
|
||
const shearEligible = | ||
displayedRapData[index - 1] && | ||
vectorDifferenceMagnitude( | ||
datum.windSpeedInKph, | ||
datum.windDirectionInDeg, | ||
displayedRapData[index - 1]?.windSpeedInKph, | ||
displayedRapData[index - 1]?.windDirectionInDeg, | ||
) > DELTA_WINDSPEED_VECTOR_THRESHOLD_KPH; | ||
|
||
return ( | ||
<TableRow key={index} opaque={negativeAltitude(datum)}> | ||
<td> | ||
<Altitude | ||
heightInMeters={datum.altitudeInM} | ||
surfaceLevelInMeters={surfaceLevel} | ||
pressure={datum.pressure} | ||
/> | ||
</td> | ||
<td> | ||
<Temperature | ||
temperature={datum.temperatureInC} | ||
dewpoint={datum.dewpointInC} | ||
lapseRate={ | ||
displayedRapData[index - 1] | ||
? -( | ||
(datum.temperatureInC - | ||
displayedRapData[index - 1].temperatureInC) / | ||
(datum.altitudeInM - displayedRapData[index - 1].altitudeInM) | ||
) | ||
: undefined | ||
} | ||
pressure={datum.pressure} | ||
hour={new Date(windsAloftHour.date)} | ||
/> | ||
</td> | ||
<td> | ||
<WindDirection | ||
curr={datum.windDirectionInDeg} | ||
prev={displayedRapData[index - 1]?.windDirectionInDeg} | ||
shearEligible={shearEligible} | ||
/> | ||
</td> | ||
<td> | ||
<WindSpeed | ||
curr={datum.windSpeedInKph} | ||
prev={displayedRapData[index - 1]?.windSpeedInKph} | ||
/> | ||
</td> | ||
</TableRow> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export function vectorDifferenceMagnitude( | ||
speed1: number, | ||
direction1: number, | ||
speed2: number, | ||
direction2: number, | ||
): number { | ||
// Convert directions from degrees to radians | ||
const radian1 = (Math.PI / 180) * direction1; | ||
const radian2 = (Math.PI / 180) * direction2; | ||
|
||
// Convert polar coordinates to Cartesian coordinates | ||
const x1 = speed1 * Math.cos(radian1); | ||
const y1 = speed1 * Math.sin(radian1); | ||
const x2 = speed2 * Math.cos(radian2); | ||
const y2 = speed2 * Math.sin(radian2); | ||
|
||
// Calculate the difference in Cartesian coordinates | ||
const dx = x2 - x1; | ||
const dy = y2 - y1; | ||
|
||
// Calculate the magnitude of the difference vector | ||
return Math.sqrt(dx * dx + dy * dy); | ||
} |