idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
14,900
def POINTER ( self , _cursor_type ) : comment = None _type = _cursor_type . get_pointee ( ) . get_canonical ( ) _p_type_name = self . get_unique_name ( _type ) size = _cursor_type . get_size ( ) align = _cursor_type . get_align ( ) log . debug ( "POINTER: size:%d align:%d typ:%s" , size , align , _type . kind ) if self...
Handles POINTER types .
14,901
def _array_handler ( self , _cursor_type ) : _type = _cursor_type . get_canonical ( ) size = _type . get_array_size ( ) if size == - 1 and _type . kind == TypeKind . INCOMPLETEARRAY : size = 0 _array_type = _type . get_array_element_type ( ) if self . is_fundamental_type ( _array_type ) : _subtype = self . parse_cursor...
Handles all array types . Resolves it s element type and makes a Array typedesc .
14,902
def FUNCTIONPROTO ( self , _cursor_type ) : returns = _cursor_type . get_result ( ) returns = self . parse_cursor_type ( returns ) attributes = [ ] obj = typedesc . FunctionType ( returns , attributes ) for i , _attr_type in enumerate ( _cursor_type . argument_types ( ) ) : arg = typedesc . Argument ( "a%d" % ( i ) , s...
Handles function prototype .
14,903
def FUNCTIONNOPROTO ( self , _cursor_type ) : returns = _cursor_type . get_result ( ) returns = self . parse_cursor_type ( returns ) attributes = [ ] obj = typedesc . FunctionType ( returns , attributes ) self . set_location ( obj , None ) return obj
Handles function with no prototype .
14,904
def UNEXPOSED ( self , _cursor_type ) : _decl = _cursor_type . get_declaration ( ) name = self . get_unique_name ( _decl ) if self . is_registered ( name ) : obj = self . get_registered ( name ) else : obj = self . parse_cursor ( _decl ) return obj
Handles unexposed types . Returns the canonical type instead .
14,905
def INIT_LIST_EXPR ( self , cursor ) : values = [ self . parse_cursor ( child ) for child in list ( cursor . get_children ( ) ) ] return values
Returns a list of literal values .
14,906
def ENUM_CONSTANT_DECL ( self , cursor ) : name = cursor . displayname value = cursor . enum_value pname = self . get_unique_name ( cursor . semantic_parent ) parent = self . get_registered ( pname ) obj = typedesc . EnumValue ( name , value , parent ) parent . add_value ( obj ) return obj
Gets the enumeration values
14,907
def ENUM_DECL ( self , cursor ) : name = self . get_unique_name ( cursor ) if self . is_registered ( name ) : return self . get_registered ( name ) align = cursor . type . get_align ( ) size = cursor . type . get_size ( ) obj = self . register ( name , typedesc . Enumeration ( name , size , align ) ) self . set_locatio...
Gets the enumeration declaration .
14,908
def FUNCTION_DECL ( self , cursor ) : name = self . get_unique_name ( cursor ) if self . is_registered ( name ) : return self . get_registered ( name ) returns = self . parse_cursor_type ( cursor . type . get_result ( ) ) attributes = [ ] extern = False obj = typedesc . Function ( name , returns , attributes , extern )...
Handles function declaration
14,909
def PARM_DECL ( self , cursor ) : _type = cursor . type _name = cursor . spelling if ( self . is_array_type ( _type ) or self . is_fundamental_type ( _type ) or self . is_pointer_type ( _type ) or self . is_unexposed_type ( _type ) ) : _argtype = self . parse_cursor_type ( _type ) else : _argtype_decl = _type . get_dec...
Handles parameter declarations .
14,910
def VAR_DECL ( self , cursor ) : name = self . get_unique_name ( cursor ) log . debug ( 'VAR_DECL: name: %s' , name ) if self . is_registered ( name ) : return self . get_registered ( name ) _type = self . _VAR_DECL_type ( cursor ) init_value = self . _VAR_DECL_value ( cursor , _type ) log . debug ( 'VAR_DECL: _type:%s...
Handles Variable declaration .
14,911
def _VAR_DECL_type ( self , cursor ) : _ctype = cursor . type . get_canonical ( ) log . debug ( 'VAR_DECL: _ctype: %s ' , _ctype . kind ) if self . is_fundamental_type ( _ctype ) : ctypesname = self . get_ctypes_name ( _ctype . kind ) _type = typedesc . FundamentalType ( ctypesname , 0 , 0 ) elif self . is_unexposed_ty...
Generates a typedesc object from a Variable declaration .
14,912
def _VAR_DECL_value ( self , cursor , _type ) : init_value = self . _get_var_decl_init_value ( cursor . type , list ( cursor . get_children ( ) ) ) _ctype = cursor . type . get_canonical ( ) if self . is_unexposed_type ( _ctype ) : init_value = '%s # UNEXPOSED TYPE. PATCH NEEDED.' % ( init_value ) elif ( self . is_poin...
Handles Variable value initialization .
14,913
def _get_var_decl_init_value ( self , _ctype , children ) : init_value = [ ] children = list ( children ) log . debug ( '_get_var_decl_init_value: children #: %d' , len ( children ) ) for child in children : _tmp = None try : _tmp = self . _get_var_decl_init_value_single ( _ctype , child ) except CursorKindException : ...
Gathers initialisation values by parsing children nodes of a VAR_DECL .
14,914
def _get_var_decl_init_value_single ( self , _ctype , child ) : init_value = None log . debug ( '_get_var_decl_init_value_single: _ctype: %s Child.kind: %s' , _ctype . kind , child . kind ) if not child . kind . is_expression ( ) and not child . kind . is_declaration ( ) : raise CursorKindException ( child . kind ) if ...
Handling of a single child for initialization value . Accepted types are expressions and declarations
14,915
def _literal_handling ( self , cursor ) : tokens = list ( cursor . get_tokens ( ) ) log . debug ( 'literal has %d tokens.[ %s ]' , len ( tokens ) , str ( [ str ( t . spelling ) for t in tokens ] ) ) final_value = [ ] log . debug ( 'cursor.type:%s' , cursor . type . kind . name ) for i , token in enumerate ( tokens ) : ...
Parse all literal associated with this cursor .
14,916
def _operator_handling ( self , cursor ) : values = self . _literal_handling ( cursor ) retval = '' . join ( [ str ( val ) for val in values ] ) return retval
Returns a string with the literal that are part of the operation .
14,917
def STRUCT_DECL ( self , cursor , num = None ) : return self . _record_decl ( cursor , typedesc . Structure , num )
Handles Structure declaration . Its a wrapper to _record_decl .
14,918
def UNION_DECL ( self , cursor , num = None ) : return self . _record_decl ( cursor , typedesc . Union , num )
Handles Union declaration . Its a wrapper to _record_decl .
14,919
def _fixup_record_bitfields_type ( self , s ) : bitfields = [ ] bitfield_members = [ ] current_bits = 0 for m in s . members : if m . is_bitfield : bitfield_members . append ( m ) if m . is_padding : size = current_bits bitfields . append ( ( size , bitfield_members ) ) bitfield_members = [ ] current_bits = 0 else : cu...
Fix the bitfield packing issue for python ctypes by changing the bitfield type and respecting compiler alignement rules .
14,920
def _fixup_record ( self , s ) : log . debug ( 'FIXUP_STRUCT: %s %d bits' , s . name , s . size * 8 ) if s . members is None : log . debug ( 'FIXUP_STRUCT: no members' ) s . members = [ ] return if s . size == 0 : log . debug ( 'FIXUP_STRUCT: struct has size %d' , s . size ) return self . _fixup_record_bitfields_type (...
Fixup padding on a record
14,921
def _make_padding ( self , members , padding_nb , offset , length , prev_member = None ) : name = 'PADDING_%d' % padding_nb padding_nb += 1 log . debug ( "_make_padding: for %d bits" , length ) if ( length % 8 ) != 0 or ( prev_member is not None and prev_member . is_bitfield ) : typename = prev_member . type . name pad...
Make padding Fields for a specifed size .
14,922
def MACRO_DEFINITION ( self , cursor ) : if ( not hasattr ( cursor , 'location' ) or cursor . location is None or cursor . location . file is None ) : return False name = self . get_unique_name ( cursor ) comment = None tokens = self . _literal_handling ( cursor ) value = True if isinstance ( tokens , list ) : if len (...
Parse MACRO_DEFINITION only present if the TranslationUnit is used with TranslationUnit . PARSE_DETAILED_PROCESSING_RECORD .
14,923
def set_location ( self , obj , cursor ) : if ( hasattr ( cursor , 'location' ) and cursor . location is not None and cursor . location . file is not None ) : obj . location = ( cursor . location . file . name , cursor . location . line ) return
Location is also used for codegeneration ordering .
14,924
def set_comment ( self , obj , cursor ) : if isinstance ( obj , typedesc . T ) : obj . comment = cursor . brief_comment return
If a comment is available add it to the typedesc .
14,925
def make_python_name ( self , name ) : for k , v in [ ( '<' , '_' ) , ( '>' , '_' ) , ( '::' , '__' ) , ( ',' , '' ) , ( ' ' , '' ) , ( "$" , "DOLLAR" ) , ( "." , "DOT" ) , ( "@" , "_" ) , ( ":" , "_" ) , ( '-' , '_' ) ] : if k in name : name = name . replace ( k , v ) if name . startswith ( "__" ) : return "_X" + name...
Transforms an USR into a valid python name .
14,926
def _make_unknown_name ( self , cursor ) : parent = cursor . lexical_parent pname = self . get_unique_name ( parent ) log . debug ( '_make_unknown_name: Got parent get_unique_name %s' , pname ) _cursor_decl = cursor . type . get_declaration ( ) _i = 0 found = False for m in parent . get_children ( ) : log . debug ( '_m...
Creates a name for unname type
14,927
def get_unique_name ( self , cursor ) : name = '' if cursor . kind in [ CursorKind . UNEXPOSED_DECL ] : return '' name = cursor . spelling if cursor . spelling == '' : if ( cursor . semantic_parent and cursor . semantic_parent . kind == CursorKind . TRANSLATION_UNIT ) : name = self . make_python_name ( cursor . get_usr...
get the spelling or create a unique name for a cursor
14,928
def get_literal_kind_affinity ( self , literal_kind ) : if literal_kind == CursorKind . INTEGER_LITERAL : return [ TypeKind . USHORT , TypeKind . UINT , TypeKind . ULONG , TypeKind . ULONGLONG , TypeKind . UINT128 , TypeKind . SHORT , TypeKind . INT , TypeKind . LONG , TypeKind . LONGLONG , TypeKind . INT128 , ] elif l...
return the list of fundamental types that are adequate for which this literal_kind is adequate
14,929
def is_newer ( source , target ) : if not os . path . exists ( source ) : raise ValueError ( "file '%s' does not exist" % source ) if not os . path . exists ( target ) : return 1 from stat import ST_MTIME mtime1 = os . stat ( source ) [ ST_MTIME ] mtime2 = os . stat ( target ) [ ST_MTIME ] return mtime1 > mtime2
Return true if source exists and is more recently modified than target or if source exists and target doesn t . Return false if both exist and target is the same age or younger than source . Raise ValueError if source does not exist .
14,930
def startElement ( self , node ) : if node is None : return if self . __filter_location is not None : if node . location . file is None : return elif node . location . file . name not in self . __filter_location : return log . debug ( '%s:%d: Found a %s|%s|%s' , node . location . file , node . location . line , node . ...
Recurses in children of this node
14,931
def register ( self , name , obj ) : if name in self . all : log . debug ( 'register: %s already existed: %s' , name , obj . name ) raise DuplicateDefinitionException ( 'register: %s already existed: %s' % ( name , obj . name ) ) log . debug ( 'register: %s ' , name ) self . all [ name ] = obj return obj
Registers an unique type description
14,932
def get_tu ( source , lang = 'c' , all_warnings = False , flags = None ) : args = list ( flags or [ ] ) name = 't.c' if lang == 'cpp' : name = 't.cpp' args . append ( '-std=c++11' ) elif lang == 'objc' : name = 't.m' elif lang != 'c' : raise Exception ( 'Unknown language: %s' % lang ) if all_warnings : args += [ '-Wall...
Obtain a translation unit from source and language .
14,933
def get_cursor ( source , spelling ) : children = [ ] if isinstance ( source , Cursor ) : children = source . get_children ( ) else : children = source . cursor . get_children ( ) for cursor in children : if cursor . spelling == spelling : return cursor result = get_cursor ( cursor , spelling ) if result is not None : ...
Obtain a cursor from a source object .
14,934
def get_cursors ( source , spelling ) : cursors = [ ] children = [ ] if isinstance ( source , Cursor ) : children = source . get_children ( ) else : children = source . cursor . get_children ( ) for cursor in children : if cursor . spelling == spelling : cursors . append ( cursor ) cursors . extend ( get_cursors ( curs...
Obtain all cursors from a source object with a specific spelling .
14,935
def enable_fundamental_type_wrappers ( self ) : self . enable_fundamental_type_wrappers = lambda : True import pkgutil headers = pkgutil . get_data ( 'ctypeslib' , 'data/fundamental_type_name.tpl' ) . decode ( ) from clang . cindex import TypeKind size = str ( self . parser . get_ctypes_size ( TypeKind . LONGDOUBLE ) /...
If a type is a int128 a long_double_t or a void some placeholders need to be in the generated code to be valid .
14,936
def enable_pointer_type ( self ) : self . enable_pointer_type = lambda : True import pkgutil headers = pkgutil . get_data ( 'ctypeslib' , 'data/pointer_type.tpl' ) . decode ( ) import ctypes from clang . cindex import TypeKind word_size = self . parser . get_ctypes_size ( TypeKind . POINTER ) // 8 word_type = self . pa...
If a type is a pointer a platform - independent POINTER_T type needs to be in the generated code .
14,937
def Alias ( self , alias ) : if self . generate_comments : self . print_comment ( alias ) print ( "%s = %s # alias" % ( alias . name , alias . alias ) , file = self . stream ) self . _aliases += 1 return
Handles Aliases . No test cases yet
14,938
def get_undeclared_type ( self , item ) : if item in self . done : return None if isinstance ( item , typedesc . FundamentalType ) : return None if isinstance ( item , typedesc . PointerType ) : return self . get_undeclared_type ( item . typ ) if isinstance ( item , typedesc . ArrayType ) : return self . get_undeclared...
Checks if a typed has already been declared in the python output or is a builtin python type .
14,939
def FundamentalType ( self , _type ) : log . debug ( 'HERE in FundamentalType for %s %s' , _type , _type . name ) if _type . name in [ "None" , "c_long_double_t" , "c_uint128" , "c_int128" ] : self . enable_fundamental_type_wrappers ( ) return _type . name return "ctypes.%s" % ( _type . name )
Returns the proper ctypes class name for a fundamental type
14,940
def _generate ( self , item , * args ) : if item in self . done : return if self . generate_locations and item . location : print ( "# %s:%d" % item . location , file = self . stream ) if self . generate_comments : self . print_comment ( item ) log . debug ( "generate %s, %s" , item . __class__ . __name__ , item . name...
wraps execution of specific methods .
14,941
def example ( ) : ldata = 200 degrees = np . arange ( ldata + 1 , dtype = float ) degrees [ 0 ] = np . inf power = degrees ** ( - 1 ) clm1 = pyshtools . SHCoeffs . from_random ( power , exact_power = False ) clm2 = pyshtools . SHCoeffs . from_random ( power , exact_power = True ) fig , ax = plt . subplots ( ) ax . plot...
Plot random phase and Gaussian random variable spectra .
14,942
def plot_rad ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = '$g_r$, m s$^{-2}$' , ax = None , show = True , fname = None , ** kwargs ) : if ax is None : fig , axes = self . rad . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label , show = False , ** kwargs ) if show ...
Plot the radial component of the gravity field .
14,943
def plot_theta ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = '$g_\\theta$, m s$^{-2}$' , ax = None , show = True , fname = None , ** kwargs ) : if ax is None : fig , axes = self . theta . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label , show = False , ** kwargs ...
Plot the theta component of the gravity field .
14,944
def plot_phi ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = '$g_\phi$, m s$^{-2}$' , ax = None , show = True , fname = None , ** kwargs ) : if ax is None : fig , axes = self . phi . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label , show = False , ** kwargs ) if sh...
Plot the phi component of the gravity field .
14,945
def plot_total ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if self . normal_gravity is True : if cb_label is None : cb_label = 'Gravity disturbance, mGal' else : if cb_label is None : cb_label = 'Gravity disturbance, m s$^{-2}$' if ax...
Plot the total gravity disturbance .
14,946
def plot_pot ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = 'Potential, m$^2$ s$^{-2}$' , ax = None , show = True , fname = None , ** kwargs ) : if ax is None : fig , axes = self . pot . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label , show = False , ** kwargs ) ...
Plot the gravitational potential .
14,947
def plot ( self , colorbar = True , cb_orientation = 'horizontal' , tick_interval = [ 60 , 60 ] , minor_tick_interval = [ 20 , 20 ] , xlabel = 'Longitude' , ylabel = 'Latitude' , axes_labelsize = 9 , tick_labelsize = 8 , show = True , fname = None , ** kwargs ) : if colorbar is True : if cb_orientation == 'horizontal' ...
Plot the three vector components of the gravity field and the gravity disturbance .
14,948
def expand ( self , nmax = None , grid = 'DH2' , zeros = None ) : if type ( grid ) != str : raise ValueError ( 'grid must be a string. ' + 'Input type was {:s}' . format ( str ( type ( grid ) ) ) ) if nmax is None : nmax = self . nmax if self . galpha . kind == 'cap' : shcoeffs = _shtools . SlepianCoeffsToSH ( self . f...
Expand the function on a grid using the first n Slepian coefficients .
14,949
def to_shcoeffs ( self , nmax = None , normalization = '4pi' , csphase = 1 ) : if type ( normalization ) != str : raise ValueError ( 'normalization must be a string. ' + 'Input type was {:s}' . format ( str ( type ( normalization ) ) ) ) if normalization . lower ( ) not in set ( [ '4pi' , 'ortho' , 'schmidt' ] ) : rais...
Return the spherical harmonic coefficients using the first n Slepian coefficients .
14,950
def _shtools_status_message ( status ) : if ( status == 1 ) : errmsg = 'Improper dimensions of input array.' elif ( status == 2 ) : errmsg = 'Improper bounds for input variable.' elif ( status == 3 ) : errmsg = 'Error allocating memory.' elif ( status == 4 ) : errmsg = 'File IO error.' else : errmsg = 'Unhandled Fortra...
Determine error message to print when a SHTOOLS Fortran 95 routine exits improperly .
14,951
def from_cap ( cls , theta , lmax , clat = None , clon = None , nmax = None , theta_degrees = True , coord_degrees = True , dj_matrix = None ) : if theta_degrees : tapers , eigenvalues , taper_order = _shtools . SHReturnTapers ( _np . radians ( theta ) , lmax ) else : tapers , eigenvalues , taper_order = _shtools . SHR...
Construct spherical cap Slepian functions .
14,952
def from_mask ( cls , dh_mask , lmax , nmax = None ) : if nmax is None : nmax = ( lmax + 1 ) ** 2 else : if nmax > ( lmax + 1 ) ** 2 : raise ValueError ( 'nmax must be less than or equal to ' + '(lmax + 1)**2. lmax = {:d} and nmax = {:d}' . format ( lmax , nmax ) ) if dh_mask . shape [ 0 ] % 2 != 0 : raise ValueError (...
Construct Slepian functions that are optimally concentrated within the region specified by a mask .
14,953
def expand ( self , flm , nmax = None ) : if nmax is None : nmax = ( self . lmax + 1 ) ** 2 elif nmax is not None and nmax > ( self . lmax + 1 ) ** 2 : raise ValueError ( "nmax must be less than or equal to (lmax+1)**2 " + "where lmax is {:s}. Input value is {:s}" . format ( repr ( self . lmax ) , repr ( nmax ) ) ) coe...
Return the Slepian expansion coefficients of the input function .
14,954
def spectra ( self , alpha = None , nmax = None , convention = 'power' , unit = 'per_l' , base = 10. ) : if alpha is None : if nmax is None : nmax = self . nmax spectra = _np . zeros ( ( self . lmax + 1 , nmax ) ) for iwin in range ( nmax ) : coeffs = self . to_array ( iwin ) spectra [ : , iwin ] = _spectrum ( coeffs ,...
Return the spectra of one or more Slepian functions .
14,955
def _taper2coeffs ( self , alpha ) : taperm = self . orders [ alpha ] coeffs = _np . zeros ( ( 2 , self . lmax + 1 , self . lmax + 1 ) ) if taperm < 0 : coeffs [ 1 , : , abs ( taperm ) ] = self . tapers [ : , alpha ] else : coeffs [ 0 , : , abs ( taperm ) ] = self . tapers [ : , alpha ] return coeffs
Return the spherical harmonic coefficients of the unrotated Slepian function i as an array where i = 0 is the best concentrated function .
14,956
def plot_total ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = '$|B|$, nT' , ax = None , show = True , fname = None , ** kwargs ) : if ax is None : fig , axes = self . total . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label , show = False , ** kwargs ) if show : fi...
Plot the total magnetic intensity .
14,957
def spharm_lm ( l , m , theta , phi , normalization = '4pi' , kind = 'real' , csphase = 1 , degrees = True ) : if l < 0 : raise ValueError ( "The degree l must be greater or equal than 0. Input value was {:s}." . format ( repr ( l ) ) ) if m > l : raise ValueError ( "The order m must be less than or equal to the degree...
Compute the spherical harmonic function for a specific degree and order .
14,958
def set_coeffs ( self , values , ls , ms ) : values = _np . array ( values ) ls = _np . array ( ls ) ms = _np . array ( ms ) mneg_mask = ( ms < 0 ) . astype ( _np . int ) self . coeffs [ mneg_mask , ls , _np . abs ( ms ) ] = values
Set spherical harmonic coefficients in - place to specified values .
14,959
def convert ( self , normalization = None , csphase = None , lmax = None ) : if normalization is None : normalization = self . normalization if csphase is None : csphase = self . csphase if lmax is None : lmax = self . lmax if type ( normalization ) != str : raise ValueError ( 'normalization must be a string. ' 'Input ...
Return an SHMagCoeffs class instance with a different normalization convention .
14,960
def pad ( self , lmax ) : clm = self . copy ( ) if lmax <= self . lmax : clm . coeffs = clm . coeffs [ : , : lmax + 1 , : lmax + 1 ] clm . mask = clm . mask [ : , : lmax + 1 , : lmax + 1 ] if self . errors is not None : clm . errors = clm . errors [ : , : lmax + 1 , : lmax + 1 ] else : clm . coeffs = _np . pad ( clm . ...
Return an SHMagCoeffs class where the coefficients are zero padded or truncated to a different lmax .
14,961
def change_ref ( self , r0 = None , lmax = None ) : if lmax is None : lmax = self . lmax clm = self . pad ( lmax ) if r0 is not None and r0 != self . r0 : for l in _np . arange ( lmax + 1 ) : clm . coeffs [ : , l , : l + 1 ] *= ( self . r0 / r0 ) ** ( l + 2 ) if self . errors is not None : clm . errors [ : , l , : l + ...
Return a new SHMagCoeffs class instance with a different reference r0 .
14,962
def expand ( self , a = None , f = None , lmax = None , lmax_calc = None , sampling = 2 ) : if a is None : a = self . r0 if f is None : f = 0. if lmax is None : lmax = self . lmax if lmax_calc is None : lmax_calc = lmax if self . errors is not None : coeffs , errors = self . to_array ( normalization = 'schmidt' , cspha...
Create 2D cylindrical maps on a flattened and rotating ellipsoid of all three components of the magnetic field the total magnetic intensity and the magnetic potential and return as a SHMagGrid class instance .
14,963
def tensor ( self , a = None , f = None , lmax = None , lmax_calc = None , sampling = 2 ) : if a is None : a = self . r0 if f is None : f = 0. if lmax is None : lmax = self . lmax if lmax_calc is None : lmax_calc = lmax if self . errors is not None : coeffs , errors = self . to_array ( normalization = 'schmidt' , cspha...
Create 2D cylindrical maps on a flattened ellipsoid of the 9 components of the magnetic field tensor in a local north - oriented reference frame and return an SHMagTensor class instance .
14,964
def legendre ( lmax , z , normalization = '4pi' , csphase = 1 , cnorm = 0 , packed = False ) : if lmax < 0 : raise ValueError ( "lmax must be greater or equal to 0. Input value was {:s}." . format ( repr ( lmax ) ) ) if normalization . lower ( ) not in ( '4pi' , 'ortho' , 'schmidt' , 'unnorm' ) : raise ValueError ( "Th...
Compute all the associated Legendre functions up to a maximum degree and order .
14,965
def legendre_lm ( l , m , z , normalization = '4pi' , csphase = 1 , cnorm = 0 ) : if l < 0 : raise ValueError ( "The degree l must be greater or equal to 0. Input value was {:s}." . format ( repr ( l ) ) ) if m < 0 : raise ValueError ( "The order m must be greater or equal to 0. Input value was {:s}." . format ( repr (...
Compute the associated Legendre function for a specific degree and order .
14,966
def _iscomment ( line ) : if line . isspace ( ) : return True elif len ( line . split ( ) ) >= 3 : try : if line . split ( ) [ 0 ] . isdecimal ( ) and line . split ( ) [ 1 ] . isdecimal ( ) : return False except : if ( line . decode ( ) . split ( ) [ 0 ] . isdecimal ( ) and line . split ( ) [ 1 ] . decode ( ) . isdecim...
Determine if a line is a comment line . A valid line contains at least three words with the first two being integers . Note that Python 2 and 3 deal with strings differently .
14,967
def process_f2pydoc ( f2pydoc ) : docparts = re . split ( '\n--' , f2pydoc ) if len ( docparts ) == 4 : doc_has_optionals = True elif len ( docparts ) == 3 : doc_has_optionals = False else : print ( '-- uninterpretable f2py documentation --' ) return f2pydoc docparts [ 0 ] = re . sub ( '[\[(,]\w+_d\d' , '' , docparts [...
this function replace all optional _d0 arguments with their default values in the function signature . These arguments are not intended to be used and signify merely the array dimensions of the associated argument .
14,968
def from_cap ( cls , theta , lwin , clat = None , clon = None , nwin = None , theta_degrees = True , coord_degrees = True , dj_matrix = None , weights = None ) : if theta_degrees : tapers , eigenvalues , taper_order = _shtools . SHReturnTapers ( _np . radians ( theta ) , lwin ) else : tapers , eigenvalues , taper_order...
Construct spherical cap localization windows .
14,969
def from_mask ( cls , dh_mask , lwin , nwin = None , weights = None ) : if nwin is None : nwin = ( lwin + 1 ) ** 2 else : if nwin > ( lwin + 1 ) ** 2 : raise ValueError ( 'nwin must be less than or equal to ' + '(lwin + 1)**2. lwin = {:d} and nwin = {:d}' . format ( lwin , nwin ) ) if dh_mask . shape [ 0 ] % 2 != 0 : r...
Construct localization windows that are optimally concentrated within the region specified by a mask .
14,970
def to_array ( self , itaper , normalization = '4pi' , csphase = 1 ) : if type ( normalization ) != str : raise ValueError ( 'normalization must be a string. ' + 'Input type was {:s}' . format ( str ( type ( normalization ) ) ) ) if normalization . lower ( ) not in ( '4pi' , 'ortho' , 'schmidt' ) : raise ValueError ( "...
Return the spherical harmonic coefficients of taper i as a numpy array .
14,971
def to_shcoeffs ( self , itaper , normalization = '4pi' , csphase = 1 ) : if type ( normalization ) != str : raise ValueError ( 'normalization must be a string. ' + 'Input type was {:s}' . format ( str ( type ( normalization ) ) ) ) if normalization . lower ( ) not in set ( [ '4pi' , 'ortho' , 'schmidt' ] ) : raise Val...
Return the spherical harmonic coefficients of taper i as a SHCoeffs class instance .
14,972
def to_shgrid ( self , itaper , grid = 'DH2' , zeros = None ) : if type ( grid ) != str : raise ValueError ( 'grid must be a string. ' + 'Input type was {:s}' . format ( str ( type ( grid ) ) ) ) if grid . upper ( ) in ( 'DH' , 'DH1' ) : gridout = _shtools . MakeGridDH ( self . to_array ( itaper ) , sampling = 1 , norm...
Evaluate the coefficients of taper i on a spherical grid and return a SHGrid class instance .
14,973
def multitaper_spectrum ( self , clm , k , convention = 'power' , unit = 'per_l' , ** kwargs ) : return self . _multitaper_spectrum ( clm , k , convention = convention , unit = unit , ** kwargs )
Return the multitaper spectrum estimate and standard error .
14,974
def multitaper_cross_spectrum ( self , clm , slm , k , convention = 'power' , unit = 'per_l' , ** kwargs ) : return self . _multitaper_cross_spectrum ( clm , slm , k , convention = convention , unit = unit , ** kwargs )
Return the multitaper cross - spectrum estimate and standard error .
14,975
def spectra ( self , itaper = None , nwin = None , convention = 'power' , unit = 'per_l' , base = 10. ) : if itaper is None : if nwin is None : nwin = self . nwin spectra = _np . zeros ( ( self . lwin + 1 , nwin ) ) for iwin in range ( nwin ) : coeffs = self . to_array ( iwin ) spectra [ : , iwin ] = _spectrum ( coeffs...
Return the spectra of one or more localization windows .
14,976
def coupling_matrix ( self , lmax , nwin = None , weights = None , mode = 'full' ) : if weights is not None : if nwin is not None : if len ( weights ) != nwin : raise ValueError ( 'Length of weights must be equal to nwin. ' + 'len(weights) = {:d}, nwin = {:d}' . format ( len ( weights ) , nwin ) ) else : if len ( weigh...
Return the coupling matrix of the first nwin tapers . This matrix relates the global power spectrum to the expectation of the localized multitaper spectrum .
14,977
def plot_coupling_matrix ( self , lmax , nwin = None , weights = None , mode = 'full' , axes_labelsize = None , tick_labelsize = None , show = True , ax = None , fname = None ) : figsize = ( _mpl . rcParams [ 'figure.figsize' ] [ 0 ] , _mpl . rcParams [ 'figure.figsize' ] [ 0 ] ) if axes_labelsize is None : axes_labels...
Plot the multitaper coupling matrix .
14,978
def _taper2coeffs ( self , itaper ) : taperm = self . orders [ itaper ] coeffs = _np . zeros ( ( 2 , self . lwin + 1 , self . lwin + 1 ) ) if taperm < 0 : coeffs [ 1 , : , abs ( taperm ) ] = self . tapers [ : , itaper ] else : coeffs [ 0 , : , abs ( taperm ) ] = self . tapers [ : , itaper ] return coeffs
Return the spherical harmonic coefficients of the unrotated taper i as an array where i = 0 is the best concentrated .
14,979
def rotate ( self , clat , clon , coord_degrees = True , dj_matrix = None , nwinrot = None ) : self . coeffs = _np . zeros ( ( ( self . lwin + 1 ) ** 2 , self . nwin ) ) self . clat = clat self . clon = clon self . coord_degrees = coord_degrees if nwinrot is not None : self . nwinrot = nwinrot else : self . nwinrot = s...
Rotate the spherical - cap windows centered on the North pole to clat and clon and save the spherical harmonic coefficients in the attribute coeffs .
14,980
def plot_vxx ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _vxx_label if ax is None : fig , axes = self . vxx . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label ,...
Plot the Vxx component of the tensor .
14,981
def plot_vyy ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _vyy_label if ax is None : fig , axes = self . vyy . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label ,...
Plot the Vyy component of the tensor .
14,982
def plot_vzz ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _vzz_label if ax is None : fig , axes = self . vzz . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label ,...
Plot the Vzz component of the tensor .
14,983
def plot_vxy ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _vxy_label if ax is None : fig , axes = self . vxy . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label ,...
Plot the Vxy component of the tensor .
14,984
def plot_vyx ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _vyx_label if ax is None : fig , axes = self . vyx . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label ,...
Plot the Vyx component of the tensor .
14,985
def plot_vxz ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _vxz_label if ax is None : fig , axes = self . vxz . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label ,...
Plot the Vxz component of the tensor .
14,986
def plot_vzx ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _vzx_label if ax is None : fig , axes = self . vzx . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label ,...
Plot the Vzx component of the tensor .
14,987
def plot_vyz ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _vyz_label if ax is None : fig , axes = self . vyz . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label ,...
Plot the Vyz component of the tensor .
14,988
def plot_vzy ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _vzy_label if ax is None : fig , axes = self . vzy . plot ( colorbar = colorbar , cb_orientation = cb_orientation , cb_label = cb_label ,...
Plot the Vzy component of the tensor .
14,989
def plot_invar ( self , colorbar = True , cb_orientation = 'horizontal' , tick_interval = [ 60 , 60 ] , minor_tick_interval = [ 20 , 20 ] , xlabel = 'Longitude' , ylabel = 'Latitude' , axes_labelsize = 9 , tick_labelsize = 8 , show = True , fname = None , ** kwargs ) : if colorbar is True : if cb_orientation == 'horizo...
Plot the three invariants of the tensor and the derived quantity I .
14,990
def plot_eig1 ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _eig1_label if self . eig1 is None : self . compute_eig ( ) if ax is None : fig , axes = self . eig1 . plot ( colorbar = colorbar , cb_o...
Plot the first eigenvalue of the tensor .
14,991
def plot_eig2 ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _eig2_label if self . eig2 is None : self . compute_eig ( ) if ax is None : fig , axes = self . eig2 . plot ( colorbar = colorbar , cb_o...
Plot the second eigenvalue of the tensor .
14,992
def plot_eig3 ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _eig3_label if self . eig3 is None : self . compute_eig ( ) if ax is None : fig , axes = self . eig3 . plot ( colorbar = colorbar , cb_o...
Plot the third eigenvalue of the tensor .
14,993
def plot_eigs ( self , colorbar = True , cb_orientation = 'vertical' , tick_interval = [ 60 , 60 ] , minor_tick_interval = [ 20 , 20 ] , xlabel = 'Longitude' , ylabel = 'Latitude' , axes_labelsize = 9 , tick_labelsize = 8 , show = True , fname = None , ** kwargs ) : if colorbar is True : if cb_orientation == 'horizonta...
Plot the three eigenvalues of the tensor .
14,994
def plot_eigh1 ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _eigh1_label if self . eigh1 is None : self . compute_eigh ( ) if ax is None : fig , axes = self . eigh1 . plot ( colorbar = colorbar ,...
Plot the first eigenvalue of the horizontal tensor .
14,995
def plot_eigh2 ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _eigh2_label if self . eigh2 is None : self . compute_eigh ( ) if ax is None : fig , axes = self . eigh2 . plot ( colorbar = colorbar ,...
Plot the second eigenvalue of the horizontal tensor .
14,996
def plot_eighh ( self , colorbar = True , cb_orientation = 'vertical' , cb_label = None , ax = None , show = True , fname = None , ** kwargs ) : if cb_label is None : cb_label = self . _eighh_label if self . eighh is None : self . compute_eigh ( ) if ax is None : fig , axes = self . eighh . plot ( colorbar = colorbar ,...
Plot the maximum absolute value eigenvalue of the horizontal tensor .
14,997
def plot_eigh ( self , colorbar = True , cb_orientation = 'vertical' , tick_interval = [ 60 , 60 ] , minor_tick_interval = [ 20 , 20 ] , xlabel = 'Longitude' , ylabel = 'Latitude' , axes_labelsize = 9 , tick_labelsize = 8 , show = True , fname = None , ** kwargs ) : if colorbar is True : if cb_orientation == 'horizonta...
Plot the two eigenvalues and maximum absolute value eigenvalue of the horizontal tensor .
14,998
def get_version ( ) : d = os . path . dirname ( __file__ ) with open ( os . path . join ( d , 'VERSION' ) ) as f : vre = re . compile ( '.Version: (.+)$' , re . M ) version = vre . search ( f . read ( ) ) . group ( 1 ) if os . path . isdir ( os . path . join ( d , '.git' ) ) : cmd = 'git describe --tags' try : git_vers...
Get version from git and VERSION file .
14,999
def get_compiler_flags ( ) : compiler = get_default_fcompiler ( ) if compiler == 'absoft' : flags = [ '-m64' , '-O3' , '-YEXT_NAMES=LCS' , '-YEXT_SFX=_' , '-fpic' , '-speed_math=10' ] elif compiler == 'gnu95' : flags = [ '-m64' , '-fPIC' , '-O3' , '-ffast-math' ] elif compiler == 'intel' : flags = [ '-m64' , '-fpp' , '...
Set fortran flags depending on the compiler .