def set_legend_to_bw(leg, style, colormap, line_style='continuous'):
    """
    Takes the figure legend and converts it to black and white. Note that
    it currently only converts lines to black and white, other artist 
    intances are currently not being supported, and might cause errors or
    other unexpected behavior.
    
    Parameters
    ----------
    leg : legend
    style : {GREYSCALE, HATCHING}
    colormap : dict
               mapping of color to B&W rendering
    line_style: str
                linestyle to use for converting, can be continuous, black
                or None
                
    # TODO:: None is strange as a value, and should be field based, see
    # set_ax_lines_bw
    
    """
    color_converter = ColorConverter()

    if leg:
        if isinstance(leg, list):
            leg = leg[0]
    
        for element in leg.legendHandles:
            if isinstance(element, mpl.collections.PathCollection):
                rgb_orig = color_converter.to_rgb(element._facecolors[0])
                new_color = color_converter.to_rgba(colormap[rgb_orig]['fill'])
                element._facecolors = np.array((new_color,))
            elif isinstance(element, mpl.patches.Rectangle):
                rgb_orig = color_converter.to_rgb(element._facecolor)
                
                if style==HATCHING:
                    element.update({'alpha':1})
                    element.update({'facecolor':'none'})
                    element.update({'edgecolor':'black'})
                    element.update({'hatch':colormap[rgb_orig]['hatch']})
                elif style==GREYSCALE:
                    ema_logging.info(colormap.keys())
                    element.update({'facecolor':colormap[rgb_orig]['fill']})
                    element.update({'edgecolor':colormap[rgb_orig]['fill']})
            else:
                line = element
                orig_color = line.get_color()
                
                line.set_color('black')
                if not line_style=='continuous':
                    line.set_dashes(colormap[orig_color]['dash'])
                    line.set_marker(colormap[orig_color]['marker'])
                    line.set_markersize(MARKERSIZE)
示例#2
0
def set_legend_to_bw(leg, style, colormap, line_style='continuous'):
    """
    Takes the figure legend and converts it to black and white. Note that
    it currently only converts lines to black and white, other artist 
    intances are currently not being supported, and might cause errors or
    other unexpected behavior.
    
    Parameters
    ----------
    leg : legend
    style : {GREYSCALE, HATCHING}
    colormap : dict
               mapping of color to B&W rendering
    line_style: str
                linestyle to use for converting, can be continuous, black
                or None
                
    # TODO:: None is strange as a value, and should be field based, see
    # set_ax_lines_bw
    
    """
    color_converter = ColorConverter()

    if leg:
        if isinstance(leg, list):
            leg = leg[0]

        for element in leg.legendHandles:
            if isinstance(element, mpl.collections.PathCollection):
                rgb_orig = color_converter.to_rgb(element._facecolors[0])
                new_color = color_converter.to_rgba(colormap[rgb_orig]['fill'])
                element._facecolors = np.array((new_color, ))
            elif isinstance(element, mpl.patches.Rectangle):
                rgb_orig = color_converter.to_rgb(element._facecolor)

                if style == HATCHING:
                    element.update({'alpha': 1})
                    element.update({'facecolor': 'none'})
                    element.update({'edgecolor': 'black'})
                    element.update({'hatch': colormap[rgb_orig]['hatch']})
                elif style == GREYSCALE:
                    ema_logging.info(colormap.keys())
                    element.update({'facecolor': colormap[rgb_orig]['fill']})
                    element.update({'edgecolor': colormap[rgb_orig]['fill']})
            else:
                line = element
                orig_color = line.get_color()

                line.set_color('black')
                if not line_style == 'continuous':
                    line.set_dashes(colormap[orig_color]['dash'])
                    line.set_marker(colormap[orig_color]['marker'])
                    line.set_markersize(MARKERSIZE)
    def test_log_messages(self):
        ema_logging.log_to_stderr(ema_logging.DEBUG)
        
        with mock.patch('ema_workbench.util.ema_logging._logger') as mocked_logger:
            message = 'test message'
            ema_logging.debug(message)
            mocked_logger.debug.assert_called_with(message)

            ema_logging.info(message)
            mocked_logger.info.assert_called_with(message)
            
            ema_logging.warning(message)
            mocked_logger.warning.assert_called_with(message)
            
            ema_logging.error(message)
            mocked_logger.error.assert_called_with(message)
            
            ema_logging.exception(message)
            mocked_logger.exception.assert_called_with(message)
            
            ema_logging.critical(message)
            mocked_logger.critical.assert_called_with(message)            
示例#4
0
    def test_log_messages(self):
        ema_logging.log_to_stderr(ema_logging.DEBUG)

        with mock.patch(
                'ema_workbench.util.ema_logging._logger') as mocked_logger:
            message = 'test message'
            ema_logging.debug(message)
            mocked_logger.debug.assert_called_with(message)

            ema_logging.info(message)
            mocked_logger.info.assert_called_with(message)

            ema_logging.warning(message)
            mocked_logger.warning.assert_called_with(message)

            ema_logging.error(message)
            mocked_logger.error.assert_called_with(message)

            ema_logging.exception(message)
            mocked_logger.exception.assert_called_with(message)

            ema_logging.critical(message)
            mocked_logger.critical.assert_called_with(message)
                     ParameterUncertainty((1, 20), "wolf-reproduce"),
                     CategoricalUncertainty(("true", "true"), "grass?") 
                     ]
    
    outcomes = [Outcome('sheep', time=True),
                Outcome('wolves', time=True),
                Outcome('grass', time=True) # TODO patches not working in reporting
                ]
    
if __name__ == "__main__":
    import multiprocessing
    ema_logging.LOG_FORMAT = multiprocessing.util.DEFAULT_LOGGING_FORMAT
    
    #turn on logging
    ema_logging.log_to_stderr(ema_logging.DEBUG)
    ema_logging.info('in main')
    
    #instantiate a model
    fh = r"./models/predatorPreyNetlogo"
    model = PredatorPrey(fh, "simpleModel")
    
    #instantiate an ensemble
    ensemble = ModelEnsemble()
    
    #set the model on the ensemble
    ensemble.model_structure = model
    
    #run in parallel, if not set, FALSE is assumed
    ensemble.parallel = True
    ensemble.processes = 2