vgrib2
Version:
[](https://badge.fury.io/js/vgrib2)
1,934 lines (1,363 loc) • 119 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _ = require('buffer/');
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
/**
*
* @param data Buffer containing entire GRIB file
* @returns Array of GRIB Chunk Buffers containing individual GRIB definitions in file
*/
var splitGribChunks = function splitGribChunks(data) {
if (data.length === 0) return [];
var length = Number(data.slice(8, 16).readBigUInt64BE(0));
var gribData = data.slice(0, length);
return [gribData].concat(splitGribChunks(data.slice(length)));
};
var createPacket = function createPacket(sections) {
return _extends({}, sections[0].contents, sections[1].contents, sections[3].contents, sections[4].contents, sections[5].contents, sections[6].contents, sections[7].contents, sections[8].contents);
};
/**
* Table 0.0 - Discipline of Processed Data
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table0-0.shtml)
*/
var lookupTable00 = function lookupTable00(code) {
switch (code) {
case 0:
return 'Meteorological Products';
case 1:
return 'Hydrological Products';
case 2:
return 'Land Surface Products';
case 3:
return 'Satellite Remote Sensing Products (formerly "Space Products")';
case 4:
return 'Space Weather Products';
case 10:
return 'Oceanographic Products';
default:
throw new Error("Table 0.0 missing code value: " + code);
}
};
/**
* Indicator Section
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect0.shtml)
*/
var parseSection0 = function parseSection0(section) {
return {
/** Number of GRIB section */
sectionNumber: 0,
/** Name of Grib section */
sectionName: 'Indicator Section',
/** Length of GRIB section (Always 16 for Section 0)*/
length: 16,
/** Section 0 Contents */
contents: {
/** GRIB string encoded */
gribEncoded: section.slice(0, 4).toString(),
/** Discipline [Table 0.0](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table0-0.shtml) */
discipline: section.readUInt8(6),
/** Edition number - 2 for GRIB2 */
gribEdition: section.readUInt8(7),
/** Total length of GRIB message in octets (All sections) */
gribLength: Number(section.readBigUInt64BE(8))
}
};
};
/**
*
* @param ins Indictor Section
* @returns Indicator Section with corresponding string values
*/
var lookupSection0 = function lookupSection0(ins) {
return _extends({}, ins, {
contents: _extends({}, ins.contents, {
/** Discipline */
discipline: lookupTable00(ins.contents.discipline)
})
});
};
/**
* Table 0 - National/International Originating Centers
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/on388/table0.html)
*/
var lookupTable0 = function lookupTable0(code) {
switch (code) {
case 1:
return 'Melbourne (WMC)';
case 2:
return 'Melbourne (WMC)';
case 3:
return 'Melbourne (WMC)';
case 4:
return 'Moscow (WMC)';
case 5:
return 'Moscow (WMC)';
case 6:
return 'Moscow (WMC)';
case 7:
return 'US National Weather Service - NCEP (WMC)';
case 8:
return 'US National Weather Service - NWSTG (WMC)';
case 9:
return 'US National Weather Service - Other (WMC)';
case 10:
return 'Cairo (RSMC/RAFC)';
case 11:
return 'Cairo (RSMC/RAFC)';
case 12:
return 'Dakar (RSMC/RAFC)';
case 13:
return 'Dakar (RSMC/RAFC)';
case 14:
return 'Nairobi (RSMC/RAFC)';
case 15:
return 'Nairobi (RSMC/RAFC)';
case 16:
return 'Casablanca (RSMC)';
case 17:
return 'Tunis (RSMC)';
case 18:
return 'Tunis-Casablanca (RSMC)';
case 19:
return 'Tunis-Casablanca (RSMC)';
case 20:
return 'Las Palmas (RAFC)';
case 21:
return 'Algiers (RSMC)';
case 22:
return 'ACMAD';
case 23:
return 'Mozambique (NMC)';
case 24:
return 'Pretoria (RSMC)';
case 25:
return 'La Reunion (RSMC)';
case 26:
return 'Khabarovsk (RSMC)';
case 27:
return 'Khabarovsk (RSMC)';
case 28:
return 'New Delhi (RSMC/RAFC)';
case 29:
return 'New Delhi (RSMC/RAFC)';
case 30:
return 'Novosibirsk (RSMC)';
case 31:
return 'Novosibirsk (RSMC)';
case 32:
return 'Tashkent (RSMC)';
case 33:
return 'Jeddah (RSMC)';
case 34:
return 'Tokyo (RSMC), Japanese Meteorological Agency';
case 35:
return 'Tokyo (RSMC), Japanese Meteorological Agency';
case 36:
return 'Bankok';
case 37:
return 'Ulan Bator';
case 38:
return 'Beijing (RSMC)';
case 39:
return 'Beijing (RSMC)';
case 40:
return 'Seoul';
case 41:
return 'Buenos Aires (RSMC/RAFC)';
case 42:
return 'Buenos Aires (RSMC/RAFC)';
case 43:
return 'Brasilia (RSMC/RAFC)';
case 44:
return 'Brasilia (RSMC/RAFC)';
case 45:
return 'Santiago';
case 46:
return 'Brazilian Space Agency - INPE';
case 47:
return 'Columbia (NMC)';
case 48:
return 'Ecuador (NMC)';
case 49:
return 'Peru (NMC)';
case 50:
return 'Venezuela (NMC)';
case 51:
return 'Miami (RSMC/RAFC)';
case 52:
return 'Miami (RSMC), National Hurricane Center';
case 53:
return 'Canadian Meteorological Service - Montreal (RSMC)';
case 54:
return 'Canadian Meteorological Service - Montreal (RSMC)';
case 55:
return 'San Francisco';
case 56:
return 'ARINC Center';
case 57:
return 'US Air Force - Air Force Global Weather Center';
case 58:
return 'Fleet Numerical Meteorology and Oceanography Center,Monterey,CA,USA';
case 59:
return 'The NOAA Forecast Systems Lab, Boulder, CO, USA';
case 60:
return 'National Center for Atmospheric Research (NCAR), Boulder, CO';
case 61:
return 'Service ARGOS - Landover, MD, USA';
case 62:
return 'US Naval Oceanographic Office';
case 63:
return 'International Research Institude for Climate and Society';
case 64:
return 'Honolulu';
case 65:
return 'Darwin (RSMC)';
case 66:
return 'Darwin (RSMC)';
case 67:
return 'Melbourne (RSMC)';
case 69:
return 'Wellington (RSMC/RAFC)';
case 70:
return 'Wellington (RSMC/RAFC)';
case 71:
return 'Nadi (RSMC)';
case 72:
return 'Singapore';
case 73:
return 'Malaysia (NMC)';
case 74:
return 'U.K. Met Office - Exeter (RSMC)';
case 75:
return 'U.K. Met Office - Exeter (RSMC)';
case 76:
return 'Moscow (RSMC/RAFC)';
case 78:
return 'Offenbach (RSMC)';
case 79:
return 'Offenbach (RSMC)';
case 80:
return 'Rome (RSMC)';
case 81:
return 'Rome (RSMC)';
case 82:
return 'Norrkoping';
case 83:
return 'Norrkoping';
case 84:
return 'French Weather Service - Toulouse';
case 85:
return 'French Weather Service - Toulouse';
case 86:
return 'Helsinki';
case 87:
return 'Belgrade';
case 88:
return 'Oslo';
case 89:
return 'Prague';
case 90:
return 'Episkopi';
case 91:
return 'Ankara';
case 92:
return 'Frankfurt/Main (RAFC)';
case 93:
return 'London (WAFC)';
case 94:
return 'Copenhagen';
case 95:
return 'Rota';
case 96:
return 'Athens';
case 97:
return 'European Space Agency (ESA)';
case 98:
return 'European Center for Medium-Range Weather Forecasts (RSMC)';
case 99:
return 'De Bilt, Netherlands';
case 100:
return 'Brazzaville';
case 101:
return 'Abidjan';
case 102:
return 'Libyan Arab Jamahiriya (NMC)';
case 103:
return 'Madagascar (NMC)';
case 104:
return 'Mauritius (NMC)';
case 105:
return 'Niger (NMC)';
case 106:
return 'Seychelles (NMC)';
case 107:
return 'Uganda (NMC)';
case 108:
return 'United Republic of Tanzania (NMC)';
case 109:
return 'Zimbabwe (NMC)';
case 110:
return 'Hong-Kong';
case 111:
return 'Afghanistan (NMC)';
case 112:
return 'Bahrain (NMC)';
case 113:
return 'Bangladesh (NMC)';
case 114:
return 'Bhutan (NMC)';
case 115:
return 'Cambodia (NMC)';
case 116:
return "Democratic People's Republic of Korea (NMC)";
case 117:
return 'Islamic Republic of Iran (NMC)';
case 118:
return 'Iraq (NMC)';
case 119:
return 'Kazakhstan (NMC)';
case 120:
return 'Kuwait (NMC)';
case 121:
return 'Kyrgyz Republic (NMC)';
case 122:
return "Lao People's Democratic Republic (NMC)";
case 123:
return 'Macao, China';
case 124:
return 'Maldives (NMC)';
case 125:
return 'Myanmar (NMC)';
case 126:
return 'Nepal (NMC)';
case 127:
return 'Oman (NMC)';
case 128:
return 'Pakistan (NMC)';
case 129:
return 'Qatar (NMC)';
case 130:
return 'Yemen (NMC)';
case 131:
return 'Sri Lanka (NMC)';
case 132:
return 'Tajikistan (NMC)';
case 133:
return 'Turkmenistan (NMC)';
case 134:
return 'United Arab Emirates (NMC)';
case 135:
return 'Uzbekistan (NMC)';
case 136:
return 'Viet Nam (NMC)';
case 140:
return 'Bolivia (NMC)';
case 141:
return 'Guyana (NMC)';
case 142:
return 'Paraguay (NMC)';
case 143:
return 'Suriname (NMC)';
case 144:
return 'Uruguay (NMC)';
case 145:
return 'French Guyana';
case 146:
return 'Brazilian Navy Hydrographic Center';
case 147:
return 'National Commission on Space Activities - Argentina';
case 148:
return 'Brazilian Department of Airspace Control - DECEA';
case 150:
return 'Antigua and Barbuda (NMC)';
case 151:
return 'Bahamas (NMC)';
case 152:
return 'Barbados (NMC)';
case 153:
return 'Belize (NMC)';
case 154:
return 'British Caribbean Territories Center';
case 155:
return 'San Jose';
case 156:
return 'Cuba (NMC)';
case 157:
return 'Dominica (NMC)';
case 158:
return 'Dominican Republic (NMC)';
case 159:
return 'El Salvador (NMC)';
case 160:
return 'US NOAA/NESDIS';
case 161:
return 'US NOAA Office of Oceanic and Atmospheric Research';
case 162:
return 'Guatemala (NMC)';
case 163:
return 'Haiti (NMC)';
case 164:
return 'Honduras (NMC)';
case 165:
return 'Jamaica (NMC)';
case 166:
return 'Mexico City';
case 167:
return 'Netherlands Antilles and Aruba (NMC)';
case 168:
return 'Nicaragua (NMC)';
case 169:
return 'Panama (NMC)';
case 170:
return 'Saint Lucia (NMC)';
case 171:
return 'Trinidad and Tobago (NMC)';
case 172:
return 'French Departments in RA IV';
case 173:
return 'US National Aeronautics and Space Administration (NASA)';
case 174:
return 'Integrated System Data Management/Marine Environmental Data Service (ISDM/MEDS) - Canada';
case 176:
return 'US Cooperative Institude for Meteorological Satellite Studies';
case 190:
return 'Cook Islands (NMC)';
case 191:
return 'French Polynesia (NMC)';
case 192:
return 'Tonga (NMC)';
case 193:
return 'Vanuatu (NMC)';
case 194:
return 'Brunei (NMC)';
case 195:
return 'Indonesia (NMC)';
case 196:
return 'Kiribati (NMC)';
case 197:
return 'Federated States of Micronesia (NMC)';
case 198:
return 'New Caledonia (NMC)';
case 199:
return 'Niue';
case 200:
return 'Papua New Guinea (NMC)';
case 201:
return 'Philippines (NMC)';
case 202:
return 'Samoa (NMC)';
case 203:
return 'Solomon Islands (NMC)';
case 204:
return 'Narional Institude of Water and Atmospheric Research - New Zealand';
case 210:
return 'Frascati (ESA/ESRIN)';
case 211:
return 'Lanion';
case 212:
return 'Lisbon';
case 213:
return 'Reykjavik';
case 214:
return 'Madrid';
case 215:
return 'Zurich';
case 216:
return 'Service ARGOS - Toulouse';
case 217:
return 'Bratislava';
case 218:
return 'Budapest';
case 219:
return 'Ljubljana';
case 220:
return 'Warsaw';
case 221:
return 'Zagreb';
case 222:
return 'Albania (NMC)';
case 223:
return 'Armenia (NMC)';
case 224:
return 'Austria (NMC)';
case 225:
return 'Azerbaijan (NMC)';
case 226:
return 'Belarus (NMC)';
case 227:
return 'Belgium (NMC)';
case 228:
return 'Bosnia and Herzegovina (NMC)';
case 229:
return 'Bulgaria (NMC)';
case 230:
return 'Cyprus (NMC)';
case 231:
return 'Estonia (NMC)';
case 232:
return 'Georgia (NMC)';
case 233:
return 'Dublin';
case 234:
return 'Israel (NMC)';
case 235:
return 'Jordan (NMC)';
case 236:
return 'Latvia (NMC)';
case 237:
return 'Lebanon (NMC)';
case 238:
return 'Lithuania (NMC)';
case 239:
return 'Luxembourg';
case 240:
return 'Malta (NMC)';
case 241:
return 'Monaco';
case 242:
return 'Romania (NMC)';
case 243:
return 'Syrian Arab Republic (NMC)';
case 244:
return 'The former Yugoslav Republic of Macedonia (NMC)';
case 245:
return 'Ukraine (NMC)';
case 246:
return 'Republic of Moldova (NMC)';
case 247:
return 'Operational Programme for the Exchange of Weather RAdar Information (OPERA) - EUMETNET';
case 250:
return 'COnsortium for Small scale MOdelling (COSMO)';
case 254:
return 'EUMETSAT Operations Center';
case 255:
return 'Missing Value';
default:
throw new Error("Table 0 missing code value: " + code);
}
};
/**
* Table A - Generating Process or Model from Originating Center 7
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/on388/tablec.html)
*/
var lookupTableA = function lookupTableA(code) {
switch (code) {
case 2:
return 'Ultra Violet Index Model';
case 3:
return 'NCEP/ARL Transport and Dispersion Model';
case 4:
return 'NCEP/ARL Smoke Model';
case 5:
return 'Satellite Derived Precipitation and temperatures, from IR (See PDS Octet 41 ... for specific satellite ID)';
case 6:
return 'NCEP/ARL Dust Model';
case 10:
return 'Global Wind-Wave Forecast Model';
case 11:
return 'Global Multi-Grid Wave Model (Static Grids)';
case 12:
return 'Probabilistic Storm Surge (P-Surge)';
case 13:
return 'Hurricane Multi-Grid Wave Model';
case 14:
return 'Extra-tropical Storm Surge Atlantic Domain';
case 15:
return 'Nearshore Wave Prediction System (NWPS)';
case 16:
return 'Extra-Tropical Storm Surge (ETSS)';
case 17:
return 'Extra-tropical Storm Surge Pacific Domain';
case 18:
return 'Probabilistic Extra-Tropical Storm Surge (P-ETSS)';
case 19:
return 'Limited-area Fine Mesh (LFM) analysis';
case 20:
return 'Extra-tropical Storm Surge Micronesia Domain';
case 25:
return 'Snow Cover Analysis';
case 30:
return 'Forecaster generated field';
case 31:
return 'Value added post processed field';
case 42:
return 'Global Optimum Interpolation Analysis (GOI) from GFS model';
case 43:
return 'Global Optimum Interpolation Analysis (GOI) from "Final" run';
case 44:
return 'Sea Surface Temperature Analysis';
case 45:
return 'Coastal Ocean Circulation Model';
case 46:
return 'HYCOM - Global';
case 47:
return 'HYCOM - North Pacific basin';
case 48:
return 'HYCOM - North Atlantic basin';
case 49:
return 'Ozone Analysis from TIROS Observations';
case 52:
return 'Ozone Analysis from Nimbus 7 Observations';
case 53:
return 'LFM-Fourth Order Forecast Model';
case 64:
return 'Regional Optimum Interpolation Analysis (ROI)';
case 68:
return '80 wave triangular, 18-layer Spectral model from GFS model';
case 69:
return '80 wave triangular, 18 layer Spectral model from "Medium Range Forecast" run';
case 70:
return 'Quasi-Lagrangian Hurricane Model (QLM)';
case 71:
return 'Hurricane Weather Research and Forecasting (HWRF) Model';
case 72:
return 'Hurricane Non-Hydrostatic Multiscale Model on the B Grid (HNMMB)';
case 73:
return 'Fog Forecast model - Ocean Prod. Center';
case 74:
return 'Gulf of Mexico Wind/Wave';
case 75:
return 'Gulf of Alaska Wind/Wave';
case 76:
return 'Bias corrected Medium Range Forecast';
case 77:
return '126 wave triangular, 28 layer Spectral model from GFS model';
case 78:
return '126 wave triangular, 28 layer Spectral model from "Medium Range Forecast" run';
case 79:
return 'Backup from the previous run';
case 80:
return '62 wave triangular, 28 layer Spectral model from "Medium Range Forecast" run';
case 81:
return 'Analysis from GFS (Global Forecast System)';
case 82:
return 'Analysis from GDAS (Global Data Assimilation System)';
case 83:
return 'High Resolution Rapid Refresh (HRRR)';
case 84:
return 'MESO NAM Model (currently 12 km)';
case 85:
return 'Real Time Ocean Forecast System (RTOFS)';
case 86:
return 'Early Hurricane Wind Speed Probability Model';
case 87:
return 'CAC Ensemble Forecasts from Spectral (ENSMB)';
case 88:
return 'NOAA Wave Watch III (NWW3) Ocean Wave Model';
case 89:
return 'Non-hydrostatic Meso Model (NMM) (Currently 8 km)';
case 90:
return '62 wave triangular, 28 layer spectral model extension of the "Medium Range Forecast" run';
case 91:
return '62 wave triangular, 28 layer spectral model extension of the GFS model';
case 92:
return '62 wave triangular, 28 layer spectral model run from the "Medium Range Forecast" final analysis';
case 93:
return '62 wave triangular, 28 layer spectral model run from the T62 GDAS analysis of the "Medium Range Forecast" run';
case 94:
return 'T170/L42 Global Spectral Model from MRF run';
case 95:
return 'T126/L42 Global Spectral Model from MRF run';
case 96:
return 'Global Forecast System Model T1534 - Forecast hours 00-384 T574 - Forecast hours 00-192 T190 - Forecast hours 204-384';
case 98:
return 'Climate Forecast System Model -- Atmospheric model (GFS) coupled to a multi level ocean model. Currently GFS spectral model at T62, 64 levels coupled to 40 level MOM3 ocean model.';
case 99:
return 'Miscellaneous Test ID';
case 100:
return 'Miscellaneous Test ID';
case 101:
return 'Conventional Observation Re-Analysis (CORE)';
case 104:
return 'National Blend GRIB';
case 105:
return 'Rapid Refresh (RAP)';
case 107:
return 'Global Ensemble Forecast System (GEFS)';
case 108:
return 'LAMP';
case 109:
return 'RTMA (Real Time Mesoscale Analysis)';
case 110:
return 'NAM Model - 15km version';
case 111:
return 'NAM model, generic resolution (Used in SREF processing)';
case 112:
return 'WRF-NMM model, generic resolution (Used in various runs) NMM=Nondydrostatic Mesoscale Model (NCEP)';
case 113:
return 'Products from NCEP SREF processing';
case 114:
return 'NAEFS Products from joined NCEP, CMC global ensembles';
case 115:
return 'Downscaled GFS from NAM eXtension';
case 116:
return 'WRF-EM model, generic resolution (Used in various runs) EM - Eulerian Mass-core (NCAR - aka Advanced Research WRF)';
case 117:
return 'NEMS GFS Aerosol Component';
case 118:
return 'URMA (UnRestricted Mesoscale Analysis)';
case 119:
return 'WAM (Whole Atmosphere Model)';
case 120:
return 'Ice Concentration Analysis';
case 121:
return 'Western North Atlantic Regional Wave Model';
case 122:
return 'Alaska Waters Regional Wave Model';
case 123:
return 'North Atlantic Hurricane Wave Model';
case 124:
return 'Eastern North Pacific Regional Wave Model';
case 125:
return 'North Pacific Hurricane Wave Model';
case 126:
return 'Sea Ice Forecast Model';
case 127:
return 'Lake Ice Forecast Model';
case 128:
return 'Global Ocean Forecast Model';
case 129:
return 'Global Ocean Data Analysis System (GODAS)';
case 130:
return 'Merge of fields from the RUC, NAM, and Spectral Model';
case 131:
return 'Great Lakes Wave Model';
case 132:
return 'High Resolution Ensemble Forecast (HREF)';
case 133:
return 'Great Lakes Short Range Wave Model';
case 134:
return 'Rapid Refresh Forecast System (RRFS)';
case 135:
return 'Hurricane Analysis and Forecast System (HAFS)';
case 140:
return 'North American Regional Reanalysis (NARR)';
case 141:
return 'Land Data Assimilation and Forecast System';
case 150:
return 'NWS River Forecast System (NWSRFS)';
case 151:
return 'NWS Flash Flood Guidance System (NWSFFGS)';
case 152:
return 'WSR-88D Stage II Precipitation Analysis';
case 153:
return 'WSR-88D Stage III Precipitation Analysis';
case 180:
return 'Quantitative Precipitation Forecast generated by NCEP';
case 181:
return 'River Forecast Center Quantitative Precipitation Forecast mosaic generated by NCEP';
case 182:
return 'River Forecast Center Quantitative Precipitation estimate mosaic generated by NCEP';
case 183:
return 'NDFD product generated by NCEP/HPC';
case 184:
return 'Climatological Calibrated Precipitation Analysis - CCPA';
case 190:
return 'National Convective Weather Diagnostic generated by NCEP/AWC';
case 191:
return 'Current Icing Potential automated product genterated by NCEP/AWC';
case 192:
return 'Analysis product from NCEP/AWC';
case 193:
return 'Forecast product from NCEP/AWC';
case 195:
return 'Climate Data Assimilation System 2 (CDAS2)';
case 196:
return 'Climate Data Assimilation System 2 (CDAS2) - used for regeneration runs';
case 197:
return 'Climate Data Assimilation System (CDAS)';
case 198:
return 'Climate Data Assimilation System (CDAS) - used for regeneration runs';
case 199:
return 'Climate Forecast System Reanalysis (CFSR) -- Atmospheric model (GFS) coupled to a multi level ocean, land and seaice model. Currently GFS spectral model at T382, 64 levels coupled to 40 level MOM4 ocean model.';
case 200:
return 'CPC Manual Forecast Product';
case 201:
return 'CPC Automated Product';
case 210:
return 'EPA Air Quality Forecast - Currently North East US domain';
case 211:
return 'EPA Air Quality Forecast - Currently Eastern US domain';
case 215:
return 'SPC Manual Forecast Product';
case 220:
return 'NCEP/OPC automated product';
case 255:
return 'Missing';
default:
throw new Error("Table A missing code value: " + code);
}
};
/**
* Table C - National Sub-Centerss
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/on388/tablec.html)
*/
var lookupTableC = function lookupTableC(code) {
switch (code) {
case 0:
return null;
case 1:
return 'NCEP Re-Analysis Project';
case 2:
return 'NCEP Ensemble Products';
case 3:
return 'NCEP Central Operations';
case 4:
return 'Environmental Modeling Center';
case 5:
return 'Weather Prediction Center';
case 6:
return 'Ocean Prediction Center';
case 7:
return 'Climate Prediction Center';
case 8:
return 'Aviation Weather Center';
case 9:
return 'Storm Prediction Center';
case 10:
return 'National Hurricane Center';
case 11:
return 'NWS Techniques Development Laboratory';
case 12:
return 'NESDIS Office of Research and Applications';
case 13:
return 'Federal Aviation Administration';
case 14:
return 'NWS Meteorological Development Laboratory';
case 15:
return 'North American Regional Reanalysis Project';
case 16:
return 'Space Weather Prediction Center';
case 17:
return 'ESRL Global Systems Division';
default:
throw new Error("Table C missing code value: " + code);
}
};
/**
* Table 1.2 - Significance of Reference Time
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-2.shtml)
*/
var lookupTable12 = function lookupTable12(code) {
switch (code) {
case 0:
return 'Analysis';
case 1:
return 'Start of Forecast';
case 2:
return 'Verifying Time of Forecast';
case 3:
return 'Observation Time';
case 255:
return 'Missing';
default:
throw new Error("Table 1.2 missing code value: " + code);
}
};
/**
* Table 1.4 - Type of Data
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-4.shtml)
*/
var lookupTable14 = function lookupTable14(code) {
switch (code) {
case 0:
return 'Analysis Products';
case 1:
return 'Forecast Products';
case 2:
return 'Analysis and Forecast Products';
case 3:
return 'Control Forecast Products';
case 4:
return 'Perturbed Forecast Products';
case 5:
return 'Control and Perturbed Forecast Products';
case 6:
return 'Processed Satellite Observations';
case 7:
return 'Processed Radar Observations';
case 8:
return 'Event Probability';
case 192:
return 'Experimental Products';
case 255:
return 'Missing';
default:
throw new Error("Table 1.4 missing code value: " + code);
}
};
/**
* Identification Section
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect1.shtml)
*/
var parseSection1 = function parseSection1(section) {
// Ref Time values
var year = section.readUInt16BE(12);
var month = section.readUInt8(14);
var day = section.readUInt8(15);
var hours = section.readUInt8(16);
var minutes = section.readUInt8(17);
var seconds = section.readUInt8(18);
var refTime = new Date(year, month - 1, day);
refTime.setUTCHours(hours);
refTime.setUTCMinutes(minutes);
refTime.setUTCSeconds(seconds);
return {
/** Number of GRIB section */
sectionNumber: section.readUInt8(4),
/** Name of Grib section */
sectionName: 'Identification Section',
/** Length of GRIB section */
length: section.readUInt32BE(0),
/** Section 1 Contents */
contents: {
/** Identification of originating/generating center [Table 0](https://www.nco.ncep.noaa.gov/pmb/docs/on388/table0.html) */
center: section.readUInt16BE(5),
/** Identification of originating/generating subcenter [Table C](https://www.nco.ncep.noaa.gov/pmb/docs/on388/tablec.html) */
subcenter: section.readUInt16BE(7),
/** GRIB master tables version number [Table 1.0](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-0.shtml) */
gribMasterTablesVersion: section.readUInt8(9),
/** Version number of GRIB local tables used to augment Master Tables [Table 1.1](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-1.shtml) */
gribLocalTablesVersion: section.readUInt8(10),
/** Significance of reference time [Table 1.2](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-2.shtml) */
significanceOfRT: section.readUInt8(11),
/** Reference Time */
refTime: refTime,
/** Type of processed data in this GRIB message [Table 1.4](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-4.shtml) */
typeOfProcessedData: section.readUInt8(20)
}
};
};
/**
*
* @param ids Identification Section
* @returns Identification Section with corresponding string values
*/
var lookupSection1 = function lookupSection1(ids) {
return _extends({}, ids, {
contents: _extends({}, ids.contents, {
/** Identification of originating/generating center */
center: lookupTable0(ids.contents.center),
/** Identification of originating/generating subcenter */
subcenter: lookupTableC(ids.contents.subcenter),
/** Significance of reference time */
significanceOfRT: lookupTable12(ids.contents.subcenter),
/** Type of processed data in this GRIB message */
typeOfProcessedData: lookupTable14(ids.contents.typeOfProcessedData)
})
});
};
/**
* Local Use Section
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect2.shtml)
*/
var parseSection2 = function parseSection2(_section) {
throw new Error('Section 2 is not supported');
};
/**
* Table 3.1 - Grid Definition Template Number
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-1.shtml)
*/
var lookupTable31 = function lookupTable31(code) {
switch (code) {
case 0:
return 'Latitude/Longitude (Also called Equidistant Cylindrical or Plate Caree)';
case 1:
return 'Rotated Latitude/Longitude';
case 2:
return 'Stretched Latitude/Longitude';
case 3:
return 'Rotated and Stretched Latitude/Longitude';
case 4:
return 'Variable Resolution Latitude/longitude';
case 5:
return 'Variable Resolution Rotated Latitude/longitude';
case 10:
return 'Mercator';
case 11:
return 'Reserved';
case 12:
return 'Transverse Mercator';
case 13:
return 'Mercator with modelling subdomains definition';
case 20:
return 'Polar Stereographic Projection (Can be North or South)';
case 23:
return 'Polar Stereographic with modelling subdomains definition';
case 30:
return 'Lambert Conformal (Can be Secant, Tangent, Conical, or Bipolar)';
case 31:
return 'Albers Equal Area';
case 32:
return 'Reserved';
case 33:
return 'Lambert conformal with modelling subdomains definition';
case 40:
return 'Gaussian Latitude/Longitude';
case 41:
return 'Rotated Gaussian Latitude/Longitude';
case 42:
return 'Stretched Gaussian Latitude/Longitude';
case 43:
return 'Rotated and Stretched Gaussian Latitude/Longitude';
case 50:
return 'Spherical Harmonic Coefficients';
case 51:
return 'Rotated Spherical Harmonic Coefficients';
case 52:
return 'Stretched Spherical Harmonic Coefficients';
case 53:
return 'Rotated and Stretched Spherical Harmonic Coefficients';
case 60:
return 'Cubed-Sphere Gnomonic Validation';
case 61:
return 'Spectral Mercator with modelling subdomains definition';
case 62:
return 'Spectral Polar Stereographic with modelling subdomains definition';
case 63:
return 'Spectral Lambert conformal with modelling subdomains definition';
case 90:
return 'Space View Perspective or Orthographic';
case 100:
return 'Triangular Grid Based on an Icosahedron';
case 101:
return 'General Unstructured Grid';
case 110:
return 'Equatorial Azimuthal Equidistant Projection';
case 120:
return 'Azimuth-Range Projection';
case 140:
return 'Lambert Azimuthal Equal Area Projection';
case 204:
return 'Curvilinear Orthogonal Grids';
case 1000:
return 'Cross Section Grid with Points Equally Spaced on the Horizontal';
case 1100:
return 'Hovmoller Diagram with Points Equally Spaced on the Horizontal';
case 1200:
return 'Time Section Grid';
case 32768:
return 'Rotated Latitude/Longitude(Arakawa Staggered E-Grid)';
case 32769:
return 'Rotated Latitude/Longitude(Arakawa Non-E Staggered Grid)';
case 65535:
return 'Missing';
default:
throw new Error("Table 3.1 missing code value: " + code);
}
};
/**
* Table 3.2 - Grid Definition Template Number
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-1.shtml)
*/
var lookupTable32 = function lookupTable32(code) {
switch (code) {
case 0:
return 'Earth assumed spherical with radius = 6,367,470.0 m';
case 1:
return 'Earth assumed spherical with radius specified (in m) by data producer';
case 2:
return 'Earth assumed oblate spheriod with size as determined by IAU in 1965 (major axis = 6,378,160.0 m, minor axis = 6,356,775.0 m, f = 1/297.0)';
case 3:
return 'Earth assumed oblate spheriod with major and minor axes specified (in km) by data producer';
case 4:
return 'Earth assumed oblate spheriod as defined in IAG-GRS80 model (major axis = 6,378,137.0 m, minor axis = 6,356,752.314 m, f = 1/298.257222101)';
case 5:
return 'Earth assumed represented by WGS84 (as used by ICAO since 1998) (Uses IAG-GRS80 as a basis)';
case 6:
return 'Earth assumed spherical with radius = 6,371,229.0 m';
case 7:
return 'Earth assumed oblate spheroid with major and minor axes specified (in m) by data producer';
case 8:
return 'Earth model assumed spherical with radius 6,371,200 m, but the horizontal datum of the resulting Latitude/Longitude field is the WGS84 reference frame';
case 9:
return 'Earth represented by the OSGB 1936 Datum, using the Airy_1830 Spheroid, the Greenwich meridian as 0 Longitude, the Newlyn datum as mean sea level, 0 height.';
case 255:
return 'Missing';
default:
throw new Error("Table 3.2 missing code value: " + code);
}
};
/**
* @description Returns a template generator for the given template number
* @param template Template number
* @returns Template generator
*/
var getTemplate3 = function getTemplate3(template) {
switch (template) {
case 0:
return template30;
default:
throw new Error("Template 3." + template + " not defined");
}
};
/**
* @description Returns a template map for the given template number
* @param table Template number
* @returns Template Map
*/
var lookupTemplate3 = function lookupTemplate3(template) {
switch (template) {
case 0:
return lookupTemplate30;
default:
throw new Error("Template 3." + template + " lookup table not defined");
}
};
/**
* Grid Definition Template 3.0
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp3-0.shtml)
*/
var template30 = function template30(section) {
var basicAngle = section.readUInt32BE(38);
var subdivisions = section.readUInt32BE(42);
var ratio = basicAngle === 0 ? 1e-6 : basicAngle / subdivisions;
return {
/** Shape of Earth [Table 3.2](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-2.shtml) */
shape: section.readUInt8(14),
/** Number of points along a parallel */
nx: section.readUInt32BE(30),
/** Number of points along a meridian */
ny: section.readUInt32BE(34),
/** Basic angle of the initial production domain */
basicAngle: basicAngle,
/** Subdivisions of basic angle used to define extreme longitudes and latitudes, and direction increments */
subdivisions: subdivisions,
/** Latitude of first grid point */
la1: (section.readInt32BE(46) < 0 ? -(section.readInt32BE(46) ^ 0x80000000) : section.readInt32BE(46)) * ratio,
/** Longitude of first grid point */
lo1: section.readInt32BE(50) * ratio,
/** Resolution and component flags [Table 3.3](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-3.shtml) */
resolution: section.readUInt8(54),
/** Latitude of last grid point */
la2: (section.readInt32BE(55) < 0 ? -(section.readInt32BE(55) ^ 0x80000000) : section.readInt32BE(55)) * ratio,
/** Longitude of last grid point */
lo2: section.readInt32BE(59) * ratio,
/** i direction increment */
dx: section.readInt32BE(63) * ratio,
/** j direction increment */
dy: section.readInt32BE(67) * ratio,
/** Scanning mode [Table 3.4](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-4.shtml) */
scanMode: section.readUInt8(71),
/** Grid Units */
gridUnits: 'degrees'
};
};
var lookupTemplate30 = function lookupTemplate30(templateValues) {
return _extends({}, templateValues, {
/** Shape of Earth [Table 3.2](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-2.shtml) */
shape: lookupTable32(templateValues.shape)
});
};
/**
* Grid Definition Section
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml)
*/
var parseSection3 = function parseSection3(section) {
var gridDefinitionTemplate = section.readUInt16BE(12);
var gridDefinition = getTemplate3(gridDefinitionTemplate)(section);
return {
/** Number of GRIB section */
sectionNumber: section.readUInt8(4),
/** Name of Grib section */
sectionName: 'Grid Definition Section',
/** Length of GRIB section */
length: section.readUInt32BE(0),
/** Section 3 Contents */
contents: {
/** Number of data points */
numberOfPoints: section.readUInt32BE(6),
/** Grid definition template number [Table 3.1](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-1.shtml) */
gridDefinitionTemplate: gridDefinitionTemplate,
/** Grid definition values */
gridDefinition: gridDefinition
}
};
};
/**
*
* @param gds Grid Definition Section
* @returns Grid Definition Section with corresponding string values
*/
var lookupSection3 = function lookupSection3(gds) {
var gridDefinitionTemplate = gds.contents.gridDefinitionTemplate;
return _extends({}, gds, {
contents: _extends({}, gds.contents, {
/** Grid definition template */
gridDefinitionTemplate: lookupTable31(gridDefinitionTemplate),
/** Grid definition values */
gridDefinition: lookupTemplate3(gridDefinitionTemplate)(gds.contents.gridDefinition)
})
});
};
/**
* Table 4.0 - PRODUCT DEFINITION TEMPLATE NUMBER
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table4-0.shtml)
*/
var lookupTable40 = function lookupTable40(code) {
switch (code) {
case 0:
return 'Analysis or forecast at a horizontal level or in a horizontal layer at a point in time.';
case 1:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time.';
case 2:
return 'Derived forecasts based on all ensemble members at a horizontal level or in a horizontal layer at a point in time.';
case 3:
return 'Derived forecasts based on a cluster of ensemble members over a rectangular area at a horizontal level or in a horizontal layer at a point in time.';
case 4:
return 'Derived forecasts based on a cluster of ensemble members over a circular area at a horizontal level or in a horizontal layer at a point in time.';
case 5:
return 'Probability forecasts at a horizontal level or in a horizontal layer at a point in time.';
case 6:
return 'Percentile forecasts at a horizontal level or in a horizontal layer at a point in time.';
case 7:
return 'Analysis or forecast error at a horizontal level or in a horizontal layer at a point in time.';
case 8:
return 'Average, accumulation, extreme values or other statistically processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval.';
case 9:
return 'Probability forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval.';
case 10:
return 'Percentile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval.';
case 11:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval.';
case 12:
return 'Derived forecasts based on all ensemble members at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval.';
case 13:
return 'Derived forecasts based on a cluster of ensemble members over a rectangular area at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval.';
case 14:
return 'Derived forecasts based on a cluster of ensemble members over a circular area at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval.';
case 15:
return 'Average, accumulation, extreme values or other statistically-processed values over a spatial area at a horizontal level or in a horizontal layer at a point in time.';
case 20:
return 'Radar product';
case 30:
return 'Satellite product NOTE: This template is deprecated. Template 4.31 should be used instead.';
case 31:
return 'Satellite product';
case 32:
return 'Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for simulate (synthetic) satellite data';
case 33:
return 'Individual Ensemble Forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time for simulated (synthetic) satellite data';
case 34:
return 'Individual Ensemble Forecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous interval for simulated (synthetic) satellite data';
case 35:
return 'Satellite product with or without associated quality values';
case 40:
return 'Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for atmospheric chemical constituents.';
case 41:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time for atmospheric chemical constituents.';
case 42:
return 'Average, accumulation, and/or extreme values or other statistically processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for atmospheric chemical constituents.';
case 43:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval for atmospheric chemical constituents.';
case 44:
return 'Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for aerosol.';
case 45:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval for aerosol.';
case 46:
return 'Average, accumulation, and/or extreme values or other statistically processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for aerosol.';
case 47:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval for aerosol.';
case 48:
return 'Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for aerosol.';
case 49:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time for optical properties of aerosol.';
case 51:
return 'Categorical forecast at a horizontal level or in a horizontal layer at a point in time.';
case 53:
return 'Partitioned names at a horizontal level or horizontal layer at a point in time.';
case 54:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time for partitioned names.';
case 55:
return 'Spatio-temporal changing tiles at a horizontal level or horizontal layer at a point in time';
case 56:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time for spatio-temporal changing tile names.';
case 57:
return 'Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for atmospheric chemical constituents based on a distribution function';
case 58:
return 'Individual Ensemble Forecast, Control and Perturbed, at a horizontal level or in a horizontal layer at a point in time interval for Atmospheric Chemical Constituents based on a distribution function';
case 59:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time for spatio-temporal changing tile names (corrected version of template 4.56 - See Template 4.59)';
case 60:
return 'Individual Ensemble Reforecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time.';
case 61:
return 'Individual Ensemble Reforecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval';
case 62:
return 'Average, Accumulation and/or Extreme values or other Statistically-processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for spatio-temporal changing tiles at a horizontal level or horizontal layer at a point in time';
case 63:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for spatio-temporal changing tiles';
case 67:
return 'Average, accumulation and/or extreme values or other statistically processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for atmospheric chemical constituents based on a distribution function';
case 68:
return 'Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for atmospheric chemical constituents based on a distribution function.';
case 70:
return 'Post-processing analysis or forecast at a horizontal level or in a horizontal layer at a point in time.';
case 71:
return 'Post-processing individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time.';
case 72:
return 'Post-processing average, accumulation, extreme values or other statistically processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval.';
case 73:
return 'Post-processing individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer, in a continuous or non-continuous time interval.';
case 91:
return 'Categorical forecast at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval.';
case 254:
return 'CCITT IA5 character string';
case 1000:
return 'Cross-section of analysis and forecast at a point in time.';
case 1001:
return 'Cross-section of averaged or otherwise statistically processed analysis or forecast over a range of time.';
case 1002:
return 'Cross-section of analysis and forecast, averaged or otherwise statistically-processed over latitude or longitude.';
case 1100:
return 'Hovmoller-type grid with no averaging or other statistical processing';
case 1101:
return 'Hovmoller-type grid with averaging or other statistical processing';
case 65535:
return 'Missing';
default:
throw new Error("Table 4.0 missing code value: " + code);
}
};
/**
* Table 4.1 - name CATEGORY BY PRODUCT DISCIPLINE
*
* [Read more...](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table4-1.shtml)