Newer
Older
#!/usr/bin/env python
# encoding: utf-8
"""
This module manages creating figures for the Glance GUI.
Created by evas Nov 2011.
Copyright (c) 2011 University of Wisconsin SSEC. All rights reserved.
"""
# these first two lines must stay before the pylab import
import matplotlib
(no author)
committed
#matplotlib.use('Qt4Agg') # use the Qt Anti-Grain Geometry rendering engine
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from pylab import *
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import logging
import numpy as np
import glance.data as dataobjects
import glance.figures as figures
import glance.gui_model as model
LOG = logging.getLogger(__name__)
# the number of bins to use for histograms
DEFAULT_NUM_BINS = 50
class GlanceGUIFigures (object) :
"""
This class handles creating figures for the glance gui.
(in future it may manage them more actively)
it includes:
self.dataModel - the GlanceGUIModel object that contains the main data
model for the GUI
self.errorHandlers - objects that want to be notified when there's a serious error
"""
def __init__ (self, dataModelToSave) :
"""
create a figure manager, hanging on to the data model, for use in creating figures
"""
self.dataModel = dataModelToSave
self.errorHandlers = [ ]
def registerErrorHandler (self, objectToRegister) :
"""
add the given object to our list of error handlers
"""
if objectToRegister not in self.errorHandlers :
self.errorHandlers.append(objectToRegister)
def spawnPlot (self) :
"""
create a matplotlib plot using the current model information
"""
imageType = self.dataModel.getImageType()
LOG.info ("Preparing variable data for plotting...")
# get Variable names
aVarName = self.dataModel.getVariableName("A")
bVarName = self.dataModel.getVariableName("B")
# get Data objects
aDataObject = self.dataModel.getVariableData("A", aVarName)
bDataObject = self.dataModel.getVariableData("B", bVarName)
# TODO, this ignores the fact that the "original" plots don't need two sets of data
message = dataobjects.DiffInfoObject.verifyDataCompatability (aDataObject, bDataObject, aVarName, bVarName)
# if the data isn't valid, stop now
if message is not None :
for errorHandler in self.errorHandlers :
errorHandler.handleWarning(message)
# we can't make any images from this data, so just return
return
# compare our data
diffData = dataobjects.DiffInfoObject(aDataObject, bDataObject, epsilonValue=self.dataModel.getEpsilon())
# get units text for display
aUnitsText = self.dataModel.getUnitsText("A", aVarName)
bUnitsText = self.dataModel.getUnitsText("B", bVarName)
LOG.info("Spawning plot window: " + imageType)
plt.ion() # make sure interactive plotting is on
# create the plot
if imageType == model.ORIGINAL_A :
tempFigure = figures.create_simple_figure(aDataObject.data, aVarName + "\nin File A",
invalidMask=aDataObject.masks.missing_mask, colorMap=cm.jet, units=aUnitsText)
elif imageType == model.ORIGINAL_B :
tempFigure = figures.create_simple_figure(bDataObject.data, bVarName + "\nin File B",
invalidMask=bDataObject.masks.missing_mask, colorMap=cm.jet, units=bUnitsText)
elif imageType == model.ABS_DIFF :
tempFigure = figures.create_simple_figure(np.abs(diffData.diff_data_object.data), "Absolute value of difference\nin " + aVarName,
invalidMask=~diffData.diff_data_object.masks.valid_mask, colorMap=cm.jet, units=aUnitsText)
elif imageType == model.RAW_DIFF :
tempFigure = figures.create_simple_figure(diffData.diff_data_object.data, "Value of (Data File B - Data File A)\nfor " + aVarName,
invalidMask=~diffData.diff_data_object.masks.valid_mask, colorMap=cm.jet, units=aUnitsText)
elif imageType == model.HISTOGRAM :
rawDiffDataClean = diffData.diff_data_object.data[diffData.diff_data_object.masks.valid_mask]
tempFigure = figures.create_histogram(rawDiffDataClean, DEFAULT_NUM_BINS, "Difference in\n" + aVarName,
"Value of (B - A) at each data point", "Number of points with a given difference", units=aUnitsText)
elif imageType == model.MISMATCH :
mismatchMask = diffData.diff_data_object.masks.mismatch_mask
tempFigure = figures.create_simple_figure(aDataObject.data, "Areas of mismatch data\nin " + aVarName,
invalidMask=aDataObject.masks.missing_mask, tagData=mismatchMask,
colorMap=figures.MEDIUM_GRAY_COLOR_MAP, units=aUnitsText)
elif imageType == model.SCATTER :
tempCleanMask = aDataObject.masks.missing_mask | bDataObject.masks.missing_mask
aDataClean = aDataObject.data[~tempCleanMask]
bDataClean = bDataObject.data[~tempCleanMask]
cleanMismatchMask = diffData.diff_data_object.masks.mismatch_mask[~tempCleanMask]
figures.create_scatter_plot(aDataClean, bDataClean, "Value in File A vs Value in File B",
"File A Value in " + aVarName,
"File B Value in " + bVarName,
badMask=cleanMismatchMask, epsilon=self.dataModel.getEpsilon(),
units_x=aUnitsText, units_y=bUnitsText)
elif imageType == model.HEX_PLOT :
tempCleanMask = aDataObject.masks.missing_mask | bDataObject.masks.missing_mask
aDataClean = aDataObject.data[~tempCleanMask]
bDataClean = bDataObject.data[~tempCleanMask]
tempFigure = figures.create_hexbin_plot(aDataClean, bDataClean,
"Value in File A vs Value in File B",
"File A Value in " + aVarName,
"File B Value in " + bVarName,
epsilon=self.dataModel.getEpsilon(),
units_x=aUnitsText, units_y=bUnitsText)
plt.draw()