"""
Functions are useful untilities for SITperturb experiments
 
Notes
-----
    Author : Zachary Labe
    Date   : 13 August 2017
    
Usage
-----
    [1] calcDecJan(varx,vary,lat,lon,level,levsq)
    [2] calcDecJanFeb(varx,vary,lat,lon,level,levsq)
    [3] calc_indttest(varx,vary)
    [4] calc_weightedAve(var,lats)
    [5] calc_spatialCorr(varx,vary,lats,lons,weight)
    [6] calc_RMSE(varx,vary,lats,lons,weight)
    [7] calc_spatialCorrHeight(varx,vary,lats,lons,weight)
    [8] calc_spatialCorrHeightLev(varx,vary,lats,lons,weight,levelq)
"""

def calcDecJan(varx,vary,lat,lon,level,levsq):
    """
    Function calculates average for December-January

    Parameters
    ----------
    varx : 4d array or 5d array
        [year,month,lat,lon] or [year,month,lev,lat,lon]
    vary : 4d array or 5d array
        [year,month,lat,lon] or [year,month,lev,lat,lon]
    lat : 1d numpy array
        latitudes
    lon : 1d numpy array
        longitudes
    level : string
        Height of variable (surface or profile)
    levsq : integer
        number of levels
        
    Returns
    -------
    varx_dj : 3d array or 4d array
        [year,lat,lon] or [year,lev,lat,lon]
    vary_dj : 3d array
        [year,lat,lon] or [year,lev,lat,lon]

    Usage
    -----
    varx_dj,vary_dj = calcDecJan(varx,vary,lat,lon,level,levsq)
    """
    print('\n>>> Using calcDecJan function!')
    
    ### Import modules
    import numpy as np
    
    ### Reshape for 3d variables
    if level == 'surface':    
        varxravel = np.reshape(varx.copy(),
                           (int(varx.shape[0]*12),
                            int(lat.shape[0]),int(lon.shape[0])))
        varyravel = np.reshape(vary.copy(),
                               (int(vary.shape[0]*12),
                                int(lat.shape[0]),int(lon.shape[0]))) 
                               
        varx_dj = np.empty((varx.shape[0]-1,lat.shape[0],lon.shape[0]))
        vary_dj = np.empty((vary.shape[0]-1,lat.shape[0],lon.shape[0]) )                 
        for i in range(0,varxravel.shape[0]-12,12):
            counter = 0
            if i >= 12:
                counter = i//12
            djappendh = np.append(varxravel[11+i,:,:],varxravel[12+i,:,:])
            djappendf = np.append(varyravel[11+i,:,:],varyravel[12+i,:,:])    
            varx_dj[counter,:,:] = np.nanmean(np.reshape(djappendh,
                                    (2,int(lat.shape[0]),int(lon.shape[0]))),
                                    axis=0)                   
            vary_dj[counter,:,:] = np.nanmean(np.reshape(djappendf,
                                    (2,int(lat.shape[0]),int(lon.shape[0]))),
                                    axis=0)
    ### Reshape for 4d variables
    elif level == 'profile':
        varxravel = np.reshape(varx.copy(),
                           (int(varx.shape[0]*12.),levsq,
                            int(lat.shape[0]),int(lon.shape[0])))
        varyravel = np.reshape(vary.copy(),
                               (int(vary.shape[0]*12.),levsq,
                                int(lat.shape[0]),int(lon.shape[0]))) 
                               
        varx_dj = np.empty((int(varx.shape[0]-1),levsq,
                            int(lat.shape[0]),int(lon.shape[0])))
        vary_dj = np.empty((int(vary.shape[0]-1),levsq,
                            int(lat.shape[0]),int(lon.shape[0])) )                 
        for i in range(0,varxravel.shape[0]-12,12):
            counter = 0
            if i >= 12:
                counter = i//12
            djappendh = np.append(varxravel[11+i,:,:,:],
                                  varxravel[12+i,:,:,:])
            djappendf = np.append(varyravel[11+i,:,:,:],
                                  varyravel[12+i,:,:,:])    
            varx_dj[counter,:,:] = np.nanmean(np.reshape(djappendh,
                                    (2,levsq,int(lat.shape[0]),
                                     int(lon.shape[0]))),axis=0)                   
            vary_dj[counter,:,:] = np.nanmean(np.reshape(djappendf,
                                    (2,levsq,int(lat.shape[0]),
                                     int(lon.shape[0]))),axis=0)                               
    else:
        print(ValueError('Selected wrong height - (surface or profile!)!'))    
                                
    print('Completed: Organized data by months (ON,DJ,FM)!')

    print('*Completed: Finished calcDecJan function!')
    return varx_dj,vary_dj

