Ignore:
Timestamp:
10/21/16 08:49:08 (9 years ago)
Author:
bdef
Message:

CHG: major cosmetic clean up we now ask shape (N,) rather than (N,1) also uniformised numpy imports

Location:
issm/trunk-jpl/src/m/boundaryconditions
Files:
5 edited

Legend:

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

    r21254 r21303  
    11import os
    2 import numpy as np
     2import numpy as  np
    33def PattynSMB(md,Tf):
    44        """
  • issm/trunk-jpl/src/m/boundaryconditions/SetIceSheetBC.py

    r19527 r21303  
    11import os
    2 import numpy
     2import numpy as np
    33from ContourToMesh import ContourToMesh
    44
     
    1414
    1515        #node on Dirichlet
    16         pos=numpy.nonzero(md.mesh.vertexonboundary)
    17         md.stressbalance.spcvx=float('nan')*numpy.ones(md.mesh.numberofvertices)
    18         md.stressbalance.spcvy=float('nan')*numpy.ones(md.mesh.numberofvertices)
    19         md.stressbalance.spcvz=float('nan')*numpy.ones(md.mesh.numberofvertices)
     16        pos=np.nonzero(md.mesh.vertexonboundary)
     17        md.stressbalance.spcvx=float('nan')*np.ones(md.mesh.numberofvertices)
     18        md.stressbalance.spcvy=float('nan')*np.ones(md.mesh.numberofvertices)
     19        md.stressbalance.spcvz=float('nan')*np.ones(md.mesh.numberofvertices)
    2020        md.stressbalance.spcvx[pos]=0
    2121        md.stressbalance.spcvy[pos]=0
    2222        md.stressbalance.spcvz[pos]=0
    23         md.stressbalance.referential=float('nan')*numpy.ones((md.mesh.numberofvertices,6))
    24         md.stressbalance.loadingforce=0*numpy.ones((md.mesh.numberofvertices,3))
     23        md.stressbalance.referential=float('nan')*np.ones((md.mesh.numberofvertices,6))
     24        md.stressbalance.loadingforce=0*np.ones((md.mesh.numberofvertices,3))
    2525
    2626        #Dirichlet Values
    27         if isinstance(md.inversion.vx_obs,numpy.ndarray) and numpy.size(md.inversion.vx_obs,axis=0)==md.mesh.numberofvertices and isinstance(md.inversion.vy_obs,numpy.ndarray) and numpy.size(md.inversion.vy_obs,axis=0)==md.mesh.numberofvertices:
     27        if isinstance(md.inversion.vx_obs,np.ndarray) and np.size(md.inversion.vx_obs,axis=0)==md.mesh.numberofvertices and isinstance(md.inversion.vy_obs,np.ndarray) and np.size(md.inversion.vy_obs,axis=0)==md.mesh.numberofvertices:
    2828                print "      boundary conditions for stressbalance model: spc set as observed velocities"
    2929                md.stressbalance.spcvx[pos]=md.inversion.vx_obs[pos]
     
    3939
    4040        #Deal with other boundary conditions
    41         if numpy.all(numpy.isnan(md.balancethickness.thickening_rate)):
    42                 md.balancethickness.thickening_rate=numpy.zeros((md.mesh.numberofvertices,1))
     41        if np.all(np.isnan(md.balancethickness.thickening_rate)):
     42                md.balancethickness.thickening_rate=np.zeros((md.mesh.numberofvertices))
    4343                print "      no balancethickness.thickening_rate specified: values set as zero"
    44         md.masstransport.spcthickness=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
    45         md.balancethickness.spcthickness=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
    46         md.damage.spcdamage=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
     44        md.masstransport.spcthickness=float('nan')*np.ones((md.mesh.numberofvertices))
     45        md.balancethickness.spcthickness=float('nan')*np.ones((md.mesh.numberofvertices))
     46        md.damage.spcdamage=float('nan')*np.ones((md.mesh.numberofvertices))
    4747
    48         if isinstance(md.initialization.temperature,numpy.ndarray) and numpy.size(md.initialization.temperature,axis=0)==md.mesh.numberofvertices:
    49                 md.thermal.spctemperature=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
     48        if isinstance(md.initialization.temperature,np.ndarray) and np.size(md.initialization.temperature,axis=0)==md.mesh.numberofvertices:
     49                md.thermal.spctemperature=float('nan')*np.ones((md.mesh.numberofvertices))
    5050                if hasattr(md.mesh,'vertexonsurface'):
    51                         pos=numpy.nonzero(md.mesh.vertexonsurface)[0]
     51                        pos=np.nonzero(md.mesh.vertexonsurface)[0]
    5252                        md.thermal.spctemperature[pos]=md.initialization.temperature[pos]    #impose observed temperature on surface
    53                 if not isinstance(md.basalforcings.geothermalflux,numpy.ndarray) or not numpy.size(md.basalforcings.geothermalflux)==md.mesh.numberofvertices:
    54                         md.basalforcings.geothermalflux=50.*10**-3*numpy.ones((md.mesh.numberofvertices,1))    #50 mW/m^2
     53                if not isinstance(md.basalforcings.geothermalflux,np.ndarray) or not np.size(md.basalforcings.geothermalflux)==md.mesh.numberofvertices:
     54                        md.basalforcings.geothermalflux=50.*10**-3*np.ones((md.mesh.numberofvertices))    #50 mW/m^2
    5555        else:
    5656                print "      no thermal boundary conditions created: no observed temperature found"
  • issm/trunk-jpl/src/m/boundaryconditions/SetIceShelfBC.py

    r20910 r21303  
    11import os
    2 import numpy
     2import numpy as np
    33from ContourToMesh import ContourToMesh
    44import MatlabFuncs as m
     
    2727                        raise IOError("SetIceShelfBC error message: ice front file '%s' not found." % icefrontfile)
    2828                nodeinsideicefront=ContourToMesh(md.mesh.elements,md.mesh.x,md.mesh.y,icefrontfile,'node',2)
    29                 nodeonicefront=numpy.logical_and(md.mesh.vertexonboundary,nodeinsideicefront.reshape(-1))
     29                nodeonicefront=np.logical_and(md.mesh.vertexonboundary,nodeinsideicefront.reshape(-1))
    3030        else:
    31                 nodeonicefront=numpy.zeros((md.mesh.numberofvertices),bool)
     31                nodeonicefront=np.zeros((md.mesh.numberofvertices),bool)
    3232
    3333#       pos=find(md.mesh.vertexonboundary & ~nodeonicefront);
    34         pos=numpy.nonzero(numpy.logical_and(md.mesh.vertexonboundary,numpy.logical_not(nodeonicefront)))[0]
    35         md.stressbalance.spcvx=float('nan')*numpy.ones(md.mesh.numberofvertices)
    36         md.stressbalance.spcvy=float('nan')*numpy.ones(md.mesh.numberofvertices)
    37         md.stressbalance.spcvz=float('nan')*numpy.ones(md.mesh.numberofvertices)
    38         md.stressbalance.referential=float('nan')*numpy.ones((md.mesh.numberofvertices,6))
    39         md.stressbalance.loadingforce=0*numpy.ones((md.mesh.numberofvertices,3))
     34        pos=np.nonzero(np.logical_and(md.mesh.vertexonboundary,np.logical_not(nodeonicefront)))[0]
     35        md.stressbalance.spcvx=float('nan')*np.ones(md.mesh.numberofvertices)
     36        md.stressbalance.spcvy=float('nan')*np.ones(md.mesh.numberofvertices)
     37        md.stressbalance.spcvz=float('nan')*np.ones(md.mesh.numberofvertices)
     38        md.stressbalance.referential=float('nan')*np.ones((md.mesh.numberofvertices,6))
     39        md.stressbalance.loadingforce=0*np.ones((md.mesh.numberofvertices,3))
    4040
    4141        #Icefront position
    42         pos=numpy.nonzero(nodeonicefront)[0]
     42        pos=np.nonzero(nodeonicefront)[0]
    4343        md.mask.ice_levelset[pos]=0
    4444
     
    5353                values=md.mask.ice_levelset[md.mesh.segments[:,0:-1]-1]
    5454                segmentsfront=1-values
    55                 numpy.sum(segmentsfront,axis=1)!=numbernodesfront
    56                 segments=numpy.nonzero(numpy.sum(segmentsfront,axis=1)!=numbernodesfront)[0]
     55                np.sum(segmentsfront,axis=1)!=numbernodesfront
     56                segments=np.nonzero(np.sum(segmentsfront,axis=1)!=numbernodesfront)[0]
    5757                #Find all nodes for these segments and spc them
    5858                pos=md.mesh.segments[segments,0:-1]-1
    5959        else:
    60                 pos=numpy.nonzero(md.mesh.vertexonboundary)[0]
     60                pos=np.nonzero(md.mesh.vertexonboundary)[0]
    6161        md.stressbalance.spcvx[pos]=0
    6262        md.stressbalance.spcvy[pos]=0
     
    6464                                                                                                                                                                                                                                           
    6565        #Dirichlet Values
    66         if isinstance(md.inversion.vx_obs,numpy.ndarray) and numpy.size(md.inversion.vx_obs,axis=0)==md.mesh.numberofvertices and isinstance(md.inversion.vy_obs,numpy.ndarray) and numpy.size(md.inversion.vy_obs,axis=0)==md.mesh.numberofvertices:
     66        if isinstance(md.inversion.vx_obs,np.ndarray) and np.size(md.inversion.vx_obs,axis=0)==md.mesh.numberofvertices and isinstance(md.inversion.vy_obs,np.ndarray) and np.size(md.inversion.vy_obs,axis=0)==md.mesh.numberofvertices:
    6767                #reshape to rank-2 if necessary to match spc arrays
    68                 if numpy.ndim(md.inversion.vx_obs)==1:
    69                         md.inversion.vx_obs=md.inversion.vx_obs.reshape(-1,1)
    70                 if numpy.ndim(md.inversion.vy_obs)==1:
    71                         md.inversion.vy_obs=md.inversion.vy_obs.reshape(-1,1)
     68                if np.ndim(md.inversion.vx_obs)==1:
     69                        md.inversion.vx_obs=md.inversion.vx_obs.reshape(-1,)
     70                if np.ndim(md.inversion.vy_obs)==1:
     71                        md.inversion.vy_obs=md.inversion.vy_obs.reshape(-1,)
    7272                print "      boundary conditions for stressbalance model: spc set as observed velocities"
    7373                md.stressbalance.spcvx[pos]=md.inversion.vx_obs[pos]
     
    8181
    8282        #Deal with other boundary conditions
    83         if numpy.all(numpy.isnan(md.balancethickness.thickening_rate)):
    84                 md.balancethickness.thickening_rate=numpy.zeros((md.mesh.numberofvertices,1))
     83        if np.all(np.isnan(md.balancethickness.thickening_rate)):
     84                md.balancethickness.thickening_rate=np.zeros((md.mesh.numberofvertices))
    8585                print "      no balancethickness.thickening_rate specified: values set as zero"
    86         md.masstransport.spcthickness=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
    87         md.balancethickness.spcthickness=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
    88         md.damage.spcdamage=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
     86        md.masstransport.spcthickness=float('nan')*np.ones((md.mesh.numberofvertices))
     87        md.balancethickness.spcthickness=float('nan')*np.ones((md.mesh.numberofvertices))
     88        md.damage.spcdamage=float('nan')*np.ones((md.mesh.numberofvertices))
    8989
    90         if isinstance(md.initialization.temperature,numpy.ndarray) and numpy.size(md.initialization.temperature,axis=0)==md.mesh.numberofvertices:
    91                 md.thermal.spctemperature=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
     90        if isinstance(md.initialization.temperature,np.ndarray) and np.size(md.initialization.temperature,axis=0)==md.mesh.numberofvertices:
     91                md.thermal.spctemperature=float('nan')*np.ones((md.mesh.numberofvertices))
    9292                if hasattr(md.mesh,'vertexonsurface'):
    93                         pos=numpy.nonzero(md.mesh.vertexonsurface)[0]
     93                        pos=np.nonzero(md.mesh.vertexonsurface)[0]
    9494                        md.thermal.spctemperature[pos]=md.initialization.temperature[pos]    #impose observed temperature on surface
    95                 if not isinstance(md.basalforcings.geothermalflux,numpy.ndarray) or not numpy.size(md.basalforcings.geothermalflux,axis=0)==md.mesh.numberofvertices:
    96                         md.basalforcings.geothermalflux=numpy.zeros((md.mesh.numberofvertices,1))
     95                if not isinstance(md.basalforcings.geothermalflux,np.ndarray) or not np.size(md.basalforcings.geothermalflux,axis=0)==md.mesh.numberofvertices:
     96                        md.basalforcings.geothermalflux=np.zeros((md.mesh.numberofvertices))
    9797        else:
    9898                print "      no thermal boundary conditions created: no observed temperature found"
  • issm/trunk-jpl/src/m/boundaryconditions/SetMarineIceSheetBC.py

    r20910 r21303  
    11import os
    2 import numpy
     2import numpy as np
    33from ContourToMesh import ContourToMesh
    44import MatlabFuncs as m
     
    2929                        raise IOError("SetMarineIceSheetBC error message: ice front file '%s' not found." % icefrontfile)
    3030                incontour=ContourToMesh(md.mesh.elements,md.mesh.x,md.mesh.y,icefrontfile,'node',2)
    31                 vertexonicefront=numpy.logical_and(md.mesh.vertexonboundary,incontour.reshape(-1))
     31                vertexonicefront=np.logical_and(md.mesh.vertexonboundary,incontour.reshape(-1))
    3232        else:
    3333                #Guess where the ice front is
    34                 vertexonfloatingice=numpy.zeros((md.mesh.numberofvertices,1))
    35                 pos=numpy.nonzero(numpy.sum(md.mask.groundedice_levelset[md.mesh.elements-1]<0.,axis=1) >0.)[0]
     34                vertexonfloatingice=np.zeros((md.mesh.numberofvertices))
     35                pos=np.nonzero(np.sum(md.mask.groundedice_levelset[md.mesh.elements-1]<0.,axis=1) >0.)[0]
    3636                vertexonfloatingice[md.mesh.elements[pos].astype(int)-1]=1.
    37                 vertexonicefront=numpy.logical_and(numpy.reshape(md.mesh.vertexonboundary,(-1,1)),vertexonfloatingice>0.)
     37                vertexonicefront=np.logical_and(np.reshape(md.mesh.vertexonboundary,(-1,)),vertexonfloatingice>0.)
    3838
    3939#       pos=find(md.mesh.vertexonboundary & ~vertexonicefront);
    40         pos=numpy.nonzero(numpy.logical_and(md.mesh.vertexonboundary,numpy.logical_not(vertexonicefront)))[0]
    41         if not numpy.size(pos):
     40        pos=np.nonzero(np.logical_and(md.mesh.vertexonboundary,np.logical_not(vertexonicefront)))[0]
     41        if not np.size(pos):
    4242                print "SetMarineIceSheetBC warning: ice front all around the glacier, no dirichlet found. Dirichlet must be added manually."
    4343
    44         md.stressbalance.spcvx=float('nan')*numpy.ones(md.mesh.numberofvertices)
    45         md.stressbalance.spcvy=float('nan')*numpy.ones(md.mesh.numberofvertices)
    46         md.stressbalance.spcvz=float('nan')*numpy.ones(md.mesh.numberofvertices)
    47         md.stressbalance.referential=float('nan')*numpy.ones((md.mesh.numberofvertices,6))
    48         md.stressbalance.loadingforce=0*numpy.ones((md.mesh.numberofvertices,3))
     44        md.stressbalance.spcvx=float('nan')*np.ones(md.mesh.numberofvertices)
     45        md.stressbalance.spcvy=float('nan')*np.ones(md.mesh.numberofvertices)
     46        md.stressbalance.spcvz=float('nan')*np.ones(md.mesh.numberofvertices)
     47        md.stressbalance.referential=float('nan')*np.ones((md.mesh.numberofvertices,6))
     48        md.stressbalance.loadingforce=0*np.ones((md.mesh.numberofvertices,3))
    4949
    5050        #Position of ice front
    51         pos=numpy.nonzero(vertexonicefront)[0]
     51        pos=np.nonzero(vertexonicefront)[0]
    5252        md.mask.ice_levelset[pos]=0
    5353
     
    6262                values=md.mask.ice_levelset[md.mesh.segments[:,0:-1]-1]
    6363                segmentsfront=1-values
    64                 numpy.sum(segmentsfront,axis=1)!=numbernodesfront
    65                 segments=numpy.nonzero(numpy.sum(segmentsfront,axis=1)!=numbernodesfront)[0]
     64                np.sum(segmentsfront,axis=1)!=numbernodesfront
     65                segments=np.nonzero(np.sum(segmentsfront,axis=1)!=numbernodesfront)[0]
    6666                #Find all nodes for these segments and spc them
    6767                pos=md.mesh.segments[segments,0:-1]-1
    6868        else:
    69                 pos=numpy.nonzero(md.mesh.vertexonboundary)[0]
     69                pos=np.nonzero(md.mesh.vertexonboundary)[0]
    7070        md.stressbalance.spcvx[pos]=0
    7171        md.stressbalance.spcvy[pos]=0
     
    7373
    7474        #Dirichlet Values
    75         if isinstance(md.inversion.vx_obs,numpy.ndarray) and numpy.size(md.inversion.vx_obs,axis=0)==md.mesh.numberofvertices and isinstance(md.inversion.vy_obs,numpy.ndarray) and numpy.size(md.inversion.vy_obs,axis=0)==md.mesh.numberofvertices:
     75        if isinstance(md.inversion.vx_obs,np.ndarray) and np.size(md.inversion.vx_obs,axis=0)==md.mesh.numberofvertices and isinstance(md.inversion.vy_obs,np.ndarray) and np.size(md.inversion.vy_obs,axis=0)==md.mesh.numberofvertices:
    7676                print "      boundary conditions for stressbalance model: spc set as observed velocities"
    7777                md.stressbalance.spcvx[pos]=md.inversion.vx_obs[pos]
     
    8080                print "      boundary conditions for stressbalance model: spc set as zero"
    8181
    82         md.hydrology.spcwatercolumn=numpy.zeros((md.mesh.numberofvertices,2))
    83         pos=numpy.nonzero(md.mesh.vertexonboundary)[0]
     82        md.hydrology.spcwatercolumn=np.zeros((md.mesh.numberofvertices,2))
     83        pos=np.nonzero(md.mesh.vertexonboundary)[0]
    8484        md.hydrology.spcwatercolumn[pos,0]=1
    8585
     
    8989
    9090        #Deal with other boundary conditions
    91         if numpy.all(numpy.isnan(md.balancethickness.thickening_rate)):
    92                 md.balancethickness.thickening_rate=numpy.zeros((md.mesh.numberofvertices,1))
     91        if np.all(np.isnan(md.balancethickness.thickening_rate)):
     92                md.balancethickness.thickening_rate=np.zeros((md.mesh.numberofvertices))
    9393                print "      no balancethickness.thickening_rate specified: values set as zero"
    9494
    95         md.masstransport.spcthickness=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
    96         md.balancethickness.spcthickness=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
    97         md.damage.spcdamage=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
     95        md.masstransport.spcthickness=float('nan')*np.ones((md.mesh.numberofvertices))
     96        md.balancethickness.spcthickness=float('nan')*np.ones((md.mesh.numberofvertices))
     97        md.damage.spcdamage=float('nan')*np.ones((md.mesh.numberofvertices))
    9898
    99         if isinstance(md.initialization.temperature,numpy.ndarray) and numpy.size(md.initialization.temperature,axis=0)==md.mesh.numberofvertices:
    100                 md.thermal.spctemperature=float('nan')*numpy.ones((md.mesh.numberofvertices,1))
     99        if isinstance(md.initialization.temperature,np.ndarray) and np.size(md.initialization.temperature,axis=0)==md.mesh.numberofvertices:
     100                md.thermal.spctemperature=float('nan')*np.ones((md.mesh.numberofvertices))
    101101                if hasattr(md.mesh,'vertexonsurface'):
    102                         pos=numpy.nonzero(md.mesh.vertexonsurface)[0]
     102                        pos=np.nonzero(md.mesh.vertexonsurface)[0]
    103103                        md.thermal.spctemperature[pos]=md.initialization.temperature[pos]    #impose observed temperature on surface
    104                 if not isinstance(md.basalforcings.geothermalflux,numpy.ndarray) or not numpy.size(md.basalforcings.geothermalflux,axis=0)==md.mesh.numberofvertices:
    105                         md.basalforcings.geothermalflux=numpy.zeros((md.mesh.numberofvertices,1))
    106                         md.basalforcings.geothermalflux[numpy.nonzero(md.mask.groundedice_levelset>0.)]=50.*10.**-3    #50mW/m2
     104                if not isinstance(md.basalforcings.geothermalflux,np.ndarray) or not np.size(md.basalforcings.geothermalflux,axis=0)==md.mesh.numberofvertices:
     105                        md.basalforcings.geothermalflux=np.zeros((md.mesh.numberofvertices))
     106                        md.basalforcings.geothermalflux[np.nonzero(md.mask.groundedice_levelset>0.)]=50.*10.**-3    #50mW/m2
    107107        else:
    108108                print "      no thermal boundary conditions created: no observed temperature found"
  • issm/trunk-jpl/src/m/boundaryconditions/love_numbers.py

    r21069 r21303  
    11from MatlabFuncs import *
    22from model import *
    3 from numpy import *
     3from np.import *
    44
    55def love_numbers(value,*varargin):
Note: See TracChangeset for help on using the changeset viewer.