Skip to content

Commit

Permalink
plot timeseries #293
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanie committed Oct 17, 2016
1 parent 0dfa0c7 commit ae5aed5
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 212 deletions.
24 changes: 12 additions & 12 deletions odmtools/controller/frmSeriesSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def OnTableRightDown(self, event):
# build pop-up menu for right-click display
self.selectedIndex = event.m_itemIndex
#self.selectedID = self.tableSeries.getColumnText(event.m_itemIndex, 1)
self.selectedID = self.tblSeries.GetSelectedObject().id
self.selectedID = self.tblSeries.GetSelectedObject().resultID

# print self.selectedID
popup_edit_series = wx.NewId()
Expand Down Expand Up @@ -374,7 +374,7 @@ def siteAndVariables(self):
:return:
"""
self.site_code = self.siteList[self.cbSites.Selection].VariableCode
self.site_code = self.siteList[self.cbSites.Selection].SamplingFeatureCode

self.cbVariables.Clear()
self.varList = self.series_service.get_variables_by_site_code(self.site_code)
Expand All @@ -400,7 +400,7 @@ def siteOnly(self):
self.cbSites.Enabled = True
self.variable_code = None

self.site_code = self.siteList[self.cbSites.Selection].code
self.site_code = self.siteList[self.cbSites.Selection].SamplingFeatureCode
self.setFilter(site_code=self.site_code)

def variableOnly(self):
Expand Down Expand Up @@ -460,17 +460,17 @@ def setFilter(self, site_code='', var_code='', advfilter=''):
:return:
"""
if site_code and var_code:
self.siteFilter = TextSearch(self.tblSeries, columns=self.tblSeries.columns[3:4],text=site_code)
self.variableFilter = TextSearch(self.tblSeries, columns=self.tblSeries.columns[6:7],text=var_code)
self.siteFilter = TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10],text=site_code)
self.variableFilter = TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10],text=var_code)
self.tblSeries.SetFilter(Chain(self.siteFilter, self.variableFilter))
elif site_code:
self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[3:4], text=site_code))
self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10], text=site_code))
elif var_code:
self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[6:7], text=var_code))
self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10], text=var_code))
elif advfilter:
self.tblSeries.SetFilter(advfilter)
else:
self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:1]))
self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10]))
self.tblSeries.RepopulateList()


Expand All @@ -492,12 +492,12 @@ def onReadyToPlot(self, event):
object = self.tblSeries.GetSelectedObject()

if not self.tblSeries.IsChecked(object):
Publisher.sendMessage("removePlot", seriesID=object.id)
Publisher.sendMessage("removePlot", seriesID=object.ResultID)
Publisher.sendMessage("updateCursor", deselectedObject=object)

else:
logger.debug("Obtained object, entering addplot")
self.pnlPlot.addPlot(self.memDB, object.id)
self.pnlPlot.addPlot(self.memDB, object.ResultID)
Publisher.sendMessage("updateCursor", selectedObject=object)

logger.debug("refreshing...")
Expand All @@ -524,7 +524,7 @@ def getSelectedObject(self, event):

## update Cursor
if self.parent.Parent.pnlPlot._seriesPlotInfo:
if self.parent.Parent.pnlPlot._seriesPlotInfo.isPlotted(editingObject.id):
if self.parent.Parent.pnlPlot._seriesPlotInfo.isPlotted(editingObject.ResultID):
#print "Updating Cursor", editingObject.id
Publisher.sendMessage("updateCursor", selectedObject=editingObject)

Expand Down Expand Up @@ -563,7 +563,7 @@ def onReadyToEdit(self):
ovl.RefreshObject(ovl.editingObject)


return True, object.id#, self.memDB
return True, object.ResultID#, self.memDB
else:
isSelected = False
logger.debug("series was not checked")
Expand Down
64 changes: 34 additions & 30 deletions odmtools/controller/logicPlotOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, prnt):
self.plotTitle = None
self.numBins = 25
self.binWidth = 1.5
self.boxWhiskerMethod = "Month"
self.boxWhiskerMethod = "month"

self.yrange = 0
self.color = ""
Expand Down Expand Up @@ -226,8 +226,10 @@ def getSelectedSeries(self, seriesID):
return self.createSeriesInfo(seriesID, seriesInfo, series)

def createSeriesInfo(self, seriesID, seriesInfo, series):
startDate = series.begin_date_time
endDate = series.end_date_time

dates = self.memDB.series_service.get_result_dates(series.ResultID)
startDate = dates[1]
endDate = dates[0]

if endDate > self.endDate:
self.endDate = endDate
Expand All @@ -237,14 +239,15 @@ def createSeriesInfo(self, seriesID, seriesInfo, series):
if not self.isSubsetted:
self.currentStart = self.startDate
self.currentEnd = self.endDate

variableName = series.variable_name
unitsName = series.variable_units_name
siteName = series.site_name
dataType = series.data_type
variable = self.memDB.series_service.get_variable_by_id(series.variable_id)

