Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Sundry rollups #1117

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 40 additions & 39 deletions htdocs/sites/obhistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function asos_formatter($i, $row)
$ts = strtotime(substr($row["local_valid"], 0, 16));
$relh = relh(f2c($row["tmpf"]), f2c($row["dwpf"]));
$relh = (!is_null($relh)) ? intval($relh) : "";
$ismadis = is_null($row["raw"]) ? FALSE: (strpos($row["raw"], "MADISHF") > 0);
$ismadis = is_null($row["raw"]) ? FALSE : (strpos($row["raw"], "MADISHF") > 0);
return sprintf(
"<tr style=\"background: %s;\" class=\"%sob\" data-madis=\"%s\">" .
"</div><td>%s</td><td>%s</td><td>%s</td>
Expand Down Expand Up @@ -165,14 +165,15 @@ function hads_formatter($i, $row, $shefcols)
$html
);
}
function scan_formatter($i, $row){
function scan_formatter($i, $row)
{
$ts = strtotime(substr($row["local_valid"], 0, 16));
return sprintf(
"<tr style=\"background: %s;\">" .
"<td>%s</td><td>%s</td><td>%s</td>".
"<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>".
"<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>".
"<td>%s</td><td>%s</td></tr>",
"<td>%s</td><td>%s</td><td>%s</td>" .
"<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>" .
"<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>" .
"<td>%s</td><td>%s</td></tr>",
($i % 2 == 0) ? "#FFF" : "#EEE",
date("g:i A", $ts),
wind_formatter($row),
Expand All @@ -192,7 +193,6 @@ function scan_formatter($i, $row){
$row["soilt40"],
$row["soilm40"],
);

}
$year = get_int404("year", date("Y"));
$month = get_int404("month", date("m"));
Expand Down Expand Up @@ -226,7 +226,8 @@ function scan_formatter($i, $row){

$savevars = array(
"year" => date("Y", $date),
"month" => date("m", $date), "day" => date("d", $date)
"month" => date("m", $date),
"day" => date("d", $date)
);
$t->jsextra = '<script type="module" src="obhistory.js"></script>';
$dstr = date("d F Y", $date);
Expand All @@ -237,43 +238,43 @@ function scan_formatter($i, $row){
$ds = daySelect(date("d", $date));

$mbutton = (preg_match("/ASOS/", $network)) ?
'<button type="button" class="btn btn-success" id="metar_toggle">'.
'<i class="fa fa-plus"></i> Show METARs</button>'.
' &nbsp; <button type="button" class="btn btn-success" id="madis_toggle">'.
'<button type="button" class="btn btn-success" id="metar_toggle">' .
'<i class="fa fa-plus"></i> Show METARs</button>' .
' &nbsp; <button type="button" class="btn btn-success" id="madis_toggle">' .
'<i class="fa fa-plus"></i> Show High Frequency MADIS</button>'
: "";
$buttons = sprintf(
"<a id=\"prevbutton\" " .
$buttons = sprintf(
"<a id=\"prevbutton\" " .
"data-year=\"%s\" data-month=\"%s\" data-day=\"%s\" " .
"href=\"obhistory.php?network=%s&station=%s&year=%s&month=%s&day=%s\" " .
"class=\"btn btn-default\"><i class=\"fa fa-arrow-left\"></i> " .
"Previous Day</a>",
date("Y", $yesterday),
date("m", $yesterday),
date("d", $yesterday),
$network,
$station,
date("Y", $yesterday),
date("m", $yesterday),
date("d", $yesterday)
);

if ($tomorrow) {
$buttons .= sprintf(
"<a id=\"nextbutton\" " .
"data-year=\"%s\" data-month=\"%s\" data-day=\"%s\" " .
"href=\"obhistory.php?network=%s&station=%s&year=%s&month=%s&day=%s\" " .
"class=\"btn btn-default\"><i class=\"fa fa-arrow-left\"></i> ".
"Previous Day</a>",
date("Y", $yesterday),
date("m", $yesterday),
date("d", $yesterday),
"class=\"btn btn-default\">Next Day <i class=\"fa fa-arrow-right\"></i></a>",
date("Y", $tomorrow),
date("m", $tomorrow),
date("d", $tomorrow),
$network,
$station,
date("Y", $yesterday),
date("m", $yesterday),
date("d", $yesterday)
date("Y", $tomorrow),
date("m", $tomorrow),
date("d", $tomorrow)
);

if ($tomorrow) {
$buttons .= sprintf(
"<a id=\"nextbutton\" " .
"data-year=\"%s\" data-month=\"%s\" data-day=\"%s\" " .
"href=\"obhistory.php?network=%s&station=%s&year=%s&month=%s&day=%s\" " .
"class=\"btn btn-default\">Next Day <i class=\"fa fa-arrow-right\"></i></a>",
date("Y", $tomorrow),
date("m", $tomorrow),
date("d", $tomorrow),
$network,
$station,
date("Y", $tomorrow),
date("m", $tomorrow),
date("d", $tomorrow)
);

}
$content = <<<EOM
<style>
.high {
Expand Down Expand Up @@ -309,7 +310,7 @@ function scan_formatter($i, $row){
</form>
<p>{$mbutton}</p>
EOM;
}

$notes = '';
if ($network == "ISUSM") {
$notes .= "<li>Wind direction and wind speed are 10 minute averages at 10 feet above the ground.</li>";
Expand Down
33 changes: 21 additions & 12 deletions scripts/ingestors/madis/to_iemaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import os
import subprocess
import sys
import warnings
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
Expand All @@ -20,18 +19,18 @@
from pyiem.util import convert_value, logger, mm2inch, ncopen, utc

LOG = logger()
MYDIR = "/mesonet/data/madis/mesonet1"
MYDIR = "/mesonet/data/madis"
MY_PROVIDERS = ["KYTC-RWIS", "NEDOR", "MesoWest", "ITD"]
warnings.filterwarnings("ignore", category=DeprecationWarning)


def find_file(offset0):
def find_file(variant, offset0):
"""Find the most recent file"""
fn = None
for i in range(offset0, offset0 + 4):
ts = utc() - timedelta(hours=i)
for j in range(300, -1, -1):
testfn = ts.strftime(f"{MYDIR}/%Y%m%d_%H00_{j}.nc")
testfn = ts.strftime(f"{MYDIR}/{variant}/%Y%m%d_%H00_{j}.nc")
if os.path.isfile(testfn):
LOG.info("processing %s", testfn)
fn = testfn
Expand All @@ -40,8 +39,8 @@ def find_file(offset0):
break

if fn is None:
LOG.warning("Found no available files to process")
sys.exit()
msg = f"Found no {variant} files to process within {offset0} hours"
LOG.warning(msg)
return fn


Expand Down Expand Up @@ -97,12 +96,12 @@ def build_roadstate_xref(ncvar):
return xref


@click.command()
@click.option("--offset", default=0, help="Offset in hours", type=int)
def main(offset: int):
"""Do Something"""
def process(offset: int, variant: str):
"""Process the MADIS file"""
pgconn, icursor = get_dbconnc("iem")
fn = find_file(offset)
fn = find_file(variant, offset)
if fn is None:
return
nc = ncopen(fn, timeout=300)

stations = chartostring(nc.variables["stationId"][:])
Expand Down Expand Up @@ -185,6 +184,7 @@ def main(offset: int):
if rstate4[recnum] is not np.ma.masked:
db[this_station]["scond3"] = road_state_xref.get(rstate4[recnum])

updates = 0
for sid, val in db.items():
iem = Observation(sid, val["network"], val["ts"])
for colname in ["scond0", "scond1", "scond2", "scond3"]:
Expand Down Expand Up @@ -221,6 +221,7 @@ def main(offset: int):
iem.data["rwis_subf"] = convert_value(val["subk"], "degK", "degF")
if val["pday"] is not None:
iem.data["pday"] = round(mm2inch(val["pday"]), 2)
updates += 1
if not iem.save(icursor) and val["network"] != "IA_RWIS":
LOG.warning(
"MADIS Extract: %s found new station: %s network: %s",
Expand All @@ -232,11 +233,19 @@ def main(offset: int):
os.chdir("../../dbutil")
subprocess.call(["sh", "SYNC_STATIONS.sh"])
os.chdir("../ingestors/madis")
LOG.info("...done with sync.")
LOG.info("Found %s/%s updates in %s", updates, len(providers), fn)
icursor.close()
pgconn.commit()
pgconn.close()


@click.command()
@click.option("--offset", default=0, help="Offset in hours", type=int)
def main(offset: int):
"""Do Something"""
for variant in ["rwis1", "mesonet1"]:
process(offset, variant)


if __name__ == "__main__":
main()