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 190609

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1109 PM PDT Sat Sep 18 2021

.SYNOPSIS...Light rain showers end overnight with a return to
drier but still cool conditions Sunday. A rapid shift towards
gusty offshore flow and warmer, drier conditions begins Sunday
night through early next week. A fire weather watch is in effect
for the potential for increased fire risk due to the drying
conditions and gusty offshore winds from Sunday night through
Tuesday morning.

&& of 09:40 PM PDT Saturday...KMUX radar shows scattered
showers continuing to move eastward over Sonoma and northern Marin
Counties. A look at 12-hour precip totals shows fairly impressive
amounts (~0.5 in) at northern coastal Sonoma sites where SSW winds
provided orographic enhancement. Just over the border in Mendocino
Co, 1+ inch totals have been measured. Farther south and in the
Sonoma Valley, amounts are under a tenth of an inch, and generally
a few hundredths or less. No bucket tips in downtown SF as of yet.
Hi-res models show the potential for very light scattered showers
making their way south through the SF Bay Area and into the Monterey
Bay Area overnight. These areas might see a trace to a few hundredths.

Satellite night imagery reveals disjointed marine stratus over the
coastal waters, with some stratus developing over coastal land areas.
Also, a band of higher level clouds associated with the precip and
frontal boundary is traversing North Bay. After the frontal boundary
passes through, winds will shift to the northwest and clouds will
scatter out, though marine stratus will likely linger through the
morning. Temperatures will also moderate a bit Sunday as the upper
trough over the coast moves inland, and a ridge builds over the eastern
Pacific. Still, most areas will remain several degrees below daily
normals. A stark transition to drier and warmer conditions with the
development of offshore flow occurs overnight Sunday into Monday. Fire
Weather Watch goes into effect for the North Bay Mountains and East Bay
Hills Sunday at 11 p.m. Read discussion below for more details and for
the weekly outlook.


.PREV of 02:30 PM PDT Saturday...The first fall-like
system of the post-summer dry season has begun to impact the
Pacific Northwest and northwestern California through midday

Remote sensing imagery shows a narrow, intense band of
200% of normal precipitable water values akin to an atmospheric
river along a dynamic cold frontal boundary on the leading edge of
this feature. Relatively high rainfall values in excess of 2
inches have been reported farther north near Eureka, CA as this
weakening atmospheric river shifts southward towards the Bay Area
with lower amounts elsewhere. The Scripps` Center for Western
Weather and Water Extremes atmospheric river index rates this
storm system as a AR 1 (of 5) for northwestern California (& AR
2-3 in the PacNW), but falls below atmospheric river criteria for
our area as it descends south of Cape Mendocino towards the Bay
Area through tonight.

This difference is due to the lack of upper level dynamics that
are present farther north near the core of the storm, but are lost
as the southern flank of the frontal boundary falls away from the
parent feature. Instead, orographic lift will be the primary
lifting mechanism to generate rainfall from this narrowing
precipitable water plume, thus there has been a recent model
trend to pull back rainfall amounts across the interior and rain
shadowed areas in favor of increasing upslope amounts along the
coastal ranges. For example, a few days ago, the forecast called
for peak amounts of perhaps 1/3" along the North Bay coastal
ranges, but increased that to 1/2" a day or two ago, and today, up
to 2/3" is now in range for our wettest spots like Venado. This
orographic upshift in the rainfall comes at the cost of a
downshift elsewhere, with 0.10-0.15" for the North Bay valleys,
0.04-0.08" for the I80 Corridor and coastal Peninsula, and a few
hundredths to a trace along the the remainder of the San Francisco
Bayshore and coastal Central Coast. The southern and eastern
peripheries of the interior are more likely to see no rain at all
than even 0.01".

In terms of timing, the bulk of the rainfall is forecast to
arrive between this evening and the overnight period, with the
frontal band fragmenting up and the last showers dissipating by
sunrise tomorrow morning. Breezy west to northwest winds will
develop in the wake of the front later tomorrow afternoon.

The weather pattern will remain progressive and fall-like in the
wake of this trough, with a rapid shift towards warmer, drier
conditions into early next week in response to a high amplitude
eastern pacific ridge building ashore in the wake of the weekend`s
storm system. This rapid shift will begin to unfold through the
day on Sunday and be heralded in with the arrival gusty offshore
flow down the western side of Sacramento Valley before funneling
through the North and East Bay interior ranges beginning late
tomorrow evening. Fuels are near or at record dry levels across
these interior slopes, and if today/tonight`s storm fails to bring
sufficiently wetting rains, then critical fire weather conditions
could present themselves as the humidity plummets through Sunday
night into Monday morning.

Offshore winds are forecast to peak between 3 am and 9 am Monday
morning, with sustained winds 15 to 25 mph with gusts to 30 to 40
mph, locally to 50 mph at ridge top levels. Some mix down to the
lower elevations is expected Monday morning, with gusts to
15-20mph possible at places like the Napa valley. A warmer, drier
air mass settles in through the day on Monday and, with offshore
flow, daytime humidities plummet into the low to mid teens in the
drier spots. Poor overnight humidity recoveries are expected for
Monday night into Tuesday morning, though on the plus side, winds
should be roughly only half as strong as the previous night. So,
both Sunday night and Monday night`s offshore wind events are
borderline critical criteria for varying reasons. For now, no
changes are planned for the fire weather watch until we review
observational rainfall numbers tomorrow morning. From here, we
will decide to cancel or upgrade some or all parts of the watch.
For more information, please review the fire weather section
written by one of our fire weather incident meteorologists below.

