Ignore:
Timestamp:
01/28/15 12:21:22 (10 years ago)
Author:
dlcheng
Message:

Updated export_gl scripts now working

File:
1 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[:]);
     1from plotoptions import plotoptions
     2from checkplotoptions import checkplotoptions
     3from model import model
     4import numpy as np
     5import math
     6from writejsfile import writejsfile
     7
     8def 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);
    414        optionslist=templist.list;
    515        options=optionslist[1];
    616        options=checkplotoptions(md,options);
    7 
     17       
    818        #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) 
    1223        #scaling factor:
    13         scaling_factor=getfieldvalue(options,'scaling_factor',50);
     24        print ('setting scaling factor')
     25        scaling_factor=options.getfieldvalue('scaling_factor',50);
    1426
    1527        #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');
    1831        else:
    1932                title='';
    2033
    2134        #initialize model:
     35        print ('initializing model')
    2236        model.title=title;
    23         model.initialZoomFactor=getfieldvalue(options,'zoom',-.25);
     37        model.initialZoomFactor=options.getfieldvalue('zoom',-.25);
    2438
    2539        #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]);
    3247
    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;
    3550
    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);
    3954       
    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);
    4458
    4559        model.contourx1=contourx1;
     
    5266
    5367        #}}}
    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')
    5970        surface=md.geometry.surface;
    6071        numberofelements=md.mesh.numberofelements;
    6172        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       
    7079        #Deal with triangulation:
     80        print('getting triangulation')
    7181        model.index=md.mesh.elements;
    7282        model.x=x;
     
    7585        model.surface=surface;
    7686       
     87        results = [""]
     88       
    7789        #Deal with data:
    78         results=struct([]);
     90        print('getting data')
    7991        for i in xrange(1,len(optionslist)):
    8092                options=optionslist[i];
    8193                options=checkplotoptions(md,options);
    82                 data=getfieldvalue(options,'data');
     94                data=options.getfieldvalue('data');
     95                results.append(ResultObj())
    8396                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)]);
    8598
    86                 label=getfieldvalue(options,'label','');
    87                 if strcmpi(label,''):
     99                label=options.getfieldvalue('label','');
     100                if label=='':
    88101                        #create generic label:
    89                         label=['data', num2str(i)];
     102                        label=['data', str(i)];
    90103                results[i].label=label;
    91104
    92                 shortlabel=getfieldvalue(options,'shortlabel','');
    93                 if strcmpi(shortlabel,''):
     105                shortlabel=options.getfieldvalue('shortlabel','');
     106                if shortlabel=='':
    94107                        #create generic short label:
    95                         shortlabel=['data', num2str(i)];
     108                        shortlabel=['data', str(i)];
    96109                results[i].shortlabel=shortlabel;
    97                
     110
    98111                if len(data[2])>1:
    99                         time_range=getfieldvalue(options,'time_range',[0, 100]);
     112                        time_range=options.getfieldvalue('time_range',[0, 100]);
    100113                        results[i].time_range=time_range;
    101114
    102                 unit=getfieldvalue(options,'unit','');
    103                 if strcmpi(unit,''):
     115                unit=options.getfieldvalue('unit','');
     116                if unit=='':
    104117                        #create generic unit:
    105118                        unit='SI';
     
    108121       
    109122        #Write model to javascript database file:
     123        print('writing to file')
    110124        writejsfile(directory + databasename + '.js',model,databasename);
    111125#}}}
Note: See TracChangeset for help on using the changeset viewer.