// Sanitization $(function() { $('#container').html('
'); }) function popup(site) { if (!site) { site = 'kslc' } alert('Something is wrong!'); window.location.href = 'https://www.weather.gov/wrh/timeseries?site='+site; } function myMonitorOBS(SITE,numHours) { SITE = SITE.toUpperCase(); $('#SITE').html(''); var numMinutes = numHours * 60; var InfoToGet = 'https://api.mesowest.net/v2/stations/timeseries?STID='+SITE+'&showemptystations=1&units=temp|F,speed|mph,english&recent='+numMinutes+'&token=d8c6aee36a994f90857925cea26934be&complete=1&obtimezone=local'; console.log('HELLO', InfoToGet); $.getJSON(InfoToGet, function(DATA) { if (DATA.SUMMARY.RESPONSE_MESSAGE == "OK") { // Metadata var stnID = DATA.STATION[0].STID; var stnNAM = DATA.STATION[0].NAME; var stnLAT = DATA.STATION[0].LATITUDE; var stnLON = DATA.STATION[0].LONGITUDE var stnELE = DATA.STATION[0].ELEVATION; var state = DATA.STATION[0].STATE; var cwa = DATA.STATION[0].CWA; var network = DATA.STATION[0].SHORTNAME; var derived = 0; // Building block for datasets var header1 = ''; var EngUnits = ''; var stamps = ''; if (DATA.STATION[0].hasOwnProperty('OBSERVATIONS')) { stamps = DATA.STATION[0].OBSERVATIONS.date_time; var numObs = DATA.STATION[0].OBSERVATIONS.date_time.length; numObs = numObs - 1; var tableData = ''; // Loop through each observation var METARString = '
'; for (j = numObs; j > -1; j--) { // Date and time var MW_TIMESTAMP = DATA.STATION[0].OBSERVATIONS.date_time[j]; var TIMEZONE = DATA.STATION[0].TIMEZONE; var TIMESTAMP = new Date(MW_TIMESTAMP); TIMESTAMP = TIMESTAMP.toLocaleString('en-US', { timeZone: TIMEZONE }); var months_arr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; var MONTH = ''; //new Date(TIMESTAMP).getMonth(); var month = MW_TIMESTAMP; //months_arr[MONTH]; var day = ''; //new Date(TIMESTAMP).getDate(); var hours = ''; //new Date(TIMESTAMP).getHours(); var minutes = ''; //new Date(TIMESTAMP).getMinutes(); // if (parseInt(minutes) < 10) { // minutes = "0" + minutes; // } else { // minutes = minutes; // } // if (hours < 12) { // var ampm = 'am'; // } else { // var ampm = 'pm'; // } // if (hours == '0') { // hours = 12; // } else if (hours > 12) { // hours = hours - 12; // } var ampm = ''; // Temperature if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('air_temp_set_1')) { var ATData = DATA.STATION[0].OBSERVATIONS.air_temp_set_1; if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.air_temp_set_1[j] !== null) { var TEMP_F = ''; } else { var TEMP_F = ''; } } else { var TEMP_F = ''; } // Dew Point if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('dew_point_temperature_set_1d')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.dew_point_temperature_set_1d[j] !== null) { var DEWPOINT = ''; } else { var DEWPOINT = ''; } } else { var DEWPOINT = ''; } // Relative Humidity if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('relative_humidity_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.relative_humidity_set_1[j] !== null) { var RH_PCT = ''; } else { var RH_PCT = ''; } } else { var RH_PCT = ''; } // Wind Chill if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('wind_chill_set_1d')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.wind_chill_set_1d[j] !== null) { var WC = ''; } else { var WC = ''; } } else { var WC = ''; } // Wind Direction if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('wind_direction_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.wind_cardinal_direction_set_1d[j] !== null) { var Wind_DIR = (DATA.STATION[0].OBSERVATIONS.wind_cardinal_direction_set_1d[j]); var WIND_DIR = ''; } else { var WIND_DIR = ''; } } else { var WIND_DIR = ''; } // Wind Speed & Gust if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('wind_speed_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.wind_speed_set_1[j] !== null) { var WIND_SPD = Math.round(DATA.STATION[0].OBSERVATIONS.wind_speed_set_1[j]); if (WIND_SPD < 20 ) { WIND_SPD = ''; } else if (WIND_GST < 40 ) { WIND_SPD += 'G'+WIND_GST+''; } else if (WIND_GST < 58 ) { WIND_SPD += 'G'+WIND_GST+''; } else { WIND_SPD += 'G'+WIND_GST+''; } } else { WIND_SPD += ''; } } } else { var WIND_SPD = ''; } // Fuel Temperature if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('fuel_temp_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.fuel_temp_set_1[j] !== null) { var FUEL_T = ''; } else { var FUEL_T = ''; } } else { var FUEL_T = ''; } // Fuel Moisture if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('fuel_moisture_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.fuel_moisture_set_1[j] !== null) { var FUEL_PCT = ''; } else { var FUEL_PCT = ''; } } else { var FUEL_PCT = ''; } // Visibility if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('visibility_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.visibility_set_1[j] !== null) { var VISIBILITY =(DATA.STATION[0].OBSERVATIONS.visibility_set_1[j]).toFixed(2); if (VISIBILITY <= 1 ) { VISIBILITY = ''; } else if (VISIBILITY <= 3 ) { VISIBILITY = ''; } else if (VISIBILITY < 7) { VISIBILITY = ''; } else { VISIBILITY = ''; } } else { var VISIBILITY = ''; } } else { var VISIBILITY = ''; } // Present Weather if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('weather_cond_code_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.weather_cond_code_set_1[j] !== null) { if (network == 'NWS/FAA') { var WEATHER = parseInt(DATA.STATION[0].OBSERVATIONS.weather_cond_code_set_1[j]); if (WEATHER < 80) { // WX_ELEM1 = getWeatherCode(WEATHER); WX_ELEM2 = ''; WX_ELEM3 = ''; } else if (WEATHER < 6400) { WX1 = Math.floor (WEATHER / 80); WX_ELEM1 = getWeatherCode(WX1); WX2 = (WEATHER % 80); WX_ELEM2 = getWeatherCode(WX2)+','; WX_ELEM3 = ''; } else { WX1 = Math.floor (WEATHER / 6400); WX_ELEM1 = getWeatherCode(WX1); WX2 = Math.floor (WEATHER / 80); WX_ELEM2 = getWeatherCode(WX2)+','; WX3 = (WEATHER % 80); WX_ELEM1 = getWeatherCode(WX3)+','; } WEATHER = ''; } else { WEATHER = ''; } } else { var WEATHER = ''; } } else { var WEATHER = ''; } //Cloud Layers if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('cloud_layer_1_code_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.cloud_layer_1_code_set_1[j] !== null) { var SKY1 =(DATA.STATION[0].OBSERVATIONS.cloud_layer_1_code_set_1[j]).toString(); var COVERAGE1 = SKY1.substr(SKY1.length -1); if (COVERAGE1 == "1") { SKY_COND1 = 'CLR'; } else if (COVERAGE1 == "2") { SKY_COND1 = 'SCT'; } else if (COVERAGE1 == "3") { SKY_COND1 = 'BKN'; } else if (COVERAGE1 == "4") { SKY_COND1 = 'OVC'; } else if (COVERAGE1 == "5") { SKY_COND1 = 'VV'; } else if (COVERAGE1 == "6") { SKY_COND1 = 'FEW'; } else { SKY_COND1 = ''; } var DECK1 = parseInt(SKY1.slice(0, -1)); if (isNaN(DECK1)) { DECK1 = ''; } else if (DECK1 < 10) { DECK1 = "00"+DECK1; } else if (DECK1 < 100) { DECK1 = "0"+DECK1; } else { DECK1 = DECK1; } } else { var SKY_COND1 = ''; var DECK1 = ''; } } else { var SKY_COND1 = ''; var DECK1 = ''; } if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('cloud_layer_2_code_set_1')) { if (DATA.STATION[0].OBSERVATIONS.cloud_layer_2_code_set_1[j] !== null) { var SKY2 =(DATA.STATION[0].OBSERVATIONS.cloud_layer_2_code_set_1[j]).toString(); var COVERAGE2 = SKY2.substr(SKY2.length -1); if (COVERAGE2 == "1") { SKY_COND2 = 'CLR'; } else if (COVERAGE2 == "2") { SKY_COND2 = 'SCT'; } else if (COVERAGE2 == "3") { SKY_COND2 = 'BKN'; } else if (COVERAGE2 == "4") { SKY_COND2 = 'OVC'; } else if (COVERAGE2 == "5") { SKY_COND2 = 'VV'; } else if (COVERAGE2 == "6") { SKY_COND2 = 'FEW'; } else { SKY_COND2 = ''; } var DECK2 = parseInt(SKY2.slice(0, -1)); if (isNaN(DECK2)) { DECK2 = ''; } else if (DECK2 < 10) { DECK2 = "00"+DECK2; } else if (DECK2 < 100) { DECK2 = "0"+DECK2; } else { DECK2 = DECK2; } } else { var SKY_COND2 = ''; var DECK2 = ''; } } else { var SKY_COND2 = ''; var DECK2 = ''; } if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('cloud_layer_3_code_set_1')) { if (DATA.STATION[0].OBSERVATIONS.cloud_layer_3_code_set_1[j] !== null) { var SKY3 =(DATA.STATION[0].OBSERVATIONS.cloud_layer_3_code_set_1[j]).toString(); var COVERAGE3 = SKY3.substr(SKY3.length -1); if (COVERAGE3 == "1") { SKY_COND3 = 'CLR'; } else if (COVERAGE3 == "2") { SKY_COND3 = 'SCT'; } else if (COVERAGE3 == "3") { SKY_COND3 = 'BKN'; } else if (COVERAGE3 == "4") { SKY_COND3 = 'OVC'; } else if (COVERAGE3 == "5") { SKY_COND3 = 'VV'; } else if (COVERAGE3 == "6") { SKY_COND3 = 'FEW'; } else { SKY_COND3 = ''; } var DECK3 = parseInt(SKY3.slice(0, -1)); if (isNaN(DECK3)) { DECK3 = ''; } else if (DECK3 < 10) { DECK3 = "00"+DECK3; } else if (DECK3 < 100) { DECK3 = "0"+DECK3; } else { DECK3 = DECK3; } } else { var SKY_COND3 = ''; var DECK3 = ''; } } else { var SKY_COND3 = ''; var DECK3 = ''; } var SKY_COND = ''; // If there was a cloud layer, THEN make the cloud cells if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('cloud_layer_1_code_set_1')) { if (SKY_COND1 == "CLR" || SKY_COND1 == "FEW" || SKY_COND1 == "SCT") { LAYER1 = SKY_COND1+DECK1; } else if (DECK1 < 10) { LAYER1 = ''+SKY_COND1+DECK1+''; } else if (DECK1 < 31) { LAYER1 = ''+SKY_COND1+DECK1+''; } else if (DECK1 < 81) { LAYER1 = ''+SKY_COND1+DECK1+''; } else { LAYER1 = SKY_COND1+DECK1; } if (SKY_COND2 == "CLR" || SKY_COND2 == "FEW" || SKY_COND2 == "SCT") { LAYER2 = SKY_COND2+DECK2; } else if (DECK2 < 10) { LAYER2 = ''+SKY_COND2+DECK2+''; } else if (DECK2 < 31) { LAYER2 = ''+SKY_COND2+DECK2+''; } else if (DECK2 < 81) { LAYER2 = ''+SKY_COND2+DECK2+''; } else { LAYER2 = SKY_COND2+DECK2; } if (SKY_COND3 == "CLR" || SKY_COND3 == "FEW" || SKY_COND3 == "SCT") { LAYER3 = SKY_COND3+DECK3; } else if (DECK3 < 10) { LAYER3 = ''+SKY_COND3+DECK3+''; } else if (DECK3 < 31) { LAYER3 = ''+SKY_COND3+DECK3+''; } else if (DECK3 < 81) { LAYER3 = ''+SKY_COND3+DECK3+''; } else { LAYER3 = SKY_COND3+DECK3; } var SKY_COND = ''; } // Station Pressure if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('pressure_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.pressure_set_1[j] !== null) { var P = ''; } else { var P = ''; } } else { var P = ''; } // Sea Level Pressure if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('sea_level_pressure_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.sea_level_pressure_set_1[j] !== null) { var SEALEVEL = ''; } else { var SEALEVEL = ''; } } else { var SEALEVEL = ''; } // Altimeter Setting if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('altimeter_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.altimeter_set_1[j] !== null) { var ALTIMTER = ''; } else { var ALTIMTER = ''; } } else { var ALTIMTER = ''; } // Station Pressure if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('station_pressure_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.station_pressure_set_1[j] !== null) { var STATION_P = ''; } else { var STATION_P = ''; } } else { var STATION_P = ''; } // Solar Radiation if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('solar_radiation_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.solar_radiation_set_1[j] !== null) { var RAW_SOLAR = (Math.round(DATA.STATION[0].OBSERVATIONS.solar_radiation_set_1[j])); var SOLAR_POSS = calcSolarPCT(MW_TIMESTAMP,stnLAT,stnLON); var PCT = Math.round (100 * RAW_SOLAR / SOLAR_POSS); if (PCT > 100) { PCT = 100; } if (RAW_SOLAR > 0 && SOLAR_POSS > 0) { var SOLAR = ''; var SOLAR_PCT = ''; } else { var SOLAR = ''; var SOLAR_PCT = ''; } } else { var SOLAR = ''; var SOLAR_PCT = ''; } } else { var SOLAR = ''; var SOLAR_PCT = ''; } // Soil Temperature if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('soil_temp_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.soil_temp_set_1[j] !== null) { var SOIL_T = ''; } else { var SOIL_T = ''; } } else { var SOIL_T = ''; } // Road Temperature if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('road_temp_set_2')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.road_temp_set_2[j] !== null) { var ROAD_T = ''; } else { var ROAD_T = ''; } } else { var ROAD_T = ''; } // Road Sub-Surface Temp if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('road_subsurface_tmp_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.road_subsurface_tmp_set_1[j] !== null) { var SROAD_T = ''; } else { var SROAD_T = ''; } } else { var SROAD_T = ''; } // If Accumulated Precip or any increment of precip up to one hour is set, // we will calculate 1, 3, 6 and 24 hour precip values on our own. // Synoptic does not consistently return ihigher interval data for those fields // Even if we get those fields, we will disable any processing of that data down the line. // Accumulated Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_set_1[j] !== null) { var ACC_Precip = (DATA.STATION[0].OBSERVATIONS.precip_accum_set_1[j]).toFixed(2); var ACC_PCPN = ''; } else { var ACC_PCPN = ''; } } else { var ACC_PCPN = ''; } // 1 Minute Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_one_minute_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_one_minute_set_1[j] !== null) { var oneMINprecip = (DATA.STATION[0].OBSERVATIONS.precip_accum_one_minute_set_1[j]).toFixed(2); if (oneMINprecip == '0.001') { oneMINprecip = 'T'; } var MIN_1_PCPN = ''; } else { var MIN_1_PCPN = ''; } } else { var MIN_1_PCPN = ''; } // 5 Minute Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_five_minute_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_five_minute_set_1[j] !== null) { var fiveMINprecip = (DATA.STATION[0].OBSERVATIONS.precip_accum_five_minute_set_1[j]).toFixed(2); if (fiveMINprecip == '0.001') { fiveMINprecip = 'T'; } var MIN_5_PCPN = ''; } else { var MIN_5_PCPN = ''; } } else { var MIN_5_PCPN = ''; } // 10 Minute Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_ten_minute_set_1')) { derived = 1; if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_ten_minute_set_1[j] !== null) { var tenMINprecip = (DATA.STATION[0].OBSERVATIONS.precip_accum_ten_minute_set_1[j]).toFixed(2); var MIN_10_PCPN = ''; } else { var MIN_10_PCPN = ''; } } else { var MIN_10_PCPN = ''; } // 15 Minute Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_fifteen_minute_set_1')) { derived = 1; if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_fifteen_minute_set_1[j] !== null) { var fifteenMINprecip = (DATA.STATION[0].OBSERVATIONS.precip_accum_fifteen_minute_set_1[j]).toFixed(2); var MIN_15_PCPN = ''; } else { var MIN_15_PCPN = ''; } } else { var MIN_15_PCPN = ''; } // 30 Minute Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_30_minute_set_1')) { derived = 1; if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_30_minute_set_1[j] !== null) { var thirtyMINprecip = (DATA.STATION[0].OBSERVATIONS.precip_accum_30_minute_set_1[j]).toFixed(2); var MIN_30_PCPN = ''; } else { var MIN_30_PCPN = ''; } } else { var MIN_30_PCPN = ''; } // 1 Hour Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_one_hour_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_one_hour_set_1[j] !== null) { if (parseFloat(DATA.STATION[0].OBSERVATIONS.precip_accum_one_hour_set_1[j]) == '0.001') { var HR_1_PCPN = ''; } else { var HR_1_PCPN = ''; } } else { var HR_1_PCPN = ''; } } else { var HR_1_PCPN = ''; } // 3 Hour Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_three_hour_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_three_hour_set_1[j] !== null) { if (parseFloat(DATA.STATION[0].OBSERVATIONS.precip_accum_three_hour_set_1[j]) == '0.001') { var HR_3_PCPN = ''; } else { var HR_3_PCPN = ''; } } else { var HR_3_PCPN = ''; } } else { var HR_3_PCPN = ''; } // 6 Hour Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_six_hour_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_six_hour_set_1[j] !== null) { if (parseFloat(DATA.STATION[0].OBSERVATIONS.precip_accum_six_hour_set_1[j]) == '0.001') { var HR_6_PCPN = ''; } else { var HR_6_PCPN = ''; } } else { var HR_6_PCPN = ''; } } else { var HR_6_PCPN = ''; } // 24 Hour Precip if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_24_hour_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_24_hour_set_1[j] !== null) { if (parseFloat(DATA.STATION[0].OBSERVATIONS.precip_accum_24_hour_set_1[j]) == '0.001') { var HR_24_PCPN = ''; } else { var HR_24_PCPN = ''; } } else { var HR_24_PCPN = ''; } } else { var HR_24_PCPN = ''; } // Precip sine midnight if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('precip_accum_since_local_midnight_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.precip_accum_since_local_midnight_set_1[j] !== null) { var MIDNIGHT = ''; } else { var MIDNIGHT = ''; } } else { var MIDNIGHT = ''; } // Snow Depth if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('snow_depth_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.snow_depth_set_1[j] !== null) { var curSnow = (DATA.STATION[0].OBSERVATIONS.snow_depth_set_1[j]).toFixed(1); var SNOW_DEPTH = ''; } else { var SNOW_DEPTH = ''; } } else { var SNOW_DEPTH = ''; } // Snow Interval if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('snow_interval_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.snow_interval_set_1[j] !== null) { var SNOW_INTERVAL = ''; } else { var SNOW_INTERVAL = ''; } } else { var SNOW_INTERVAL = ''; } // Snow Water Equivalent if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('snow_water_equiv_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.snow_water_equiv_set_1[j] !== null) { var SWE = ''; } else { var SWE = ''; } } else { var SWE = ''; } // 6 Hour Max T if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('air_temp_high_6_hour_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.air_temp_high_6_hour_set_1[j] !== null) { var HR6_MAXT = ''; } else { var HR6_MAXT = ''; } } else { var HR6_MAXT = ''; } // 6 Hour Min T if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('air_temp_low_6_hour_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.air_temp_low_6_hour_set_1[j] !== null) { var HR6_MINT = ''; } else { var HR6_MINT = ''; } } else { var HR6_MINT = ''; } // 24 Hour Max T if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('air_temp_high_24_hour_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.air_temp_high_24_hour_set_1[j] !== null) { var HR24_MAXT = ''; } else { var HR24_MAXT = ''; } } else { var HR24_MAXT = ''; } // 24 Hour Min T if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('air_temp_low_24_hour_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.air_temp_low_24_hour_set_1[j] !== null) { var HR24_MINT = ''; } else { var HR24_MINT = ''; } } else { var HR24_MINT = ''; } // Water Temperature if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('T_water_temp_set_1')) { if (j == 0) { header1 += ''; EngUnits += ''; } if (DATA.STATION[0].OBSERVATIONS.T_water_temp_set_1[j] !== null) { var WATER_T = ''; } else { var WATER_T = ''; } } else { var WATER_T = ''; } // Append one row of data to the stream tableData += ''+TEMP_F+DEWPOINT+RH_PCT+WC+WIND_DIR+WIND_SPD+FUEL_T+FUEL_PCT+VISIBILITY+WEATHER+SKY_COND+P+SEALEVEL+ALTIMTER+STATION_P+SOLAR+SOLAR_PCT+SOIL_T+ROAD_T+SROAD_T+ACC_PCPN+MIN_1_PCPN+MIN_5_PCPN+MIN_10_PCPN+MIN_15_PCPN+MIN_30_PCPN+HR_1_PCPN+HR_3_PCPN+HR_6_PCPN+HR_24_PCPN+MIDNIGHT+SNOW_DEPTH+SNOW_INTERVAL+SWE+HR6_MAXT+HR6_MINT+HR24_MAXT+HR24_MINT+WATER_T+''; } // Successful return of data var header0 = '

Weather conditions for:
'+stnNAM+', '+ state +' ('+network+' - '+cwa+')
Elev: '+stnELE+' ft; Lat/Lon: '+stnLAT+'/'+stnLON+'

Get Yearly Precip Total (non QA/QC\'d data)
Get Water Year Precip Total (non QA/QC\'d data):

 '; $('#OBS').html(header0 + header1 +'' + EngUnits + '' + tableData+'
Temp.
 
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.air_temp_set_1[j])+' Dew
Point
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.dew_point_temperature_set_1d[j])+' Relative
Humidity
(%)'+Math.round(DATA.STATION[0].OBSERVATIONS.relative_humidity_set_1[j])+' Wind
Chill
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.wind_chill_set_1d[j])+' Wind
Direction
 '+Wind_DIR+' Wind
Speed
(mph)'+WIND_SPD; } else if (WIND_SPD < 40 ) { WIND_SPD = ''+WIND_SPD+''; } else if (WIND_SPD < 58 ) { WIND_SPD = ''+WIND_SPD+''; } else { WIND_SPD = ''+WIND_SPD+''; } } else { var WIND_SPD = '0'; } if (DATA.STATION[0].OBSERVATIONS.hasOwnProperty('wind_gust_set_1')) { if (DATA.STATION[0].OBSERVATIONS.wind_gust_set_1[j] !== null) { var WIND_GST =Math.round(DATA.STATION[0].OBSERVATIONS.wind_gust_set_1[j]); if (WIND_GST < 20 ) { WIND_SPD += 'G'+WIND_GST+'Fuel
Temp.
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.fuel_temp_set_1[j])+' Fuel
Moisture
(%)'+Math.round(DATA.STATION[0].OBSERVATIONS.fuel_moisture_set_1[j])+' Visibility
 
