Exemplo n.º 1
0
    def OnBake(self, event=None):
        out_dir = self.dcOutput.GetPath()

        if self.cbSpawnWorkerProcs.GetValue():
            num_procs = batchProcess.NUM_PROCS
        else:
            num_procs = 1
        
        #validate our choices:
        if (self.rm.activeRecipe is None) or (len(self.rm.activeRecipe.modules) == 0):
            wx.MessageBox('No Recipe: Please open (or build) a recipe', 'Error', wx.OK|wx.ICON_ERROR)
            return
            
        inputs = [l.filenames for l in self._file_lists]
        
        if not len(inputs[0]) > 0:
            wx.MessageBox('No input files', 'Error', wx.OK|wx.ICON_ERROR)
            return
            
        if (out_dir == '') or not os.path.exists(out_dir):
            wx.MessageBox('Ouput directory does not exist', 'Error', wx.OK|wx.ICON_ERROR)
            return

        
        #old_style_output = any([('output' in m.outputs) for m in self.rm.activeRecipe.modules])
            
        if not any([isinstance(m, modules.base.OutputModule) for m in self.rm.activeRecipe.modules]):
            # no output module defined
    
            # if old_style_output:
            #     #old style output, warn and give option to continue
            #     if not wx.MessageBox(
            #         "Relying on old-style magic 'output' variable, consider using output modules instead. Continue?",
            #         'Warning', wx.OK|wx.CANCEL|wx.ICON_WARNING) == wx.OK:
            #         return
            # else:
                
            wx.MessageBox('No outputs defined - add an output module', 'Error', wx.OK | wx.ICON_ERROR)
            return
        
        # elif old_style_output:
        #     wx.MessageBox("Both new and old style outputs defined, choose another name for the 'output' variable", 'Error', wx.OK | wx.ICON_ERROR)
        #     return
        
        if (len(inputs[1]) > 0) and not (len(inputs[0]) == len(inputs[1])):
            wx.MessageBox('Length of input file lists not equal', 'Error', wx.OK | wx.ICON_ERROR)
            return
        
        from PYME.ui import progress
        
        try:
            with progress.ComputationInProgress(self, 'Batch Analysis'):
                if not len(inputs[1]) > 0:
                    batchProcess.bake(self.rm.activeRecipe, {'input':inputs[0]}, out_dir, num_procs=num_procs, metadata_defaults=self._default_md)
                else:
                    batchProcess.bake(self.rm.activeRecipe, {'input':inputs[0], 'input2':inputs[1]}, out_dir, num_procs=num_procs, metadata_defaults=self._default_md)
        except:
            if (num_procs > 1):
                wx.MessageBox('Uncheck "spawn worker process for each core" for easier debugging', 'Error occurred during multiple process run', wx.OK | wx.ICON_ERROR)
            raise
Exemplo n.º 2
0
    def OnBake(self, event=None):
        out_dir = self.dcOutput.GetPath()

        if self.cbSpawnWorkerProcs.GetValue():
            num_procs = batchProcess.NUM_PROCS
        else:
            num_procs = 1

        #validate our choices:
        if (self.rm.activeRecipe is None) or (len(self.rm.activeRecipe.modules)
                                              == 0):
            wx.MessageBox('No Recipe: Please open (or build) a recipe',
                          'Error', wx.OK | wx.ICON_ERROR)
            return

        if not len(self.inputFiles) > 0:
            wx.MessageBox('No input files', 'Error', wx.OK | wx.ICON_ERROR)
            return

        if (out_dir == '') or not os.path.exists(out_dir):
            wx.MessageBox('Ouput directory does not exist', 'Error',
                          wx.OK | wx.ICON_ERROR)
            return

        if not len(self.inputFiles) == len(self.inputFiles2):
            batchProcess.bake(self.rm.activeRecipe, {'input': self.inputFiles},
                              out_dir,
                              num_procs=num_procs)
        else:
            batchProcess.bake(self.rm.activeRecipe, {
                'input': self.inputFiles,
                'input2': self.inputFiles2
            },
                              out_dir,
                              num_procs=num_procs)
Exemplo n.º 3
0
def on_bake(image, parentWindow=None, glCanvas=None):
    with wx.FileDialog(parentWindow, "Choose all series", wildcard='H5 (*.h5)|*.h5',
                       style=wx.FD_OPEN | wx.FD_MULTIPLE) as dialog:

        if dialog.ShowModal() == wx.ID_CANCEL:
            return

        filelist = dialog.GetPaths()
        
    inputGlobs = {'input' : filelist}
    map_dir = os.path.dirname(filelist[0])
    output_dir = os.path.join(map_dir,'analysis')
     
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    recipe_str = """
- processing.DarkAndVarianceMap:
    input: input
    output_dark: dark
    output_variance: variance
- output.ImageOutput:
    filePattern: '{output_dir}/{file_stub}_dark.tif'
    inputName: dark
- output.ImageOutput:
    filePattern: '{output_dir}/{file_stub}_variance.tif'
    inputName: variance
"""

    recipe = modules.ModuleCollection.fromYAML(recipe_str)

    bake(recipe, inputGlobs, output_dir)