Ignore:
Timestamp:
08/25/20 00:32:13 (5 years ago)
Author:
jdquinn
Message:

CHG: Saving chnages so that Basile has access to potential fix to solidearthmodel class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/qmu/helpers.py

    r25065 r25455  
    66
    77class struct(object):
    8     '''An empty struct that can be assigned arbitrary attributes'''
     8    """An empty struct that can be assigned arbitrary attributes"""
    99    pass
    1010
    1111
    1212class Lstruct(list):
    13     '''
     13    """
    1414    An empty struct that can be assigned arbitrary attributes but can also be
    1515    accesed as a list. Eg. x.y = 'hello', x[:] = ['w', 'o', 'r', 'l', 'd']
     
    4646    Sources:
    4747    -https://github.com/Vectorized/Python-Attribute-List
    48     '''
     48    """
    4949
    5050    def __new__(self, *args, **kwargs):
     
    6464
    6565class OrderedStruct(object):
    66     '''
     66    """
    6767    A form of dictionary-like structure that maintains the ordering in which
    6868    its fields/attributes and their corresponding values were added.
     
    113113    Note: to access internal fields use dir(x) (input fields will be included,
    114114    but are not technically internals)
    115     '''
     115    """
    116116
    117117    def __init__(self, *args):
    118         '''
     118        """
    119119        Provided either nothing or a series of strings, construct a structure
    120120        that will, when accessed as a list, return its fields in the same order
    121121        in which they were provided
    122         '''
     122        """
    123123
    124124        # keys and values
     
    187187
    188188    def __copy__(self):
    189         '''
     189        """
    190190        shallow copy, hard copies of trivial attributes,
    191191        references to structures like lists/OrderedDicts
    192192        unless redefined as an entirely different structure
    193         '''
     193        """
    194194        newInstance = type(self)()
    195195        for k, v in list(self.items()):
     
    198198
    199199    def __deepcopy__(self, memo=None):
    200         '''
     200        """
    201201        hard copy of all attributes
    202202        same thing but call deepcopy recursively
     
    204204        (see https://docs.python.org/2/library/copy.html  #copy.deepcopy )
    205205        but will generally work in this case
    206         '''
     206        """
    207207        newInstance = type(self)()
    208208        for k, v in list(self.items()):
     
    232232
    233233def isempty(x):
    234     '''
     234    """
    235235    returns true if object is +/-infinity, NaN, None, '', has length 0, or is
    236236    an array/matrix composed only of such components (includes mixtures of
    237237    "empty" types)
    238     '''
     238    """
    239239
    240240    if type(x) in [list, np.ndarray, tuple]:
     
    270270
    271271def fieldnames(x, ignore_internals=True):
    272     '''
     272    """
    273273    returns a list of fields of x
    274274    ignore_internals ignores all fieldnames starting with '_' and is True by
    275275    default
    276     '''
     276    """
    277277    result = list(vars(x).keys())
    278278
     
    284284
    285285def isfield(x, y, ignore_internals=True):
    286     '''
     286    """
    287287    is y is a field of x?
    288288    ignore_internals ignores all fieldnames starting with '_' and is True by
    289289    default
    290     '''
     290    """
    291291    return str(y) in fieldnames(x, ignore_internals)
    292292
    293293
    294294def fileparts(x):
    295     '''
     295    """
    296296    given:   "path/path/.../file_name.ext"
    297297    returns: [path, file_name, ext] (list of strings)
    298     '''
     298    """
    299299    try:
    300300        a = x[:x.rindex('/')]  #path
     
    311311
    312312def fullfile(*args):
    313     '''
     313    """
    314314    usage:
    315315        fullfile(path, path, ... , file_name + ext)
     
    322322        as final arguments ('file.doc') or ('file' + '.doc') will work
    323323        ('final', '.doc'), and the like, will not (you'd get 'final/.doc')
    324     '''
     324    """
    325325    result = str(args[0])
    326326    for i in range(len(args[1:])):
     
    334334
    335335def findline(fidi, s):
    336     '''
     336    """
    337337    returns full first line containing s (as a string), or None
    338338
     
    340340    use str(findline(f, s)).strip() to remove these, str() in case result is
    341341    None
    342     '''
     342    """
    343343    for line in fidi:
    344344        if s in line:
     
    348348
    349349def empty_nd_list(shape, filler=0., as_numpy_ndarray=False):
    350     '''
     350    """
    351351    returns a python list of the size/shape given (shape must be int or tuple)
    352352    the list will be filled with the optional second argument
     
    363363        empty_nd_list((5, 5), 0.0)  # returns a 5x5 matrix of 0.0's
    364364        empty_nd_list(5, None)  # returns a 5 long array of NaN
    365     '''
     365    """
    366366    result = np.empty(shape)
    367367    result.fill(filler)
Note: See TracChangeset for help on using the changeset viewer.