(miles)'+VISIBILITY+''+VISIBILITY+''+VISIBILITY+''+VISIBILITY+' Weather
 
 '+WX_ELEM3+' '+WX_ELEM2+' '+WX_ELEM1+''+(DATA.STATION[0].OBSERVATIONS.weather_condition_set_1d[j])+' Clouds
 
(x100 ft)'+LAYER1+' '+LAYER2+' '+LAYER3+'Station
Pressure
(in Hg)'+(DATA.STATION[0].OBSERVATIONS.pressure_set_1[j]).toFixed(2)+' Sea Level
Pressure
(mb)'+(DATA.STATION[0].OBSERVATIONS.sea_level_pressure_set_1[j]).toFixed(2)+' Altimeter
Setting
(in Hg)'+(DATA.STATION[0].OBSERVATIONS.altimeter_set_1[j]).toFixed(2)+' Station
Pressure
(in Hg)'+(DATA.STATION[0].OBSERVATIONS.station_pressure_set_1[j]).toFixed(2)+' Solar
Radiation
Percent
Possible
(W/m²)(%)'+RAW_SOLAR+''+PCT+' %0--  Soil
Temp.
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.soil_temp_set_1[j])+' Road
Temp.
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.road_temp_set_2[j])+' Road Sub
Temp.
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.road_subsurface_tmp_set_1[j])+' Accumulated
Precip
(inches)'+ACC_Precip+' 1 Min.
Precip
(inches)'+oneMINprecip+' 5 Min.
Precip
(inches)'+fiveMINprecip+' 10 Min.
Precip
(inches)'+tenMINprecip+' 15 Min.
Precip
(inches)'+fifteenMINprecip+' 30 Min.
Precip
(inches)'+thirtyMINprecip+' 1 Hour
Precip
(inches)T'+(DATA.STATION[0].OBSERVATIONS.precip_accum_one_hour_set_1[j]).toFixed(2)+' 3 Hour
Precip
(inches)T'+(DATA.STATION[0].OBSERVATIONS.precip_accum_three_hour_set_1[j]).toFixed(2)+' 6 Hour
Precip
(inches)T'+(DATA.STATION[0].OBSERVATIONS.precip_accum_six_hour_set_1[j]).toFixed(2)+' 24 Hour
Precip
(inches)T'+(DATA.STATION[0].OBSERVATIONS.precip_accum_24_hour_set_1[j]).toFixed(2)+' Precip
Since 12am
(°F)'+(DATA.STATION[0].OBSERVATIONS.precip_accum_since_local_midnight_set_1[j]).toFixed(2)+' Snow
Depth
(inches)'+curSnow+' Snow
Interval
(inches)'+(DATA.STATION[0].OBSERVATIONS.snow_interval_set_1[j]).toFixed(1)+' Snow/Water
Equivalent
(inches)'+(DATA.STATION[0].OBSERVATIONS.snow_water_equiv_set_1[j]).toFixed(2)+' 6 Hr
Max
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.air_temp_high_6_hour_set_1[j])+' 6 Hr
Min
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.air_temp_low_6_hour_set_1[j])+' 24 Hr
Max
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.air_temp_high_24_hour_set_1[j])+' 24 Hr
Min
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.air_temp_low_24_hour_set_1[j])+' Water
Temp.
(°F)'+Math.round(DATA.STATION[0].OBSERVATIONS.T_water_temp_set_1[j])+' 
'+month+' '+day+', '+hours+':'+minutes+' '+ampm+'
'); } else { // Station has not reported in the specified number of hours $('#OBS').html('