###############################################################################
###############################################################################
###############################################################################

def calcDecJanFeb(varx,vary,lat,lon,level,levsq):
    """
    Function calculates average for December-January-February

    Parameters
    ----------
    varx : 4d array or 5d array
        [year,month,lat,lon] or [year,month,lev,lat,lon]
    vary : 4d array or 5d array
        [year,month,lat,lon] or [year,month,lev,lat,lon]
    lat : 1d numpy array
        latitudes
    lon : 1d numpy array
        longitudes
    level : string
        Height of variable (surface or profile)
    levsq : integer
        number of levels
        
    Returns
    -------
    varx_djf : 3d array or 4d array
        [year,lat,lon] or [year,lev,lat,lon]
    vary_djf : 3d array
        [year,lat,lon] or [year,lev,lat,lon]

    Usage
    -----
    varx_djf,vary_djf = calcDecJanFeb(varx,vary,lat,lon,level,levsq)
    """
    print('\n>>> Using calcDecJan function!')
    
    ### Import modules
    import numpy as np
    
    ### Reshape for 3d variables
    if level == 'surface':    
        varxravel = np.reshape(varx.copy(),
                           (int(varx.shape[0]*12),
                            int(lat.shape[0]),int(lon.shape[0])))
        varyravel = np.reshape(vary.copy(),
                               (int(vary.shape[0]*12),
                                int(lat.shape[0]),int(lon.shape[0]))) 
                               
        varx_djf = np.empty((varx.shape[0]-1,lat.shape[0],lon.shape[0]))
        vary_djf = np.empty((vary.shape[0]-1,lat.shape[0],lon.shape[0]) )                 
        for i in range(0,varxravel.shape[0]-12,12):
            counter = 0
            if i >= 12:
                counter = i//12
            djfappendh1 = np.append(varxravel[11+i,:,:],varxravel[12+i,:,:])
            djfappendf1 = np.append(varyravel[11+i,:,:],varyravel[12+i,:,:])  
            djfappendh = np.append(djfappendh1,varxravel[13+i,:,:])
            djfappendf = np.append(djfappendf1,varyravel[13+i,:,:]) 
            varx_djf[counter,:,:] = np.nanmean(np.reshape(djfappendh,
                                    (3,int(lat.shape[0]),int(lon.shape[0]))),
                                    axis=0)                   
            vary_djf[counter,:,:] = np.nanmean(np.reshape(djfappendf,
                                    (3,int(lat.shape[0]),int(lon.shape[0]))),
                                    axis=0)
    ### Reshape for 4d variables
    elif level == 'profile':
        varxravel = np.reshape(varx.copy(),
                           (int(varx.shape[0]*12.),levsq,
                            int(lat.shape[0]),int(lon.shape[0])))
        varyravel = np.reshape(vary.copy(),
                               (int(vary.shape[0]*12.),levsq,
                                int(lat.shape[0]),int(lon.shape[0]))) 
                               
        varx_djf = np.empty((int(varx.shape[0]-1),levsq,
                            int(lat.shape[0]),int(lon.shape[0])))
        vary_djf = np.empty((int(vary.shape[0]-1),levsq,
                            int(lat.shape[0]),int(lon.shape[0])) )                 
        for i in range(0,varxravel.shape[0]-12,12):
            counter = 0
            if i >= 12:
                counter = i//12
            djfappendh1 = np.append(varxravel[11+i,:,:,:],
                                  varxravel[12+i,:,:,:])
            djfappendf1 = np.append(varyravel[11+i,:,:,:],
                                  varyravel[12+i,:,:,:]) 
            djfappendh = np.append(djfappendh1,
                                  varxravel[13+i,:,:,:])
            djfappendf = np.append(djfappendf1,
                                  varyravel[13+i,:,:,:])  
            varx_djf[counter,:,:] = np.nanmean(np.reshape(djfappendh,
                                    (3,levsq,int(lat.shape[0]),
                                     int(lon.shape[0]))),axis=0)                   
            vary_djf[counter,:,:] = np.nanmean(np.reshape(djfappendf,
                                    (3,levsq,int(lat.shape[0]),
                                     int(lon.shape[0]))),axis=0)                               
    else:
        print(ValueError('Selected wrong height - (surface or profile!)!'))    
                                
    print('Completed: Organized data by months (DJF)!')

    print('*Completed: Finished calcDecJanFeb function!')
    return varx_djf,vary_djf

