Changeset 3966 for nappy


Ignore:
Timestamp:
01/06/08 23:24:09 (11 years ago)
Author:
astephen
Message:

Updated nappy so it can handle numpy and cdms2 - but only partially tested!

Location:
nappy/trunk/nappy
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy/cdms_utils/axis_utils.py

    r3482 r3966  
    1818 
    1919# Import external packages 
    20 import cdms 
     20try: 
     21    import cdms2 as cdms 
     22except: 
     23    import cdms 
     24 
    2125 
    2226def areAxesIdentical(ax1, ax2, is_subset=False, check_id=True): 
     
    4347    if is_subset == False: 
    4448        # Check lengths and values 
    45         if len(ax1) != len(ax2) or ax1._data_ != ax2._data_: return False 
     49        if (len(ax1) != len(ax2)) or (ax1.getData()[:].tolist() != ax2.getData()[:].tolist()): return False 
    4650    elif is_subset == True: 
    4751        # Check whether values are a subset 
  • nappy/trunk/nappy/cdms_utils/var_utils.py

    r3741 r3966  
    1919 
    2020# Import external packages 
    21 import cdms 
     21try: 
     22    import cdms2 as cdms 
     23except: 
     24    import cdms 
     25 
    2226cdms.setAutoBounds("off")  
    2327 
  • nappy/trunk/nappy/na_file/na_file_2010.py

    r3521 r3966  
    7070 
    7171        for i in range(self.NIV - 1): 
     72            print "NIV:", self.NIV, "NXDEF[i]:", self.NXDEF[i], "self.X[i + 1][0:self.NXDEF[i]]", self.X[i + 1][0:self.NXDEF[i]] 
    7273            X_lines.append((self.format * self.NXDEF[i] % tuple(self.X[i + 1][0:self.NXDEF[i]])).rstrip(" ,") + "\n") 
    7374 
  • nappy/trunk/nappy/nappy_api.py

    r3630 r3966  
    126126# Import third-party software 
    127127try: 
    128     import cdms 
     128    import cdms2 as cdms 
    129129except: 
    130     print "WARNING: You cannot use NAPpy's NetCDF conversion tools as your system does not have CDMS installed, or it is not in your sys.path." 
    131     cdms = False 
     130    try: 
     131        import cdms 
     132    except: 
     133        print "WARNING: You cannot use NAPpy's NetCDF conversion tools as your system does not have CDMS installed, or it is not in your sys.path." 
     134        cdms = False 
    132135 
    133136# Import local modules 
  • nappy/trunk/nappy/nc_interface/cdms_to_na.py

    r3492 r3966  
    2727    raise na_error.NAPlatformError("Windows does not support CDMS. CDMS is required to convert to CDMS objects and NetCDF.") 
    2828try: 
    29     import cdms, Numeric 
     29    import cdms2 as cdms 
     30    import numpy as N 
    3031except: 
    31     raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.") 
     32    try: 
     33        import cdms 
     34        import Numeric as N 
     35    except: 
     36        raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.") 
    3237 
    3338cdms.setAutoBounds("off")  
     
    133138                var_metadata = var_obj.attributes        
    134139                var_value = var_obj 
    135                 var_obj = cdms.createVariable(Numeric.array(var_obj),  
     140                var_obj = cdms.createVariable(N.array(var_obj),  
    136141                id=nappy.cdms_utils.var_utils.getBestName(var_metadata).replace(" ", "_"),  
    137142                                   attributes=var_metadata) 
  • nappy/trunk/nappy/nc_interface/na_content_collector.py

    r3615 r3966  
    3232    raise na_error.NAPlatformError("Windows does not support CDMS. CDMS is required to convert to CDMS objects and NetCDF.") 
    3333try: 
    34     import cdms, Numeric 
     34    import cdms2 as cdms 
     35    import numpy as N 
    3536except: 
    36     raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.") 
     37    try: 
     38        import cdms 
     39        import Numeric as N 
     40    except: 
     41        raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.") 
    3742 
    3843cdms.setAutoBounds("off")  
     
    133138            
    134139            # Update highest if highest found or if equals highest with bigger size 
    135             if rank > highest_rank or (rank == highest_rank and var.size() > best_var.size()): 
     140            try: 
     141                var.size = var.size() ; best_var.size = best_var.size() 
     142            except: 
     143                pass 
     144            if rank > highest_rank or (rank == highest_rank and var.size > best_var.size): 
    136145                highest_rank = rank 
    137146                best_var = var 
     
    625634 
    626635            for scom,value in var.attributes.items(): 
    627                 if type(value) in (type([]), type(Numeric.array([0]))) and len(value) == 1: 
     636                if type(value) in (type([]), type(N.array([0]))) and len(value) == 1: 
    628637                    value = value[0] 
    629638 
     
    681690        key/value pairs. 
    682691        """ 
     692        warning_message = "Nappy Warning: Could not get the first date in the file. You will need to manually edit the output file." 
     693 
    683694        # Check if DATE field previously known in NASA Ames file 
    684695        time_now = [int(i) for i in time.strftime("%Y %m %d", time.localtime(time.time())).split()] 
     
    695706                self.na_dict["DATE"] = [int(i) for i in str(first_day).split(" ")[0].replace("-", " ").split()] 
    696707            except: 
    697                 msg = "Nappy Warning: Could not get the first date in the file. You will need to manually edit the output file." 
     708                msg = warning_message 
    698709                print msg 
    699710                self.output_message.append(msg) 
     
    701712        else:  
    702713            if not self.na_dict.has_key("DATE"): 
    703                 msg = "Nappy Warning: Could not get the first date in the file. You will need to manually edit the output file." 
     714                msg = warning_message 
    704715                print msg 
    705716                self.output_message.append(msg) 
  • nappy/trunk/nappy/nc_interface/na_to_cdms.py

    r3615 r3966  
    2727if sys.platform.find("win") > -1: 
    2828    raise na_error.NAPlatformError("Windows does not support CDMS. CDMS is required to convert to CDMS objects and NetCDF.") 
     29 
    2930try: 
    30     import cdms, Numeric 
     31    import cdms2 as cdms 
     32    import numpy as N 
    3133except: 
    32     raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.") 
    33 cdms.setAutoBounds("off")  
     34    try: 
     35        import cdms 
     36        import Numeric as N 
     37    except: 
     38        raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.") 
     39 
    3440 
    3541# Define global variables 
     
    222228        print msg 
    223229        self.output_message.append(msg) 
    224         array = Numeric.array(self.na_file_obj.V[var_number]) 
     230        array = N.array(self.na_file_obj.V[var_number]) 
    225231        array = array * scal 
    226232        # Set up axes 
     
    277283        """ 
    278284        (var_name, units, miss, scal) = self.na_file_obj.getAuxVariable(avar_number) 
    279         array = Numeric.array(self.na_file_obj.A[avar_number]) 
     285        array = N.array(self.na_file_obj.A[avar_number]) 
    280286        array = array * scal 
    281287 
  • nappy/trunk/nappy/nc_interface/na_to_nc.py

    r3405 r3966  
    1414 
    1515# Imports from external packages 
    16 import cdms 
     16try: 
     17    import cdms2 as cdms 
     18except: 
     19    try: 
     20        import cdms 
     21    except: 
     22        raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.") 
     23 
    1724 
    1825# Import from nappy package 
  • nappy/trunk/nappy/nc_interface/nc_to_na.py

    r3630 r3966  
    2626if sys.platform.find("win") > -1: 
    2727    raise na_error.NAPlatformError("Windows does not support CDMS. CDMS is required to convert to CDMS objects and NetCDF.") 
     28 
    2829try: 
    29     import cdms, Numeric 
     30    import cdms2 as cdms 
    3031except: 
    31     raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.") 
     32    try: 
     33        import cdms 
     34    except: 
     35        raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.") 
    3236 
    3337cdms.setAutoBounds("off")  
Note: See TracChangeset for help on using the changeset viewer.