In [3]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import pandas as pd
import datetime
import os

In [4]:
data = pd.read_fwf('combined.txt')
data['start'] = data.apply(lambda x: pd.datetime.strptime("{:4.0f} {:2.0f} {:2.0f} {:2.0f}:00".format(x['Year'], x['Month'], x['Day'], x['Hour']), "%Y %m %d %H:%M"), axis=1)
"""
data["Month_rolled"] = 0
for i in range(len(data.Month)):
    if data.Month[i] > 6:
        data["Month_rolled"][i] = data.Month[i]-6
    else:
        data["Month_rolled"][i] = abs(data.Month[i]-6)
"""
df = data[['start','length', 'hsig', 'tps', 'a_hsig', 'a_tps']]
df['end'] = pd.datetime(1900,12,31)
for i in range(len(df['length'])):
    df['end'].iloc[i] = df['start'].iloc[i]+pd.Timedelta(hours=df['length'].iloc[i])


/home/user/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:12: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/home/user/anaconda3/lib/python3.5/site-packages/pandas/core/indexing.py:128: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self._setitem_with_indexer(indexer, value)
/home/user/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:14: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

In [5]:
os.chdir(r"/media/sf_C_DRIVE/Users/jdorvinen/Documents/Jared/Projects/East Hampton/met_data/montauk_tide")
data2 = pd.read_csv("8510560_swel.csv")
df2 = data2[[" Water Level", "Date Time"]]
df2.columns = ['swel', 'datetime']
df2['datetime'] = pd.to_datetime(df2['datetime'])
df2.set_index('datetime', inplace=True)
swel = []
for indexer in range(len(df['start'])):
    begin = df['start'].loc[indexer]
    end = df['end'].loc[indexer]
    swel.append(df2['swel'][begin:end].quantile(0.6))
df['swel'] = pd.Series(swel)


/home/user/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:5: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/home/user/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:12: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

In [4]:
pd.tools.plotting.scatter_matrix(df, alpha=0.5, figsize=(15,13))


Out[4]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7fc5956022e8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc595327fd0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5952f75f8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5952b4a20>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5952035f8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5951bdb00>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7fc59518c7f0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc595149828>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5951165f8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5950d2828>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc59509ba20>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc59503e7f0>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7fc594e23b38>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594df3128>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594dad780>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594d77f60>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594d37748>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594c81978>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7fc594c3d748>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594c0b978>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594bd3e48>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594b94898>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594b5ee80>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594b1ea58>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7fc594aee630>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594a93978>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594a63fd0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc594a737b8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5949eddd8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc59493d8d0>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7fc5948fd208>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5948c7cc0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5948880f0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc59484eda0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc59480ceb8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7fc5947dc128>]], dtype=object)

In [ ]:
fig = pd.tools.plotting.scatter_plot(df, 'hsig', 'tps')

In [ ]:
sequence = ['start', 'end', 'length', 'swel', 'hsig', 'tps', 'a_hsig', 'a_tps']
df = df.reindex(columns=sequence)

In [ ]:
#df[df['swel'].isnull()]

In [ ]:
outputfile = 'combined_data.csv'

In [ ]:
def write_files(storms,outputfile):
    """Write list of storms to output file"""
    with open(outputfile, "w") as output:
        line = "              start                   end  length    swel    hsig     tps  a_hsig   a_tps\n"
        output.write(line)
        for storm in range(len(storms["start"])):
            start = '{!s}'.format(str(storms["start"][storm]))
            end = '   {!s}'.format(str(storms["end"][storm]))
            length = '{:>8}'.format(storms["length"][storm])
            swel = '{:>8.2f}'.format(storms["swel"][storm])
            hsig = '{:>8.2f}'.format(storms["hsig"][storm])
            tps = '{:>8.2f}'.format(storms["tps"][storm])
            a_hsig = '{:>8.2f}'.format(storms["a_hsig"][storm])
            a_tps = '{:>8.2f}'.format(storms["a_tps"][storm])
            line = start+end+length+swel+hsig+tps+a_hsig+a_tps+"\n"
            output.write(line)

In [ ]:
write_files(df, outputfile)

In [6]:
x = df['hsig'].values
y = df['length'].values

In [7]:
from ambhas.copula import Copula

In [8]:
frank = Copula(x,y,family='frank')
gumbel = Copula(x,y,family='gumbel')
clayton = Copula(x,y,family='clayton')

In [9]:
uf,vf = frank.generate_xy(1000)
ug,vg = gumbel.generate_xy(1000)
uc,vc = clayton.generate_xy(1000)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-9-9c36c59e8ffa> in <module>()
----> 1 uf,vf = frank.generate_xy(1000)
      2 ug,vg = gumbel.generate_xy(1000)
      3 uc,vc = clayton.generate_xy(1000)

/home/user/anaconda3/lib/python3.5/site-packages/ambhas/copula.py in generate_xy(self, n)
    176 
    177         # estimate inverse cdf of x and y
--> 178         self._inverse_cdf()
    179 
    180         # estimate X1 and Y1

/home/user/anaconda3/lib/python3.5/site-packages/ambhas/copula.py in _inverse_cdf(self)
    253         to relate cdf at 100 points to data
    254         """
--> 255         x2, x1 = st.cpdf(self.X, kernel = 'Epanechnikov', n = 100)
    256         self._inv_cdf_x = interp1d(x2, x1)
    257 

NameError: name 'st' is not defined

In [ ]:
fig, ax = plt.subplots(2,2, figsize=[10,9])

ax[0,0].scatter(x, y)
ax[0,1].scatter(uf, uf)
ax[1,0].scatter(ug, ug)
ax[1,1].scatter(uc, uc)

ax[0,0].set_xlim(0.95*min(x),1.05*max(x))
ax[0,0].set_ylim(0.95*min(y),1.05*max(y))
ax[0,1].set_xlim(0,1)
ax[0,1].set_ylim(0,1)
ax[1,0].set_xlim(0,1)
ax[1,0].set_ylim(0,1)
ax[1,1].set_xlim(0,1)
ax[1,1].set_ylim(0,1)

In [ ]:
Copula??

In [ ]:
frank.theta

In [ ]:
x.ndim

In [ ]:
ax[0]

In [ ]:
import statistics

In [ ]:
statistics.

In [ ]:
import numpy as np
import stats

In [ ]:
import copulalib

In [ ]:
copulalib??

In [ ]:
ambhas??

In [ ]:
import ambhas

In [ ]:
ambhas??

In [9]:
import scipy.stats as spt

In [ ]: