From 479eee876111b2ef1e0ace14e9049d6abedcbe5f Mon Sep 17 00:00:00 2001 From: dpinney Date: Fri, 8 Dec 2023 21:01:22 -0500 Subject: [PATCH] removing extraneous matplotlib backend selections --- omf/cymeToGridlab.py | 10 +--------- omf/feeder.py | 4 ---- omf/loadModelingScada.py | 4 ---- omf/models/cvrDynamic.py | 9 +-------- omf/models/cvrStatic.py | 4 ---- omf/models/derInterconnection.py | 12 +----------- omf/models/evInterconnection.py | 4 ---- omf/models/faultAnalysis.py | 10 +--------- omf/models/flisr.py | 17 ++--------------- omf/models/networkStructure.py | 13 +------------ omf/models/phaseId.py | 9 +-------- omf/models/resilientDist.py | 11 ++--------- omf/models/smartSwitching.py | 5 ----- omf/models/solarConsumer.py | 10 +--------- omf/models/solarEngineering.py | 5 ----- omf/models/transmission.py | 8 +------- omf/models/voltageDrop.py | 9 +-------- omf/runOmf.command | 2 +- 18 files changed, 14 insertions(+), 132 deletions(-) diff --git a/omf/cymeToGridlab.py b/omf/cymeToGridlab.py index 8855828cf..691fe82ba 100644 --- a/omf/cymeToGridlab.py +++ b/omf/cymeToGridlab.py @@ -18,18 +18,9 @@ from os.path import join as pJoin import numpy as np from numpy.linalg import inv - -import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') -from matplotlib import pyplot as plt - from omf import feeder from omf.solvers import gridlabd - m2ft = 1.0 / 0.3048 # Conversion factor for meters to feet @@ -3466,6 +3457,7 @@ def _tests(keepFiles=True): # Draw the GLM. myGraph = feeder.treeToNxGraph(cyme_base) feeder.latLonNxGraph(myGraph, neatoLayout=False) + from matplotlib import pyplot as plt plt.savefig(outputDir + testFilename + ".png") with open(pJoin(outputDir, "convResults.txt"), "a") as resultsFile: resultsFile.write("DREW GLM FOR " + testFilename + "\n") diff --git a/omf/feeder.py b/omf/feeder.py index 63dfd67a1..30112a49e 100644 --- a/omf/feeder.py +++ b/omf/feeder.py @@ -5,10 +5,6 @@ import networkx as nx from omf.solvers.opendss import dssConvert import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt # Wireframe for new OMD objects: diff --git a/omf/loadModelingScada.py b/omf/loadModelingScada.py index e8dde1b74..1c30c6d90 100644 --- a/omf/loadModelingScada.py +++ b/omf/loadModelingScada.py @@ -3,10 +3,6 @@ from os.path import join as pJoin import numpy as np import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt from omf import feeder from omf.solvers import gridlabd diff --git a/omf/models/cvrDynamic.py b/omf/models/cvrDynamic.py index c242a952c..6afb042ab 100644 --- a/omf/models/cvrDynamic.py +++ b/omf/models/cvrDynamic.py @@ -1,16 +1,9 @@ ''' Calculate CVR impacts using a targetted set of dynamic loadflows. ''' -import json, os, shutil, math, calendar, platform +import json, os, shutil, math, calendar from datetime import datetime as dt, timedelta from os.path import join as pJoin - -import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt - # OMF feeder from omf import feeder from omf.solvers import gridlabd diff --git a/omf/models/cvrStatic.py b/omf/models/cvrStatic.py index 937fe95f2..40ee4f843 100644 --- a/omf/models/cvrStatic.py +++ b/omf/models/cvrStatic.py @@ -5,10 +5,6 @@ from os.path import join as pJoin import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt # OMF imports diff --git a/omf/models/derInterconnection.py b/omf/models/derInterconnection.py index 9b510bb86..fec009816 100644 --- a/omf/models/derInterconnection.py +++ b/omf/models/derInterconnection.py @@ -1,21 +1,11 @@ ''' perform analysis pertaining to the addition of a DER interconnection on a feeder. ''' -import glob, json, os, tempfile, shutil, csv, math, warnings, random, copy, base64, platform +import glob, json, os, tempfile, shutil, csv, math, random, copy, base64 from os.path import join as pJoin import networkx as nx - -# Hack: Agg backend doesn't work for interactivity. Switch to something we can use: import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt - -# dateutil imports from dateutil import parser from dateutil.relativedelta import * - -# OMF imports from omf import feeder from omf.solvers import gridlabd from omf.models import __neoMetaModel__ diff --git a/omf/models/evInterconnection.py b/omf/models/evInterconnection.py index 1fc99f1e5..ec09a1500 100644 --- a/omf/models/evInterconnection.py +++ b/omf/models/evInterconnection.py @@ -6,10 +6,6 @@ import numpy as np import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt #plt.style.use('seaborn') diff --git a/omf/models/faultAnalysis.py b/omf/models/faultAnalysis.py index e4ced4f59..c95456bcb 100644 --- a/omf/models/faultAnalysis.py +++ b/omf/models/faultAnalysis.py @@ -1,17 +1,9 @@ ''' Determine impacts of distribution faults. ''' -import json, os, shutil, csv, warnings, base64, platform +import json, os, shutil, csv, base64 from os.path import join as pJoin -import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') -from matplotlib import pyplot as plt - # dateutil imports -from dateutil import parser from dateutil.relativedelta import * # OMF imports diff --git a/omf/models/flisr.py b/omf/models/flisr.py index ea7e4a9b3..cfd250966 100644 --- a/omf/models/flisr.py +++ b/omf/models/flisr.py @@ -1,23 +1,10 @@ ''' Calculate FLISR, fault location isolation and restoration. ''' -import random, re, datetime, json, os, tempfile, shutil, csv, math, platform, base64 +import re, json, os, tempfile, shutil from os.path import join as pJoin import pandas as pd -import numpy as np -import scipy -from scipy import spatial -import scipy.stats as st -from sklearn.preprocessing import LabelEncoder -import plotly as py -import plotly.graph_objs as go -import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') -from matplotlib import pyplot as plt import networkx as nx # OMF imports -from omf import feeder, geo, distNetViz +from omf import feeder, geo import omf import omf.feeder import omf.geo diff --git a/omf/models/networkStructure.py b/omf/models/networkStructure.py index 2965a69c2..7ff928f30 100644 --- a/omf/models/networkStructure.py +++ b/omf/models/networkStructure.py @@ -1,24 +1,13 @@ ''' Reconstruct distribution network structure from meter data. ''' -import json, os, tempfile, shutil, csv, math, re, base64, platform +import json, os, tempfile, shutil, csv, math, re, base64 from os.path import join as pJoin import pandas as pd import networkx as nx from sklearn import svm from sklearn import metrics from numpy import array - -import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt - -# dateutil imports -from dateutil import parser from dateutil.relativedelta import * - -# OMF imports import omf from omf import feeder, geo from omf.models import __neoMetaModel__ diff --git a/omf/models/phaseId.py b/omf/models/phaseId.py index 42ae0004a..99437dad2 100644 --- a/omf/models/phaseId.py +++ b/omf/models/phaseId.py @@ -1,5 +1,5 @@ ''' Identify phasing from meter data.''' -import json, datetime, csv, os, shutil, re, warnings, itertools, base64, platform +import datetime, csv, os, shutil, re, itertools, base64, platform from os.path import join as pJoin from base64 import b64decode from zipfile import ZipFile @@ -11,14 +11,7 @@ from scipy.stats import linregress from sklearn import preprocessing from sklearn.metrics import confusion_matrix - -import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt - from omf.models import __neoMetaModel__ from omf.models.__neoMetaModel__ import * from omf.solvers import sandia_ami_phase_id diff --git a/omf/models/resilientDist.py b/omf/models/resilientDist.py index 70d0471cd..312f52575 100644 --- a/omf/models/resilientDist.py +++ b/omf/models/resilientDist.py @@ -1,19 +1,12 @@ ''' Run micot-GFM, micot-RDT, and GridLAB-D to determine an optimal distribution resiliency investment. ''' -import json, os, shutil, subprocess, datetime, re, random, copy, warnings, base64, platform +import json, os, shutil, subprocess, datetime, random, copy, base64, platform import os.path from os.path import join as pJoin import numpy as np import networkx as nx - import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt - -# OMF imports import omf from omf import feeder, weather, distNetViz from omf.models import __neoMetaModel__ @@ -128,7 +121,7 @@ def changeCellSize(self, cellSize): self.hazardObj["cellsize"] = cellSize def mapValue(self, value, fromMin, fromMax, toMin=.7, toMax=1): - newValue = float(value - fromMind) / float(fromMax-fromMin) + newValue = float(value - fromMin) / float(fromMax-fromMin) return toMin + (newValue * (toMax-toMin)) def mapRanges(self, values, fromMin, fromMax): diff --git a/omf/models/smartSwitching.py b/omf/models/smartSwitching.py index 8afb1a719..fa590382a 100644 --- a/omf/models/smartSwitching.py +++ b/omf/models/smartSwitching.py @@ -8,12 +8,7 @@ import plotly.graph_objs as go from plotly.tools import make_subplots import networkx as nx - import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt # dateutil imports diff --git a/omf/models/solarConsumer.py b/omf/models/solarConsumer.py index e7ea55b1b..62e2d7083 100644 --- a/omf/models/solarConsumer.py +++ b/omf/models/solarConsumer.py @@ -1,16 +1,8 @@ ''' Calculate solar costs and benefits for consumers. ''' -import shutil, datetime, platform +import shutil, datetime from os.path import join as pJoin - -import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt - -# OMF imports from omf import weather from omf.solvers import nrelsam2013 from omf.models import __neoMetaModel__ diff --git a/omf/models/solarEngineering.py b/omf/models/solarEngineering.py index 87b0871f0..2cc1fa480 100644 --- a/omf/models/solarEngineering.py +++ b/omf/models/solarEngineering.py @@ -9,11 +9,6 @@ from matplotlib import pyplot as plt from matplotlib import animation from matplotlib.animation import FuncAnimation -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') - # plt.rcParams['animation.ffmpeg_path'] = '/usr/local/bin/ffmpeg' -else: - matplotlib.use('Agg') from omf import feeder, weather from omf.solvers import gridlabd from omf.models import __neoMetaModel__ diff --git a/omf/models/transmission.py b/omf/models/transmission.py index ce6c79830..ad33c5813 100644 --- a/omf/models/transmission.py +++ b/omf/models/transmission.py @@ -3,18 +3,12 @@ Tested on Linux and macOS. ''' -import json, os, shutil, subprocess, math, platform, base64 +import json, os, shutil, platform, base64 from os.path import join as pJoin - import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt import matplotlib.cm as cm import pandapower as ppow - from omf import transmission as network from omf.models import __neoMetaModel__ from omf.models.__neoMetaModel__ import * diff --git a/omf/models/voltageDrop.py b/omf/models/voltageDrop.py index 59a3c5586..912304209 100644 --- a/omf/models/voltageDrop.py +++ b/omf/models/voltageDrop.py @@ -1,19 +1,12 @@ ''' Graph the voltage drop on a feeder. ''' -import json, os, tempfile, shutil, csv, math, warnings, base64, platform +import json, os, tempfile, shutil, csv, math, base64 from os.path import join as pJoin import networkx as nx - import matplotlib -if platform.system() == 'Darwin': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') from matplotlib import pyplot as plt - # dateutil imports from dateutil import parser from dateutil.relativedelta import * - # OMF imports import omf from omf import feeder diff --git a/omf/runOmf.command b/omf/runOmf.command index 5ef434013..536cb87e3 100644 --- a/omf/runOmf.command +++ b/omf/runOmf.command @@ -2,5 +2,5 @@ # Command to start up the OMF web server locally. Works on Unix, macOS. script_dir=$(dirname "$0") cd "$script_dir" -python web.py +python3 web.py read -n1 -r -p "Server stopped. Press space to continue..." key \ No newline at end of file