Skip to content

Commit

Permalink
Clean up properties that don't need to be properties
Browse files Browse the repository at this point in the history
Fixes #63
  • Loading branch information
vr2262 committed Apr 28, 2016
1 parent 0a8c26a commit 7427cea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
34 changes: 12 additions & 22 deletions sequencer/NetworkPlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ def __init__(self, network, metrics, **kwargs):
self.priority_metric = kwargs['prioritize'] if 'prioritize' in kwargs else 'population'
self.proj = kwargs.get('proj', 'utm')

# original_metrics is the unprocessed metrics DataFrame
# FIXME:
# Remove the dependency that sequencer has on the
# original metrics file (this is terrible coupling)
# see sequencer:_clean_results()
self._original_metrics = metrics
self.original_metrics = metrics

self._init_helper(network, metrics)

Expand All @@ -40,9 +41,12 @@ def _init_helper(self, network, metrics):

# Load in and align input data
logger.info('Aligning Network Nodes With Input Metrics')
self._network, self._metrics = prep_data(network,
metrics,
loc_tol = self.TOL)

# network is the DiGraph Object representation of the graph
# metrics is the nodal metrics Pandas DataFrame
self.network, self.metrics = prep_data(network,
metrics,
loc_tol = self.TOL)

self.coord_values = self.coords.values()

Expand All @@ -60,7 +64,7 @@ def _init_helper(self, network, metrics):
self.fake_nodes = self.fakes(self.metrics.index)

#Fillna values with Zero
self._metrics = self.metrics.fillna(0)
self.metrics = self.metrics.fillna(0)


@classmethod
Expand Down Expand Up @@ -206,7 +210,7 @@ def direct_network(self):
"""Decomposes a full graph into its components and directs them away from their roots"""
#print list(self.get_subgraphs())
graphs = [self._depth_first_directed(g) for g in self.get_subgraphs()]
self._network = reduce(lambda a, b: nx.union(a, b), graphs)
self.network = reduce(lambda a, b: nx.union(a, b), graphs)

def downstream(self, n):
"""
Expand Down Expand Up @@ -249,11 +253,11 @@ def get_subgraphs(self):

def get_predecessors(self, n):
"""wrap networkx call"""
return self._network.predecessors(n)
return self.network.predecessors(n)

def get_successors(self, n):
"""wrap networkx call"""
return self._network.successors(n)
return self.network.successors(n)

def network_to_dict(self):
"""returns a dictionary representation of the full graph"""
Expand All @@ -273,21 +277,7 @@ def coords(self):
def adj_matrix(self):
"""returns the matrix representation of the graph"""
return nx.adj_matrix(self.network)

@property
def network(self):
"""returns the DiGraph Object representation of the graph"""
return self._network

@property
def original_metrics(self):
"""returns the original (unprocessed) metrics data_frame"""
return self._original_metrics

@property
def metrics(self):
"""returns the nodal metrics Pandas DataFrame"""
return self._metrics

def download_scenario(scenario_number, directory_name=None, username=None, password=None,
np_url='http://networkplanner.modilabs.org/'):
Expand Down
4 changes: 2 additions & 2 deletions sequencer/Tests/Test_Suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_sequencer_with_fakes():
class TestNetworkPlan(NetworkPlan):

def __init__(self):
self._metrics, self._network = gen_data()
self.metrics, self.network = gen_data()
self.proj = 'wgs4'
self.priority_metric = 'Population'
self.coord_values = self.coords.values()
Expand All @@ -122,7 +122,7 @@ def __init__(self):
self.fake_nodes = [0]

# Fillna with 0
self._metrics = self.metrics.fillna(0)
self.metrics = self.metrics.fillna(0)

class TestSequencer(Sequencer):

Expand Down

0 comments on commit 7427cea

Please sign in to comment.