def precomputeLISA(self): """ """ n = len(self.data_sel_keys) progress_dlg = wx.ProgressDialog( "Progress", "Pre-computing LISAs with 499 permutations... ", maximum=n, parent=self, style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE) progress_dlg.CenterOnScreen() moran_locals = [] try: # C++ DLL call from stars.core.LISAWrapper import call_lisa for i, data in enumerate(self.data_sel_values): progress_dlg.Update(i + 1) localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa( data, str(self.weight_file), 499) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] moran_locals.append(ml) except: # old for pysal for i, data in enumerate(self.data_sel_values): progress_dlg.Update(i + 1) localMoran = pysal.Moran_Local(data, self.weight, transformation="r", permutations=499) ml = [localMoran.Is, localMoran.p_sim, [], localMoran.q] moran_locals.append(ml) progress_dlg.Destroy() return moran_locals
def precomputeLISA(self): """ """ n = len(self.data_sel_keys) progress_dlg = wx.ProgressDialog( "Progress", "Pre-computing LISAs with 499 permutations... ", maximum = n, parent=self, style = wx.PD_APP_MODAL|wx.PD_AUTO_HIDE ) progress_dlg.CenterOnScreen() moran_locals = [] try: # C++ DLL call from stars.core.LISAWrapper import call_lisa for i,data in enumerate(self.data_sel_values): progress_dlg.Update(i+1) localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa( data, str(self.weight_file), 499) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] moran_locals.append(ml) except: # old for pysal for i,data in enumerate(self.data_sel_values): progress_dlg.Update(i+1) localMoran = pysal.Moran_Local(data, self.weight, transformation = "r", permutations = 499) ml = [localMoran.Is, localMoran.p_sim, [], localMoran.q] moran_locals.append(ml) progress_dlg.Destroy() return moran_locals
def process_LISA(parent, data, weight_path): """ """ progress_dlg = wx.ProgressDialog( "Progress", "Computing LISA with 499 permutations... ", maximum=2, parent=parent, style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE) progress_dlg.CenterOnScreen() progress_dlg.Update(1) id_groups = [[] for i in range(6)] try: # call Geoda LISA DLL first from stars.core.LISAWrapper import call_lisa localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa( data, str(weight_path), 499) # prepare drawing map # 0 not significant, 1 HH, 2 LL, 3 LH, 4 HL, 5 Neighborless lm_moran = np.array(localMoran) lm_p_sim = np.array(sigLocalMoran) lm_sig = np.array(sigFlag) lm_q = np.array(clusterFlag) for i, sig in enumerate(lm_sig): if sig > 0: id_groups[lm_q[i]].append(i) else: id_groups[0].append(i) except: # if DLL call is failed, try pysal LISA instead w = pysal.open(weight_path).read() lm = pysal.Moran_Local(data, w, transformation="r", permutations=499) for i, sig in enumerate(lm.p_sim): if sig < parent.siglevel: id_groups[lm.q[i]].append(i) else: id_groups[0].append(i) progress_dlg.Update(2) progress_dlg.Destroy() return id_groups
def process_LISA(parent, data,weight_path): """ """ progress_dlg = wx.ProgressDialog( "Progress", "Computing LISA with 499 permutations... ", maximum = 2, parent=parent, style = wx.PD_APP_MODAL|wx.PD_AUTO_HIDE ) progress_dlg.CenterOnScreen() progress_dlg.Update(1) id_groups = [[] for i in range(6)] try: # call Geoda LISA DLL first from stars.core.LISAWrapper import call_lisa localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa(data, str(weight_path), 499) # prepare drawing map # 0 not significant, 1 HH, 2 LL, 3 LH, 4 HL, 5 Neighborless lm_moran = np.array(localMoran) lm_p_sim = np.array(sigLocalMoran) lm_sig = np.array(sigFlag) lm_q = np.array(clusterFlag) for i,sig in enumerate(lm_sig): if sig > 0: id_groups[lm_q[i]].append(i) else: id_groups[0].append(i) except: # if DLL call is failed, try pysal LISA instead w = pysal.open(weight_path).read() lm = pysal.Moran_Local(data, w, transformation = "r", permutations = 499) for i, sig in enumerate(lm.p_sim): if sig < parent.siglevel: id_groups[lm.q[i]].append(i) else: id_groups[0].append(i) progress_dlg.Update(2) progress_dlg.Destroy() return id_groups
def processLISAMaps(self): """ Create LISA maps for each interval data """ try: # precomputing LISA maps n = len(self.data_sel_keys) progress_dlg = wx.ProgressDialog( "Progress", "Computing LISA with 499 permutations... ", maximum = n, parent=self, style = wx.PD_APP_MODAL|wx.PD_AUTO_HIDE ) progress_dlg.CenterOnScreen() from stars.core.LISAWrapper import call_lisa self.moran_locals = [] for i, data in enumerate(self.data_sel_values): progress_dlg.Update(i+1) localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa( data, str(self.weight_file), 499 ) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] self.moran_locals.append(ml) progress_dlg.Destroy() # default color schema for LISA color_group =[ stars.LISA_NOT_SIG_COLOR, stars.LISA_HH_COLOR, stars.LISA_LL_COLOR, stars.LISA_LH_COLOR, stars.LISA_HL_COLOR, stars.LISA_OBSOLETE_COLOR] self.lisa_color_group = color_group label_group = ["Not Significant","High-High","Low-Low","Low-High","High-Low","Neighborless"] self.color_schema_dict[self.layer.name] = ColorSchema(self.lisa_color_group,label_group) except: raise Exception("Compute LISA error. Please check weight file.")
def processLISAMaps(self): """ Create LISA maps for each interval data """ try: # precomputing LISA maps n = len(self.data_sel_keys) progress_dlg = wx.ProgressDialog( "Progress", "Computing LISA with 499 permutations... ", maximum=n, parent=self, style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE) progress_dlg.CenterOnScreen() from stars.core.LISAWrapper import call_lisa self.moran_locals = [] for i, data in enumerate(self.data_sel_values): progress_dlg.Update(i + 1) localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa( data, str(self.weight_file), 499) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] self.moran_locals.append(ml) progress_dlg.Destroy() # default color schema for LISA color_group = [ stars.LISA_NOT_SIG_COLOR, stars.LISA_HH_COLOR, stars.LISA_LL_COLOR, stars.LISA_LH_COLOR, stars.LISA_HL_COLOR, stars.LISA_OBSOLETE_COLOR ] self.lisa_color_group = color_group label_group = [ "Not Significant", "High-High", "Low-Low", "Low-High", "High-Low", "Neighborless" ] self.color_schema_dict[self.layer.name] = ColorSchema( self.lisa_color_group, label_group) except: raise Exception("Compute LISA error. Please check weight file.")
def __init__(self,parent, layer, data, **kwargs): PlottingCanvas.__init__(self,parent,data) try: #self.weight_file = kwargs["weight"] self.cs_data_dict = kwargs["query_data"] self.step, self.step_by = kwargs["step"] ,kwargs["step_by"] self.start_date, self.end_date = kwargs["start"],kwargs["end"] self.lbls = kwargs['lbls'] self.layer = layer self.data_sel_keys = sorted(self.cs_data_dict.keys()) self.data_sel_values = [self.cs_data_dict[i] for i in self.data_sel_keys] #self.weight = pysal.open(self.weight_file).read() self.t = len(self.cs_data_dict) # number of data slices self.n = len(self.data_sel_values[0]) # number of shape objects self.datetime_intervals, self.interval_labels = GetDateTimeIntervals(self.start_date, self.end_date,self.t, self.step, self.step_by) from stars.core.LISAWrapper import call_lisa from stars.visualization.dialogs import TimeWeightsDlg # promote for time weights tw_dlg = TimeWeightsDlg(self.main, self.t, self.layer.name) tw_path = tw_dlg.Show() if tw_path == False: raise Exception("no time weights") timeWeights = pysal.open(tw_path).read() self.timeNeighbors = timeWeights.neighbors # time LISA self.tseries_data = {} for pid in range(self.n): tseries = [] for tid in range(self.t): tseries.append(self.cs_data_dict[tid][pid]) self.tseries_data[pid] = tseries self.time_moran_locals = {} for pid in range(self.n): tseries = self.tseries_data[pid] localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa(tseries,str(tw_path),499) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] self.time_moran_locals[pid] = ml data = [self.tseries_data,self.time_moran_locals, self.timeNeighbors,[]] self.data = data[0] self.localMorans = data[1] self.timeNeighbors = data[2] self.highlight_ids = data[3] self.margin_right = 50 self.margin_left = 100 self.margin_bottom = 140 self.enable_axis = False self.enable_axis_x = False self.enable_axis_y = False self.selected_path_ids = [] self.line_marker = [] self.selected_line = None self.layer_name = layer.name self.layer = layer self.n = len(self.data) self.title = "LISA Trend Graph: %s[%s]" % (self.layer_name,len(self.timeNeighbors)) self.parentFrame.SetTitle = self.title self.x_label = "" self.y_label = "Number of observations" self.font_size_title = 8 if os.name == "posix": self.font_size_title= 10 self.font_size_x_axis = 8 self.font_size_y_axis = 8 self.font_size_xy_label = 8 if os.name == "posix": self.font_size_xy_label = 10 all_values = self.data.values() self.x_min = 1 self.x_max = len(all_values[0]) self.x_max = self.x_max if self.x_max > self.x_min else self.x_max*1.5 all_values = np.array(all_values) self.y_min = np.min(all_values) self.y_min = self.y_min if self.y_min > 0 else 0 self.y_max = np.max(all_values) self.local_paths = [] self.extent = (self.x_min, self.y_min, self.x_max,self.y_max) self.status_bar = self.parentFrame.status_bar except Exception as err: self.ShowMsgBox("""LISA trend graph could not be created. Please check the time weights file. Details: """+str(err.message)) self.isValidPlot = False self.parentFrame.Close(True) return None # linking-brushing events self.Register(stars.EVT_OBJS_SELECT, self.OnPathsSelected) self.Register(stars.EVT_OBJS_UNSELECT, self.OnNoPathSelect)
def __init__(self, parent, layer, data, **kwargs): PlottingCanvas.__init__(self, parent, data) try: #self.weight_file = kwargs["weight"] self.cs_data_dict = kwargs["query_data"] self.step, self.step_by = kwargs["step"], kwargs["step_by"] self.start_date, self.end_date = kwargs["start"], kwargs["end"] self.layer = layer self.data_sel_keys = sorted(self.cs_data_dict.keys()) self.data_sel_values = [ self.cs_data_dict[i] for i in self.data_sel_keys ] #self.weight = pysal.open(self.weight_file).read() self.t = len(self.cs_data_dict) # number of data slices self.n = len(self.data_sel_values[0]) # number of shape objects self.datetime_intervals, self.interval_labels = GetDateTimeIntervals( self.start_date, self.end_date, self.t, self.step, self.step_by) from stars.core.LISAWrapper import call_lisa from stars.visualization.dialogs import TimeWeightsDlg # promote for time weights tw_dlg = TimeWeightsDlg(self.main, self.t, self.layer.name) tw_path = tw_dlg.Show() if tw_path == False: raise Exception("no time weights") timeWeights = pysal.open(tw_path).read() self.timeNeighbors = timeWeights.neighbors # time LISA self.tseries_data = {} for pid in range(self.n): tseries = [] for tid in range(self.t): tseries.append(self.cs_data_dict[tid][pid]) self.tseries_data[pid] = tseries self.time_moran_locals = {} for pid in range(self.n): tseries = self.tseries_data[pid] localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa( tseries, str(tw_path), 499) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] self.time_moran_locals[pid] = ml data = [ self.tseries_data, self.time_moran_locals, self.timeNeighbors, [] ] self.data = data[0] self.localMorans = data[1] self.timeNeighbors = data[2] self.highlight_ids = data[3] self.margin_right = 50 self.margin_left = 100 self.margin_bottom = 140 self.enable_axis = False self.enable_axis_x = False self.enable_axis_y = False self.selected_path_ids = [] self.line_marker = [] self.selected_line = None self.layer_name = layer.name self.layer = layer self.n = len(self.data) self.title = "LISA Trend Graph: %s[%s] %s" % ( self.layer_name, len(self.timeNeighbors), kwargs["title"]) self.parentFrame.SetTitle = self.title self.x_label = "" self.y_label = "Number of observations" self.font_size_title = 8 if os.name == "posix": self.font_size_title = 10 self.font_size_x_axis = 8 self.font_size_y_axis = 8 self.font_size_xy_label = 8 if os.name == "posix": self.font_size_xy_label = 10 all_values = self.data.values() self.x_min = 1 self.x_max = len(all_values[0]) self.x_max = self.x_max if self.x_max > self.x_min else self.x_max * 1.5 all_values = np.array(all_values) self.y_min = np.min(all_values) self.y_min = self.y_min if self.y_min > 0 else 0 self.y_max = np.max(all_values) self.local_paths = [] self.extent = (self.x_min, self.y_min, self.x_max, self.y_max) self.status_bar = self.parentFrame.status_bar except Exception as err: self.ShowMsgBox( """LISA trend graph could not be created. Please check the time weights file. Details: """ + str(err.message)) self.isValidPlot = False self.parentFrame.Close(True) return None # linking-brushing events self.Register(stars.EVT_OBJS_SELECT, self.OnPathsSelected) self.Register(stars.EVT_OBJS_UNSELECT, self.OnNoPathSelect)
def processLISASpaceTimeMap(self): from stars.core.LISAWrapper import call_lisa # promote for time weights tw_dlg = TimeWeightsDlg(self.main, self.t, self.layer.name) tw_path = tw_dlg.Show() if tw_path == False: raise Exception("no time weights") timeWeights = pysal.open(tw_path).read() self.timeNeighbors = timeWeights.neighbors # time LISA self.tseries_data = {} for pid in range(self.n): tseries = [] for tid in range(self.t): tseries.append(self.cs_data_dict[tid][pid]) self.tseries_data[pid] = tseries self.time_moran_locals = {} for pid in range(self.n): tseries = self.tseries_data[pid] localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa( tseries, str(tw_path), 499) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] self.time_moran_locals[pid] = ml # show LISA trend graph trendgraphWidget = PlotWidget( self, self.layer, [ self.tseries_data, self.time_moran_locals, self.timeNeighbors, [] ], LISATrendGraph, pos=(self.parentFrame.Position[0] + self.parentFrame.Size[0], self.parentFrame.Position[1]), title="Trend Graph Plot for Time LISA (%s): %s" % (self.t, self.layer.name)) trendgraphWidget.Show() self.trendgraphWidget = trendgraphWidget # space LISA self.space_moran_locals = dict() for tid, data in self.cs_data_dict.iteritems(): localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa( data, str(self.weight_file), 499) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] self.space_moran_locals[tid] = ml # default color schema for LISA self.lisa_color_group = [ stars.LISA_NOT_SIG_COLOR, stars.LISA_HH_COLOR, stars.LISA_LL_COLOR, stars.LISA_LH_COLOR, stars.LISA_HL_COLOR, stars.LISA_OBSOLETE_COLOR ] label_group = [ "Not Significant", "High-High", "Low-Low", "Low-High", "High-Low", "Neighborless" ] self.color_schema_dict[self.layer.name] = ColorSchema( self.lisa_color_group, label_group) self.internalLISA = False # inital drawing markov lisa map self.updateDraw(0) # Thread-based controller for dynamic LISA self.dynamic_control = DynamicMapControl(self.parentFrame, self.t, self.updateDraw)
def processLISASpaceTimeMap(self): from stars.core.LISAWrapper import call_lisa # promote for time weights tw_dlg = TimeWeightsDlg(self.main, self.t, self.layer.name) tw_path = tw_dlg.Show() if tw_path == False: raise Exception("no time weights") timeWeights = pysal.open(tw_path).read() self.timeNeighbors = timeWeights.neighbors # time LISA self.tseries_data = {} for pid in range(self.n): tseries = [] for tid in range(self.t): tseries.append(self.cs_data_dict[tid][pid]) self.tseries_data[pid] = tseries self.time_moran_locals = {} for pid in range(self.n): tseries = self.tseries_data[pid] localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa(tseries,str(tw_path),499) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] self.time_moran_locals[pid] = ml # show LISA trend graph trendgraphWidget = PlotWidget( self, self.layer, [self.tseries_data,self.time_moran_locals, self.timeNeighbors,[]], LISATrendGraph, pos = (self.parentFrame.Position[0] + self.parentFrame.Size[0], self.parentFrame.Position[1]), title="Trend Graph Plot for Time LISA (%s): %s"%(self.t, self.layer.name) ) trendgraphWidget.Show() self.trendgraphWidget = trendgraphWidget # space LISA self.space_moran_locals = dict() for tid,data in self.cs_data_dict.iteritems(): localMoran, sigLocalMoran, sigFlag, clusterFlag = call_lisa(data,str(self.weight_file),499) ml = [localMoran, sigLocalMoran, sigFlag, clusterFlag] self.space_moran_locals[tid] = ml # default color schema for LISA self.lisa_color_group =[ stars.LISA_NOT_SIG_COLOR, stars.LISA_HH_COLOR, stars.LISA_LL_COLOR, stars.LISA_LH_COLOR, stars.LISA_HL_COLOR, stars.LISA_OBSOLETE_COLOR ] label_group = ["Not Significant","High-High","Low-Low","Low-High","High-Low","Neighborless"] self.color_schema_dict[self.layer.name] = ColorSchema(self.lisa_color_group,label_group) self.internalLISA = False # inital drawing markov lisa map self.updateDraw(0) # Thread-based controller for dynamic LISA self.dynamic_control = DynamicMapControl(self.parentFrame,self.t,self.updateDraw)