UNPKG

eccodes-ts

Version:

TypeScript wrapper for eccodes GRIB file handling

684 lines (641 loc) 21.9 kB
export declare interface BaseGrib2Message { discipline: Discipline; editionNumber: number; centre: number; subCentre: number; gridDefinitionTemplateNumber: number; Ni: number; Nj: number; gridType: string; latitudeOfFirstGridPointInDegrees: number; longitudeOfFirstGridPointInDegrees: number; latitudeOfLastGridPointInDegrees: number; longitudeOfLastGridPointInDegrees: number; iDirectionIncrementInDegrees: number; jDirectionIncrementInDegrees: number; dataDate: number; dataTime: number; forecastTime: number; stepRange: string; values: (number | null | LocationForecast)[]; maximum: number; minimum: number; average: number; numberOfValues: number; numberOfMissing: number; parameterCategory: ParameterCategory; parameterNumber: ParameterNumber; parameterUnits: GribParameterUnits; parameterName: string; shortName: string; cfVarName: string; } export declare type CommandStreamParams = { discipline?: Discipline; category: ParameterCategory; number?: ParameterNumber; }; export declare enum Discipline { Meteorological = 0, Hydrological = 1, LandSurface = 2, SatelliteRemoteSensing = 3, SpaceWeather = 4, Oceanographic = 10, HealthAndSocioeconomic = 20, Missing = 255 } export declare class EccodesWrapper { private tempFilePath; private readonly gribFilePath; private initPromise; private static readonly DEFAULT_TIMEOUT; private static readonly DEFAULT_RETRIES; constructor(input: InputSource); private resolveFilePath; private findProjectRoot; private isValidUrl; fetchAndSaveFile(url: string, options?: FetchOptions): Promise<void>; private createTempFile; private execGribCommandStream; private execFullGribDump; getCommandStreamParams({ discipline, category, number, }: CommandStreamParams): string; private mapValuesToLatLon; private addLatLonToGribValues; getSignificantWaveHeight(options: { addLatLon: true; }): Promise<WithLatLon<WaveParameter>[]>; getSignificantWaveHeight(options?: { addLatLon?: false; }): Promise<WaveParameter[]>; getPrimaryWavePeriod(options: { addLatLon: true; }): Promise<WithLatLon<WaveParameter>[]>; getPrimaryWavePeriod(options?: { addLatLon?: false; }): Promise<WaveParameter[]>; getSignificantWindWaveHeight(options: { addLatLon: true; }): Promise<WithLatLon<WaveParameter>[]>; getSignificantWindWaveHeight(options?: { addLatLon?: false; }): Promise<WaveParameter[]>; getPrimaryWaveDirection(options: { addLatLon: true; }): Promise<WithLatLon<WaveParameter>[]>; getPrimaryWaveDirection(options?: { addLatLon?: false; }): Promise<WaveParameter[]>; getWindSpeed(options: { addLatLon: true; }): Promise<WithLatLon<WindParameter>[]>; getWindSpeed(options?: { addLatLon?: false; }): Promise<WindParameter[]>; getWindDirection(options: { addLatLon: true; }): Promise<WithLatLon<WindParameter>[]>; getWindDirection(options?: { addLatLon?: false; }): Promise<WindParameter[]>; getWaveParameters(options: { addLatLon: true; }): Promise<WithLatLon<WaveParameter>[]>; getWaveParameters(options?: { addLatLon?: false; }): Promise<WaveParameter[]>; getWindParameters(options: { addLatLon: true; }): Promise<WithLatLon<WindParameter>[]>; getWindParameters(options?: { addLatLon?: false; }): Promise<WindParameter[]>; getParametersByType<T extends GribParameter>(options: GribParametersByType & { addLatLon: true; }): Promise<WithLatLon<T>[]>; getParametersByType<T extends GribParameter>(options: Omit<GribParametersByType, "addLatLon"> & { addLatLon?: false; }): Promise<T[]>; getMetadata(): Promise<BaseGrib2Message[]>; readToJson(options?: GribParsingOptions): Promise<BaseGrib2Message[]>; dispose(): Promise<void>; cleanup(): Promise<void>; } declare interface FetchOptions { timeout?: number; retries?: number; } export declare interface ForecastMessage { metadata: GribMetadata; parameterCategory: number; parameterNumber: number; parameterName: string; parameterUnits: string; shortName: string; values: (number | null | LocationForecast)[]; maximum: number; minimum: number; average: number; standardDeviation: number; } export declare interface GribMetadata { gridType: string; Ni: number; Nj: number; latitudeOfFirstGridPointInDegrees: number; longitudeOfFirstGridPointInDegrees: number; latitudeOfLastGridPointInDegrees: number; longitudeOfLastGridPointInDegrees: number; iDirectionIncrementInDegrees: number; jDirectionIncrementInDegrees: number; centre: number; editionNumber: number; typeOfGeneratingProcess: number; generatingProcessIdentifier: number; dataDate: number; dataTime: number; stepUnits: string; forecastTime: number; stepRange: string; numberOfValues: number; numberOfMissing: number; getNumberOfValues: number; } export declare type GribParameter = WaveParameter | WindParameter; export declare type GribParametersByType = CommandStreamParams & { keys?: string[]; addLatLon?: boolean; }; export declare enum GribParameterUnits { Meters = "m", Seconds = "s", Kilograms = "kg", Kelvin = "K", Pascals = "Pa", Newtons = "N", Watts = "W", Joules = "J", Degrees = "\u00B0", DegreeTrue = "degree true", DegreesLatLon = "deg", MetersPerSecond = "m s-1", MetersPerSecondSquared = "m s-2", SquareMetersPerSecond = "m2 s-1", SquareMetersPerSecondSquared = "m2 s-2", SquareMeters = "m2", CubicMeters = "m3", CubicMetersPerSquareMeter = "m3m-2",// New NewtonsPerSquareMeter = "N m-2", NewtonsPerSquareMeterSeconds = "N m-2 s", PascalsPerSecond = "Pa s-1", PascalMeters = "Pa m",// New NewtonsPerMeter = "N m-1",// New WattsPerSquareMeter = "W m-2", WattsPerMeter = "W m-1", JoulesPerKilogram = "J kg-1", JoulesPerSquareMeter = "J m-2",// New KilogramsPerCubicMeter = "kg m-3", KilogramsPerSquareMeter = "kg m-2", KelvinSquareMetersPerKilogramPerSecond = "K m2 kg-1 s-1", KelvinMetersPerSecond = "K*m s-1", PerSecond = "s-1", Knots = "kt", Fraction = "fraction", Proportion = "proportion", Numeric = "Numeric", Percentage = "%" } export declare type GribParsingOptions = { addLatLon?: boolean; }; export declare type GribResponse<T extends BaseGrib2Message, O = { addLatLon?: boolean; }> = O extends { addLatLon: true; } ? Array<{ [K in keyof T]: K extends "values" ? LocationForecast[] : T[K]; }> : T[]; export declare type InputSource = string; export declare const isWaveHeight: (msg: BaseGrib2Message) => msg is WaveHeight; export declare const isWavePeriod: (msg: BaseGrib2Message) => msg is WavePeriod; export declare type LocationForecast = { lat: number; lon: number; value: number | null; }; export declare type MeteorologicalData = { discipline: Discipline.Meteorological; category: MeteorologicalParameterCategory; parameter: MeteorologicalParameterNumber; }; export declare enum MeteorologicalMomentumParameterNumber { WindDirection = 0, WindSpeed = 1, UComponentWind = 2, VComponentWind = 3, StreamFunction = 4, VelocityPotential = 5, MontgomeryStreamFunction = 6, SigmaCoordinateVerticalVelocity = 7, VerticalVelocityPressure = 8, VerticalVelocityGeometric = 9, AbsoluteVorticity = 10, AbsoluteDivergence = 11, RelativeVorticity = 12, RelativeDivergence = 13, PotentialVorticity = 14, VerticalUComponentShear = 15, VerticalVComponentShear = 16, MomentumFluxU = 17, MomentumFluxV = 18, WindMixingEnergy = 19, BoundaryLayerDissipation = 20, MaximumWindSpeed = 21, WindSpeedGust = 22, UComponentWindGust = 23, VComponentWindGust = 24, VerticalSpeedShear = 25, HorizontalMomentumFlux = 26, UComponentStormMotion = 27, VComponentStormMotion = 28, DragCoefficient = 29, FrictionalVelocity = 30, TurbulentDiffusionCoefficientMomentum = 31, EtaCoordinateVerticalVelocity = 32, WindFetch = 33, NormalWindComponent = 34, TangentialWindComponent = 35, AmplitudeFunctionRossbyWave = 36, NorthwardTurbulentSurfaceStress = 37, EastwardTurbulentSurfaceStress = 38, EastwardWindTendencyParamaterizations = 39, NorthwardWindTendencyParamaterizations = 40, UComponentGeostrophicWind = 41, VComponentGeostrophicWind = 42, GeostrophicWindDirection = 43, GeostrophicWindSpeed = 44, UnbalancedComponentDivergence = 45, VorticityAdvection = 46, SurfaceRoughnessHeat = 47, SurfaceRoughnessMoisture = 48, WindStress = 49, EastwardWindStress = 50, NorthwardWindStress = 51, UComponentWindStress = 52, VComponentWindStress = 53, NaturalLogSurfaceRoughnessHeat = 54, NaturalLogSurfaceRoughnessMoisture = 55, UComponentNeutralWind = 56, VComponentNeutralWind = 57, TurbulentSurfaceStressMagnitude = 58, VerticalDivergence = 59, DragThermalCoefficient = 60, DragEvaporationCoefficient = 61, EastwardTurbulentSurfaceStress2 = 62, NorthwardTurbulentSurfaceStress2 = 63, EastwardTurbulentSurfaceStressOrographic = 64, NorthwardTurbulentSurfaceStressOrographic = 65, EastwardTurbulentSurfaceStressSurfaceRoughness = 66, NorthwardTurbulentSurfaceStressSurfaceRoughness = 67, VerticalSpeedShearLocal = 192, HorizontalMomentumFluxLocal = 193, UComponentStormMotionLocal = 194, VComponentStormMotionLocal = 195, DragCoefficientLocal = 196, FrictionalVelocityLocal = 197, LatitudeUWindComponent = 198, LongitudeUWindComponent = 199, LatitudeVWindComponent = 200, LongitudeVWindComponent = 201, LatitudePressurePoint = 202, LongitudePressurePoint = 203, VerticalEddyDiffusivityHeat = 204, CovarianceMeridionalZonalWind = 205, CovarianceTemperatureZonalWind = 206, CovarianceTemperatureMeridionalWind = 207, VerticalDiffusionZonalAcceleration = 208, VerticalDiffusionMeridionalAcceleration = 209, GravityWaveDragZonalAcceleration = 210, GravityWaveDragMeridionalAcceleration = 211, ConvectiveZonalMomentumMixingAcceleration = 212, ConvectiveMeridionalMomentumMixingAcceleration = 213, VerticalVelocityTendency = 214, OmegaDividedByDensity = 215, ConvectiveGravityWaveDragZonalAcceleration = 216, ConvectiveGravityWaveDragMeridionalAcceleration = 217, VelocityPointModelSurface = 218, PotentialVorticityMassWeighted = 219, HourlyMaxUpwardVerticalVelocity = 220, HourlyMaxDownwardVerticalVelocity = 221, UComponentHourlyMax10mWindSpeed = 222, VComponentHourlyMax10mWindSpeed = 223, VentilationRate = 224, TransportWindSpeed = 225, TransportWindDirection = 226, EarliestReasonableArrivalTime = 227, MostLikelyArrivalTime = 228, MostLikelyDepartureTime = 229, LatestReasonableDepartureTime = 230, TropicalWindDirection = 231, TropicalWindSpeed = 232, InflowBasedShearMagnitude = 233, UComponentInflowBasedShearVector = 234, VComponentInflowBasedShearVector = 235, UComponentBunkersEffectiveRight = 236, VComponentBunkersEffectiveRight = 237, Missing = 255 } export declare enum MeteorologicalMomentumParameterUnits { Degrees = "\u00B0", MetersPerSecond = "m s-1", SquareMetersPerSecond = "m2 s-1", SquareMetersPerSecondSquared = "m2 s-2", PerSecond = "s-1", PascalsPerSecond = "Pa s-1", KelvinSquareMetersPerKilogramPerSecond = "K m2 kg-1 s-1", NewtonsPerSquareMeter = "N m-2", Joules = "J", WattsPerSquareMeter = "W m-2", Meters = "m", Numeric = "Numeric", NewtonsPerSquareMeterSeconds = "N m-2 s", MetersPerSecondSquared = "m s-2", Knots = "kt", DegreesLatLon = "deg", KelvinMetersPerSecond = "K*m s-1", Seconds = "s" } export declare enum MeteorologicalParameterCategory { Temperature = 0, Moisture = 1, Momentum = 2, Mass = 3, ShortWaveRadiation = 4, LongWaveRadiation = 5, Cloud = 6, ThermodynamicStabilityIndices = 7, KinematicStabilityIndices = 8, TemperatureProbabilities = 9,// Deprecated MoistureProbabilities = 10,// Deprecated MomentumProbabilities = 11,// Deprecated MassProbabilities = 12,// Deprecated Aerosols = 13, TraceGases = 14, Radar = 15, ForecastRadarImagery = 16, Electrodynamics = 17, NuclearRadiology = 18, PhysicalAtmosphericProperties = 19, AtmosphericChemicalConstituents = 20, ThermodynamicProperties = 21, DroughtIndices = 22, CCITTIA5String = 190, Miscellaneous = 191, Covariance = 192, Missing = 255 } export declare type MeteorologicalParameterNumber = MeteorologicalMomentumParameterNumber; export declare enum OceanographicCurrentParameterUnits { DegreeTrue = "degree true", MetersPerSecond = "m s-1", Percentage = "%" } export declare enum OceanographicCurrentsParameterNumber { CurrentDirection = 0, CurrentSpeed = 1, UComponentCurrent = 2, VComponentCurrent = 3, RipCurrentOccurrenceProbability = 4, EastwardCurrent = 5, NorthwardCurrent = 6, OceanMixedLayerUVelocity = 192, OceanMixedLayerVVelocity = 193, BarotropicUVelocity = 194, BarotropicVVelocity = 195, Missing = 255 } export declare type OceanographicData = { discipline: Discipline.Oceanographic; category: OceanographicParameterCategory; parameter: OceanographicParameterNumber; }; export declare enum OceanographicIceParameterNumber { IceCover = 0, IceThickness = 1, IceDriftDirection = 2, IceDriftSpeed = 3, UComponentIceDrift = 4, VComponentIceDrift = 5, IceGrowthRate = 6, IceDivergence = 7, IceTemperature = 8, IceInternalPressure = 9, ZonalVectorIcePressure = 10, MeridionalVectorIcePressure = 11, CompressiveIceStrength = 12, SnowTemperatureOverSeaIce = 13, Albedo = 14, SeaIceVolumePerUnitArea = 15, SnowVolumeOverSeaIcePerUnitArea = 16, SeaIceHeatContent = 17, SnowOverSeaIceHeatContent = 18, IceFreeboardThickness = 19, IceMeltPondFraction = 20, IceMeltPondDepth = 21, IceMeltPondVolumePerUnitArea = 22, SeaIceFractionTendency = 23, XComponentIceDrift = 24, YComponentIceDrift = 25, FreezingMeltingPotential = 27, MeltOnsetDate = 28, FreezeOnsetDate = 29, Missing = 255 } export declare enum OceanographicIceParameterUnits { Proportion = "proportion", Meters = "m", DegreeTrue = "degree true", MetersPerSecond = "m s-1", PerSecond = "s-1", Kelvin = "K", PascalMeters = "Pa m", NewtonsPerMeter = "N m-1", CubicMetersPerSquareMeter = "m3m-2", JoulesPerSquareMeter = "J m-2", Fraction = "fraction", Numeric = "Numeric", WattsPerSquareMeter = "W m-2" } export declare enum OceanographicParameterCategory { Waves = 0, Currents = 1, Ice = 2, SurfaceProperties = 3, SubSurfaceProperties = 4, Miscellaneous = 191, Missing = 255 } export declare type OceanographicParameterNumber = OceanographicWaveParameterNumber | OceanographicCurrentsParameterNumber | OceanographicIceParameterNumber; export declare enum OceanographicWaveParameterNumber { WaveSpectra1 = 0, WaveSpectra2 = 1, WaveSpectra3 = 2, SignificantHeightCombined = 3, WindWaveDirection = 4, WindWaveHeight = 5, WindWavePeriod = 6, SwellWaveDirection = 7, SwellWaveHeight = 8, SwellWavePeriod = 9, PrimaryWaveDirection = 10, PrimaryWavePeriod = 11, SecondaryWaveDirection = 12, SecondaryWavePeriod = 13, CombinedWaveDirection = 14, CombinedWavePeriod = 15, DragCoefficient = 16, FrictionVelocity = 17, WaveStress = 18, NormalisedWaveStress = 19, MeanSquareSlope = 20, StokesDriftU = 21, StokesDriftV = 22, MaxWaveHeightPeriod = 23, MaxWaveHeight = 24, InverseMeanFrequency = 25, InverseMeanFrequencyWind = 26, InverseMeanFrequencySwell = 27, MeanZeroCrossingPeriod = 28, MeanZeroCrossingPeriodWind = 29, MeanZeroCrossingPeriodSwell = 30, WaveDirectionalWidth = 31, WindWaveDirectionalWidth = 32, SwellDirectionalWidth = 33, PeakWavePeriod = 34, PeakPeriodWindWaves = 35, PeakPeriodSwell = 36, AltimeterWaveHeight = 37, AltimeterCorrectedWaveHeight = 38, AltimeterRangeCorrection = 39, NeutralWindSpeed10m = 40, WindDirection10m = 41, WaveEnergySpectrum = 42, WaveElevationKurtosis = 43, BenjaminFeirIndex = 44, SpectralPeakedness = 45, PeakWaveDirection = 46, SwellHeight1 = 47, SwellHeight2 = 48, SwellHeight3 = 49, SwellPeriod1 = 50, SwellPeriod2 = 51, SwellPeriod3 = 52, SwellDirection1 = 53, SwellDirection2 = 54, SwellDirection3 = 55, SwellDirectionalWidth1 = 56, SwellDirectionalWidth2 = 57, SwellDirectionalWidth3 = 58, SwellFrequencyWidth1 = 59, SwellFrequencyWidth2 = 60, SwellFrequencyWidth3 = 61, WaveFrequencyWidth = 62, WindWaveFrequencyWidth = 63, TotalSwellFrequencyWidth = 64, SwellPeakPeriod1 = 65, SwellPeakPeriod2 = 66, SwellPeakPeriod3 = 67, SwellPeakDirection1 = 68, SwellPeakDirection2 = 69, SwellPeakDirection3 = 70, WindWavePeakDirection = 71, TotalSwellPeakDirection = 72, WhitecapFraction = 73, TotalSwellMeanDirection = 74, WindWaveMeanDirection = 75, Charnock = 76, WaveSpectralSkewness = 77, WaveEnergyFluxMagnitude = 78, WaveEnergyFluxDirection = 79, WaveAngularFrequencyWidthRatio = 80, FreeConvectiveVelocity = 81, AirDensity = 82, NormalizedWaveEnergyFlux = 83, NormalizedOceanStress = 84, NormalizedOceanEnergyFlux = 85, SurfaceElevationVariance = 86, WaveInducedMeanSeaLevel = 87, SpectralWidthIndex = 88, FreakWaveEventCount = 89, SurfaceMomentumFluxU = 90, SurfaceMomentumFluxV = 91, WaveTurbulentEnergyFlux = 92, EnvelopeMaxWaveHeight = 93, TimeDomainMaxCrestHeight = 94, TimeDomainMaxWaveHeight = 95, SpaceTimeMaxCrestHeight = 96, SpaceTimeMaxWaveHeight = 97, GodaPeakednessFactor = 98, WaveSteepness = 192, WaveLength = 193, Missing = 255 } export declare enum OceanographicWaveParameterUnits { Meters = "m", Seconds = "s", DegreeTrue = "degree true", MetersPerSecond = "m s-1", NewtonsPerSquareMeter = "N m-2", WattsPerMeter = "W m-1", KilogramsPerCubicMeter = "kg m-3", WattsPerSquareMeter = "W m-2", SquareMeters = "m2", Fraction = "fraction", Numeric = "Numeric", Proportion = "proportion" } export declare type ParameterCategory = OceanographicParameterCategory | MeteorologicalParameterCategory; export declare interface ParameterMetadata { parameterCategory: number[]; parameterNumber: number[]; parameterUnits: string[]; parameterName: string[]; shortName: string[]; cfVarName: string[]; } export declare type ParameterNumber = OceanographicWaveParameterNumber | MeteorologicalMomentumParameterNumber; export declare interface StdOutMsg { messages: GribParameter[]; [key: string]: unknown; } export declare interface WaveDirection extends BaseGrib2Message { parameterCategory: OceanographicParameterCategory.Waves; parameterNumber: OceanographicWaveParameterNumber.PrimaryWaveDirection; parameterUnits: GribParameterUnits.DegreeTrue; } export declare interface WaveHeight extends BaseGrib2Message { parameterCategory: OceanographicParameterCategory.Waves; parameterNumber: OceanographicWaveParameterNumber.SignificantHeightCombined; parameterUnits: GribParameterUnits.Meters; } export declare type WaveParameter = WaveHeight | WavePeriod | WaveDirection; export declare interface WavePeriod extends BaseGrib2Message { parameterCategory: OceanographicParameterCategory.Waves; parameterNumber: OceanographicWaveParameterNumber.PrimaryWavePeriod; parameterUnits: GribParameterUnits.Seconds; } export declare interface WindDirection extends BaseGrib2Message { parameterCategory: MeteorologicalParameterCategory.Momentum; parameterNumber: MeteorologicalMomentumParameterNumber.WindDirection; parameterUnits: GribParameterUnits.DegreeTrue; } export declare type WindParameter = WindSpeed | WindDirection; export declare interface WindSpeed extends BaseGrib2Message { parameterCategory: MeteorologicalParameterCategory.Momentum; parameterNumber: MeteorologicalMomentumParameterNumber.WindSpeed; parameterUnits: GribParameterUnits.MetersPerSecond; } export declare type WithLatLon<T extends BaseGrib2Message> = { [K in keyof T]: K extends "values" ? LocationForecast[] : T[K]; }; export { }