def load_topology_realisations(path, **args): """ Loads all model topology realisations and returns them as an array of NoddyTopology objects **Arguments**: - *path* = The root directory that models should be loaded from. All models with the same base_name as this class will be loaded (including subdirectoriess) **Optional Arguments**: - *load_attributes* = True if nodes and edges in the topology network should be attributed with properties such as volume and surface area and lithology colour. Default is True. - *verbose* = True if this function should write debug information to the print buffer. Default is True. **Returns**: - a list of NoddyTopology objects """ vb = args.get('verbose', True) attr = args.get('load_attributes', True) if vb: print "Loading models in %s" % path # array of topology objects from pynoddy.output import NoddyTopology topologies = [] for root, dirnames, filenames in os.walk(path): # walk the directory for f in filenames: if '.g23' in f: # find all topology files base = os.path.join(root, f.split('.')[0]) if vb: print 'Loading %s' % base # load & store topology topologies.append(NoddyTopology(base, load_attributes=attr)) return topologies
def test_resolution(self, numTrials, **kwds): '''Tests the sensitivity of a model to block size by generating models of different resolutions and comparing them. **Arguments**: - *numTrials* = the number of different model resolutions to test **Optional Keywords**: - *cleanup* = True if this function should delete any models it creates. Otherwise models of different resolutions are left in the same directory as the .his file they derive from. Default is True. - *verbose* = If true, this function sends information to the print buffer. Otherwise it runs silently. Default is False. **Returns**: - The function returns a list containing the cumulative number of model topologies observed, starting from the highest resolution (smallest block size) to the lowest block size (largest block size) ''' #get args outFile = kwds.get("output", "") cleanup = kwds.get("cleanup", True) verbose = kwds.get("verbose", False) #import pynoddy bindings import pynoddy #store null volume threshold and then set to zero old_threshold = pynoddy.null_volume_threshold pynoddy.null_volume_threshold = 0 #place to keep topologies self.topo_list = [] self.res_list = [] self.nUnique = 0 #number of unique topologies self.count = [] #number of differen topologies observed at each step self.size = [] #number of edges (relationships) observed at each step #run test step = (self.maxSize - self.minSize) / numTrials #step change between resolutions for res in range(self.minSize, self.maxSize, step): if verbose: print(("Computing model with %d block size" % res)) #change cube size self.change_cube_size(res) self.change_cube_size(res) print("Cube size: %d:" % self.get_cube_size()) #store cube size self.res_list.append(res) #save history file basename = self.path + "_cube_size_%d" % res self.write_history(basename + ".his") #run saved history file if verbose: print(("Running resolution %d... " % res)) print((pynoddy.compute_model(basename + ".his", basename + "_0001", sim_type="TOPOLOGY"))) print("Complete.\n") else: pynoddy.compute_model(basename + ".his", basename + "_0001", sim_type="TOPOLOGY") #calculate topology if verbose: print('Computing model topologies...') print((pynoddy.compute_topology(basename))) print('Finished.\n') else: pynoddy.compute_topology(basename, 1) #load and store topology output topo = NoddyTopology(basename + "_0001") #cull small nodes #topo.filter_node_volumes(self.min_node_volume) #see if this is on the list if topo.is_unique(self.topo_list): self.nUnique += 1 #increment unique topologies #store cumulative sequence self.count.append(self.nUnique) #add to list of observed topologies self.topo_list.append(topo) #append number of edges to edges list self.size.append(topo.graph.number_of_edges()) #cleanup if cleanup: import os, glob #remove noddy files for f in glob.glob(basename + "*"): os.remove(f) print("Complete. A total of %d topologies were observed" % self.nUnique) print("The size of the network at each step was:") print(self.size) print("The cumulative observation sequence was:") print(self.count) #restore pynoddy.null_volume_threshold = old_threshold return self.count