Skip to topic | Skip to bottom
Home
Main
Main.CarolinasCoastGetDatar1.1 - 17 Aug 2006 - 21:17 - CharltonPurvistopic end

Start of topic | Skip to actions

Carolinas Coast : Get Data

This page includes code snippets to illustrate how we might optimally aggregate obs for specific sites.

NWS

http://search.cpan.org/~mslagle/Geo-WeatherNWS-1.03/WeatherNWS.pm

code

use Geo::WeatherNWS;

@stations = (
   'KCHS'
  ,'KNKT'
);

my $rpt = Geo::WeatherNWS::new();

foreach $s (@stations) {
  $rpt->getreport($s);
  print "STATION $s\n"
    ."\tTemperature is $rpt->{temperature_c} deg C, $rpt->{temperature_f} deg F\n"
    ."\tAir Pressure is $rpt->{pressure_inhg} inches\n";
}

output
STATION KCHS
        Temperature is 32 deg C, 89 deg F
        Air Pressure is 30.01 inches
STATION KNKT
        Temperature is 29 deg C, 84 deg F
        Air Pressure is 30.05 inches

NOS / COOPS

Eric Bridger's cookbook sample, http://twiki.sura.org/twiki/bin/view/Main/CoopsPerlClient.

code

#!/usr/bin/perl
use strict;
use SOAP::Lite;

my $station_id = '8454000';
# COOPS time format: 'YYYYMMDD HH:MM'
my $start_time = '20060608 00:00';
my $end_time = '20060608 01:00';

# Pass the WSDL url to the service method. But add ->want_som(1) 
# so we can check resonse->fault and use XPath query to loop thru
# response.
my $service = SOAP::Lite->service('http://opendap.co-ops.nos.noaa.gov/axis/services/WaterLevelRawSixMin?wsdl')->want_som(1);

my $response = $service->getWaterLevelRawSixMin($station_id, $start_time, $end_time, 'MLLW', 0, 0);

if($response->fault())
{
    print 'Error: -' . $response->faultcode . '- ' . $response->faultstring . "\n";
    print $response->faultstring .  " for station $station_id\n";
    exit;
}