noDataValue = variable.no_data_value
#TODO odm2

unitsName = series.UnitsObj.UnitsName
siteName = series.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName
dataType = "datatype"#series.data_type
#variable = self.memDB.series_service.get_variable_by_id(series.variable_id)
variable =series.VariableObj
variableName = variable.VariableNameCV
noDataValue = variable.NoDataValue
if self.editID == seriesID:
#d= DataFrame(pandas.read_sql())
logger.debug("editing -- getting datavalues for graph")
Expand All @@ -256,6 +259,7 @@ def createSeriesInfo(self, seriesID, seriesInfo, series):
data = self.memDB.getDataValuesforGraph(seriesID, noDataValue, self.currentStart, self.currentEnd)
logger.debug("Finished plotting -- getting datavalues for graph")


logger.debug("assigning variables...")
seriesInfo.seriesID = seriesID
seriesInfo.series = series
Expand All @@ -266,13 +270,13 @@ def createSeriesInfo(self, seriesID, seriesInfo, series):
seriesInfo.siteName = siteName
seriesInfo.variableName = variableName
seriesInfo.variableUnits = unitsName
seriesInfo.plotTitle = "Site: " + siteName + "\nVarName: " + variableName + "\nQCL: " + series.quality_control_level_code
seriesInfo.axisTitle = variableName + " (" + unitsName + ")"
seriesInfo.plotTitle = "Site: %s \nVarName: %s \nQCL: %s" %(siteName, variableName, series.ProcessingLevelID)
seriesInfo.axisTitle = "%s (%s)"%(variableName, unitsName)
seriesInfo.noDataValue = noDataValue
seriesInfo.dataTable = data

if len(data) > 0:
seriesInfo.yrange = np.max(data['DataValue']) - np.min(data['DataValue'])
seriesInfo.yrange = np.max(data['datavalue']) - np.min(data['datavalue'])
else:
seriesInfo.yrange = 0

Expand All @@ -298,9 +302,9 @@ def getSeriesInfo(self, seriesID):

def buildPlotInfo(self, seriesInfo):
#remove all of the nodatavalues from the pandas table
filteredData = seriesInfo.dataTable[seriesInfo.dataTable["DataValue"] != seriesInfo.noDataValue]
val = filteredData["Month"].map(calcSeason)
filteredData["Season"] = val
filteredData = seriesInfo.dataTable[seriesInfo.dataTable["datavalue"] != seriesInfo.noDataValue]
val = filteredData["month"].map(calcSeason)
filteredData["season"] = val

