UNPKG

arso-rainfall-intensity

Version:

!!!Only for slovenia!!! Provides simple api for fetching radar images of rainfall intensity and parsing from pixels and converting pixel coordinates to pairs of latitude and longitude or vice versa.

103 lines 4.57 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArsoHailProbabilityProjection = exports.radarHailProbabilityColorsInfo = exports.radarRainfallColorsInfo = void 0; const radar_image_projection_1 = __importDefault(require("./radar-image-projection")); const assertions_1 = require("./assertions"); const noReadingPixelResult = { pixel: [0, 0, 0], value: 0, group: 0 }; exports.radarRainfallColorsInfo = [ { pixel: [203, 0, 204], value: 57, group: 4 }, { pixel: [181, 3, 3], value: 54, group: 4 }, { pixel: [211, 0, 0], value: 51, group: 4 }, { pixel: [255, 62, 1], value: 48, group: 3 }, { pixel: [254, 132, 0], value: 45, group: 3 }, { pixel: [254, 198, 0], value: 42, group: 3 }, { pixel: [249, 250, 1], value: 39, group: 3 }, { pixel: [184, 250, 0], value: 36, group: 2 }, { pixel: [108, 249, 0], value: 33, group: 2 }, { pixel: [66, 235, 66], value: 30, group: 2 }, { pixel: [4, 216, 131], value: 27, group: 2 }, { pixel: [0, 220, 254], value: 24, group: 1 }, { pixel: [0, 174, 253], value: 21, group: 1 }, { pixel: [0, 120, 254], value: 18, group: 1 }, { pixel: [8, 70, 254], value: 15, group: 1 }, noReadingPixelResult ]; exports.radarHailProbabilityColorsInfo = [ { pixel: [250, 0, 0], value: 3, group: 3 }, { pixel: [250, 125, 0], value: 2, group: 2 }, { pixel: [250, 225, 0], value: 1, group: 1 }, noReadingPixelResult ]; class ArsoProjection extends radar_image_projection_1.default { constructor(radarPixelColorsInfo) { const degreeProj = 'EPSG:900913'; const meterProj = 'EPSG:4326'; const bboxSW = { x: 12.10, y: 44.657 }; const bboxNE = { x: 17.44, y: 47.407 }; super(degreeProj, meterProj, bboxSW, bboxNE); this.interestPixelBounds = { x1: 25, x2: 774, y1: 12, y2: 585 }; this._radarColorsInfoMap = new Map(radarPixelColorsInfo .map((colors) => [`${colors.pixel[0]}-${colors.pixel[1]}-${colors.pixel[2]}`, colors])); this._imagePixelRadarMap = null; } loadImageFromBuffer(buffer) { super.loadImageFromBuffer(buffer); this._preprocessLoadedImage(); } isPixelInInterestBounds({ x, y }) { const { x1, y1, x2, y2 } = this.interestPixelBounds; return x1 <= x && x <= x2 && y1 <= y && y <= y2; } getPixelRadarValue({ x, y }) { assertions_1.assertNotNull(this._imagePixelRadarMap, 'Image not loaded.'); return this._imagePixelRadarMap[y][x]; } _mapPixelLocationToRadarValue({ x, y }) { const { r, g, b, a } = this.getPixelInfo({ x, y }); if (a !== 255) { return noReadingPixelResult; } const colorResult = this._radarColorsInfoMap.get(`${r}-${g}-${b}`); if (!colorResult) { return noReadingPixelResult; } return colorResult; } _preprocessLoadedImage() { assertions_1.assertNotNull(this.image, 'Image not loaded.'); const { width, height, data } = this.image; this._imagePixelRadarMap = new Array(width).fill(null) .map(() => new Array(height).fill(null)); for (let y = 0; y < height; y++) { for (let x = 0; x < width; x++) { const idx = (width * y + x) << 2; const pixelValue = this._mapPixelLocationToRadarValue({ x, y }); const pixelOutOfBounds = !this.isPixelInInterestBounds({ x, y }); const pixelUnknownValue = !pixelValue; const isIrrelevant = pixelOutOfBounds || pixelUnknownValue; this._imagePixelRadarMap[y][x] = pixelValue; if (isIrrelevant) { data[idx] = 0; data[idx + 1] = 0; data[idx + 2] = 0; data[idx + 3] = 0; } } } } } class ArsoRainfallProjection extends ArsoProjection { constructor() { super(exports.radarRainfallColorsInfo); } } exports.default = ArsoRainfallProjection; class ArsoHailProbabilityProjection extends ArsoProjection { constructor() { super(exports.radarHailProbabilityColorsInfo); } } exports.ArsoHailProbabilityProjection = ArsoHailProbabilityProjection; //# sourceMappingURL=arso-projection.js.map