Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions catchment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ def read_variable_from_csv(filename):

return newdataset

def read_variable_from_xml(filename):
"""Reads a named variable from a xml file, and returns a
pandas dataframe containing that variable.

:param filename: Filename of xml to load
:return: 2D array of given variable. Index will be dates,
Columns will be the individual sites
"""
dataset = pd.read_xml(filename#, usecols=['Date', 'Site', 'Rainfall (mm)']
)
dataset = dataset.rename({'Date':'OldDate', 'Site_Name':'Site Name', 'Rainfall_mm':'Rainfall (mm)'}, axis='columns')
dataset['Date'] = [pd.to_datetime(x,dayfirst=True) for x in dataset['OldDate']]
dataset = dataset.drop('OldDate', axis='columns')

newdataset = pd.DataFrame(index=dataset['Date'].unique())

for site in dataset['Site Name'].unique():
newdataset[site] = dataset[dataset['Site Name'] == site].set_index('Date')["Rainfall (mm)"]

newdataset = newdataset.sort_index()

return newdataset

def daily_total(data):
"""Calculate the daily total of a 2D data array.
Index must be np.datetime64 compatible format."""
Expand Down
Loading