Add wind direction drawing

This commit is contained in:
Guntis Smaukstelis
2025-02-04 22:47:01 +02:00
parent e03ae14cfa
commit 9c8902e746
4 changed files with 22 additions and 6 deletions
+1
View File
@@ -15,6 +15,7 @@ case class GribGrid(
template: Short, template: Short,
cols: Int, cols: Int,
rows: Int, rows: Int,
lambert: List[Int],
) )
case class MeteoParam( case class MeteoParam(
+4 -1
View File
@@ -98,7 +98,10 @@ object GribParser {
template = ByteBuffer.wrap(bytes.slice(12, 14)).getShort template = ByteBuffer.wrap(bytes.slice(12, 14)).getShort
cols = ByteBuffer.wrap(bytes.slice(30, 34)).getInt cols = ByteBuffer.wrap(bytes.slice(30, 34)).getInt
rows = ByteBuffer.wrap(bytes.slice(34, 38)).getInt rows = ByteBuffer.wrap(bytes.slice(34, 38)).getInt
} yield (GribGrid(template, cols, rows), length) lambert1 = ByteBuffer.wrap(bytes.slice(34, 38)).getInt
lambert2 = ByteBuffer.wrap(bytes.slice(38, 42)).getInt
lambert = List(lambert1, lambert2)
} yield (GribGrid(template, cols, rows, lambert), length)
} }
private def parse4(path: Path, ptr: Long, discipline: Int, referenceTime: ZonedDateTime): IO[(MeteoParam, GribTime, Int)] = { private def parse4(path: Path, ptr: Long, discipline: Int, referenceTime: ZonedDateTime): IO[(MeteoParam, GribTime, Int)] = {
+7 -3
View File
@@ -5,7 +5,7 @@ import { apiHost } from '../consts'
import { GribMessage } from './interfaces' import { GribMessage } from './interfaces'
import { fetchBuffer } from '../helpers/fetch' import { fetchBuffer } from '../helpers/fetch'
import { drawGrib } from './draw/drawGrib' import { drawGrib } from './draw/drawGrib'
import { fetchWindData } from './draw/windDirection' import { fetchWindData, getFakeWindDirection } from './draw/windDirection'
const CROP_BOUNDS = { x: 1906-1-400, y: 950, width: 400, height: 300 } const CROP_BOUNDS = { x: 1906-1-400, y: 950, width: 400, height: 300 }
@@ -32,7 +32,11 @@ export const GribFile: Component<{
if (getGribList().length === 0) { if (getGribList().length === 0) {
fetch(`${apiHost}/api/show/grib/${name}`) fetch(`${apiHost}/api/show/grib/${name}`)
.then(re => re.json()) .then(re => re.json())
.then(setGribList) .then((gribList: GribMessage[]) => {
const windSpeed = gribList.find(m => m.meteo.discipline===0 && m.meteo.category===2 && m.meteo.product===1)
if (windSpeed) gribList.push(getFakeWindDirection(windSpeed))
setGribList(gribList)
})
} }
} }
@@ -66,7 +70,7 @@ export const GribFile: Component<{
const binaryOffset = binarySection.offset + 5 const binaryOffset = binarySection.offset + 5
const binaryLength = binarySection.size - 5 const binaryLength = binarySection.size - 5
const fetchPromise: Promise<[GribMessage[], ArrayBuffer[], ArrayBuffer[]]> = grib.meteo.discipline === 0 && grib.meteo.category === 2 && grib.meteo.product === 192 const fetchPromise: Promise<[GribMessage[], ArrayBuffer[], ArrayBuffer[]]> = grib.meteo.discipline === 0 && grib.meteo.category === 2 && grib.meteo.product === 192
? fetchWindData(grib, getGribList()) ? fetchWindData(grib, getGribList(), name)
: Promise.all([ : Promise.all([
Promise.resolve([grib]), Promise.resolve([grib]),
fetchBuffer(`${apiHost}/api/grib/binary-chunk/${binaryOffset}/${binaryLength}/${name}`).then(b=>[b]), fetchBuffer(`${apiHost}/api/grib/binary-chunk/${binaryOffset}/${binaryLength}/${name}`).then(b=>[b]),
+10 -2
View File
@@ -141,6 +141,7 @@ export function windSpeedColors(
export function fetchWindData( export function fetchWindData(
customMessage: GribMessage, customMessage: GribMessage,
gribArr: GribMessage[], gribArr: GribMessage[],
fileName: string,
): Promise<[GribMessage[], ArrayBuffer[], ArrayBuffer[]]> { ): Promise<[GribMessage[], ArrayBuffer[], ArrayBuffer[]]> {
const windU = gribArr.find(m => m.meteo.discipline===0 && m.meteo.category===2 && m.meteo.product===2 && m.meteo.levelType===103 && m.meteo.levelValue===10) const windU = gribArr.find(m => m.meteo.discipline===0 && m.meteo.category===2 && m.meteo.product===2 && m.meteo.levelType===103 && m.meteo.levelValue===10)
const windV = gribArr.find(m => m.meteo.discipline===0 && m.meteo.category===2 && m.meteo.product===3 && m.meteo.levelType===103 && m.meteo.levelValue===10) const windV = gribArr.find(m => m.meteo.discipline===0 && m.meteo.category===2 && m.meteo.product===3 && m.meteo.levelType===103 && m.meteo.levelValue===10)
@@ -157,8 +158,8 @@ export function fetchWindData(
const vBinaryLength = section7v.size - 5 const vBinaryLength = section7v.size - 5
return Promise.all([ return Promise.all([
fetchBuffer(`${apiHost}/api/binary-chunk/${uBinaryOffset}/${uBinaryLength}`), fetchBuffer(`${apiHost}/api/grib/binary-chunk/${uBinaryOffset}/${uBinaryLength}/${fileName}`),
fetchBuffer(`${apiHost}/api/binary-chunk/${vBinaryOffset}/${vBinaryLength}`), fetchBuffer(`${apiHost}/api/grib/binary-chunk/${vBinaryOffset}/${vBinaryLength}/${fileName}`),
]).then(([bufferU, bufferV]) => { ]).then(([bufferU, bufferV]) => {
const buffer = new Uint8Array(bufferU.byteLength + bufferV.byteLength) const buffer = new Uint8Array(bufferU.byteLength + bufferV.byteLength)
buffer.set(new Uint8Array(bufferU)) buffer.set(new Uint8Array(bufferU))
@@ -172,3 +173,10 @@ export function fetchWindData(
function toInt(bytes: Uint8Array): number { function toInt(bytes: Uint8Array): number {
return bytes.reduce((acc, curr) => acc * 256 + curr) return bytes.reduce((acc, curr) => acc * 256 + curr)
} }
export function getFakeWindDirection(windSpeed: GribMessage): GribMessage {
const modifiedWindSpeed = structuredClone(windSpeed)
modifiedWindSpeed.meteo = {...modifiedWindSpeed.meteo, product: 192}
modifiedWindSpeed.title = 'meteorology, momentum, wind direction 10m (calc u,v)'
return modifiedWindSpeed
}