###############################################################################
###############################################################################
###############################################################################
    
def calc_indttest(varx,vary):
    """
    Function calculates statistical difference for 2 independent
    sample t-test

    Parameters
    ----------
    varx : 3d array
    vary : 3d array
    
    Returns
    -------
    stat = calculated t-statistic
    pvalue = two-tailed p-value

    Usage
    -----
    stat,pvalue = calc_ttest(varx,vary)
    """
    print('\n>>> Using calc_ttest function!')
    
    ### Import modules
    import numpy as np
    import scipy.stats as sts
    
    ### 2-independent sample t-test
    stat,pvalue = sts.ttest_ind(varx,vary,nan_policy='omit')
    
    ### Significant at 95% confidence level
    pvalue[np.where(pvalue >= 0.05)] = np.nan
    pvalue[np.where(pvalue < 0.05)] = 1.
    
    print('*Completed: Finished calc_ttest function!')
    return stat,pvalue

###############################################################################
###############################################################################
###############################################################################

def calc_weightedAve(var,lats):
    """
    Area weights sit array 5d [ens,year,month,lat,lon] into [ens,year,month]
    
    Parameters
    ----------
    var : 5d,4d,3d array of a gridded variable
    lats : 2d array of latitudes
    
    Returns
    -------
    meanvar : weighted average for 3d,2d,1d array

    Usage
    -----
    meanvar = calc_weightedAve(var,lats)
    """
    print('\n>>> Using calc_weightedAve function!')
    
    ### Import modules
    import numpy as np
    
    ### Calculate weighted average for various dimensional arrays
    if var.ndim == 5:
        meanvar = np.empty((var.shape[0],var.shape[1],var.shape[2]))
        for ens in range(var.shape[0]):
            for i in range(var.shape[1]):
                for j in range(var.shape[2]):
                    varq = var[ens,i,j,:,:]
                    mask = np.isfinite(varq) & np.isfinite(lats)
                    varmask = varq[mask]
                    areamask = np.cos(np.deg2rad(lats[mask]))
                    meanvar[ens,i,j] = np.nansum(varmask*areamask) \
                                        /np.sum(areamask)  
    elif var.ndim == 4:
        meanvar = np.empty((var.shape[0],var.shape[1]))
        for i in range(var.shape[0]):
            for j in range(var.shape[1]):
                varq = var[i,j,:,:]
                mask = np.isfinite(varq) & np.isfinite(lats)
                varmask = varq[mask]
                areamask = np.cos(np.deg2rad(lats[mask]))
                meanvar[i,j] = np.nansum(varmask*areamask)/np.sum(areamask)
    elif var.ndim == 3:
        meanvar = np.empty((var.shape[0]))
        for i in range(var.shape[0]):
            varq = var[i,:,:]
            mask = np.isfinite(varq) & np.isfinite(lats)
            varmask = varq[mask]
            areamask = np.cos(np.deg2rad(lats[mask]))
            meanvar[i] = np.nansum(varmask*areamask)/np.sum(areamask)
    elif var.ndim == 2:
        meanvar = np.empty((var.shape[0]))
        varq = var[:,:]
        mask = np.isfinite(varq) & np.isfinite(lats)
        varmask = varq[mask]
        areamask = np.cos(np.deg2rad(lats[mask]))
        meanvar = np.nansum(varmask*areamask)/np.sum(areamask)
    else:
        print(ValueError('Variable has the wrong dimensions!'))
     
    print('Completed: Weighted variable average!')
    
    print('*Completed: Finished calc_weightedAve function!')
    return meanvar

###############################################################################
###############################################################################
###############################################################################
    
