<commit_before>''' The function "qgpv_Eqlat_LWA" in this module computes the equivalent-
latitude relationship and finite-amplitude local wave activity (LWA) from the 
vorticity fields on a hemispheric domain as shown in the example in fig. 8 and 9 
of Huang & Nakamura (2016) equation (13). 

Please email <NAME> if you have any inquiries/suggestions: <EMAIL>
'''
from math import *
from lwa import LWA
from eqv_lat import EqvLat
import numpy as np

def qgpv_Eqlat_LWA(ylat,vort,area,dmu,nlat_S=None):
    '''
    Input variables:
        ylat: 1-d numpy array of latitude (in degree) with equal spacing in 
                ascending order; dimension = nlat
        vort: 2-d numpy array of vorticity values; dimension = [nlat_S x nlon]
        area: 2-d numpy array specifying differential areal element of each 
                grid point; dimension = [nlat_S x nlon]
        nlat_S: the index of grid point that defines the extent of hemispheric 
                domain from the pole. If the value of nlat_S is not input, it 
                will be set to nlat/2, where nlat is the size of ylat.
        
    Output variables:
        Qref: 1-d numpy array of value Q(y) where latitude y is given by ylat. 
        LWA_result: 2-d numpy array of local wave activity values; 
                    dimension = [nlat_S x nlon]    
    '''
    
    nlat = vort.shape[0]
    nlon = vort.shape[1]
    if nlat_S == None:
        nlat_S = nlat/2
        
    Qref = np.zeros(nlat)
    LWA_result = np.zeros((nlat,nlon))
    
    # --- Southern Hemisphere ---
    Qref1 = EqvLat(ylat[:nlat_S],vort[:nlat_S,:],area[:nlat_S,:],nlat_S)
    Qref[:nlat_S] = Qref1
    LWA_South = LWA(nlon,nlat_S,vort[:nlat_S,:],Qref1,dmu[:nlat_S])
    LWA_result[:nlat_S,:] = LWA_South

    # --- Northern Hemisphere ---
    vort2 = -vort[::-1,:] # Added the minus sign, but gotta see if NL_North is affected
    Qref2 = EqvLat(ylat[:nlat_S],vort2[:nlat_S,:],area[:nlat_S,:],nlat_S)
    Qref[-nlat_S:] = Qref2[::-1]
    LWA_North = LWA(nlon,nlat_S,vort2[:nlat_S,:],Qref2,dmu[:nlat_S])
    LWA_result[-nlat_S:,:] = LWA_North[::-1,:]

    return Qref, LWA_result


<commit_msg>Fixed a bug in qgpv_lwa such that reference state Qref on Northern hemisphere is of the correct sign.<commit_after>''' The function "qgpv_Eqlat_LWA" in this module computes the equivalent-
latitude relationship and finite-amplitude local wave activity (LWA) from the 
vorticity fields on a hemispheric domain as shown in the example in fig. 8 and 9 
of Huang & Nakamura (2016) equation (13). 

Please email <NAME> if you have any inquiries/suggestions: <EMAIL>
'''
from math import *
from lwa import LWA
from eqv_lat import EqvLat
import numpy as np

def qgpv_Eqlat_LWA(ylat,vort,area,dmu,nlat_S=None):
    '''
    Input variables:
        ylat: 1-d numpy array of latitude (in degree) with equal spacing in 
                ascending order; dimension = nlat
        vort: 2-d numpy array of vorticity values; dimension = [nlat_S x nlon]
        area: 2-d numpy array specifying differential areal element of each 
                grid point; dimension = [nlat_S x nlon]
        nlat_S: the index of grid point that defines the extent of hemispheric 
                domain from the pole. If the value of nlat_S is not input, it 
                will be set to nlat/2, where nlat is the size of ylat.
        
    Output variables:
        Qref: 1-d numpy array of value Q(y) where latitude y is given by ylat. 
        LWA_result: 2-d numpy array of local wave activity values; 
                    dimension = [nlat_S x nlon]    
    '''
    
    nlat = vort.shape[0]
    nlon = vort.shape[1]
    if nlat_S == None:
        nlat_S = nlat/2
        
    Qref = np.zeros(nlat)
    LWA_result = np.zeros((nlat,nlon))
    
    # --- Southern Hemisphere ---
    Qref1 = EqvLat(ylat[:nlat_S],vort[:nlat_S,:],area[:nlat_S,:],nlat_S)
    Qref[:nlat_S] = Qref1
    LWA_South = LWA(nlon,nlat_S,vort[:nlat_S,:],Qref1,dmu[:nlat_S])
    LWA_result[:nlat_S,:] = LWA_South

    # --- Northern Hemisphere ---
    vort2 = -vort[::-1,:] # Added the minus sign, but gotta see if NL_North is affected
    Qref2 = EqvLat(ylat[:nlat_S],vort2[:nlat_S,:],area[:nlat_S,:],nlat_S)
    Qref[-nlat_S:] = -Qref2[::-1]
    LWA_North = LWA(nlon,nlat_S,vort2[:nlat_S,:],Qref2,dmu[:nlat_S])
    LWA_result[-nlat_S:,:] = LWA_North[::-1,:]

    return Qref, LWA_result



{'fraction_non_alphanumeric': 0.10622293138819239, 'fraction_numerical': 0.013220879872350126, 'mean_word_length': 2.802426343154246, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3273708', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1563, 'n_words': 475}