#NEWLINE# def fit_pixel_multiprocess_nnls( exp_data , matv , param , use_snip = False ) : #NEWLINE# #INDENT# '\n    Multiprocess fit of experiment data.\n    Parameters\n    ----------\n    exp_data : array\n        3D data of experiment spectrum,\n        with x,y positions as the first 2-dim, and energy as the third one.\n    matv : array\n        matrix for regression analysis\n    param : dict\n        fitting parameters\n    use_snip : bool, optional\n        use snip algorithm to remove background or not\n\n    Returns\n    -------\n    array\n        Fitting values for all the elements\n    ' #NEWLINE# num_processors_to_use = multiprocessing . cpu_count ( ) #NEWLINE# logger . info ( 'cpu count: {}' . format ( num_processors_to_use ) ) #NEWLINE# pool = multiprocessing . Pool ( num_processors_to_use ) #NEWLINE# result_pool = [ pool . apply_async ( _log_and_fit , ( n , data , matv , param , use_snip ) ) for ( n , data ) in enumerate ( exp_data ) ] #NEWLINE# results = [ r . get ( ) for r in result_pool ] #NEWLINE# pool . terminate ( ) #NEWLINE# pool . join ( ) #NEWLINE# return np . array ( results )