In [2]:
%pylab notebook


Populating the interactive namespace from numpy and matplotlib

In [3]:
from charistools.charisTimeseries import CharisTimeseries
import glob
import matplotlib.pyplot as plt

In [4]:
%cd /projects/CHARIS/charistools_test_data/streamflow
list = sort(glob.glob("??_*dat"))
list


/projects/CHARIS/charistools_test_data/streamflow
Out[4]:
array(['AM_Vakhsh_at_Komsomolabad.month_runoff.dat',
       'GA_Karnali_at_Benighat.month_runoff.dat',
       'GA_Narayani_at_Devghat.month_runoff.dat',
       'GA_SaptaKosi_at_Chatara.month_runoff.dat',
       'IN_Hunza_at_DainyorBridge.month_runoff.dat'], 
      dtype='|S42')

In [5]:
fig, ax = plt.subplots(5, 1, sharex=True, sharey=True, figsize=(8,8))
for filename_idx, filename in enumerate(list):
    data = CharisTimeseries(filename=filename)
    tdf = data.data[data.data > -9999.99]
    tdf['runoff'].loc['2001-01-01':'2014-12-31'].plot(ax=ax[filename_idx], title=filename)
plt.tight_layout()


parse_date_format: ['%Y', '%m']
colnames:   ['year', 'month', 'runoff']
_datetime_cols:  ['year', 'month']
parse_date_format: ['%Y', '%m']
colnames:   ['year', 'month', 'runoff']
_datetime_cols:  ['year', 'month']
parse_date_format: ['%Y', '%m']
colnames:   ['year', 'month', 'runoff']
_datetime_cols:  ['year', 'month']
parse_date_format: ['%Y', '%m']
colnames:   ['year', 'month', 'runoff']
_datetime_cols:  ['year', 'month']
parse_date_format: ['%Y', '%m']
colnames:   ['year', 'month', 'runoff']
_datetime_cols:  ['year', 'month']

In [5]:
for filename in list:
    data = CharisTimeseries(filename=filename)
    tdf = data.data[data.data > -9999.99]
    tdf.plot()
    tdf.loc['2001-01-01':'2010-12-31'].plot()


parse_date_format: ['%Y', '%m']
colnames:   ['year', 'month', 'runoff']
_datetime_cols:  ['year', 'month']

In [6]:
help(data)


Help on CharisTimeseries in module charistools.charisTimeseries object:

class CharisTimeseries(__builtin__.object)
 |  Class to represent timeseries data for CHARIS (discharge, runoff,
 |  precipitation, etc.).  Expected file format is ASCII text, with header
 |  lines beginning with '#', and data in two whitespace-separated columns:
 |  year and annual runoff (km^3) or mean annual discharge (m^3/s).
 |  
 |  Returns an object containing a pandas timeseries object in "data", and
 |  header comments in "comments" with the leading hash ('#') characters
 |  retained.
 |  
 |  Methods defined here:
 |  
 |  __init__(self, filename, default_year=2000)
 |  
 |  as_text(self)
 |  
 |  comments(self)
 |  
 |  comments_array(self)
 |  
 |  summary(self)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)


In [7]:
data.comments()


Out[7]:
'# Station ID: 35749301\n# Basin: Hunza at Dainyor Bridge\n# Latitude: 35.92778\n# Longitude: 74.37639\n# Elevation: 1370 m\n# Area: 13157 km**2\n# Units: km**3\n# COLUMNS: year month runoff'

In [8]:
data.comments_array()


Out[8]:
['# Station ID: 35749301',
 '# Basin: Hunza at Dainyor Bridge',
 '# Latitude: 35.92778',
 '# Longitude: 74.37639',
 '# Elevation: 1370 m',
 '# Area: 13157 km**2',
 '# Units: km**3',
 '# COLUMNS: year month runoff']

In [9]:
data.data


Out[9]:
runoff
datetime
1966-01-01 0.15
1966-02-01 0.12
1966-03-01 0.10
1966-04-01 0.13
1966-05-01 0.29
1966-06-01 2.01
1966-07-01 3.16
1966-08-01 3.49
1966-09-01 1.61
1966-10-01 0.45
1966-11-01 0.20
1966-12-01 0.16
1967-01-01 0.15
1967-02-01 0.13
1967-03-01 0.15
1967-04-01 0.18
1967-05-01 0.29
1967-06-01 1.60
1967-07-01 3.93
1967-08-01 3.64
1967-09-01 1.62
1967-10-01 0.38
1967-11-01 0.19
1967-12-01 0.14
1968-01-01 0.11
1968-02-01 0.10
1968-03-01 0.10
1968-04-01 0.12
1968-05-01 0.33
1968-06-01 1.93
... ...
2011-07-01 -9999.99
2011-08-01 -9999.99
2011-09-01 -9999.99
2011-10-01 -9999.99
2011-11-01 -9999.99
2011-12-01 -9999.99
2012-01-01 -9999.99
2012-02-01 -9999.99
2012-03-01 -9999.99
2012-04-01 -9999.99
2012-05-01 -9999.99
2012-06-01 -9999.99
2012-07-01 -9999.99
2012-08-01 -9999.99
2012-09-01 -9999.99
2012-10-01 -9999.99
2012-11-01 -9999.99
2012-12-01 -9999.99
2013-01-01 -9999.99
2013-02-01 -9999.99
2013-03-01 -9999.99
2013-04-01 -9999.99
2013-05-01 -9999.99
2013-06-01 -9999.99
2013-07-01 -9999.99
2013-08-01 -9999.99
2013-09-01 -9999.99
2013-10-01 -9999.99
2013-11-01 -9999.99
2013-12-01 -9999.99

576 rows × 1 columns


In [19]:
tdf = data.data[data.data > -9999.99]
tdf.plot()


Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fec3e8ad890>

In [20]:
tdf.loc['2001-01-01':'2010-12-31'].plot()


Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fec3e3ad650>

In [18]:
#tdf.loc['2001-01-01':'2004-12-31'].plot()
tdf.plot()


Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fec3ec49490>

In [ ]: