示例#1
0
 def __init__(self,path, params=None,n=None, **kwds):
     '''
     Performs a topological uncertainty analysis. If a directory is given, all the history files within
     the directory are loaded and the analyses performed on them. If a history file is given, n perturbations
     are performed on it using the params file.
     
     **Arguments**:
      - *path* = The directory or history file to perform this analysis on.
      
     **Optional Arguments**:
      - *params* = The params file to use for MonteCarlo perturbation (if a history file is provided)
      - *n* = The number of model perturbations to generate (if a history file is provided)
     
     **Optional Keywords**:
      - *verbose* = True if this experiment should write to the print buffer. Default is True
      - *threads* = The number of threads this experiment should utilise. The default is 4.
      - *force* = True if all noddy models should be recalculated. Default is False.
     '''
     #init variables
     self.base_history_path = None
     self.base_path = path #if a history file has been given, this will be changed
     vb = kwds.get("verbose",True)
     n_threads = kwds.get("threads",4)
     force = kwds.get("force",False)
     
     #a history file has been given, generate model stuff
     if '.' in path:
         if not '.his' in path: #foobar
             print "Error: please provide a valid history file (*.his)"
             return
         if params is None or n is None: #need this info
             print "Error: please provide valid arguments [params,n]"
         
         self.base_history_path = path
         self.base_path=path.split('.')[0] #trim file extension
         self.num_trials = n
         
         #ensure path exists
         if not os.path.exists(self.base_path):
             os.makedirs(self.base_path)
         
         #do monte carlo simulations
         MC = MonteCarlo(path,params)
         MC.generate_model_instances(self.base_path,n, sim_type='TOPOLOGY', verbose=vb, threads=n_threads, write_changes=None)
     else:
         #ensure that models have been run
         MonteCarlo.generate_models_from_existing_histories(self.base_path,sim_type='TOPOLOGY',force_recalculate=force,verbose=vb,threads=n_threads)
         
     #load models from base directory
     self.models = TopologyAnalysis.ModelRealisation.loadModels(self.base_path, verbose=vb)
     
     ###########################################
     #GENERATE TOPOLOGY LISTS
     ###########################################
     #declare lists
     self.all_litho_topologies=[]
     self.all_struct_topologies=[]
     
     #generate lists
     for m in self.models:
         self.all_litho_topologies.append(m.topology)
         self.all_struct_topologies.append(m.topology.collapse_stratigraphy())
     
     ############################################
     #FIND UNIQUE TOPOLOGIES
     ############################################
     self.accumulate_litho_topologies = []
     self.accumulate_struct_topologies = []
     
     self.unique_litho_topologies=NoddyTopology.calculate_unique_topologies(self.all_litho_topologies, output=self.accumulate_litho_topologies)
     self.unique_struct_topologies=NoddyTopology.calculate_unique_topologies(self.all_struct_topologies, output=self.accumulate_struct_topologies)
     
     ############################################
     #GENERATE SUPER TOPOLOGY
     ############################################
     self.super_litho_topology = NoddyTopology.combine_topologies(self.all_litho_topologies)
     self.super_struct_topology = NoddyTopology.combine_topologies(self.all_struct_topologies)
示例#2
0
    #generate 100 random perturbations using 4 separate threads (in TOPOLOGY mode)
    output_name = "mc_out"
<<<<<<< HEAD:pynoddy/experiment/MonteCarlo.py
    n = 10
    mc.generate_model_instances(output_name,n,sim_type="TOPOLOGY",threads=4)
=======
    n = 4
    print(mc.generate_model_instances(output_name,n,threads=4))
>>>>>>> refs/remotes/flohorovicic/master:pynoddy/experiment/monte_carlo_bak.py
    
    #load output
    topologies = MonteCarlo.load_topology_realisations(output_name, verbose=True)
    
    #calculate unique topologies
    from pynoddy.output import NoddyTopology
    uTopo = NoddyTopology.calculate_unique_topologies(topologies,output="accumulate.csv")
    print "%d unique topologies found in %d simulations" % (len(uTopo),len(topologies))
    
    #cleanup
    #mc.cleanup()
    
#    ###################################################
#    #run existing .his files example (in TOPOLOGY mode)
#    ###################################################
#    
#    #setup working environment
#    os.chdir(r'C:\Users\Sam\SkyDrive\Documents\Masters\Models\Primitive\monte carlo test')
#    path = 'multi_his_test'
#    basename='GBasin123_random_draw'
#    
#    #run noddy in 'TOPOLOGY' mode (multithreaded)