print "$station_id\n";
for my $t ($response->valueof('//data/item') ) {
    print "$t->{timeStamp} $t->{WL}\n";
    # some QA flags.
    #print "$t->{sigma} $t->{O} $t->{F} $t->{R} $

output
8454000
2006-06-08 00:00:00.0 1.051
2006-06-08 00:06:00.0 1.023
2006-06-08 00:12:00.0 1.003
2006-06-08 00:18:00.0 0.979
2006-06-08 00:24:00.0 0.942
2006-06-08 00:30:00.0 0.901
2006-06-08 00:36:00.0 0.867
2006-06-08 00:42:00.0 0.843
2006-06-08 00:48:00.0 0.823
2006-06-08 00:54:00.0 0.803
2006-06-08 01:00:00.0 0.784

USGS

Eric Bridger said he'll try to hook us up w/ USGS's experimental SOAP service (and give us code)!

Until then, how about a friendly and stable screen scrape?

code

#!/usr/bin/perl

use LWP::Simple;

$stations = '02110704,02110725';

# A God awful URL that is a 1 time thing, thankfully done interactively, that
# indicates we only want the latest station name, date & time, and water_temp in C as our main cols.

$url = "http://waterdata.usgs.gov/nwis/current?multiple_site_no=$stations&index_pmcode_STATION_NM=1&index_pmcode_DATETIME=2&index_pmcode_72019=&index_pmcode_70227=&index_pmcode_72020=&index_pmcode_99020=&index_pmcode_00062=&index_pmcode_50051=&index_pmcode_00059=&index_pmcode_99065=&index_pmcode_30207=&index_pmcode_00065=&index_pmcode_62611=&index_pmcode_62615=&index_pmcode_62614=&index_pmcode_MEAN=&index_pmcode_MEDIAN=&index_pmcode_00064=&index_pmcode_72022=&index_pmcode_00054=&index_pmcode_00072=&index_pmcode_00055=&index_pmcode_63160=&index_pmcode_63158=&index_pmcode_00060=&index_pmcode_50042=&index_pmcode_99060=&index_pmcode_00067=&index_pmcode_62620=&index_pmcode_62619=&index_pmcode_81904=&index_pmcode_63518=&index_pmcode_00625=&index_pmcode_00608=&index_pmcode_99123=&index_pmcode_71845=&index_pmcode_99220=&index_pmcode_50060=&index_pmcode_32209=&index_pmcode_32210=&index_pmcode_32234=&index_pmcode_62361=&index_pmcode_00301=&index_pmcode_00300=&index_pmcode_72106=&index_pmcode_00618=&index_pmcode_00620=&index_pmcode_00631=&index_pmcode_00630=&index_pmcode_00090=&index_pmcode_70301=&index_pmcode_00096=&index_pmcode_00480=&index_pmcode_90860=&index_pmcode_00931=&index_pmcode_90856=&index_pmcode_81203=&index_pmcode_00095=&index_pmcode_00402=&index_pmcode_80154=&index_pmcode_99409=&index_pmcode_80155=&index_pmcode_00010=1&index_pmcode_00011=&index_pmcode_00047=&index_pmcode_63680=&index_pmcode_00076=&index_pmcode_61028=&index_pmcode_63682=&index_pmcode_63684=&index_pmcode_99111=&index_pmcode_71994=&index_pmcode_00400=&index_pmcode_00025=&index_pmcode_75969=&index_pmcode_62607=&index_pmcode_62603=&index_pmcode_00030=&index_pmcode_72124=&index_pmcode_99988=&index_pmcode_00193=&index_pmcode_00117=&index_pmcode_46529=&index_pmcode_99772=&index_pmcode_00045=&index_pmcode_00052=&index_pmcode_99986=&index_pmcode_99987=&index_pmcode_46515=&index_pmcode_46516=&index_pmcode_00020=&index_pmcode_00021=&index_pmcode_62608=&index_pmcode_00036=&index_pmcode_61729=&index_pmcode_61727=&index_pmcode_61728=&index_pmcode_82127=&index_pmcode_62625=&index_pmcode_00035=&index_pmcode_00042=&index_pmcode_72001=&index_pmcode_81903=&index_pmcode_72135=&index_pmcode_50050=&index_pmcode_45585=&index_pmcode_45592=&index_pmcode_45591=&index_pmcode_00053=&index_pmcode_98232=&index_pmcode_50294=&index_pmcode_74207=&index_pmcode_00063=&index_pmcode_70968=&index_pmcode_00003=&index_pmcode_72147=&index_pmcode_30215=&index_pmcode_82300=&index_pmcode_62846=&index_pmcode_81027=&index_pmcode_50011=&index_pmcode_81026=&index_pmcode_99900=&index_pmcode_99901=&index_pmcode_99902=&index_pmcode_99903=&index_pmcode_99904=&index_pmcode_99905=&index_pmcode_99906=&index_pmcode_99907=&index_pmcode_99908=&index_pmcode_99909=&index_pmcode_99910=&index_pmcode_99911=&index_pmcode_99912=&index_pmcode_99913=&index_pmcode_99914=&index_pmcode_99915=&index_pmcode_99916=&index_pmcode_99968=&index_pmcode_70969=&index_pmcode_72115=&index_pmcode_72113=&index_pmcode_72112=&index_pmcode_72111=&index_pmcode_72117=&index_pmcode_82292=&index_pmcode_72114=&index_pmcode_99969=&index_pmcode_99970=&index_pmcode_99971=&index_pmcode_72116=&index_pmcode_30214=&index_pmcode_45587=&index_pmcode_61035=&sort_key=site_no&group_key=NONE&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&sort_key_2=site_no&html_table_group_key=NONE&format=rdb&rdb_compression=value&list_of_search_criteria=multiple_site_no%2Crealtime_parameter_selection";
@d = split(/\n/,get($url));

foreach (@d) {
  split(/\t/,$_);
  if ($_[0] eq 'USGS') {
    print "station $_[1] @ $_[5] : water temp $_[6] deg C\n";
  }
}

output
station 41013 @ 2006-08-16 22:50 wspd = 11.0; wtmp = 27.7
station 41025 @ 2006-08-16 22:50 wspd = 2.0; wtmp = 28.7

NDBC

From http://ndbc.noaa.gov/data/hourly2.

code

#!/usr/bin/perl

use LWP::Simple;

$utc_hh = `date +%H --utc`;
chomp($utc_hh);
$url = "http://ndbc.noaa.gov/data/hourly2/hour_$utc_hh.txt";
@d = split(/\n/,get($url));

%stations = (
   '41025', 1
  ,'41013', 1
);

foreach (@d) {
  ($stn
  ,$yyyy
  ,$mm
  ,$dd
  ,$hh
  ,$mi
  ,$wd
  ,$wspd
  ,$gst
  ,$wvht
  ,$dpd
  ,$apd
  ,$mwd
  ,$baro
  ,$atmp
  ,$wtmp
  ,$desp
  ,$vis
  ,$ptdy
  ,$tide
  ) = split(/ +/,$_);
  if ($stations{$stn}) {
    print "station $stn @ $yyyy-$mm-$dd $hh:$mi wspd = $wspd; wtmp = $wtmp\n";
  }
}

output
station 41013 @ 2006-08-16 22:50 wspd = 11.0; wtmp = 27.7
station 41025 @ 2006-08-16 22:50 wspd = 2.0; wtmp = 28.7

to top

You are here: Main > CarolinasCoastGetData

to top

Copyright © 1999-2014 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding DMCC? Send feedback