source: issm/oecreview/Archive/24684-25833/ISSM-25062-25063.diff@ 27230

Last change on this file since 27230 was 25834, checked in by Mathieu Morlighem, 4 years ago

CHG: added 24684-25833

File size: 4.3 KB
  • ../trunk-jpl/src/m/contrib/defleurian/netCDF/export_netCDF.py

     
    66
    77
    88def export_netCDF(md, filename):  # {{{
    9     res_time = time.time()
    109    debug = False
    1110    if path.exists(filename):
    1211        print('File {} allready exist'.format(filename))
     
    8685                    except AttributeError:
    8786                        subfields = dict.keys(md.__dict__[group].__dict__[field].__getitem__(0))
    8887
    89                     # for subfield in subfields:
    90                     #     if subfield not in['errlog', 'outlog']:
    91                     #         #first create the variable
    92                     #         try:
    93                     #             Var = md.__dict__[group].__dict__[field].__getitem__(0).__dict__[subfield]
    94                     #         except AttributeError:
    95                     #             Var = md.__dict__[group].__dict__[field].__getitem__(0)[subfield]
    96                     #         Var = SqueezeVar(Var)
    97                     #         #If first time we create a nc variable
    98                     #         if Listsize == len(TimeDim):
    99                     #             ExtraDim = 'Time'
    100                     #         else:
    101                     #             ExtraDim = 'Unlim'
    102                     #         if debug:
    103                     #             print("=$$=creating var for {}.{}.{}".format(group, field, subfield))
    104                     #         DimDict, ncvar = CreateVar(NCData, Var, subfield, Subgroup, DimDict, ExtraDim)
    105 
    106                     #         for listindex in range(0, Listsize):
    107                     #             try:
    108                     #                 Var = md.__dict__[group].__dict__[field].__getitem__(listindex).__dict__[subfield]
    109                     #             except AttributeError:
    110                     #                 Var = md.__dict__[group].__dict__[field].__getitem__(listindex)[subfield]
    111                     #             Var = SqueezeVar(Var)
    112                     #             #and fill it up
    113                     #             FillVar(ncvar, Var, listindex)
    114 
    11588                    for subfield in subfields:
    11689                        if subfield not in['errlog', 'outlog']:
    11790                            try:
     
    12598                                    Var = md.__dict__[group].__dict__[field].__getitem__(listindex).__dict__[subfield]
    12699                                except AttributeError:
    127100                                    Var = md.__dict__[group].__dict__[field].__getitem__(listindex)[subfield]
     101                                except KeyError:
     102                                    #Some fields only exist for the first step
     103                                    continue
    128104                                Var = SqueezeVar(Var)
    129105                                StackedVar = np.vstack((StackedVar, Var))
    130106                            if debug:
     
    173149                        if ncvar is not None:
    174150                            FillVar(ncvar, Var)
    175151    NCData.close()
    176     print("export time is {}".format(time.time() - res_time))
    177152
    178153# }}}
    179154
  • ../trunk-jpl/src/m/io/loadvars.py

     
    123123                        keylist = [key for key in curclass.variables]
    124124                        dimlist = [curclass.variables[key].dimensions for key in keylist]
    125125                        indexlist = np.arange(0, len(NCFile.dimensions['Time']))
    126                         if 'Time' in np.all(dimlist):
     126                        AllHaveTime = np.all(['Time' in dimtuple for dimtuple in dimlist])
     127                        if AllHaveTime:
    127128                            #Time dimension is in all the variables so we take that as stepnumber for the results
    128129                            listtype = curclass.classtype
    129130                            nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(NCFile.dimensions['Time'])))]
Note: See TracBrowser for help on using the repository browser.