Changeset 19044
- Timestamp:
- 01/28/15 12:21:22 (10 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/export_gl.py
r19039 r19044 1 def export_gl(md,varargin): 2 return; 3 templist=plotoptions(varargin[:]); 1 from plotoptions import plotoptions 2 from checkplotoptions import checkplotoptions 3 from model import model 4 import numpy as np 5 import math 6 from writejsfile import writejsfile 7 8 def export_gl(md,*varargin): 9 class ResultObj(object): 10 def __getattr__(self, attr): 11 return self.__dict__.get(attr) 12 print ('getting options') 13 templist=plotoptions(varargin); 4 14 optionslist=templist.list; 5 15 options=optionslist[1]; 6 16 options=checkplotoptions(md,options); 7 17 8 18 #Setup unique directory in present dir: 9 directory=getfieldvalue(options,'directory','./'); 10 databasename=getfieldvalue(options,'database','webgl'); 11 19 print ('setting directory') 20 directory=options.getfieldvalue('directory','./'); 21 databasename=options.getfieldvalue('database','Pig'); 22 print(directory +databasename) 12 23 #scaling factor: 13 scaling_factor=getfieldvalue(options,'scaling_factor',50); 24 print ('setting scaling factor') 25 scaling_factor=options.getfieldvalue('scaling_factor',50); 14 26 15 27 #Deal with title: 16 if options['title']: 17 title=getfieldvalue(options,'title'); 28 print ('setting title') 29 if options.exist('title'): 30 title=options.getfieldvalue('title'); 18 31 else: 19 32 title=''; 20 33 21 34 #initialize model: 35 print ('initializing model') 22 36 model.title=title; 23 model.initialZoomFactor= getfieldvalue(options,'zoom',-.25);37 model.initialZoomFactor=options.getfieldvalue('zoom',-.25); 24 38 25 39 #Deal with contour {{{ 26 contour_lat1=md.mesh.lat(md.mesh.segments[:,1]); 27 contour_lat2=md.mesh.lat(md.mesh.segments[:,2]); 28 contour_long1=md.mesh.long(md.mesh.segments[:,1]); 29 contour_long2=md.mesh.long(md.mesh.segments[:,2]); 30 contour_surface1=md.geometry.surface(md.mesh.segments[:,1]); 31 contour_surface2=md.geometry.surface(md.mesh.segments[:,2]); 40 print ('getting contour') 41 contour_lat1=md.mesh.lat.take(md.mesh.segments[:,0]) 42 contour_lat2=md.mesh.lat.take(md.mesh.segments[:,1]); 43 contour_long1=md.mesh.long.take(md.mesh.segments[:,0]); 44 contour_long2=md.mesh.long.take(md.mesh.segments[:,1]); 45 contour_surface1=md.geometry.surface.take(md.mesh.segments[:,0]); 46 contour_surface2=md.geometry.surface.take(md.mesh.segments[:,1]); 32 47 33 R1=6371000* ones(len(contour_surface1),1)+scaling_factor*contour_surface1;34 R2=6371000* ones(len(contour_surface2),1)+scaling_factor*contour_surface2;48 R1=6371000*np.ones(len(contour_surface1))+scaling_factor*contour_surface1; 49 R2=6371000*np.ones(len(contour_surface2))+scaling_factor*contour_surface2; 35 50 36 contourx1 = R1 * cosd(contour_lat1) * cosd(contour_long1);37 contoury1 = R1 * cosd(contour_lat1) * sind(contour_long1);38 contourz1 = R1 * sind(contour_lat1);51 contourx1 = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.cos(math.radians(long)), R1, contour_lat1, contour_long1); 52 contoury1 = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.sin(math.radians(long)), R1, contour_lat1, contour_long1); 53 contourz1 = map(lambda r, lat: r * math.sin(math.radians(lat)), R1, contour_lat1); 39 54 40 contourx2 = R2 * cosd(contour_lat2) * cosd(contour_long2); 41 contoury2 = R2 * cosd(contour_lat2) * sind(contour_long2); 42 contourz2 = R2 * sind(contour_lat2); 43 55 contourx2 = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.cos(math.radians(long)), R2, contour_lat2, contour_long2); 56 contoury2 = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.sin(math.radians(long)), R2, contour_lat2, contour_long2); 57 contourz2 = map(lambda r, lat: r * math.sin(math.radians(lat)), R2, contour_lat2); 44 58 45 59 model.contourx1=contourx1; … … 52 66 53 67 #}}} 54 #Deal with mesh and results {{{ 55 56 57 lat=md.mesh.lat; 58 long=md.mesh.long; 68 #Deal with mesh and results {{{ 69 print ('getting mesh') 59 70 surface=md.geometry.surface; 60 71 numberofelements=md.mesh.numberofelements; 61 72 numberofvertices=md.mesh.numberofvertices; 62 63 R=6371000*ones(numberofvertices,1)+scaling_factor*surface; 64 65 x = R * cosd(lat) * cosd(long); 66 y = R * cosd(lat) * sind(long); 67 z = R * sind(lat); 68 69 73 R=6371000*np.ones(len(md.mesh.lat))+scaling_factor*surface.flatten(); 74 75 x = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.cos(math.radians(long)), R, md.mesh.lat,md.mesh.long); 76 y = map(lambda r, lat, long: r * math.cos(math.radians(lat)) * math.sin(math.radians(long)), R, md.mesh.lat,md.mesh.long); 77 z = map(lambda r, lat: r * math.sin(math.radians(lat)), R, md.mesh.lat); 78 70 79 #Deal with triangulation: 80 print('getting triangulation') 71 81 model.index=md.mesh.elements; 72 82 model.x=x; … … 75 85 model.surface=surface; 76 86 87 results = [""] 88 77 89 #Deal with data: 78 results=struct([]);90 print('getting data') 79 91 for i in xrange(1,len(optionslist)): 80 92 options=optionslist[i]; 81 93 options=checkplotoptions(md,options); 82 data=getfieldvalue(options,'data'); 94 data=options.getfieldvalue('data'); 95 results.append(ResultObj()) 83 96 results[i].data=data; 84 results[i].caxis= getfieldvalue(options,'caxis',[min(data), max(data)]);97 results[i].caxis=options.getfieldvalue('caxis',[min(data), max(data)]); 85 98 86 label= getfieldvalue(options,'label','');87 if strcmpi(label,''):99 label=options.getfieldvalue('label',''); 100 if label=='': 88 101 #create generic label: 89 label=['data', num2str(i)];102 label=['data', str(i)]; 90 103 results[i].label=label; 91 104 92 shortlabel= getfieldvalue(options,'shortlabel','');93 if s trcmpi(shortlabel,''):105 shortlabel=options.getfieldvalue('shortlabel',''); 106 if shortlabel=='': 94 107 #create generic short label: 95 shortlabel=['data', num2str(i)];108 shortlabel=['data', str(i)]; 96 109 results[i].shortlabel=shortlabel; 97 110 98 111 if len(data[2])>1: 99 time_range= getfieldvalue(options,'time_range',[0, 100]);112 time_range=options.getfieldvalue('time_range',[0, 100]); 100 113 results[i].time_range=time_range; 101 114 102 unit= getfieldvalue(options,'unit','');103 if strcmpi(unit,''):115 unit=options.getfieldvalue('unit',''); 116 if unit=='': 104 117 #create generic unit: 105 118 unit='SI'; … … 108 121 109 122 #Write model to javascript database file: 123 print('writing to file') 110 124 writejsfile(directory + databasename + '.js',model,databasename); 111 125 #}}} -
issm/trunk-jpl/src/m/plot/writejsfield.py
r19037 r19044 6 6 # 7 7 #write array: 8 if len(variable[2])==1: 9 fid.write('<!-- {0}{{{-->\n'.format(name)) 8 #if not isinstance(variable, list): 9 if True: 10 fid.write('<!-- {0}{{{{{{-->\n'.format(name)) 10 11 fid.write('{0}=['.format(name)) 11 12 for i in xrange(1, nods-1): 12 fid.write('{0},' ,variable[i])13 fid.write('{0}];\n' ,variable[-1])14 fid.write('<!--}}} -->\n')13 fid.write('{0},'.format(variable[i])) 14 fid.write('{0}];\n'.format(variable[-1])) 15 fid.write('<!--}}}}}}-->\n') 15 16 else: 16 17 #multi-sized array: 17 fid.write('<!-- {0}{{{ -->\n'.format(name))18 fid.write('<!-- {0}{{{{{{-->\n'.format(name)) 18 19 fid.write('{0}=[]\n'.format(name)) 19 20 for i in xrange(1, len(variable[2])): 20 21 fid.write('{0}["{1}"]=['.format(name,i)) 21 22 for j in xrange(1, nods-1): 22 fid.write('{0},'.format(variable[j ,i]))23 fid.write('{0}];\n'.format(variable[-1 ,i]))24 fid.write('<!--}}} -->\n')23 fid.write('{0},'.format(variable[j][i])) 24 fid.write('{0}];\n'.format(variable[-1][i])) 25 fid.write('<!--}}}}}}-->\n') -
issm/trunk-jpl/src/m/plot/writejsfile.py
r19037 r19044 1 from writejsfield import writejsfield 1 2 def writejsfile(filename,model,keyname): 2 3 #WRITEJSFILE - write model file to javascript database … … 7 8 8 9 nods=len(model.x) 9 nel=len(model.index [1])10 nel=len(model.index) 10 11 nx=len(model.contourx1) 11 12 fid=open(filename,'w' )12 print(filename) 13 fid=open(filename,'w', 0) 13 14 14 15 fid.write('model = {};\n') 15 16 fid.write('model["title"]="{0}";\n'.format(model.title)) 16 17 fid.write('model["initialZoomFactor"]={0};\n'.format(model.initialZoomFactor)) 17 18 18 #write index: 19 19 fid.write('<!-- model["index"]{{{-->\n') 20 20 fid.write('model["index"]=[') 21 for i in xrange(1, nel-1):22 fid.write('[{0}, {1}, {2}],'.format(model.index[i][ 1],model.index[i][2],model.index[i][3]))23 fid.write('[{0}, {1}, {2}]];\n'.format(model.index[-1][ 1],model.index[-1][2],model.index[-1][3]))21 for i in xrange(1, nel-1): 22 fid.write('[{0}, {1}, {2}],'.format(model.index[i][0],model.index[i][1],model.index[i][2])) 23 fid.write('[{0}, {1}, {2}]];\n'.format(model.index[-1][0],model.index[-1][1],model.index[-1][2])) 24 24 fid.write('<!--}}}-->\n') 25 25 print('writing model coordinates') 26 26 writejsfield(fid,'model["x"]',model.x,nods) 27 27 writejsfield(fid,'model["y"]',model.y,nods) … … 35 35 writejsfield(fid,'model["contourz2"]',model.contourz2,nx) 36 36 37 37 print('writing results') 38 38 results=model.results 39 39 fid.write('results={};\n') … … 43 43 writejsfield(fid,'result["data"]',results[i].data,nods) 44 44 fid.write('<!--{{{-->\n') 45 fid.write('result["caxis"]=[{0},{1}];\n'.format(results[i].caxis[ 1],results[i].caxis[2]))45 fid.write('result["caxis"]=[{0},{1}];\n'.format(results[i].caxis[0],results[i].caxis[1])) 46 46 fid.write('result["label"]="{0}";\n'.format(results[i].label)) 47 47 fid.write('result["shortlabel"]="{0}";\n'.format(results[i].shortlabel)) 48 48 fid.write('result["unit"]="{0}";\n'.format(results[i].unit)) 49 49 if len(results[i].data[2])>1: 50 fid.write('result["time_range"]=[{0},{1}];\n'.format(results[i].time_range[ 1],results[i].time_range[2]))50 fid.write('result["time_range"]=[{0},{1}];\n'.format(results[i].time_range[0],results[i].time_range[1])) 51 51 fid.write('results["{0}"]=result;\n'.format(i)) 52 52 fid.write('<!--}}}-->\n')
Note:
See TracChangeset
for help on using the changeset viewer.