Changeset 3336


Ignore:
Timestamp:
08/02/08 20:08:53 (11 years ago)
Author:
astephen
Message:
 
Location:
nappy/trunk/nappy/utils
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy/utils/common_utils.py

    r3321 r3336  
    7575    else: 
    7676        raise Exception("Could not resolve the dictionary object to create a suitable NASA Ames File Format Index (FFI). Please modify the contents and try again.") 
     77     
    7778 
    7879 
    79 def openNAFile(filename, mode="r", naDict=None, spacer="    ", floatFormat="%8.3f"): 
     80def modifyNADictCopy(indict, v_new, start, end, ivol, nvol): 
    8081    """ 
    81     Function wrapper around the NASA Ames File classes. Any NASA Ames 
    82     file can be opened through this function and the appropriate read or 
    83     write NASA Ames File class instance is returned. 
     82    Returns a copy of a dictionary with some modifications. 
    8483    """ 
    85     if mode == "r": 
    86         ffi = readFFI(filename) 
    87         return apply(getNAFileClass(ffi), (filename, mode)) 
     84    newDict = {} 
     85    for key,value in indict.items():  
     86        if key == "X": 
     87            newlist = indict["X"][start:end] 
     88            newDict["X"] = newlist 
     89        elif key == "V": 
     90            newDict["V"] = v_new 
     91        elif key == "IVOL": 
     92            newDict["IVOL"] = ivol 
     93        elif key == "NVOL": 
     94            newDict["NVOL"] = nvol 
     95        else: 
     96            newDict[key] = value 
     97    return newDict 
    8898 
    89     elif mode == "w": 
    90         if naDict.has_key('FFI') and type(naDict['FFI']) == type(3): 
    91             ffi = naDict['FFI'] 
    92         else: 
    93             ffi = chooseFFI(naDict) 
    94             naDict['FFI'] = ffi 
    95             print "\nFormat identified as:", ffi     
    96         return apply(getNAFileClass(ffi), (filename,), {"mode":mode, "naDict":naDict, "spacer":spacer, "floatFormat":floatFormat}) 
    97     else: 
    98         raise Exception("File mode not recognised '" + mode + "'.") 
    99      
    10099 
    101100def getVersion(): 
  • nappy/trunk/nappy/utils/list_manipulator.py

    r3321 r3336  
    77=================== 
    88 
    9 A container module for RecursiveListManipulator classes that transform 
     9Contains a set of list-related functions and the RecursiveListManipulator  
     10class that is wrapped in nice functions. This class transforms 
    1011arrays into multi-dimensional list objects. Wrapper functions are 
    1112provided to call these directly as functions. 
     
    1314""" 
    1415 
     16def arrayToList(array, inlist): 
     17    """  
     18    Takes an n-dimensional Numeric array and converts it to an  
     19    n-dimensional list object. 
     20    """ 
     21    dimlist = array.shape 
     22    if len(dimlist[1:])>0: 
     23        for i in range(dimlist[0]): 
     24            arrayToList(inlist[i], array[i]) 
     25    else: 
     26        for i in range(dimlist[0]): 
     27            inlist.append(array[i]) 
     28    return inlist 
     29 
     30 
     31def listOfListsCreator(inlist, dimlist): 
     32    """ 
     33    Creates a list of lists with dimensions defined in dimlist (a list of integers). 
     34    """ 
     35    if len(dimlist[1:]) > 0: 
     36        for i in range(dimlist[0]): 
     37            inlist.append([]) 
     38            listOfListsCreator(inlist[i], array, dimlist[1:]) 
     39    return inlist 
     40 
     41 
    1542def recursiveListPopulator(inlist, array, dimlist): 
    16     """ 
    17     Function wrapper around class method RecursiveListManipulator().populator(). 
    18     """ 
     43    "Function wrapper around class method RecursiveListManipulator().populator()." 
    1944    return RecursiveListManipulator().populator(inlist, array, dimlist) 
    2045 
    2146 
    2247def recursiveListWriter(inlist, dimlist, spacer="    ", floatFormat="%8.3f"): 
    23     """ 
    24     Function wrapper around class method RecursiveListManipulator().writeLines(). 
    25     """ 
     48    "Function wrapper around class method RecursiveListManipulator().writeLines()." 
    2649    return RecursiveListManipulator().writeLines(inlist, dimlist, spacer=spacer, floatFormat=floatFormat) 
    2750 
    2851 
    2952class RecursiveListManipulator: 
    30  
    3153    """ 
    32     Methods to convert a 1-D array into a multi-dimensional list. 
     54    Container class with methods to convert a 1-D array into a multi-dimensional list. 
    3355    """ 
    3456 
Note: See TracChangeset for help on using the changeset viewer.