'+SITE +' has no data available for the requested time period

'); } } else if (DATA.SUMMARY.RESPONSE_MESSAGE == 'No stations found for this request.') { // Station ID not valid $('#OBS').html('

'+SITE +' is not a valid station identifier.

'); } }) } function getWeatherCode(WEATHER) { // Documentation: https://blog.synopticlabs.org/blog/2016/09/26/weather-condition-codes.html // Coloring from MesoWest: // '/TS|SQ|FC/ $r_wx"; } // '/RA|SN|GS|GR $r_wx"; } // '/FG|FU|BS/ $r_wx"; } // '/BR|HZ/ $r_wx"; } if (WEATHER == -3) { HTML = 'FC'; DESC = 'Water Spout'; } else if (WEATHER == -2) { HTML = 'FC'; DESC = 'Funnel Cloud'; } else if (WEATHER == -1) { HTML = 'FC'; DESC = 'Tornado'; } else if (WEATHER == 1) { HTML = 'RA'; DESC = 'Rain'; } else if (WEATHER == 2) { HTML = 'DZ'; DESC = 'Drizzle'; } else if (WEATHER == 3) { HTML = 'SN'; DESC = 'Snow'; } else if (WEATHER == 4) { HTML = 'GR'; DESC = 'Hail'; } else if (WEATHER == 5) { HTML = 'TS'; DESC = 'Thunder'; } else if (WEATHER == 6) { HTML = 'HZ'; DESC = 'Haze'; } else if (WEATHER == 7) { HTML = 'FU'; DESC = 'Smoke'; } else if (WEATHER == 8) { HTML = 'DU'; DESC = 'Dust'; } else if (WEATHER == 9) { HTML = 'FG'; DESC = 'Fog'; } else if (WEATHER == 10) { HTML = 'SQ'; DESC = 'Squalls'; } else if (WEATHER == 11) { HTML = 'VA'; DESC = 'Volcanic Ash'; } else if (WEATHER == 13) { HTML = '-RA'; DESC = 'Lt rain'; } else if (WEATHER == 14) { HTML = '+RA'; DESC = 'Hvy rain'; } else if (WEATHER == 15) { HTML = 'ZR'; DESC = 'Freezing rain'; } else if (WEATHER == 16) { HTML = 'SH'; DESC = 'Shwrs'; } else if (WEATHER == 17) { HTML = '-DZ'; DESC = 'Lt drizzle'; } else if (WEATHER == 18) { HTML = '+DZ'; DESC = 'Hvy drizzle'; } else if (WEATHER == 19) { HTML = 'FZDZ'; DESC = 'Freezing drizzle'; } else if (WEATHER == 20) { HTML = '-SN'; DESC = 'Lt snow'; } else if (WEATHER == 21) { HTML = '+SN'; DESC = 'Hvy snow'; } else if (WEATHER == 22) { HTML = 'SN'; DESC = 'Snow'; } else if (WEATHER == 23) { HTML = 'PL'; DESC = 'Ice pellets'; } else if (WEATHER == 24) { HTML = 'SG'; DESC = 'Snow grains'; } else if (WEATHER == 25) { HTML = 'GS'; DESC = 'Snow pellets'; } else if (WEATHER == 26) { HTML = '-GR'; DESC = 'Lt hail'; } else if (WEATHER == 27) { HTML = '+GR'; DESC = 'Hvy hail'; } else if (WEATHER == 28) { HTML = '-TS'; DESC = 'Lt thunderstorm'; } else if (WEATHER == 29) { HTML = '+TS'; DESC = 'Hvy thunderstorm'; } else if (WEATHER == 30) { HTML = 'FZFG'; DESC = 'Freezing Fog'; } else if (WEATHER == 31) { HTML = 'BR'; DESC = 'Mist'; } else if (WEATHER == 32) { HTML = 'BLSN'; DESC = 'Blowing snow'; } else if (WEATHER == 33) { HTML = 'BLDU'; DESC = 'Blowing dust'; } else if (WEATHER == 34) { HTML = 'BLPY'; DESC = 'Blowing spray'; } else if (WEATHER == 35) { HTML = 'BLSA'; DESC = 'Blowing sand'; } else if (WEATHER == 36) { HTML = 'IC'; DESC = 'Ice crystals'; } else if (WEATHER == 37) { HTML = 'IC'; DESC = 'Ice needles'; } else if (WEATHER == 38) { HTML = '-GR'; DESC = 'Lt hail'; } else if (WEATHER == 39) { HTML = 'FUHZ'; DESC = 'Smoke, haze'; } else if (WEATHER == 40) { HTML = 'DU'; DESC = 'Dust whirls'; } else if (WEATHER == 41) { HTML = 'UP'; DESC = 'Unknown precipitation'; } else if (WEATHER == 49) { HTML = '-ZR'; DESC = 'Lt freezing rain'; } else if (WEATHER == 50) { HTML = '+ZR'; DESC = 'Heavy freezing rain'; } else if (WEATHER == 51) { HTML = '-SH'; DESC = 'Lt shwrs'; } else if (WEATHER == 52) { HTML = '+SH'; DESC = 'Hvy shwrs'; } else if (WEATHER == 53) { HTML = '-FZDZ'; DESC = 'Lt freezing drizzle'; } else if (WEATHER == 54) { HTML = '+FZDZ'; DESC = 'Hvy freezing drizzle'; } else if (WEATHER == 55) { HTML = '-SN'; DESC = 'Lt snow'; } else if (WEATHER == 56) { HTML = '+SN'; DESC = 'Hvy snow'; } else if (WEATHER == 57) { HTML = '-PL'; DESC = 'Lt ice pellets'; } else if (WEATHER == 58) { HTML = '+PL'; DESC = 'Hvy ice pellets'; } else if (WEATHER == 59) { HTML = '-SG'; DESC = 'Lt snow grains'; } else if (WEATHER == 60) { HTML = '+SG'; DESC = 'Heavy snow grains'; } else if (WEATHER == 61) { HTML = '-GS'; DESC = 'Lt snow pellets'; } else if (WEATHER == 62) { HTML = '+GS'; DESC = 'Hvy snow pellets'; } else if (WEATHER == 63) { HTML = 'PL'; DESC = 'Ice pellets'; } else if (WEATHER == 64) { HTML = '-IC'; DESC = 'Lt ice crystals'; } else if (WEATHER == 65) { HTML = '+IC'; DESC = 'Hvy ice crystals'; } else if (WEATHER == 66) { HTML = 'TSRA'; DESC = 'Thunder shwr'; } else if (WEATHER == 67) { HTML = 'GS'; DESC = 'Snow pellets'; } else if (WEATHER == 68) { HTML = '+BLDU'; DESC = 'Hvy blowing dust'; } else if (WEATHER == 69) { HTML = '+BLSA'; DESC = 'Hvy blowing sand'; } else if (WEATHER == 69) { HTML = '+BLSN'; DESC = 'Hvy blowing snow'; } else if (WEATHER == 75) { HTML = '-PL'; DESC = 'Lt ice pellets'; } else if (WEATHER == 76) { HTML = '+PL'; DESC = 'Hvy ice pellets'; } else if (WEATHER == 77) { HTML = '-TSRA'; DESC = 'Lt thunder shwr'; } else if (WEATHER == 78) { HTML = '+TSRA'; DESC = 'Hvy thunder shwr'; } return(DESC); } // Need to figure out function calcSolarPCT(dattim,xlat,xlon) { //console.log(dattim,xlat,xlon) var utcMoment = moment.utc(dattim); var d = new Date(utcMoment.format()); var rd = new Date(utcMoment.format()); rd.setHours(rd.getHours() - 1); var hours = utcMoment.format("H"); var minutes = d.getMinutes(); minutes = minutes < 10 ? '0' + minutes : minutes; var solpot = 0; while (rd < d) { var start = new Date(rd.getFullYear(), 0, 0); var diff = rd - start; var oneDay = 1000 * 60 * 60 * 24; var julday = Math.floor(diff / oneDay) - 1; var hr = rd.getHours(); hr = utcMoment.format("H") - 1; var min = rd.getMinutes(); min = utcMoment.format('m'); xt24 = hr + (min / 60.); var degrad = 0.017453293; var dpd = 0.986301; var solset = -999; var sinob = Math.sin(23.5 * degrad); var julian = (julday) + hr; var xlong; if (julian > 80.) { xlong = dpd * (julian - 80.); } else { xlong = dpd * (julian + 285.); } xlong = xlong * degrad; declin = Math.asin(sinob * Math.sin(xlong)); decdeg = declin / degrad; djul = julian * 360. / 365.; rjul = djul * degrad; eccfac = 1.000110 + 0.034221 * Math.cos(rjul) + 0.00128 * Math.sin(rjul) + 0.000719 * Math.cos(2 * rjul) + 0.000077 * Math.sin(2 * rjul); solcon = 1370. * eccfac; tlocap = xt24 + (xlon / 15.); omega = 15. * (tlocap - 12.) * degrad; xxlat = xlat * degrad; fracsc = Math.sin(declin) * Math.sin(xxlat) + Math.cos(declin) * Math.cos(xxlat) * Math.cos(omega); solpot = solpot + (fracsc * solcon); utcMoment.add(10, 'm'); rd = new Date(rd.getTime() + 10 * 60000); } solpot = solpot / 6.; // return solpot.toFixed(0); if (solpot > 0) { return(solpot.toFixed(0)); } else { return '--'; } } function getCalYearPrecip(SITE,units) { const d = new Date(); var year = d.getFullYear(); $.getJSON('https://api.synopticdata.com/v2/stations/precip?stid='+SITE+'&start='+year+'01010000&end=210001010000&pmode=totals&token=d8c6aee36a994f90857925cea26934be&units='+units, function (DATA) { if (DATA.STATION[0]) { var VALUE = DATA.STATION[0].OBSERVATIONS.precipitation[0].total.toFixed(2); $('#CAL_YEAR').html('Current calendar year total (since January 1, '+year+'): ' +VALUE +' '+ DATA.UNITS.precipitation.toLowerCase()+''); } else { $('#CAL_YEAR').html('Data not available at this location.'); } }) } function getH2OYearPrecip(SITE,units) { var d = new Date(); var year = d.getFullYear(); var month = d.getMonth(); month = parseInt(month); if (month < 9) { year = parseInt(year) - 1; } $.getJSON('https://api.synopticdata.com/v2/stations/precip?stid='+SITE+'&start='+year+'10010000&end=210001010000&pmode=totals&token=d8c6aee36a994f90857925cea26934be&units='+units, function (DATA) { if (DATA.STATION[0]) { var VALUE = DATA.STATION[0].OBSERVATIONS.precipitation[0].total.toFixed(2); $('#H2O_YEAR').html('Current water year total (since October 1, '+year+'): ' +VALUE +' '+ DATA.UNITS.precipitation.toLowerCase()+''); } else { $('#H2O_YEAR').html('Data not available at this location.'); } }) }