# construct tasks for the task server
tasks = [("Probability", filteredData),
Expand Down Expand Up @@ -353,12 +357,12 @@ class Statistics(object):
def __init__(self, data):
start_time = timeit.default_timer()

dvs = data["DataValue"]
dvs = data["datavalue"]
count = len(dvs)
if count > 0:

time = timeit.default_timer()
self.NumberofCensoredObservations = len(data[data["CensorCode"] != "nc"])
self.NumberofCensoredObservations = len(data[data["censorcodecv"] != "nc"])
elapsed = timeit.default_timer() - time
logger.debug("censored observations using len: %s" % elapsed)

Expand Down Expand Up @@ -396,13 +400,13 @@ def __init__(self, data, method):
self.intervals = {}
self.method = method

interval_types = ["Overall", "Year", "Month", "Season"]
intervals = ["Overall", "Year", "Month", "Season"]
interval_types = ["overall", "year", "month", "season"]
intervals = ["overall", "year", "month", "season"]

interval_options = zip(interval_types, intervals)
for interval_type, interval in interval_options:
start_time = timeit.default_timer()
if interval_type == "Overall":
if interval_type == "overall":
interval = data
else:
interval = data.groupby(interval_type)
Expand All @@ -421,18 +425,18 @@ def calculateBoxWhiskerData(self, interval, interval_type):

results = self.calculateIntervalsOnGroups(interval)

if interval_type == "Season" or interval_type == "Month":
if interval_type == "season" or interval_type == "month":
func = None
if interval_type == "Season":
if interval_type == "season":
func = numToSeason
elif interval_type == "Month":
elif interval_type == "month":
func = numToMonth

self.intervals[interval_type] = BoxWhiskerPlotInfo(
interval_type, interval_type, [func(x) for x in results["names"]],
[results["median"], results["conflimit"], results["mean"], results["confint"]])

elif interval_type == "Overall":
elif interval_type == "overall":
self.intervals[interval_type] = BoxWhiskerPlotInfo(
interval_type, None, [],
[results["median"], results["conflimit"], results["mean"], results["confint"]])
Expand All @@ -452,7 +456,7 @@ def calculateIntervalsOnGroups(self, interval):

if isinstance(interval, pd.core.groupby.DataFrameGroupBy):
for name, group in interval:
datavalue = group['DataValue']
datavalue = group['datavalue']
group_mean = np.mean(datavalue)
group_median = np.median(datavalue)
group_std = math.sqrt(np.var(datavalue))
Expand All @@ -467,8 +471,8 @@ def calculateIntervalsOnGroups(self, interval):
median.append(group_median)
mean.append(group_mean)
else:
name = "Overall"
datavalue = interval['DataValue']
name = "overall"
datavalue = interval['datavalue']
data_mean = np.mean(datavalue)
data_median = np.median(datavalue)
data_std = math.sqrt(np.var(datavalue))
Expand Down Expand Up @@ -539,7 +543,7 @@ def __init__(self, data):
:param data:
:return:
"""
self.yAxis = data['DataValue']
self.yAxis = data['datavalue']
# Determine rank, sorting values doesn't change outcome while using pandas.
ranks = self.yAxis.rank()
PrbExc = ranks / (len(ranks) + 1) * 100
Expand Down
2 changes: 1 addition & 1 deletion odmtools/gui/mnuRibbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def enableButtons(self, plot, isActive):
self.spnBins.Enabled = False
self.enableDateSelection(True)

##HIstogram
##Histogram
elif plot == 2:
self.PlotsOptions_bar.EnableButton(wxID_RIBBONPLOTTSTYPE, False)
self.PlotsOptions_bar.EnableButton(wxID_RIBBONPLOTTSLEGEND, False)
Expand Down
20 changes: 10 additions & 10 deletions odmtools/gui/plotBoxWhisker.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ def _createPlot(self, oneSeries, rows, cols, index):
ax.scatter([range(1, len(med) + 1)], med, marker='s', c="k", s=10)

# bp = onSeries.dataTable.boxplot(
bp = oneSeries.dataTable[oneSeries.dataTable["DataValue"]<>oneSeries.noDataValue].boxplot(column="DataValue", ax=ax, by=oneSeries.BoxWhisker.currinterval.groupby,
bp = oneSeries.dataTable[oneSeries.dataTable["datavalue"]<>oneSeries.noDataValue].boxplot(column="datavalue", ax=ax, by=oneSeries.BoxWhisker.currinterval.groupby,
rot=35, notch=True, sym="-s", conf_intervals=ci, return_type='dict',
grid=False)

# Set Colors of the Box Whisker plot
try:
plt.setp(bp['DataValue']['whiskers'], color='k', linestyle='-')
plt.setp(bp['DataValue']['medians'], color='k', linestyle='-')
plt.setp(bp['DataValue']['boxes'], color='GREY', linestyle='-')
plt.setp(bp['DataValue']['caps'], color='k')
plt.setp(bp['DataValue']['fliers'], markersize=3.5, color=oneSeries.color)
plt.setp(bp['datavalue']['whiskers'], color='k', linestyle='-')
plt.setp(bp['datavalue']['medians'], color='k', linestyle='-')
plt.setp(bp['datavalue']['boxes'], color='GREY', linestyle='-')
plt.setp(bp['datavalue']['caps'], color='k')
plt.setp(bp['datavalue']['fliers'], markersize=3.5, color=oneSeries.color)
except:
plt.setp(bp['whiskers'], color='k', linestyle='-')
plt.setp(bp['medians'], color='k', linestyle='-')
Expand Down Expand Up @@ -169,22 +169,22 @@ def setColor(self, color):

def monthly(self, str):
# print "monthly"
self.seriesPlotInfo.setBoxInterval("Month")
self.seriesPlotInfo.setBoxInterval("month")
self.updatePlot()

def seasonaly(self, str):
# print"seasonal"
self.seriesPlotInfo.setBoxInterval("Season")
self.seriesPlotInfo.setBoxInterval("season")
self.updatePlot()

def yearly(self, str):
# print "yearly"
self.seriesPlotInfo.setBoxInterval("Year")
self.seriesPlotInfo.setBoxInterval("year")
self.updatePlot()

def overall(self, str):
# print "overall"
self.seriesPlotInfo.setBoxInterval("Overall")
self.seriesPlotInfo.setBoxInterval("overall")
self.updatePlot()


Expand Down
4 changes: 2 additions & 2 deletions odmtools/gui/plotTimeSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def updatePlot(self):
data = oneSeries.dataTable
dates = data.index.astype(datetime.datetime)
#data.plot(ax=curraxis)
curraxis.plot_date(dates, data['DataValue'],
curraxis.plot_date(dates, data['datavalue'],
color=oneSeries.color, fmt=self.format, xdate=True, tz=None, antialiased=True,
label=oneSeries.plotTitle, alpha=self.alpha, picker=5.0, pickradius=5.0,
markersize=4)
Expand Down Expand Up @@ -484,7 +484,7 @@ def updateCursor(self, selectedObject=None, deselectedObject=None):
Activate Cursor. Happens when a plot is selected
"""
if self.seriesPlotInfo:
seriesInfo = self.seriesPlotInfo.getSeries(selectedObject.id)
seriesInfo = self.seriesPlotInfo.getSeries(selectedObject.ResultID)

if seriesInfo:
currentAxis = None
Expand Down
Loading

0 comments on commit ae5aed5

Please sign in to comment.