&& of 11:00 PM PDT Saturday...For the 06z TAFs. A
system is currently moving southward through the area. The FROPA
is currently impacting the North Bay, brining MVFR/IFR ceilings, -RA/DZ,
and reduced visibilities to KSTS/KAPC. Patchy low clouds ahead of
the front for the Bay Area and Monterey terminals. FROPA should
continue down the coast, giving MVFR/IFR ceilings and -RA to most
sites. Lower confidence on -RA for KMRY/KSNS as FROPA is
forecasted to weaken south of the Bay Area. Winds will remain
AOB 15kts area wide with mostly light speeds. Light southerly
winds ahead of the FROPA, then northwesterly behind. VFR returns
Sunday afternoon behind the front, with onshore winds building in
afternoon hours.

Vicinity of KSFO... MVFR conditions expected to prevail overnight
and through mid Sunday morning. Some light showers or drizzle
will be possible with the frontal passage around 08-09Z.  Winds
are expected to shift more out of the W/NW tomorrow behind the

KSFO Bridge Approach...Similar to KSFO.

Monterey Bay...MVFR/IFR conditions prevailing overnight. Some
drizzle possible overnight, most precipitation from the
aforementioned cold front is not expected to make it this far
south. VFR conditions anticipated by late tomorrow morning/early


.FIRE WEATHER...As of 3:34 AM PDT Saturday...Fire Weather Watch
in effect for North and East Bay hills from 11 pm Sunday night
through 11 am Tuesday. As noted above in the short term we do
expect some wetting rains for coastal Sonoma county. Wetting rains
for Napa and East Bay hills look unlikely at this time though a
few hundredths is certainly possible. Did look at the updated
fuels charts that literally just updated. For the North Bay the
ERC readings are down from record highs but still running near the
97th percentile (though thats obviously not accounting for any
precip we receive the next 24 hours). The Bay Area marine zones
that are continuously impacted by the marine layer and thus higher
humidity are actually now running below normal for this time of
year. Finally the Diablo/Santa Cruz mountains are around the 90th
percentile but will likely drop slightly over the next 24 hours.

Anyway, we`ll be monitoring rainfall totals closely through Sunday
morning. High confidence for warming and drying to start Sunday
afternoon but the airmass being replaced is very moist as noted by
the high PW values. Watch start time of 11 pm Sunday still looks
good with latest NAM model showing an abrupt increase in northeast
wind around 925 mb between 06-09z. Given the stability profile
would expect most of the winds to stay at or above 2000 feet
with gusts generally in the 30-40 mph range (50 mph Mt Saint
Helena). RH values look to stay above 30% into Monday morning
which may be a limiting factor. In addition should wetting rains
occur across much of the North Bay that could put us out of
Red Flag criteria for 24 hours after the rain ends.

High confidence for rapid warming and drying Monday as temps will
quickly rebound into the upper 80s and 90s with humidity dropping
into the teens as persistent but light offshore winds continue.
The entire Bay Area will dry out Monday night into Tuesday but
wind speeds look light as the strongest pressure gradient stays
over the northern Sierra.

General trend looks to be above average temps and continued dry
next week though the models are grappling with a potential cut-
off low. The more likely scenario is a transient midweek system
passes to our north with another potential offshore wind event
late in the week followed by building high pressure and
unseasonably warm and dry wx through the end of the month.

&& of 10:42 PM PDT Saturday...Generally light to locally
breezy south to southwest winds ahead of an approaching cold front
overnight. Winds will quickly shift back out of the northwest in
the wake of the frontal passage. The front may also bring some
light precipitation over the waters. Northwest winds will
strengthen in the post frontal environment later tomorrow with
hazardous seas conditions developing over  much of the waters,
particularly for smaller vessels. Mixed seas  persist with a short
period northwest swell and a weak longer  period southerly swell.
An additional longer period northwest  swell will arrive around
mid week.


     .Tday...SCA...Mry Bay from 2 PM
             SCA...Pigeon Pt to Pt Pinos 0-10 nm from 2 PM
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm until 3 AM
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm from 2 PM
             SCA...Pt Arena to Pt Reyes 0-10 nm from 2 PM



AVIATION: Dhuyvetter

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 Friday, September 17, 2021

High Temperature

104°F at Cotulla La Salle County Ap, TX

Low Temperature

16°F at Stanley Ranger Station, ID

High Precipatation

2.53in at Quillayute State Airport, WA

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).