p = "data/Letter-low" ds = "Letter-low" z = read_tud(p, ds, False) import Visualization as v G1 = z[0]["1"][0] pos1 = t.get_pos(G1) G2 = z[0]["9"][0] pos2 = t.get_pos(G2) v.cool_GIF(G1, pos1, G2, pos2, frames=720) ######################## Binary ShapeMatcher Models ########################### matrices = [None, None, None, None] # For you to reference later alienDict = read_sm("data/Shape-Matcher-models/ALIEN.xml") t.rename_key(alienDict, oldKey="models/ALIEN/ALIEN", newKey="alien") camelDict = read_sm("data/Shape-Matcher-models/camel.xml") t.rename_key(camelDict, oldKey="models/camel/camel", newKey="camel") eagleDict = read_sm("data/Shape-Matcher-models/eagle.xml") t.rename_key(eagleDict, oldKey="models/eagle/eagle", newKey="eagle") kangaDict = read_sm("data/Shape-Matcher-models/KANGAROO.xml") t.rename_key(kangaDict, oldKey="models/KANGAROO/KANGAROO", newKey="kangaroo") # see data/DataCleaning.py for how we picked outliers biasedAliens = [ 'alien67', 'alien0', 'alien1', 'alien2', 'alien4', 'alien5', 'alien6', 'alien9', 'alien16', 'alien18', 'alien19', 'alien27', 'alien28', 'alien30', 'alien31', 'alien32', 'alien33', 'alien34', 'alien36', 'alien37',
def read_ppm(DBname, ppmDir, ppmList=None, SMD=None): if SMD == None: SMD = '../images/ShapeMatcher' print("Converting", ppmDir, "...") with cd(SMD): # Directory finagling begins with cd(ppmDir): # finagling x 2 OS = p.system() if OS == 'Windows': contents = cmd('dir') elif OS in ['Darwin', 'Linux']: contents = cmd('ls') else: s = sorry.format("Unknown Operating System") print(s) return None if contents.returncode != 0: s = sorry.format("Couldn't read the directory.") print(s) return None # There is a built in ShapeMatcher commands that reads everything in a folder # But I found it to be buggy at times string = str(contents) string = string[string.find(ppmDir) + 1:] fileList = string.split(".ppm") fileList = fileList[:-1] # Need to work backwards from the end of the file name # This is why file names can't have spaces for i in range(len(fileList)): file = None j = -1 while j >= (-1 * len(fileList[i])): if fileList[i][j] == " ": break j -= 1 j += 1 file = fileList[i][j + len(fileList[i]):] file += ".ppm" fileList[i] = file # Now we have a list of all the files in the folder # So we can make a database consisting of all of these files # Start building the sm command for creating a database file createDB = 'sm -doExtSimp 0 -c ' + DBname + '.db' # Now add each of the files for file in fileList: createDB += " " + ppmDir + '/' + file # Make a database of the graphs cmd(createDB) # Convert database to XML file toXML = "sm -toXML " + DBname + ".xml " + DBname + ".db" cmd(toXML) print("----------") g = read_sm(DBname + ".xml") print("\t----------") t.rename_key(g, list(g.keys())[0], DBname) print("\t----------") print("\nConversion complete. Returning NetworkX graph object.") print("\nYour", DBname, "database and XML file should be in ", SMD) return g
""" Created on Tue Jul 7 19:36:23 2020 @author: Candace Todd """ # Script recording our data cleaning methodology # Note: this is an interactive program import DataReader as dr import networkx as nx import lib.Tools as t import matplotlib.pyplot as plt ################## Code for picking out outlier binary images ######################## alienDict = dr.read_sm("data/Shape-Matcher-models/ALIEN.xml") t.rename_key(alienDict, oldKey="models/ALIEN/ALIEN", newKey="alien") childDict = dr.read_sm("data/Shape-Matcher-models/m_chld.xml") t.rename_key(childDict, oldKey="models/m_chld/m_chld", newKey="child") camelDict = dr.read_sm("data/Shape-Matcher-models/camel.xml") t.rename_key(camelDict, oldKey="models/camel/camel", newKey="camel") # 17 is a good camel model horseDict = dr.read_sm("data/Shape-Matcher-models/HORSE.xml") t.rename_key(horseDict, oldKey="models/HORSE/HORSE", newKey="horse") # 52 isa good horse model eagleDict = dr.read_sm("data/Shape-Matcher-models/eagle.xml") t.rename_key(eagleDict, oldKey="models/eagle/eagle", newKey="eagle") # 35 is a good eagle model