Changeset 21170


Ignore:
Timestamp:
08/25/16 21:53:46 (9 years ago)
Author:
agscott1
Message:

BUG: Fixed archread incorrectly reading the order of a matrix, and fixed Par python files to correctly read arch files

Location:
issm/trunk-jpl
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/archive/arch.py

    r21166 r21170  
    216216                        rows=struct.unpack('>i',fid.read(struct.calcsize('>i')))[0]
    217217                        cols=struct.unpack('>i',fid.read(struct.calcsize('>i')))[0]
    218                         data=numpy.zeros(shape=(rows,cols),dtype=float)
     218                        raw_data=numpy.zeros(shape=(rows,cols),dtype=float)
    219219                        for i in xrange(rows):
    220                                 data[i,:]=struct.unpack('>%dd' % cols,fid.read(cols*struct.calcsize('>d')))
     220                                raw_data[i,:]=struct.unpack('>%dd' % cols,fid.read(cols*struct.calcsize('>d')))
     221                        # The matrix will be unpacked in order and will be filled left -> right by column
     222                        # We need to reshape and transpose the matrix so it can be read correctly
     223                        data=raw_data.reshape(raw_data.shape[::-1]).T
    221224                else:
    222225                        raise TypeError("Cannot read data type %d" % data_type)
  • issm/trunk-jpl/test/Par/79North.py

    r19527 r21170  
    11import os.path
    22import inspect
    3 import netCDF4
     3from arch import *
    44import numpy
    55from verbose import verbose
     
    1111
    1212#Geometry and observation
    13 f         = netCDF4.Dataset('../Data/79North.nc','r')
    14 x         = numpy.reshape(f.variables['x'][:],(-1))
    15 y         = numpy.reshape(f.variables['y'][:],(-1))
    16 vx        = f.variables['vx'][:]
    17 vy        = f.variables['vy'][:]
    18 index     = f.variables['index'][:]
    19 surface   = f.variables['surface'][:]
    20 thickness = f.variables['thickness'][:]
    21 f.close()
     13x         = numpy.array(archread('../Data/79North.arch','x'))
     14y         = numpy.array(archread('../Data/79North.arch','y'))
     15vx        = numpy.array(archread('../Data/79North.arch','vx'));
     16vy        = numpy.array(archread('../Data/79North.arch','vy'));
     17index     = numpy.array(archread('../Data/79North.arch','index'));
     18surface   = numpy.array(archread('../Data/79North.arch','surface'));
     19thickness = numpy.array(archread('../Data/79North.arch','thickness'));
    2220
    2321[md.initialization.vx]  = InterpFromMeshToMesh2d(index,x,y,vx,md.mesh.x,md.mesh.y)
  • issm/trunk-jpl/test/Par/ISMIPE.py

    r17769 r21170  
    11import numpy
    2 import netCDF4
     2from arch import *
    33from SetIceSheetBC import SetIceSheetBC
    44
     
    66
    77print "      creating thickness"
    8 f = netCDF4.Dataset('../Data/ISMIPE.nc','r')
    9 data = f.variables['data'][:]
    10 f.close()
     8data = numpy.array(archread('../Data/ISMIPE.arch','data'));
    119md.geometry.surface=numpy.zeros((md.mesh.numberofvertices,1))
    1210md.geometry.base=numpy.zeros((md.mesh.numberofvertices,1))
  • issm/trunk-jpl/test/Par/Pig.py

    r17769 r21170  
    11import os.path
    22import inspect
    3 import netCDF4
     3from arch import *
    44import numpy
    55from verbose import verbose
     
    1111
    1212#Geometry and observation
    13 f = netCDF4.Dataset('../Data/Pig.nc','r')
    14 x         = numpy.reshape(f.variables['x'][:],(-1))
    15 y         = numpy.reshape(f.variables['y'][:],(-1))
    16 vx_obs    = f.variables['vx_obs'][:]
    17 vy_obs    = f.variables['vy_obs'][:]
    18 index     = f.variables['index'][:]
    19 surface   = f.variables['surface'][:]
    20 thickness = f.variables['thickness'][:]
    21 f.close()
     13x         = numpy.array(archread('../Data/Pig.arch','x'))
     14y         = numpy.array(archread('../Data/Pig.arch','y'))
     15vx_obs    = numpy.array(archread('../Data/Pig.arch','vx_obs'))
     16vy_obs    = numpy.array(archread('../Data/Pig.arch','vy_obs'))
     17index     = numpy.array(archread('../Data/Pig.arch','index'))
     18surface   = numpy.array(archread('../Data/Pig.arch','surface'))
     19thickness = numpy.array(archread('../Data/Pig.arch','thickness'))
    2220
    2321[md.inversion.vx_obs]   =InterpFromMeshToMesh2d(index,x,y,vx_obs,md.mesh.x,md.mesh.y)
  • issm/trunk-jpl/test/Par/SquareSheetConstrained.py

    r20468 r21170  
    11import os.path
    2 import netCDF4
    32import numpy
    43import inspect
     
    76from paterson import paterson
    87from SetIceSheetBC import SetIceSheetBC
     8from arch import *
    99
    1010#Start defining model parameters here
     
    2222
    2323#Initial velocity
    24 f = netCDF4.Dataset('../Data/SquareSheetConstrained.nc','r')
    25 x     = numpy.reshape(f.variables['x'][:],(-1))
    26 y     = numpy.reshape(f.variables['y'][:],(-1))
    27 vx    = f.variables['vx'][:]
    28 vy    = f.variables['vy'][:]
    29 index = f.variables['index'][:]
    30 f.close()
     24x         = numpy.array(archread('../Data/SquareSheetConstrained.arch','x'))
     25y         = numpy.array(archread('../Data/SquareSheetConstrained.arch','y'))
     26vx        = numpy.array(archread('../Data/SquareSheetConstrained.arch','vx'));
     27vy        = numpy.array(archread('../Data/SquareSheetConstrained.arch','vy'));
     28index     = archread('../Data/SquareSheetConstrained.arch','index').astype(int);
    3129
    3230[md.initialization.vx]=InterpFromMeshToMesh2d(index,x,y,vx,md.mesh.x,md.mesh.y)
  • issm/trunk-jpl/test/Par/SquareSheetShelf.py

    r19527 r21170  
    11import os.path
    22import inspect
    3 import netCDF4
     3from arch import *
    44import numpy
    55from verbose import verbose
     
    2525
    2626#Initial velocity
    27 f = netCDF4.Dataset('../Data/SquareSheetShelf.nc','r')
    28 x         = numpy.reshape(f.variables['x'][:],(-1))
    29 y         = numpy.reshape(f.variables['y'][:],(-1))
    30 vx        = f.variables['vx'][:]
    31 vy        = f.variables['vy'][:]
    32 index     = f.variables['index'][:]
    33 f.close()
     27x         = numpy.array(archread('../Data/SquareSheetShelf.arch','x'))
     28y         = numpy.array(archread('../Data/SquareSheetShelf.arch','y'))
     29vx        = numpy.array(archread('../Data/SquareSheetShelf.arch','vx'));
     30vy        = numpy.array(archread('../Data/SquareSheetShelf.arch','vy'));
     31index     = numpy.array(archread('../Data/SquareSheetShelf.arch','index'));
    3432
    3533[md.initialization.vx]  = InterpFromMeshToMesh2d(index,x,y,vx,md.mesh.x,md.mesh.y)
  • issm/trunk-jpl/test/Par/SquareShelf.py

    r17769 r21170  
    11import os.path
    22import inspect
    3 import netCDF4
     3from arch import *
    44import numpy
    55from verbose import verbose
     
    2121
    2222#Initial velocity and pressure
    23 iVelF = netCDF4.Dataset('../Data/SquareShelf.nc','r')
    24 
    25 x=numpy.reshape(iVelF.variables['x'][:],(-1))
    26 y=numpy.reshape(iVelF.variables['y'][:],(-1))
    27 vx=iVelF.variables['vx'][:]
    28 vy=iVelF.variables['vy'][:]
    29 index=iVelF.variables['index'][:].astype(int)
     23x         = numpy.array(archread('../Data/SquareShelf.arch','x'))
     24y         = numpy.array(archread('../Data/SquareShelf.arch','y'))
     25vx        = numpy.array(archread('../Data/SquareShelf.arch','vx'));
     26vy        = numpy.array(archread('../Data/SquareShelf.arch','vy'));
     27index     = archread('../Data/SquareShelf.arch','index').astype(int);
    3028
    3129#dbg - begin
     
    3432# #     print v
    3533#dbg - end
    36 
    37 iVelF.close()
    3834
    3935[md.initialization.vx]=InterpFromMeshToMesh2d(index,x,y,vx,md.mesh.x,md.mesh.y)
  • issm/trunk-jpl/test/Par/SquareShelf2.py

    r17769 r21170  
    11import os.path
    22import inspect
    3 import netCDF4
     3from arch import *
    44import numpy
    55from verbose import verbose
     
    2121
    2222#Initial velocity and pressure
    23 iVelF = netCDF4.Dataset('../Data/SquareShelf.nc','r')
    24 
    25 x=numpy.reshape(iVelF.variables['x'][:],(-1))
    26 y=numpy.reshape(iVelF.variables['y'][:],(-1))
    27 vx=iVelF.variables['vx'][:]
    28 vy=iVelF.variables['vy'][:]
    29 index=iVelF.variables['index'][:].astype(int)
    30 
     23x         = numpy.array(archread('../Data/SquareShelf.arch','x'))
     24y         = numpy.array(archread('../Data/SquareShelf.arch','y'))
     25vx        = numpy.array(archread('../Data/SquareShelf.arch','vx'));
     26vy        = numpy.array(archread('../Data/SquareShelf.arch','vy'));
     27index     = archread('../Data/SquareShelf.arch','index').astype(int);
    3128#dbg - begin
    3229# #print 'vars in SquareShelf.nc:'
     
    3431# #     print v
    3532#dbg - end
    36 
    37 iVelF.close()
    3833
    3934[md.initialization.vx]=InterpFromMeshToMesh2d(index,x,y,vx,md.mesh.x,md.mesh.y)
  • issm/trunk-jpl/test/Par/SquareShelfConstrained.py

    r20988 r21170  
    11import os.path
    2 import netCDF4
     2from arch import *
    33import numpy
    44import inspect
     
    2222
    2323#Initial velocity
    24 f = netCDF4.Dataset('../Data/SquareShelfConstrained.nc','r')
    25 #Reshape as Rank-1 arrays
    26 x=numpy.reshape(f.variables['x'][:],(-1))
    27 y=numpy.reshape(f.variables['y'][:],(-1))
    28 vx=f.variables['vx'][:]
    29 vy=f.variables['vy'][:]
    30 index=f.variables['index'][:]
    31 f.close()
     24#x         = numpy.reshape(numpy.array(archread('../Data/SquareShelfConstrained.arch','x')),(-1))
     25#y         = numpy.reshape(numpy.array(archread('../Data/SquareShelfConstrained.arch','y')),(-1))
     26x         = numpy.array(archread('../Data/SquareShelfConstrained.arch','x'))
     27y         = numpy.array(archread('../Data/SquareShelfConstrained.arch','y'))
     28vx        = numpy.array(archread('../Data/SquareShelfConstrained.arch','vx'))
     29vy        = numpy.array(archread('../Data/SquareShelfConstrained.arch','vy'))
     30index     = numpy.array(archread('../Data/SquareShelfConstrained.arch','index').astype(int))
    3231
    3332[md.initialization.vx]=InterpFromMeshToMesh2d(index,x,y,vx,md.mesh.x,md.mesh.y)
  • issm/trunk-jpl/test/Par/ValleyGlacierShelf.py

    r20468 r21170  
    11import os.path
    2 import netCDF4
     2from arch import *
    33import numpy
    44import inspect
Note: See TracChangeset for help on using the changeset viewer.