Weather station scripts

They're free, but use at your own risk

The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

Many of these scripts are now available on GitHub at

If you find one or more of the scripts useful to you, please consider making a donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

This page was updated Tuesday, 28-Jul-2020 2:45 PM

PHP for NWS Area Forecast Discussion

This PHP script will fetch and cache the Forecast Area Discussion issued by your local NWS office.
Thanks to Mike Challis of Long Beach, WA for the inspiration for and enhancement of this script.

FXUS66 KMTR 282055

Area Forecast Discussion
National Weather Service San Francisco Bay Area
155 PM PDT Mon Sep 28 2020

.SYNOPSIS...Red Flag Warnings remain in effect for the North and
East Bay through this evening due to gusty offshore winds and
very low humidity. A Heat Advisory also remains in effect until 7
pm for all interior portions of the San Francisco Bay Area, as
well as the San Francisco Bay Shoreline and the City of San
Francisco. Hot and dry conditions across the entire San Francisco
Bay Area are expected again today, with very warm temperatures
extending south along the Central Coast. A cooling trend is
expected to begin along the coast and around the Bays on Tuesday
but with very warm to hot weather conditions forecast to persist
across inland areas through much of the work week. Cooling is
expected to develop inland over the upcoming weekend.

&& of 01:55 PM PDT Monday...The Glass/Shady/Boysen
fires have merged and are now referred soley as the Glass Fire. It
has continued moving towards the southwest with the help of
offshore flow, although those winds have been steadily decreasing
over the last few hours. Elevated smoke from the fires has
engulfed most of central and northern Sonoma County and approached
the northern portions of Marin County. Weakening of the offshore
winds has been observed since dawn as well, which has allowed for
more of that smoke to travel more towards the west. In terms of
intensities, gusts around Santa Rosa have still remained around
the 25-30mph range. Expecting these winds to let up sometime later
this afternoon/evening.

In terms of temperatures for today across the region,
portions of southeastern and downtown SF made it up to 91-93 F,
with 90s F currently observed over much of the Bay Shoreline. Of
interesting note, the western half of the SF Peninsula is already
showing the effects of the southerly surge that is being observed
along the coast, resulting in temps along the western side of the
city plummeting from 88 to 71 F in the span of an hour this
afternoon. Interior East Bay locations will not be spared as
easily, as they are currently in the low-90s this afternoon, with
Livermore currently at 95 F, and are expected to get into the
97-102 F mark this afternoon. Expecting temps to peak around the
Bay Shoreline and the East side of the City proper early this
afternoon before quickly tumbling down as the southerly surge
brings in marine stratus and fog past the Golden Gate. For now,the
Heat Advisory for the San Francisco Bay Shoreline, SF shoreline,
and the city proper is valid through 7PM tonight.

Temps are actually substantially cooler today across much of Central
and Northern Sonoma county (including Santa Rosa), with several
stations reporting 10-15 F temperature difference between now and 24
hours ago. Unfortunately this sharp drop-off has all to do with
the smoke canopy associated with the active fires which has
largely limited incident solar radiation across the area
underneath it. By contrast, surrounding locations just outside the
smoke plume are notably in the mid-to-upper 90s (e.g. Petaluma
and Vallejo). Temps are expected to get up into the triple digits
this afternoon in the ridges of the North Bay not under the smoke
canopy and the East Bay. Red Flag Warning is valid through 9PM
tonight, while the Heat Advisory for the San Francisco Bay
Shoreline, SF shoreline, and the city proper is valid through 7PM

For the latest on active wildfires and firefighting efforts, please
refer to CALFIRE and your local Sheriffs Office.

Ashfall has been reported in several locations across Sonoma County
this afternoon as elevated smoke has permeated most of the central
and northern portions of the county. Haze is also visible across
much of the North Bay that is downstream from the incident site.
As such, HRRRx smoke run for the afternoon expects most of this
smoke to remain in the North Bay, with some particulates making
it down into the SF Peninsula and East Bay. However, southerly
surge should help to keep most of the Glass Fire smoke canopy away
from the center of the Bay Area. It should be noted, however,
that elevated smoke from the active wildfires in the Sierra has
now made it into the skies of the South Bay and San Benito
counties. Expecting more of this elevated smoke to move over the
CWA this evening as it is advected by southerly winds into the
core of the Bay Area.

For the latest on air quality concentrations in your area, please
refer to either the Bay Area Air Quality District or AirNow.

Short and Mid-range guidance in agreement that this southerly surge
will help keep temperatures along the coast predominantly in the
70s-to mid-80s F range tomorrow, with max temps in the Bay Area
Shoreline dropping down to the upper-70s F to low 80s F. Max temps
for SF tomorrow expected to be around 15 F cooler than today in
places like Downtown and Twin Peaks, while Oakland and the coastal
South Bay will experience similar drop-offs. The same cannot
entirely be said for near-coastal locations like San Jose, where
max temps are still expected to be around 90F, albeit 6 degrees F
cooler than today. The primary focus is still on the North Bay,
where interior Sonoma and Napa counties are only expecting little
in the way of temperature recoveries. The good news is that winds
are expected to weaken through tonight and into tomorrow all
across the North Bay as the offshore flow gradually comes to a
halt and is replaced by onshore SW winds. Unfortunately, these
will be short-lived and will not bring in much needed moisture
into the area. As such, overnight humidity recoveries are still
expected to be poor over the next few days, with min RH values
struggling to get over the 20th percentile through Wednesday.

Looking into the second half of this week, not expecting much of a
change in extended forecast given that both the GEFS and ECMWF
ensembles have the upper-level ridge locked in over the northern
portions of the Great Basin through Friday. As such, the interior
will not be seeing much in the way of temperature recoveries through
the workweek. Do expect the ridge to finally break down sometime by
this weekend, which will allow for the interior to finally some
relief as well.