def calc_spatialCorr(varx,vary,lats,lons,weight):
    """
    Calculates spatial correlation from pearson correlation coefficient
    
    Parameters
    ----------
    varx : 2d array
    vary : 2d array
    lats : 1d array
    lons : 1d array of latitude
    weight : string (yes or no)
    
    Returns
    -------
    corrcoef : 1d array of correlation coefficient (pearson r)
    
    Usage
    -----
    corrcoef = calc_spatialCorr(varx,vary,lats,lons)
    """
    
    print('\n>>> Using calc_spatialCorr function!')
    ### Import modules
    import numpy as np
    
    if weight == 'yes': # Computed weighted correlation coefficient   
        ### mask 
        mask = 'yes'
        if mask == 'yes':
            latq = np.where(lats > 40)[0]
            lats = lats[latq]
            varx = varx[latq,:]
            vary = vary[latq,:]
            print('MASKING LATITUDES!')
        
        ### Create 2d meshgrid for weights 
        lon2,lat2 = np.meshgrid(lons,lats)
        
        ### Create 2d array of weights based on latitude
        gw = np.cos(np.deg2rad(lat2))
        
        def m(x, w):
            """Weighted Mean"""
    
            wave = np.sum(x * w) / np.sum(w)
            print('Completed: Computed weighted average!') 
            return wave
        
        def cov(x, y, w):
            """Weighted Covariance"""
            
            wcov = np.sum(w * (x - m(x, w)) * (y - m(y, w))) / np.sum(w)
            print('Completed: Computed weighted covariance!')
            return wcov
        
        def corr(x, y, w):
            """Weighted Correlation"""
            
            wcor = cov(x, y, w) / np.sqrt(cov(x, x, w) * cov(y, y, w))
            print('Completed: Computed weighted correlation!')
            return wcor
        
        corrcoef = corr(varx,vary,gw)
        
    elif weight == 'no':   
        ### Correlation coefficient from numpy function (not weighted)
        corrcoef= np.corrcoef(varx.ravel(),vary.ravel())[0][1]
        print('Completed: Computed NON-weighted correlation!')
        
    else:
        ValueError('Wrong weighted arguement in function!')
    
    print('*Completed: Finished calc_SpatialCorr function!')
    return corrcoef

###############################################################################
###############################################################################
###############################################################################

def calc_RMSE(varx,vary,lats,lons,weight):
        """
        Calculates root mean square weighted average
        
        Parameters
        ----------
        varx : 2d array
        vary : 2d array
        lons : 1d array of latitude
        weight : string (yes or no)
        
        Returns
        -------
        rmse : 1d array
        
        Usage
        -----
        rmse = calc_RMSE(varx,vary,lats,lons)
        """
        
        print('\n>>> Using calc_RMSE function!')
        ### Import modules
        import numpy as np
        from sklearn.metrics import mean_squared_error
        
        if weight == 'yes': # Computed weighted correlation coefficient   
            ### mask
            mask = 'yes'
            if mask == 'yes':
                latq = np.where(lats > 40)[0]
                lats = lats[latq]
                varx = varx[latq,:]
                vary = vary[latq,:]
                print('MASKING LATITUDES!')
            
            ### Create 2d meshgrid for weights 
            lon2,lat2 = np.meshgrid(lons,lats)
            
            ### Create 2d array of weights based on latitude
            gw = np.cos(np.deg2rad(lat2))
            
            ### Calculate rmse 
            sq_err = (varx - vary)**2
            rmse = np.sqrt((np.sum(sq_err*gw))/np.sum(gw))
     
        elif weight == 'no':   
            ### Root mean square error from sklearn (not weighted)
            rmse = np.sqrt(mean_squared_error(varx.ravel(),vary.ravel()))
            print('Completed: Computed NON-weighted correlation!')
            
        else:
            ValueError('Wrong weighted arguement in function!')
        
        print('*Completed: Finished calc_RMSE function!')
        return rmse
    
###############################################################################
###############################################################################
###############################################################################
    
