Changeset 13032


Ignore:
Timestamp:
08/14/12 14:55:08 (13 years ago)
Author:
jschierm
Message:

CHG: Python any/all vs. numpy.any/numpy.all modifications (and more).

Location:
issm/trunk-jpl/src/m
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/boundaryconditions/SetIceShelfBC.py

    r13030 r13032  
    6969
    7070        #Create zeros basalforcings and surfaceforcings
    71         if all(numpy.isnan(md.surfaceforcings.precipitation)):
     71        if numpy.all(numpy.isnan(md.surfaceforcings.precipitation)):
    7272                md.surfaceforcings.precipitation=numpy.zeros(md.mesh.numberofvertices)
    7373                print '      no surfaceforcings.precipitation specified: values set as zero'
    74         if all(numpy.isnan(md.surfaceforcings.mass_balance)):
     74        if numpy.all(numpy.isnan(md.surfaceforcings.mass_balance)):
    7575                md.surfaceforcings.mass_balance=numpy.zeros(md.mesh.numberofvertices)
    7676                print '      no surfaceforcings.mass_balance specified: values set as zero'
    77         if all(numpy.isnan(md.basalforcings.melting_rate)):
     77        if numpy.all(numpy.isnan(md.basalforcings.melting_rate)):
    7878                md.basalforcings.melting_rate=numpy.zeros(md.mesh.numberofvertices)
    7979                print '      no basalforcings.melting_rate specified: values set as zero'
    80         if all(numpy.isnan(md.balancethickness.thickening_rate)):
     80        if numpy.all(numpy.isnan(md.balancethickness.thickening_rate)):
    8181                md.balancethickness.thickening_rate=numpy.zeros(md.mesh.numberofvertices)
    8282                print '      no balancethickness.thickening_rate specified: values set as zero'
  • issm/trunk-jpl/src/m/classes/diagnostic.py

    r13030 r13032  
    139139
    140140                #singular solution
    141                 if not any(numpy.logical_and(numpy.logical_not(numpy.isnan(md.diagnostic.spcvx)),numpy.logical_not(numpy.isnan(md.diagnostic.spcvy)))):
     141                if not numpy.any(numpy.logical_and(numpy.logical_not(numpy.isnan(md.diagnostic.spcvx)),numpy.logical_not(numpy.isnan(md.diagnostic.spcvy)))):
    142142                        md.checkmessage("model is not well posed (singular). You need at least one node with fixed velocity!")
    143143                #CHECK THAT EACH LINES CONTAINS ONLY NAN VALUES OR NO NAN VALUES
     
    148148                        pos=[i for i,item in enumerate(numpy.sum(numpy.isnan(md.diagnostic.referential),axis=1)) if item==0]
    149149#                       numpy.inner (and numpy.dot) calculate all the dot product permutations, resulting in a full matrix multiply
    150 #                       if any(numpy.abs(numpy.inner(md.diagnostic.referential[pos,0:2],md.diagnostic.referential[pos,3:5]).diagonal())>sys.float_info.epsilon):
     150#                       if numpy.any(numpy.abs(numpy.inner(md.diagnostic.referential[pos,0:2],md.diagnostic.referential[pos,3:5]).diagonal())>sys.float_info.epsilon):
    151151#                               md.checkmessage("Vectors in diagnostic.referential (columns 1 to 3 and 4 to 6) must be orthogonal")
    152152                        for item in md.diagnostic.referential[pos,:]:
     
    156156                if md.mesh.dimension==3 and md.flowequation.isstokes:
    157157                        pos=numpy.nonzero(numpy.logical_and(md.mask.vertexongroundedice,md.mesh.vertexonbed))
    158                         if any(not numpy.isnan(md.diagnostic.referential[pos,:])):
     158                        if numpy.any(numpy.logical_not(numpy.isnan(md.diagnostic.referential[pos,:]))):
    159159                                md.checkmessage("no referential should be specified for basal vertices of grounded ice")
    160160
  • issm/trunk-jpl/src/m/classes/flaim.py

    r13023 r13032  
    6868
    6969                md = checkfield(md,'flaim.tracks','file',1)
    70                 if any(numpy.isnan(md.flaim.criterion)) or not md.flaim.criterion:
     70                if numpy.any(numpy.isnan(md.flaim.criterion)) or not md.flaim.criterion:
    7171                        md = checkfield(md,'flaim.targets','file',1)
    7272                else:
  • issm/trunk-jpl/src/m/classes/flowequation.py

    r13020 r13032  
    7171                if DiagnosticHutterAnalysisEnum() in analyses:
    7272                        if any(md.flowequation.element_equation==1):
    73                                 if any(numpy.logical_and(md.flowequation.element_equation,md.mask.elementonfloatingice)):
     73                                if numpy.any(numpy.logical_and(md.flowequation.element_equation,md.mask.elementonfloatingice)):
    7474                                        print "\n !!! Warning: Hutter's model is not consistent on ice shelves !!!\n"
    7575
  • issm/trunk-jpl/src/m/classes/groundingline.py

    r13020 r13032  
    5050
    5151                if not strcmp(self.migration,'None'):
    52                         if any(numpy.isnan(md.geometry.bathymetry)):
     52                        if numpy.any(numpy.isnan(md.geometry.bathymetry)):
    5353                                md.checkmessage("requesting grounding line migration, but bathymetry is absent!")
    5454                        pos=numpy.nonzero(md.mask.vertexongroundedice)
  • issm/trunk-jpl/src/m/classes/initialization.py

    r13020 r13032  
    5454        def checkconsistency(self,md,solution,analyses):    # {{{
    5555                if DiagnosticHorizAnalysisEnum() in analyses:
    56                         if not any(numpy.isnan(md.initialization.vx) or numpy.isnan(md.initialization.vy)):
     56                        if not numpy.any(numpy.logical_or(numpy.isnan(md.initialization.vx),numpy.isnan(md.initialization.vy))):
    5757                                md = checkfield(md,'initialization.vx','NaN',1,'size',[md.mesh.numberofvertices])
    5858                                md = checkfield(md,'initialization.vy','NaN',1,'size',[md.mesh.numberofvertices])
     
    6666                        md = checkfield(md,'initialization.vy','NaN',1,'size',[md.mesh.numberofvertices])
    6767                        #Triangle with zero velocity
    68                         if any(numpy.logical_and(numpy.sum(numpy.abs(md.initialization.vx[md.mesh.elements.astype(int)-1]),axis=1)==0,\
    69                                                  numpy.sum(numpy.abs(md.initialization.vy[md.mesh.elements.astype(int)-1]),axis=1)==0)):
     68                        if numpy.any(numpy.logical_and(numpy.sum(numpy.abs(md.initialization.vx[md.mesh.elements.astype(int)-1]),axis=1)==0,\
     69                                                       numpy.sum(numpy.abs(md.initialization.vy[md.mesh.elements.astype(int)-1]),axis=1)==0)):
    7070                                md.checkmessage("at least one triangle has all its vertices with a zero velocity")
    7171                if ThermalAnalysisEnum() in analyses:
  • issm/trunk-jpl/src/m/classes/mesh.py

    r13020 r13032  
    137137                else:
    138138                        md = checkfield(md,'mesh.elements','size',[md.mesh.numberofelements,6])
    139                 if any(numpy.logical_not(ismember(range(1,md.mesh.numberofvertices+1),md.mesh.elements))):
     139                if numpy.any(numpy.logical_not(ismember(range(1,md.mesh.numberofvertices+1),md.mesh.elements))):
    140140                        md.checkmessage("orphan nodes have been found. Check the mesh outline")
    141141                md = checkfield(md,'mesh.dimension','values',[2,3])
  • issm/trunk-jpl/src/m/parameterization/setflowequation.py

    r13031 r13032  
    6969        #Check that no pattyn or stokes for 2d mesh
    7070        if md.mesh.dimension==2:
    71                 if any(numpy.logical_or(stokesflag,pattynflag)):
     71                if numpy.any(numpy.logical_or(stokesflag,pattynflag)):
    7272                        raise TypeError("setflowequation error message: stokes and pattyn elements not allowed in 2d mesh, extrude it first")
    7373
     
    124124
    125125                #initialize and fill in penalties structure
    126                 if all(numpy.logical_not(numpy.isnan(bordernodes2d))):
     126                if numpy.all(numpy.logical_not(numpy.isnan(bordernodes2d))):
    127127                        penalties=numpy.zeros((0,2))
    128128                        for     i in xrange(1,numlayers):
     
    146146                        pos=numpy.nonzero(macayealpattynflag)
    147147                        elist=numpy.zeros(len(pos))
    148                         elist = elist + any(numpy.sum(nodeonmacayeal[md.mesh.elements[pos,:].astype(int)-1],axis=1),axis=1)
    149                         elist = elist - any(numpy.sum(nodeonpattyn[md.mesh.elements[pos,:].astype(int)-1]  ,axis=1),axis=1)
     148                        elist = elist + numpy.any(numpy.sum(nodeonmacayeal[md.mesh.elements[pos,:].astype(int)-1],axis=1),axis=1)
     149                        elist = elist - numpy.any(numpy.sum(nodeonpattyn[md.mesh.elements[pos,:].astype(int)-1]  ,axis=1),axis=1)
    150150                        pos1=[i for i,item in enumerate(elist) if item==1]
    151151                        macayealflag[pos[pos1]]=1
     
    178178                        pos=numpy.nonzero(pattynstokesflag)
    179179                        elist=numpy.zeros(len(pos))
    180                         elist = elist + any(numpy.sum(nodeonstokes[md.mesh.elements[pos,:].astype(int)-1],axis=1),axis=1)
    181                         elist = elist - any(numpy.sum(nodeonpattyn[md.mesh.elements[pos,:].astype(int)-1],axis=1),axis=1)
     180                        elist = elist + numpy.any(numpy.sum(nodeonstokes[md.mesh.elements[pos,:].astype(int)-1],axis=1),axis=1)
     181                        elist = elist - numpy.any(numpy.sum(nodeonpattyn[md.mesh.elements[pos,:].astype(int)-1],axis=1),axis=1)
    182182                        pos1=[i for i,item in enumerate(elist) if item==1]
    183183                        stokesflag[pos[pos1]]=1
     
    210210                        pos=numpy.nonzero(macayealstokesflag)
    211211                        elist=numpy.zeros(len(pos))
    212                         elist = elist + any(numpy.sum(nodeonmacayeal[md.mesh.elements[pos,:].astype(int)-1],axis=1),axis=1)
    213                         elist = elist - any(numpy.sum(nodeonstokes[md.mesh.elements[pos,:].astype(int)-1]  ,axis=1),axis=1)
     212                        elist = elist + numpy.any(numpy.sum(nodeonmacayeal[md.mesh.elements[pos,:].astype(int)-1],axis=1),axis=1)
     213                        elist = elist - numpy.any(numpy.sum(nodeonstokes[md.mesh.elements[pos,:].astype(int)-1]  ,axis=1),axis=1)
    214214                        pos1=[i for i,item in enumerate(elist) if item==1]
    215215                        macayealflag[pos[pos1]]=1
     
    271271        #figure out solution types
    272272        md.flowequation.ishutter=float(any(md.flowequation.element_equation==1))
    273         md.flowequation.ismacayealpattyn=float(any(numpy.logical_or(md.flowequation.element_equation==2,md.flowequation.element_equation==3)))
     273        md.flowequation.ismacayealpattyn=float(numpy.any(numpy.logical_or(md.flowequation.element_equation==2,md.flowequation.element_equation==3)))
    274274        md.flowequation.isstokes=float(any(md.flowequation.element_equation==4))
    275275
Note: See TracChangeset for help on using the changeset viewer.