&& of 10:41 AM PDT Monday...For the 18z TAFs.
Generally VFR conditions to persist over the terminals through
the day with the exception being KSTS where smoke from nearby
wildfires have produced MVFR ceilings. With stronger winds aloft
across the North Bay, have kept in wind shear for a while longer
as well over those terminals. Otherwise, generally light winds and
VFR conditions to prevail. Meanwhile, stratus and fog over the
Pacific is forecast to advect northward through the day
along/near the coast and then potentially spread inland overnight
around the Monterey Bay region, thus likely resulting in the
potential for low ceilings and/or fog. However, confidence remains
low at this time on the exact timing and/or inland extent. Hazy
conditions cann`t be ruled out either across just about all of the
terminals today given ongoing wildfires across the region.
However, most locations through the day should see visibilities
remain at or above 6SM.

Vicinity of KSFO...VFR with light and variable winds this morning
increasing becoming onshore and increasing slightly this
afternoon. Smoke advected from wildfires around the region may
create slant range visibility issues today upon approach.
Approaching coastal stratus not expected to impact local terminals
through Tuesday morning.

SFO Bridge Approach...Possible slant-range vis issues with smoke
and haze. Otherwise, similar to KSFO.

Monterey Bay Terminals...VFR conditions with generally light
winds. Hazy conditions may also be possible at times, yet
visibilities not currently expected to lower below 6SM. Onshore
flow may increase a bit this afternoon and may help to advect in
stratus/fog into the terminals later tonight and into Tuesday
morning. However, confidence in timing and/or extent of low
stratus and fog late in the forecast period remains low.
Regardless, do expect the possibility of lower
ceilings/visibilities tonight into Tuesday morning.


.CLIMATE...Here are record high temperatures for Monday...

SANTA ROSA...........104 in 2010
KENTFIELD............102 in 1921
NAPA.................102 in 1966
RICHMOND..............97 in 2010
LIVERMORE............105 in 2010
SAN FRANCISCO.........95 in 1966
SF AIRPORT............95 in 2010
REDWOOD CITY..........98 in 2010
HALF MOON BAY.........91 in 1958
OAKLAND DOWNTOWN......92 in 2010
SAN JOSE..............99 in 2010
GILROY...............101 in 1963
SANTA CRUZ...........100 in 1917
SALINAS...............99 in 1970
KING CITY............102 in 1973


.FIRE WEATHER...As of 3:30 AM PDT Monday...Another round of gusty
offshore winds is occurring early this morning, especially across
the North Bay where northeast winds are gusting between 40 and 60
mph in the hills above 1500 feet. Gusts of between 30 and 40 mph
are occurring elsewhere in the hills of the North Bay above 500
feet and also in the East Bay Hills. In addition, there has been
no humidity recovery overnight and current RH values are mostly in
the teens. The combination of gusty northeast winds and very low
humidity is resulting in rapid fire growth and spread of the
existing wildfires in western Napa County and eastern Sonoma
County. This dangerous situation will continue as long as gusty
winds persist. Latest forecast models are consistent with previous
models in maintaining current wind speeds through about mid
morning. Also, winds are expected to continue to veer more to the
east by daybreak. Wind speeds are expected to subside
significantly by early afternoon. But even with the expected
decrease in winds, critical fire weather conditions are expected
to continue through late in the day across the North and East Bay
due to hot and very dry conditions. A Red Flag Warning remains in
effect until 9 PM PDT for the entire North Bay as well as the East
Bay Hills and Interior Valleys.

A cooling trend is expected to begin along the coast and around
the Bays on Tuesday. However, very warm to hot weather conditions
are forecast to persist across inland areas through much of the
work week. After Monday however, winds are forecast to remain
mostly light.

&& of 10:41 AM PDT Monday...Generally light southerly
winds will develop over the coastal waters today and continue into
Tuesday before turning westerly.  Locally gusty west to southwest
winds developing north of the Bay Bridge this afternoon and
evening. Northwest winds will redevelop later in the week. Seas
will be a mix of moderate northwest swell and a longer period,
light southerly swell.


     .Tngt...Heat Advisory...*CAZ006-505>508-510>513*
             Red Flag Warning...*CAZ505>507-510-511*
             SCA...SF Bay until 10 PM




Visit us at

Follow us on Facebook, Twitter, and YouTube at:

NWS MTR Office Area Forecast Discussion

To use, include the output of the script on your webpage by using

$doIncludeFD = true;
include("forecast-discussion.php"); ?>

to perform the include. Settings inside the script are:

// settings:
//  change myNWS to abbreviation for your local NWS office
//    other settings are optional
    $myNWS = 'MTR';   // San Francisco, NWS office
//  $myNWS = 'PQR';   // Portland, OR
//  $myNWS = 'OAX';   // Omaha, NE (Carter Lake, IA)
$cacheName = "forecast-discussion.txt"; // used to store the file so we don't have to // fetch it each time $refetchSeconds = 1800; // refetch every nnnn seconds
$cacheFileDir = './'; // default cache file directory // end of settings

The only required setting is for $myNWS which designates the local NWS office.
To find the 3-character abbreviation for your local NWS office for the $myNWS variable, follow these steps:

  1. Browse to
  2. Use the search box on the left to search for your city, state
  3. Look at the URL in the 'Forecast Discussion' link near the bottom of the page
  4. Use the 3-character abbreviation is in the &issuedby=XXX parameter on the Forecast Discussion link (XXX will be your local office)
  5. put the XXX in the $myNWS = 'XXX'; statement

The script has two optional parameters when you call it by URL from your website::

Will return the contents without the surrounding <html><head></head><body> and </body></html> tags
Will override the default $refetchSeconds=1800 so that the cache is refreshed immediately

NWS Area Forecast Discussion PHP script Demo and Download (1.06 - 27-Feb-2018 see history).

PHP for NWS CPC World Extremes

This script was originated by Michael of and has been rewritten to use the NWS Climate Prediction Center's CSV file for world observations. The script does not produce output (other than HTML comments for status), so you are free to include it in a page, and format the text output as you desire. The script returns data in variables:

$omittedCountry (text list of countries excluded from $world high/low/precip scans)
Note: the setting $ignoreCountrys is the array of country names to to exclude

$selectedCountry (setting: country name for selected country high/low/precip)
Note: run to see the list of country names to use

$usahigh (Note: for lower-48 USA states)
$usalow (Note: for lower-48 USA states)
$usaprecip (Note: for lower-48 USA states)

$selectedState (setting: USA state 2-character name abbreviation in settings area)
$selectState (a copy of $selectedState for compatibility with old stateextremes.php)

$reportDate (nicely formatted date of the report)
$stateReportDate (a copy of $reportDate for compatibility with old stateextremes.php)

You can run the script by using:


print "<p>USA Extremes for $reportDate</p>\n";
print "<p>High Temperature<br/><br/>$usahigh</p>\n";
print "<p>Low Temperature<br/><br/>$usalow</p>\n";
print "<p>High Precipatation<br/><br/>$usaprecip</p>\n";
print "<p><small>Data courtesy of <a href=\"";
print "";
print "\">NWS-CPC</a></small></p>\n";


which produces this result (with live data):

USA Extremes for Sunday, September 27, 2020

High Temperature

105°F at Dryden Terrell County Ap, TX

Low Temperature

18°F at Berthoud Pass, CO

High Precipatation

3.27in at St Augustine Airport, FL

Data courtesy of NWS-CPC

The script has internal settings which you can adjust. If run in a Saratoga template, the cache file will be stored in the ./cache/ directory based on $SITE['cacheFileDir'] in Settings.php.

$cacheFileDir = './'; // directory to store cache file in.
$cacheFile2 = "worldextremesCache.txt";  
// Age of cache file before re-fetch caching time, in seconds (3600 = 1 hour)
$cache_life = '3600';
$reportDateFormat = "l, F j, Y"; // Day, Month d, yyyy 
$tUOM = '&deg;F'; // or ='' for no temperature unit display (display in C is default)
$rUOM = 'in';     // or ='' for no rain unit display (display in mm is default)
$ignoreCountrys = array('Antarctica','Greenland');     // for world extremes - exclude these country(s)
$ignoreStations = array('99KLRJ');     // list of stn_id (field 0) to ignore for bogus data
$tempDiffAllowed = 40; // max difference Tmax-Tmin (C) for valid data
$selectedCountry = 'Canada'; // for country max/min/precip in $country* variables
// note: the $usa* variables will have the min/max/precip for the lower-48 states
$selectedState   = 'CA';  // for USA state max/min/precip in $state* variables

Note that $cacheFileDir, $tUOM, $rUOM will use the Saratoga template Settings.php values if used in a Saratoga template.

NWS CPC One Day Extremes PHP script Download (5.04 - 28-Jul-2020 see history).