Example #1
0
    def _gather_frames_column(self, key):
        results = {}
        for name, df in self.frames.iteritems():
            results[name] = df[key]

        df = DataFrame(results)
        df.name = key
        return df
Example #2
0
    def _init_dataframe(self, df, name=None):
        name = name or df.name
        self.columns = [name]
        if name is None:
            raise Exception("need a name for df")

        for col, series in df.iteritems():
            frame = DataFrame({name: series})
            frame.name = col
            self.frames[col] = frame
Example #3
0
    def _gather_column(self, key):
        if key in self._cache:
            return self._cache[key]

        results = {}
        for name, df in self.frames.iteritems():
            results[name] = df[key]

        df = DataFrame(results)
        df.name = key
        self._cache[key] = df
        return df
Example #4
0
def collector2df(collector, station, sos_name):
    """Request CSV response from SOS and convert to Pandas DataFrames."""
    collector.features = [station]
    collector.variables = [sos_name]

    long_name = get_station_longName(station)
    try:

        response = collector.raw(responseFormat="text/csv")
        data_df = read_csv(BytesIO(response.encode("utf-8")), parse_dates=True, index_col="date_time")
    except ExceptionReport as e:
        # warn("Station %s is not NAVD datum. %s" % (long_name, e))
        print(str(e))
        data_df = DataFrame()  # Assigning an empty DataFrame for now.

    data_df.name = long_name
    return data_df
Example #5
0
def coops2df(collector, coops_id, sos_name):
    """Request CSV response from SOS and convert to Pandas DataFrames."""
    collector.features = [coops_id]
    collector.variables = [sos_name]
    long_name = get_Coops_longName(coops_id)

    try:
        response = collector.raw(responseFormat="text/csv")
        data_df = read_csv(BytesIO(response.encode("utf-8")), parse_dates=True, index_col="date_time")
        col = "water_surface_height_above_reference_datum (m)"
        if False:
            data_df["Observed Data"] = data_df[col] - data_df["vertical_position (m)"]
        data_df["Observed Data"] = data_df[col]
    except ExceptionReport as e:
        warn("Station %s is not NAVD datum. %s" % (long_name, e))
        data_df = DataFrame()  # Assing an empty DataFrame for now.

    data_df.name = long_name
    return data_df
# Create a list of obs dataframes, one for each station:

# <codecell>

obs_df = []
sta_names = []
sta_failed = []
for sta in stations:
    b = coops2df(collector, sta, sos_name)
    name = b.name
    sta_names.append(name)
    print(name)
    if b.empty:
        sta_failed.append(name)
        b = DataFrame(np.arange(len(ts)) * np.NaN, index=ts.index, columns=["Observed Data"])
        b.name = name
    # Limit interpolation to 10 points (10 @ 6min = 1 hour).
    col = "Observed Data"
    concatenated = concat([b, ts], axis=1).interpolate(limit=10)[col]
    obs_df.append(DataFrame(concatenated))
    obs_df[-1].name = b.name

# <codecell>

geodetic = ccrs.Geodetic(globe=ccrs.Globe(datum="WGS84"))
tiler = MapQuestOpenAerial()
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(projection=tiler.crs))
# Open Source Imagery from MapQuest (max zoom = 16?)
zoom = 8
extent = [box[0], box[2], box[1], box[3]]
ax.set_extent(extent, geodetic)
Example #7
0
def df_loads(stream):
    """ Returns dataframe from a serialized stream"""
    tempobj = cPickle.loads(stream)  # loads not load
    df = tempobj.dataframe
    for attr, value in tempobj._metadict.items():
        setattr(df, attr, value)
    return df


if __name__ == "__main__":
    ### Make a random dataframe, add some attributes
    df = DataFrame(((randn(3, 3))), columns=["a", "b", "c"])
    print_customattr(df)
    print "adding some attributes"
    df.name = "Billy"
    df.junk = "in the trunk"
    print_customattr(df)

    ### Serialize into memory
    stream = df_dumps(df)
    print "wrote dataframe to memory"
    ### Restore from memory
    dfnew = df_loads(stream)
    print "restored from memory"
    print_customattr(dfnew)

    ### Serialize into file
    outfile = "dftest.df"  # What file extension is commonly used for this?
    df_dump(df, outfile)
    print "wrote dataframe to file %s" % outfile