Skip to content

Commit c8f82f1

Browse files
committed
refactor: remove unused imports and optimize network module by importing networkx locally
1 parent 40220e9 commit c8f82f1

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

pydsm/analysis/dsm2study.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,10 @@
99

1010
# our imports
1111
import pyhecdss
12-
import pydsm
1312
from pydsm.input import parser, network
1413
from pydsm.output import hydroh5
1514
from vtools.functions.filter import godin
1615

17-
# viz imports
18-
import geoviews as gv
19-
import hvplot.pandas
20-
import holoviews as hv
21-
from holoviews import opts
22-
23-
hv.extension("bokeh")
24-
import colorcet as cc
25-
26-
#
27-
import param
28-
import panel as pn
29-
30-
pn.extension()
31-
3216
import logging
3317

3418
logger = logging.getLogger(__name__)

pydsm/analysis/postpro.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,19 @@ def build_processors(dssfile, locationfile, vartype, units, study_name, observed
614614
return processors
615615

616616

617-
def run_processor(processor, store=True, clear=True):
617+
def run_processor(processor, store=True, clear=True, skip_if_cached=False):
618+
if skip_if_cached:
619+
key = processor.cache.get_cache_key(
620+
processor.location.name,
621+
processor.vartype.name,
622+
PostProcessor.TIME_INTERVAL,
623+
)
624+
if key in processor.cache.cache:
625+
logging.info(
626+
"Skipping %s/%s (already cached)"
627+
% (processor.location.name, processor.vartype.name)
628+
)
629+
return
618630
logging.info("Running %s/%s" % (processor.location.name, processor.vartype.name))
619631
processed = False
620632
try:

pydsm/input/network.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Creates a network containing channel and reservoir connections as nodes and channels and reservoirs as arcs.
2-
import networkx as nx
32

43

54
def build_network_channels(tables):
65
'''
76
Builds network with channel upnodes -> downnodes. Stores the columns as attributes of each node
87
'''
8+
import networkx as nx
99
c = tables['CHANNEL']
1010
gc = nx.from_pandas_edgelist(c, source='UPNODE', target='DOWNNODE', edge_attr=list(
1111
c.columns), create_using=nx.MultiDiGraph)
@@ -18,6 +18,7 @@ def build_network_reservoirs(tables):
1818
each resevoir connection, one from reservoir to node and from node to the reservoir.
1919
In this way, each reservoir is treated as a node in the graph
2020
'''
21+
import networkx as nx
2122
rc = tables['RESERVOIR_CONNECTION']
2223
grc1 = nx.from_pandas_edgelist(rc, source='RES_NAME', target='NODE', edge_attr=list(
2324
rc.columns), create_using=nx.MultiDiGraph)
@@ -34,5 +35,6 @@ def build_network(tables):
3435
'''
3536
gc = build_network_channels(tables)
3637
grc = build_network_reservoirs(tables)
38+
import networkx as nx
3739
g = nx.compose(gc, grc)
3840
return g

0 commit comments

Comments
 (0)