def calc_spatialCorrHeight(varx,vary,levs,lons,weight):
    """
    Calculates spatial correlation from pearson correlation coefficient for
    grids over vertical height (17 pressure coordinate levels)
    
    Parameters
    ----------
    varx : 2d array
    vary : 2d array
    levs : 1d array of levels
    lons : 1d array of latitude
    weight : string (yes or no)
    
    Returns
    -------
    corrcoef : 1d array of correlation coefficient (pearson r)
    
    Usage
    -----
    corrcoef = calc_spatialCorrHeight(varx,vary,lats,lons)
    """
    
    print('\n>>> Using calc_spatialCorrHeight function!')
    ### Import modules
    import numpy as np
    
    if weight == 'yes': # Computed weighted correlation coefficient   
        
        ### Create 2d meshgrid for weights 
        lon2,lev2 = np.meshgrid(lons,levs)
        
        ### Create 2d array of weights based on latitude
        gwq = np.array([0.25,0.25,0.25,0.25,0.25,0.25,0.4,0.5,0.5,0.5,
              0.5,0.5,0.5,0.7,0.7,0.7,1.])
        gw,gw2 = np.meshgrid(lons,gwq)
        
        def m(x, w):
            """Weighted Mean"""
    
            wave = np.sum(x * w) / np.sum(w)
            print('Completed: Computed weighted average (17 P Levels)!') 
            return wave
        
        def cov(x, y, w):
            """Weighted Covariance"""
            
            wcov = np.sum(w * (x - m(x, w)) * (y - m(y, w))) / np.sum(w)
            print('Completed: Computed weighted covariance (17 P Levels)!')
            return wcov
        
        def corr(x, y, w):
            """Weighted Correlation"""
            
            wcor = cov(x, y, w) / np.sqrt(cov(x, x, w) * cov(y, y, w))
            print('Completed: Computed weighted correlation (17 P Levels)!')
            return wcor
        
        corrcoef = corr(varx,vary,gw)
        
    elif weight == 'no':   
        ### Correlation coefficient from numpy function (not weighted)
        corrcoef= np.corrcoef(varx.ravel(),vary.ravel())[0][1]
        print('Completed: Computed NON-weighted correlation!')
        
    else:
        ValueError('Wrong weighted argument in function!')
    
    print('*Completed: Finished calc_SpatialCorrHeight function!')
    return corrcoef

###############################################################################
###############################################################################
###############################################################################
    
def calc_spatialCorrHeightLev(varx,vary,levs,lons,weight,levelq):
    """
    Calculates spatial correlation from pearson correlation coefficient for
    grids over vertical height (17 pressure coordinate levels). Change the 
    weighting for different level correlations
    
    Parameters
    ----------
    varx : 2d array
    vary : 2d array
    levs : 1d array of levels
    lons : 1d array of latitude
    weight : string (yes or no)
    levelq : string (all, tropo, strato)
    
    Returns
    -------
    corrcoef : 1d array of correlation coefficient (pearson r)
    
    Usage
    -----
    corrcoef = calc_spatialCorrHeight(varx,vary,lats,lons,levels)
    """
    
    print('\n>>> Using calc_spatialCorrHeightLev function!')
    ### Import modules
    import numpy as np
    
    if weight == 'yes': # Computed weighted correlation coefficient   
        
        ### Create 2d meshgrid for weights 
        lon2,lev2 = np.meshgrid(lons,levs)
        
        if levelq == 'all':
            ### Create 2d array of weights based on latitude
            gwq = np.array([0.25,0.25,0.25,0.25,0.25,0.25,0.4,0.5,0.5,0.5,
                  0.5,0.5,0.5,0.7,0.7,0.7,1.])
            gw,gw2 = np.meshgrid(lons,gwq)
        elif levelq == 'tropo':
           gwq = np.array([1.0,1.0,1.0,1.0,0.5,0.5,0.5,0.2,0.2,0.,0.,0.,
                           0.,0.,0.,0.,0.])
           gw,gw2 = np.meshgrid(lons,gwq)
        elif levelq == 'strato':
           gwq = np.array([0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.5,1.,1.,1.,1.
                           ,1.,1.])
           gw,gw2 = np.meshgrid(lons,gwq)
        
        def m(x, w):
            """Weighted Mean"""
    
            wave = np.sum(x * w) / np.sum(w)
            print('Completed: Computed weighted average (17 P Levels)!') 
            return wave
        
        def cov(x, y, w):
            """Weighted Covariance"""
            
            wcov = np.sum(w * (x - m(x, w)) * (y - m(y, w))) / np.sum(w)
            print('Completed: Computed weighted covariance (17 P Levels)!')
            return wcov
        
        def corr(x, y, w):
            """Weighted Correlation"""
            
            wcor = cov(x, y, w) / np.sqrt(cov(x, x, w) * cov(y, y, w))
            print('Completed: Computed weighted correlation (17 P Levels)!')
            return wcor
        
        corrcoef = corr(varx,vary,gw)
        
    elif weight == 'no':   
        ### Correlation coefficient from numpy function (not weighted)
        corrcoef= np.corrcoef(varx.ravel(),vary.ravel())[0][1]
        print('Completed: Computed NON-weighted correlation!')
        
    else:
        ValueError('Wrong weighted argument in function!')
    
    print('*Completed: Finished calc_SpatialCorrHeightLev function!')
    return corrcoef
