Exemple #1
0
def load_year_data(basin, elem, year, include_sites):
    sys.stderr.write("Loading %s data...\n" % year)
    sdate = parse_date('%s-01-01' % year).date()
    edate = parse_date('%s-12-31' % year).date()
    sitedata = StationDataIO(
        basin=basin,
        start_date=sdate,
        end_date=edate,
        parameter=elem,
    )
    sitedata = {site.uid: site for site in sitedata}
    dates = {}
    date = sdate
    while date <= edate:
        dates[date] = {}
        date += one_day

    for site in include_sites:
        if site.uid not in sitedata:
            continue
        data = sitedata[site.uid].data
        for row in data:
            dates[row.date][site.uid] = getattr(row, elem)

    date = sdate
    while date <= edate:
        data = list(
            map(str,
                [dates[date].get(site.uid, "") for site in include_sites]))
        sys.stdout.write(",".join([str(date)] + data))
        sys.stdout.write("\n")
        date += one_day
def fetch_historical_temperature_data(date, state):
    """Fetchs temperature data of a given day from a given state.

    Args:
        date (str): String with the day to fetch data in YYYY-MM-DD format.
        state (str): String with the state or US territory acronym. Ex: "PR" or "NY" for Puerto Rico and New York respectevly.

    Returns:
        [[[Float, Float, Float]]]: Array containing multiple Arrays of size 3 corresponding to Latituded of measuring station, Longituded of measuring station, and Temperatue in Fahrenheit. 
    """
    next_date = datetime.strptime(date, "%Y-%m-%d") + timedelta(days=1)

    sites = StationDataIO(state=state,
                          start_date=date,
                          end_date=datetime.strftime(next_date, "%Y-%m-%d"),
                          parameter="avgt")

    data_points = []
    for i in range(0, len(sites)):
        try:
            if type(sites[i].latitude) == str or type(
                    sites[i].longitude) == str or type(
                        sites[i].data[0].avgt) == str:  #Case with missing data
                continue
            if sites[i].latitude is None or sites[i].longitude is None or sites[
                    i].data[0].avgt is None:  #Case with missing data
                continue

            data_points.append(
                [sites[i].latitude, sites[i].longitude, sites[i].data[0].avgt])

        except:
            continue

    return data_points
Exemple #3
0
    def test_station_data(self):
        data = StationDataIO(
            county='27053',
            start_date='2014-07-01',
            end_date='2014-07-01',
            parameter='pcpn',
        )

        self.assertGreater(len(data), 0)
        item = data[0]
        self.assertHasFields(item, ("latitude", "longitude", "data"))

        row = item.data[0]
        self.assertHasFields(row, ("date", "pcpn"))
#--- https://pypi.org/project/climata/
from climata.acis import StationDataIO

# Load average temperature for sites in Upper Klamath Lake basin
sites = StationDataIO(basin="18010203",
                      start_date="2017-01-01",
                      end_date="2017-01-31",
                      parameter="avgt")

# Display site information and time series data
for site in sites:
    print(site.name)
    for evt in site.data:
        print(evt.date, evt.avgt)