[20225] | 1 | from MatlabFuncs import *
|
---|
| 2 | from model import *
|
---|
[21759] | 3 | import numpy as np
|
---|
[20225] | 4 | from os import getenv, putenv
|
---|
| 5 | import subprocess
|
---|
| 6 |
|
---|
| 7 | def gmtmask(lat,long,*varargin):
|
---|
| 8 | #GMTMASK - figure out which lat,long points are on the ocean
|
---|
| 9 | #
|
---|
| 10 | # Usage:
|
---|
| 11 | # mask.ocean = gmtmask(md.mesh.lat,md.mesh.long);
|
---|
| 12 | #
|
---|
| 13 | lenlat=len(lat)
|
---|
[21759] | 14 | mask=np.empty(lenlat)
|
---|
[20225] | 15 |
|
---|
| 16 | #are we doing a recursive call?
|
---|
| 17 | if len(varargin)==3:
|
---|
| 18 | recursive=1
|
---|
| 19 | else:
|
---|
| 20 | recursive=0
|
---|
| 21 |
|
---|
| 22 | if recursive:
|
---|
| 23 | string=' recursing: num vertices #i'+str(lenlat)
|
---|
| 24 | else:
|
---|
| 25 | string='gmtmask: num vertices #i'+str(lenlat)
|
---|
| 26 |
|
---|
| 27 | #Check lat and long size is not more than 50,000 If so, recursively call gmtmask:
|
---|
| 28 |
|
---|
| 29 | if lenlat>50000:
|
---|
| 30 | for i in range(ceil(lenlat/50000)):
|
---|
| 31 | j=(i+1)*50000-1
|
---|
| 32 | if j>lenlat:
|
---|
| 33 | j=lenlat
|
---|
| 34 | mask[i:j]=gmtmask(lat[i:j],long[i:j],1)
|
---|
| 35 | return mask
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | #First, write our lat,long file for gmt:
|
---|
| 39 | nv=lenlat
|
---|
[21759] | 40 | np.savetxt('./all_vertices.txt',np.transpose([long, lat, np.arange(1,nv+1)]),delimiter='\t',fmt='%.10f')
|
---|
[20225] | 41 |
|
---|
| 42 | #Avoid bypassing of the ld library path by Matlab (:()
|
---|
| 43 | try:
|
---|
| 44 | issmdir
|
---|
| 45 | except:
|
---|
| 46 | issmdir=getenv('ISSM_DIR')
|
---|
| 47 | try:
|
---|
| 48 | ismac
|
---|
| 49 | except:
|
---|
| 50 | ismac=False
|
---|
| 51 |
|
---|
| 52 | if ismac:
|
---|
| 53 | dyld_library_path_old=getenv('DYLD_LIBRARY_PATH')
|
---|
| 54 | putenv('DYLD_LIBRARY_PATH',issmdir+'/externalpackages/curl/install/lib:'+issmdir+'/externalpackages/hdf5/install/lib:'+issmdir+'/externalpackages/netcdf/install/lib')
|
---|
| 55 |
|
---|
| 56 | #figure out which vertices are on the ocean, which one on the continent:
|
---|
| 57 | subprocess.call(issmdir+'/externalpackages/gmt/install/bin/gmt gmtselect ./all_vertices.txt -h0 -Df -R0/360/-90/90 -A0 -JQ180/200 -Nk/s/s/k/s > ./oce_vertices.txt',shell=True)
|
---|
| 58 |
|
---|
| 59 | #reset DYLD_LIBRARY_PATH to what it was:
|
---|
| 60 | if ismac:
|
---|
| 61 | putenv('DYLD_LIBRARY_PATH',dyld_library_path_old)
|
---|
| 62 |
|
---|
| 63 | #read the con_vertices.txt file and flag our mesh vertices on the continent
|
---|
| 64 | fid=open('./oce_vertices.txt','r')
|
---|
| 65 | line=fid.readline()
|
---|
| 66 | line=fid.readline()
|
---|
| 67 | oce_vertices=[]
|
---|
| 68 | while line:
|
---|
[20283] | 69 | ind=int(float(line.split()[2]))-1;
|
---|
[20225] | 70 | oce_vertices.append(ind)
|
---|
| 71 | line=fid.readline()
|
---|
| 72 | fid.close()
|
---|
| 73 |
|
---|
[21759] | 74 | mask=np.zeros([nv,1])
|
---|
[20225] | 75 | mask[oce_vertices]=1
|
---|
| 76 |
|
---|
| 77 | subprocess.call('rm -rf ./all_vertices.txt ./oce_vertices.txt ./gmt.history',shell=True)
|
---|
| 78 | if not recursive:
|
---|
| 79 | string='gmtmask: done'
|
---|
| 80 | return mask
|
---|