[(247, 'scipy.stats.ttest_ind', 'sts.ttest_ind', True, 'import scipy.stats as sts\n'), (65, 'numpy.empty', 'np.empty', True, 'import numpy as np\n'), (66, 'numpy.empty', 'np.empty', True, 'import numpy as np\n'), (162, 'numpy.empty', 'np.empty', True, 'import numpy as np\n'), (163, 'numpy.empty', 'np.empty', True, 'import numpy as np\n'), (284, 'numpy.empty', 'np.empty', True, 'import numpy as np\n'), (366, 'numpy.meshgrid', 'np.meshgrid', True, 'import numpy as np\n'), (445, 'numpy.meshgrid', 'np.meshgrid', True, 'import numpy as np\n'), (498, 'numpy.meshgrid', 'np.meshgrid', True, 'import numpy as np\n'), (501, 'numpy.array', 'np.array', True, 'import numpy as np\n'), (503, 'numpy.meshgrid', 'np.meshgrid', True, 'import numpy as np\n'), (574, 'numpy.meshgrid', 'np.meshgrid', True, 'import numpy as np\n'), (71, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (72, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (168, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (169, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (170, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (171, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (250, 'numpy.where', 'np.where', True, 'import numpy as np\n'), (251, 'numpy.where', 'np.where', True, 'import numpy as np\n'), (295, 'numpy.empty', 'np.empty', True, 'import numpy as np\n'), (369, 'numpy.deg2rad', 'np.deg2rad', True, 'import numpy as np\n'), (448, 'numpy.deg2rad', 'np.deg2rad', True, 'import numpy as np\n'), (578, 'numpy.array', 'np.array', True, 'import numpy as np\n'), (580, 'numpy.meshgrid', 'np.meshgrid', True, 'import numpy as np\n'), (96, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (98, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (195, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (197, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (199, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (201, 'numpy.append', 'np.append', True, 'import numpy as np\n'), (304, 'numpy.empty', 'np.empty', True, 'import numpy as np\n'), (359, 'numpy.where', 'np.where', True, 'import numpy as np\n'), (374, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (374, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (381, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (438, 'numpy.where', 'np.where', True, 'import numpy as np\n'), (452, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (452, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (508, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (508, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (515, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (582, 'numpy.array', 'np.array', True, 'import numpy as np\n'), (584, 'numpy.meshgrid', 'np.meshgrid', True, 'import numpy as np\n'), (593, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (593, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (600, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (312, 'numpy.empty', 'np.empty', True, 'import numpy as np\n'), (586, 'numpy.array', 'np.array', True, 'import numpy as np\n'), (588, 'numpy.meshgrid', 'np.meshgrid', True, 'import numpy as np\n'), (289, 'numpy.isfinite', 'np.isfinite', True, 'import numpy as np\n'), (289, 'numpy.isfinite', 'np.isfinite', True, 'import numpy as np\n'), (291, 'numpy.deg2rad', 'np.deg2rad', True, 'import numpy as np\n'), (292, 'numpy.nansum', 'np.nansum', True, 'import numpy as np\n'), (293, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (299, 'numpy.isfinite', 'np.isfinite', True, 'import numpy as np\n'), (299, 'numpy.isfinite', 'np.isfinite', True, 'import numpy as np\n'), (301, 'numpy.deg2rad', 'np.deg2rad', True, 'import numpy as np\n'), (302, 'numpy.nansum', 'np.nansum', True, 'import numpy as np\n'), (302, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (307, 'numpy.isfinite', 'np.isfinite', True, 'import numpy as np\n'), (307, 'numpy.isfinite', 'np.isfinite', True, 'import numpy as np\n'), (309, 'numpy.deg2rad', 'np.deg2rad', True, 'import numpy as np\n'), (310, 'numpy.nansum', 'np.nansum', True, 'import numpy as np\n'), (310, 'numpy.sum', 'np.sum', True, 'import numpy as np\n'), (314, 'numpy.isfinite', 'np.isfinite', True, 'import numpy as np\n'), (314, 'numpy.isfinite', 'np.isfinite', True, 'import numpy as np\n'), (316, 'numpy.deg2rad', 'np.deg2rad', True, 'import numpy as np\n'), (317, 'numpy.nansum', 'np.nansum', True, 'import numpy as np\n'), (317, 'numpy.sum', 'np.sum', True, 'import numpy as np\n')]