Changeset 25065
- Timestamp:
- 06/18/20 16:01:39 (5 years ago)
- Location:
- issm/trunk-jpl/src/m
- Files:
-
- 7 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/basin.m
r24779 r25065 19 19 methods 20 20 function self = basin(varargin) % {{{ 21 switch nargin 22 case 0 23 self=setdefaultparameters(self); 24 otherwise 25 26 self=setdefaultparameters(self); 27 options=pairoptions(varargin{:}); 28 29 %recover field values: 30 self.boundaries=getfieldvalue(options,'boundaries',{}); 31 self.name=getfieldvalue(options,'name',''); 32 self.continent=getfieldvalue(options,'continent',''); 33 34 %figure out projection string: 21 self=setdefaultparameters(self); 22 23 if nargin>0, 24 options=pairoptions(varargin{:}); 25 26 %recover field values: 27 self.boundaries=getfieldvalue(options,'boundaries',{}); 28 self.name=getfieldvalue(options,'name',''); 29 self.continent=getfieldvalue(options,'continent',''); 30 31 %figure out projection string: 32 if exist(options,'epsg'), 33 if exist(options,'proj'), 34 error(['Error in constructor for basin ' self.name '. Cannot supply epsg and proj at the same time!']); 35 end 36 epsg=getfieldvalue(options,'epsg'); 37 proj=epsg2proj(epsg); %convert to PROJ.4 format 38 elseif exist(options,'proj'), 35 39 if exist(options,'epsg'), 36 if exist(options,'proj'), 37 error(['Error in constructor for boundary ' self.shppath '.Cannot supply epsg and proj at the same time!']); 38 end 39 epsg=getfieldvalue(options,'epsg'); 40 %convert into proj4: 41 proj=epsg2proj(epsg); 42 elseif exist(options,'proj'), 43 if exist(options,'epsg'), 44 error(['Error in constructor for boundary ' self.shppath '.Cannot supply epsg and proj at the same time!']); 45 end 46 proj=getfieldvalue(options,'proj'); 47 else 48 proj= '+proj=longlat +datum=WGS84 +no_defs'; 40 error(['Error in constructor for basin ' self.name '. Cannot supply proj and epsg at the same time!']); 49 41 end 50 self.proj=proj; 42 proj=getfieldvalue(options,'proj'); 43 else 44 proj='+proj=longlat +datum=WGS84 +no_defs'; 45 end 46 47 self.proj=proj; 51 48 end 52 49 end % }}} … … 54 51 self.name=''; 55 52 self.continent=''; 56 self.proj='+proj=longlat +datum=WGS84 +no_defs 53 self.proj='+proj=longlat +datum=WGS84 +no_defs'; %EPSG 4326 57 54 self.boundaries={}; 58 55 … … 93 90 extension=getfieldvalue(options,'extension',1); 94 91 95 [path,n me,ext]=fileparts(self.name);92 [path,name,ext]=fileparts(self.name); 96 93 if extension, 97 output=[n me ext];94 output=[name ext]; 98 95 else 99 output=n me;96 output=name; 100 97 end 101 98 end % }}} … … 174 171 outputshapefile=getfieldvalue(options,'outputshapefile',''); 175 172 176 if (exist(options,'epsgshapefile') & 173 if (exist(options,'epsgshapefile') & exist(options,'projshapefile')), 177 174 error('Basin shapefilecrop error message: cannot specify epsgshapefile and projshapefile at the same time'); 178 175 end … … 186 183 187 184 188 %create list of contours that have critical length > threshold : (in lat,long)185 %create list of contours that have critical length > threshold (in lat,long): 189 186 contours=shpread(inshapefile); 190 187 llist=[]; … … 212 209 for i=1:length(contours), 213 210 h=contours(i); 214 i n=inpolygon(h.x,h.y,ba.x,ba.y);215 if ~isempty(find(i n==0)),211 isin=inpolygon(h.x,h.y,ba.x,ba.y); 212 if ~isempty(find(isin==0)), 216 213 flags(i)=1; 217 214 end -
issm/trunk-jpl/src/m/classes/boundary.m
r24779 r25065 20 20 methods 21 21 function self = boundary(varargin) % {{{ 22 switch nargin 23 case 0 24 self=setdefaultparameters(self); 25 otherwise 26 self=setdefaultparameters(self); 27 options=pairoptions(varargin{:}); 28 29 %recover field values: 30 self.shppath=getfieldvalue(options,'shppath',''); 31 self.shpfilename=getfieldvalue(options,'shpfilename',''); 32 self.orientation=getfieldvalue(options,'orientation','normal'); 33 34 %figure out projection string: 22 self=setdefaultparameters(self); 23 24 if nargin > 0, 25 options=pairoptions(varargin{:}); 26 27 %recover field values: 28 self.shppath=getfieldvalue(options,'shppath',''); 29 self.shpfilename=getfieldvalue(options,'shpfilename',''); 30 self.orientation=getfieldvalue(options,'orientation','normal'); 31 32 %figure out projection string: 33 if exist(options,'epsg'), 34 if exist(options,'proj'), 35 error(['Error in constructor for boundary ' self.shppath '. Cannot supply epsg and proj at the same time!']); 36 end 37 epsg=getfieldvalue(options,'epsg'); 38 proj=epsg2proj(epsg); % convert to PROJ.4 format 39 elseif exist(options,'proj'), 35 40 if exist(options,'epsg'), 36 if exist(options,'proj'), 37 error(['Error in constructor for boundary ' self.shppath '.Cannot supply epsg and proj at the same time!']); 38 end 39 epsg=getfieldvalue(options,'epsg'); 40 %convert into proj4: 41 proj=epsg2proj(epsg); 42 elseif exist(options,'proj'), 43 if exist(options,'epsg'), 44 error(['Error in constructor for boundary ' self.shppath '.Cannot supply epsg and proj at the same time!']); 45 end 46 proj=getfieldvalue(options,'proj'); 47 else 48 proj= '+proj=longlat +datum=WGS84 +no_defs'; 49 end 50 self.proj=proj; 41 error(['Error in constructor for boundary ' self.shppath '. Cannot supply proj and epsg at the same time!']); 42 end 43 proj=getfieldvalue(options,'proj'); 44 else 45 proj= '+proj=longlat +datum=WGS84 +no_defs'; 46 end 47 self.proj=proj; 51 48 end 52 49 end % }}} … … 55 52 self.shpfilename=''; 56 53 self.orientation='normal'; 57 self.proj='+proj=longlat +datum=WGS84 +no_defs 54 self.proj='+proj=longlat +datum=WGS84 +no_defs'; %EPSG 4326 58 55 end % }}} 59 56 function disp(self) % {{{ … … 70 67 end % }}} 71 68 function output=edges(self) % {{{ 72 73 %read domain:74 [path,name,ext]=fileparts(self.shpfilename);75 if ~strcmpi(ext,'shp'),76 ext='shp';77 end78 output=shpread([self.shppath '/' name '.' ext]);79 80 %do we reverse?81 if strcmpi(self.orientation,'reverse'),82 output.x=flipud(output.x);83 output.y=flipud(output.y);84 end69 70 %read domain: 71 [path,name,ext]=fileparts(self.shpfilename); 72 if ~strcmpi(ext,'shp'), 73 ext='shp'; 74 end 75 output=shpread([self.shppath '/' name '.' ext]); 76 77 %do we reverse? 78 if strcmpi(self.orientation,'reverse'), 79 output.x=flipud(output.x); 80 output.y=flipud(output.y); 81 end 85 82 end % }}} 86 83 function plot(self,varargin) % {{{ … … 101 98 label=getfieldvalue(options,'label','on'); 102 99 103 if (exist(options,'epsg') & exist(options,'proj')), 104 error('Boundary plot error message: cannot specify epsg and proj at the same time for plot projection'); 105 end 106 if exist(options,'epsg'), 100 if (exist(options,'epsg'), 101 if exist(options,'proj')), 102 error('Boundary plot error message: cannot specify epsg and proj at the same time for plot projection'); 107 103 proj=epsg2proj(getfieldvalue(options,'epsg')); 108 104 elseif exist(options,'proj'), … … 119 115 domain=shpread([self.shppath '/' name '.' ext]); 120 116 121 %convert boundary to another reference frame: 117 %convert boundary to another reference frame: {{{ 122 118 for i=1:length(domain), 123 119 try, … … 169 165 isidentical=find(distance<dmax*tolerance); 170 166 if ~isempty(isidentical), 171 error(['boundary ' shpfilename ' has two 167 error(['boundary ' shpfilename ' has two vertices extremely close to one another']); 172 168 end 173 169 end … … 190 186 label=getfieldvalue(options,'label','on'); 191 187 188 if (exist(options,'epsg'), 189 if exist(options,'proj')), 190 error('Boundary plot error message: cannot specify epsg and proj at the same time for plot projection'); 191 proj=epsg2proj(getfieldvalue(options,'epsg')); 192 elseif exist(options,'proj'), 193 proj=getfieldvalue(options,'proj'); 194 else 195 proj=epsg2proj(4326); 196 end 197 192 198 %read domain: 193 199 [path,name,ext]=fileparts(self.shpfilename); -
issm/trunk-jpl/src/m/classes/plotoptions.py
r25012 r25065 1 1 from collections import OrderedDict 2 2 3 import pairoptions 3 4 … … 7 8 PLOTOPTIONS class definition 8 9 9 10 10 Usage: 11 plotoptions = plotoptions(*arg) 11 12 ''' 12 13 … … 36 37 #check length of input 37 38 if len(arg) % 2: 38 raise TypeError('Invalid parameter /value pair arguments')39 raise TypeError('Invalid parameter/value pair arguments') 39 40 40 41 #go through args and build list (like pairoptions) … … 103 104 continue 104 105 if False in [x.isdigit() for x in nums]: 105 raise ValueError('error: in option i -j both i and j must be integers')106 raise ValueError('error: in option i-j both i and j must be integers') 106 107 for j in range(int(nums[0]) - 1, int(nums[1])): 107 108 self.list[j].addfield(field, rawlist[i][1]) -
issm/trunk-jpl/src/m/classes/sealevelmodel.m
r24886 r25065 163 163 end % }}} 164 164 function addbasin(self,bas) % {{{ 165 if ~strcmpi(class(bas),'basin')166 error('addbasin method only takes a ''basin'' class object as input');167 end;168 self.basins{end+1}=bas;165 if ~strcmpi(class(bas),'basin') 166 error('addbasin method only takes a ''basin'' class object as input'); 167 end; 168 self.basins{end+1}=bas; 169 169 end % }}} 170 170 function intersections(self,varargin) % {{{ -
issm/trunk-jpl/src/m/classes/sealevelmodel.py
r25035 r25065 11 11 from TwoDToThreeD import TwoDToThreeD 12 12 13 13 14 class sealevelmodel(object): 14 15 ''' 15 16 SEALEVELMODEL class definition 16 17 17 18 18 Usage: 19 slm = sealevelmodel(*args) 19 20 20 21 where args is a variable list of options 21 22 22 23 24 25 26 27 23 Example: 24 slm = sealevelmodel( 25 'icecap', md_greenland, 26 'icecap', md_antarctica, 27 'earth', md_earth 28 ) 28 29 ''' 29 30 … … 59 60 60 61 def __repr__(self): # {{{ 61 s = ' %s\n' % fielddisplay(self, 'icecaps', 'ice caps')62 s += ' %s\n' % fielddisplay(self, 'earth', 'earth')63 s += ' %s\n' % fielddisplay(self, 'settings', 'settings properties')64 s += ' %s\n' % fielddisplay(self, 'cluster', 'cluster parameters (number of cpus...')65 s += ' %s\n' % fielddisplay(self, 'miscellaneous', 'miscellaneous fields')62 s = '{}\n'.format(fielddisplay(self, 'icecaps', 'ice caps')) 63 s += '{}\n'.format(fielddisplay(self, 'earth', 'earth')) 64 s += '{}\n'.format(fielddisplay(self, 'settings', 'settings properties')) 65 s += '{}\n'.format(fielddisplay(self, 'cluster', 'cluster parameters (number of cpus...')) 66 s += '{}\n'.format(fielddisplay(self, 'miscellaneous', 'miscellaneous fields')) 66 67 #}}} 67 68 … … 85 86 for i in range(len(slm.icecaps)): 86 87 if slm.icecaps[i].transient.iscoupler == 0: 87 warnings.warn('sealevelmodel checkconsistency error: icecap model %s should have the transient coupler option turned on!' % slm.icecaps[i].miscellaneous.name)88 warnings.warn('sealevelmodel checkconsistency error: icecap model {} should have the transient coupler option turned on!'.format(slm.icecaps[i].miscellaneous.name)) 88 89 89 90 if slm.earth.transient.iscoupler == 0: … … 93 94 for i in range(len(slm.icecaps)): 94 95 if slm.icecaps[i].mesh.numberofvertices != len(slm.earth.slr.transitions[i]): 95 raise RuntimeError('sealevelmodel checkconsistency issue with size of transition vector for ice cap: %i name: %s' %(i, slm.icecaps[i].miscellaneous.name))96 raise RuntimeError('sealevelmodel checkconsistency issue with size of transition vector for ice cap: {} name: {}'.format(i, slm.icecaps[i].miscellaneous.name)) 96 97 97 98 # Check that run frequency is the same everywhere 98 99 for i in range(len(slm.icecaps)): 99 100 if slm.icecaps[i].slr.geodetic_run_frequency != slm.earth.geodetic_run_frequency: 100 raise RuntimeError('sealevelmodel checkconsistency error: icecap model %s should have the same run frequency as earth!' % slm.icecaps[i].miscellaneous.name)101 raise RuntimeError('sealevelmodel checkconsistency error: icecap model {} should have the same run frequency as earth!'.format(slm.icecaps[i].miscellaneous.name)) 101 102 102 103 # Make sure steric_rate is the same everywhere … … 104 105 md = slm.icecaps[i] 105 106 if np.nonzero(md.slr.steric_rate - slm.earth.slr.steric_rate[slm.earth.slr.transitions[i]]) != []: 106 raise RuntimeError('steric rate on ice cap %s is not the same as for the earth' % md.miscellaneous.name)107 raise RuntimeError('steric rate on ice cap {} is not the same as for the earth'.format(md.miscellaneous.name)) 107 108 #}}} 108 109 … … 138 139 def listcaps(self): # {{{ 139 140 for i in range(len(self.icecaps)): 140 print(' %i: %s' %(i, self.icecaps[i].miscellaneous.name))141 print('{}: {}'.format(i, self.icecaps[i].miscellaneous.name)) 141 142 #}}} 142 143 … … 185 186 zei = mdi.mesh.z[mdi.mesh.elements] * onesmatrix / 3 186 187 187 print('Computing vertex intersections for basin %s' % self.basins[i].name)188 print('Computing vertex intersections for basin {}'.format(self.basins[i].name)) 188 189 189 190 self.transitions.append(meshintersect3d(self.earth.mesh.x, self.earth.mesh.y, self.earth.mesh.z, mdi.mesh.x, mdi.mesh.y, mdi.mesh.z, 'force', force)) -
issm/trunk-jpl/src/m/coordsystems/gdaltransform.m
r25035 r25065 20 20 % +proj=stere +lat_0=90 +lat_ts=71 +lon_0=-39 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.448564109 +units=m +no_defs 21 21 % 22 % 22 % To get proj.4 string from EPSG, use gdalsrsinfo. Example: 23 23 % 24 % 24 % gdalsrsinfo epsg:4326 | grep "PROJ.4" | sed "s/PROJ.4 : //" 25 25 26 26 %give ourselves unique file names -
issm/trunk-jpl/src/m/coordsystems/gdaltransform.py
r25035 r25065 6 6 from loadvars import * 7 7 8 8 9 def gdaltransform(x, y, proj_in, proj_out): #{{{ 9 10 ''' 10 11 GDALTRANSFORM - switch from one projection system to another 11 12 12 13 13 Usage: 14 [x, y] = gdaltransform(x1, y1, epsg_in, epsg_out) 14 15 15 16 16 Example: 17 [x, y] = gdaltranform(md.mesh.long, md.mesh.lat, 'EPSG:4326', 'EPSG:3031') 17 18 18 19 20 21 19 For reference: 20 EPSG: 4326 (lat, long) 21 EPSG: 3341 (Greenland, UPS 45W, 70N) 22 EPSG: 3031 (Antarctica, UPS 0E, 71S) 22 23 23 24 25 26 27 28 24 ll2xy default projection Antarctica: 25 +proj = stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.448564109 +units=m +no_defs 26 ll2xy default projection Greenland: 27 +proj = stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.448564109 +units=m +no_defs 28 Bamber's Greenland projection 29 +proj = stere +lat_0=90 +lat_ts=71 +lon_0=-39 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.448564109 +units=m +no_defs 29 30 30 31 To get proj.4 string form EPSG, use gdalsrsinfo. Example: 31 32 32 gdalsrsinfo epsg:4326 | grep "PROJ.4" | sed "s/PROJ.4 : //" 33 gdalsrsinfo epsg:4326 | grep "PROJ.4" | sed "s/PROJ.4 : //" 34 35 TODO: 36 - Remove shlex and follow subprocess pattern implemented in src/m/coordsystems/epsg2proj.py 33 37 ''' 34 38 … … 42 46 file_in.close() 43 47 44 args = shlex.split('gdaltransform -s_srs %s -t_srs %s < %s > %s' %(proj_in, proj_out, filename_in, filename_out))48 args = shlex.split('gdaltransform -s_srs {} -t_srs {} < {} > {}'.format(proj_in, proj_out, filename_in, filename_out)) 45 49 subprocess.check_call(args) # Will raise CalledProcessError if return code is not 0 46 50 … … 53 57 os.remove(filename_in) 54 58 os.remove(filename_out) 59 60 return [xout, yout] 55 61 #}}} -
issm/trunk-jpl/src/m/mech/analyticaldamage.py
r24213 r25065 1 1 import numpy as np 2 2 3 from averaging import averaging 3 #from plotmodel import plotmodel4 4 from thomasparams import thomasparams 5 5 -
issm/trunk-jpl/src/m/mesh/meshintersect3d.py
r25035 r25065 7 7 from pairoptions import pairoptions 8 8 9 9 10 def meshintersect3d(x, y, z, xs, ys, zs, *args): #{{{ 10 11 ''' 11 MESHINTERSECT - returns indices (into x, y, and z) of common values between (x, y, z) and (xs, ys, zs) (i.e. x(index) = xs; y(index) = ys). 12 MESHINTERSECT - returns indices (into x, y, and z) of common values between 13 (x, y, z) and (xs, ys, zs) (i.e. x(index) = xs; y(index) = ys). 12 14 ''' 13 15 -
issm/trunk-jpl/src/m/mesh/planet/gmsh/gmshplanet.py
r24942 r25065 1 import os2 1 import subprocess 3 2 … … 10 9 11 10 12 def gmshplanet(* varargin):11 def gmshplanet(*args): 13 12 ''' 14 13 GMSHPLANET - mesh generation for a sphere. Very specific code for gmsh from $ISSM_DIR/src/demos/simple_geo/sphere.geo … … 34 33 35 34 #process options 36 options = pairoptions(* varargin)35 options = pairoptions(*args) 37 36 #options = deleteduplicates(options, 1) 38 37 -
issm/trunk-jpl/src/m/plot/applyoptions.m
r24745 r25065 307 307 end 308 308 end 309 310 309 311 310 %text (default value is empty, not NaN...) … … 352 351 end 353 352 354 %streamlines s353 %streamlines 355 354 if exist(options,'streamlines'), 356 355 plot_streamlines(md,options); -
issm/trunk-jpl/src/m/plot/applyoptions.py
r24565 r25065 1 from cmaptools import getcolormap 2 try: 3 import matplotlib as mpl 4 import matplotlib.pyplot as plt 5 from matplotlib.ticker import MaxNLocator 6 except ImportError: 7 print("could not import pylab, matplotlib has not been installed, no plotting capabilities enabled") 1 8 import numpy as np 2 from cmaptools import getcolormap 9 10 from expdisp import expdisp 3 11 from plot_contour import plot_contour 4 12 from plot_streamlines import plot_streamlines 5 from expdisp import expdisp6 7 try:8 from matplotlib.ticker import MaxNLocator9 import matplotlib as mpl10 import matplotlib.pyplot as plt11 except ImportError:12 print("could not import pylab, matplotlib has not been installed, no plotting capabilities enabled")13 13 14 14 … … 20 20 render the data. This object is used for adding a colorbar. 21 21 22 23 24 25 22 Usage: 23 applyoptions(md, data, options) 24 25 See also: PLOTMODEL, PARSE_OPTIONS 26 26 ''' 27 27 … … 34 34 fontweight = options.getfieldvalue('fontweight', 'normal') 35 35 fontfamily = options.getfieldvalue('fontfamily', 'sans - serif') 36 font = {'fontsize': fontsize, 37 'fontweight': fontweight, 38 'family': fontfamily} 36 font = { 37 'fontsize': fontsize, 38 'fontweight': fontweight, 39 'family': fontfamily 40 } 39 41 # }}} 40 42 # {{{ title -
issm/trunk-jpl/src/m/plot/plot_manager.m
r25038 r25065 15 15 %figure out if this is a special plot 16 16 if ischar(data), 17 18 17 switch data, 19 20 18 case 'boundaries', 21 19 plot_boundaries(md,options,subplotwidth,i); … … 33 31 plot_highlightelements(md,options,subplotwidth,i); 34 32 return; 35 36 33 case 'qmumean', 37 34 plot_qmumean(md,options,nlines,ncols,i); 38 35 return; 39 40 36 case 'qmustddev', 41 37 plot_qmustddev(md,options,nlines,ncols,i); 42 38 return; 43 44 39 case 'qmuhistnorm', 45 40 plot_qmuhistnorm(md,options,nlines,ncols,i); 46 41 return; 47 48 42 case 'qmu_mass_flux_segments', 49 43 plot_qmu_mass_flux_segments(md,options,nlines,ncols,i); 50 44 return; 51 52 45 case 'part_hist', 53 46 plot_parthist(md,options,nlines,ncols,i); … … 121 114 plot_segments(md,options,subplotwidth,i,data) 122 115 return 123 124 116 case 'quiver' 125 117 data=[md.initialization.vx md.initialization.vy]; %Go ahead and try plot_unit 126 127 118 case {'strainrate_tensor','strainrate','strainrate_principal','strainrate_principalaxis1','strainrate_principalaxis2','strainrate_principalaxis3',... 128 119 'stress_tensor','stress','stress_principal','stress_principalaxis1','stress_principalaxis2','stress_principalaxis3',... … … 138 129 case 'transient_results', 139 130 plot_transient_results(md,options,subplotwidth,i); 140 141 131 case 'transient_field', 142 132 plot_transient_field(md,options,subplotwidth,i); 143 133 return; 144 145 134 otherwise, 146 147 135 if ismember(data,properties('model')), 148 136 data=eval(['md.' data ';']); … … 159 147 end 160 148 161 %Figure out if this is a semi-transparentplot.149 %Figure out if this is a Google Maps plot. 162 150 if exist(options,'googlemaps'), 163 151 plot_googlemaps(md,data,options,nlines,ncols,i); … … 165 153 end 166 154 167 %Figure out if this is a semi-transparent plot.155 %Figure out if this is a landsat plot. 168 156 if getfieldvalue(options,'landsat',0), 169 157 plot_landsat(md,data,options,nlines,ncols,i); … … 171 159 end 172 160 173 %Figure out if this is a semi-transparentplot.161 %Figure out if this is a gridded plot. 174 162 if exist(options,'gridded'), 175 163 plot_gridded(md,data,options,nlines,ncols,i); -
issm/trunk-jpl/src/m/plot/plot_manager.py
r24269 r25065 1 2 from checkplotoptions import checkplotoptions3 from plot_mesh import plot_mesh4 from plot_BC import plot_BC5 from plot_elementnumbering import plot_elementnumbering6 from plot_vertexnumbering import plot_vertexnumbering7 from processmesh import processmesh8 from processdata import processdata9 from plot_unit import plot_unit10 from applyoptions import applyoptions11 12 1 try: 13 2 from osgeo import gdal … … 17 6 overlaysupport = False 18 7 8 from applyoptions import applyoptions 9 from checkplotoptions import checkplotoptions 10 from plot_BC import plot_BC 11 from plot_mesh import plot_mesh 12 from plot_elementnumbering import plot_elementnumbering 19 13 if overlaysupport: 20 14 from plot_overlay import plot_overlay 15 from plot_unit import plot_unit 16 from plot_vertexnumbering import plot_vertexnumbering 17 from processdata import processdata 18 from processmesh import processmesh 21 19 22 20 … … 27 25 'fig' is a handle to the figure instance created by plotmodel. 28 26 29 'ax ' is a handle to the axes instance created by plotmodel.This is27 'axgrid' is a handle to the axes instance created by plotmodel. This is 30 28 currently generated using matplotlib's AxesGrid toolkit. 29 30 'gridindex' is passed through to specialized plot* functions and 31 applyoptions. 31 32 32 33 Usage: … … 37 38 #parse options and get a structure of options 38 39 options = checkplotoptions(md, options) 40 39 41 #get data to be plotted 40 42 data = options.getfieldvalue('data') 43 41 44 #add ticklabel has a default option 45 # 46 # TODO: Check why we are doing this and if it is absolutely necessary (see 47 # also src/m/plot/plot_mesh.py, src/m/plot/applyoptions.py) 42 48 options.addfielddefault('ticklabels', 'on') 43 49 … … 58 64 if data == 'mesh': 59 65 plot_mesh(md, options, fig, axgrid, gridindex) 60 61 #fig.delaxes(fig.axes[1]) # hack to remove colorbar after the fact 66 #fig.delaxes(fig.axes[1]) # hack to remove colorbar after the fact 62 67 return 63 68 elif data == 'BC': -
issm/trunk-jpl/src/m/plot/plot_overlay.py
r24256 r25065 1 import numpy as np 2 from processmesh import processmesh 3 from processdata import processdata 4 from xy2ll import xy2ll 1 import os 2 5 3 import matplotlib.pyplot as plt 6 4 import matplotlib as mpl 7 import os8 5 try: 9 6 from mpl_toolkits.basemap import Basemap 10 7 except ImportError: 11 8 print('Basemap toolkit not installed') 9 import numpy as np 12 10 try: 13 11 from osgeo import gdal … … 15 13 print('osgeo/gdal for python not installed, plot_overlay is disabled') 16 14 15 from processdata import processdata 16 from processmesh import processmesh 17 from xy2ll import xy2ll 18 17 19 18 20 def plot_overlay(md, data, options, ax): 19 21 ''' 20 Function for plotting a georeferenced image. This function is called 21 from within the plotmodel code. 22 Function for plotting a georeferenced image. Called from plot_manager by 23 call to plotmodel. 24 25 Usage: 26 plot_overlay(md, data, options, ax) 27 28 See also: PLOTMODEL 22 29 ''' 23 30 … … 81 88 plt.title('histogram of overlay image, use for setting overlaylims') 82 89 plt.show() 83 plt.sca(ax) # return to original axes /figure90 plt.sca(ax) # return to original axes/figure 84 91 85 92 # get parameters from cropped geotiff -
issm/trunk-jpl/src/m/plot/plot_unit.py
r24569 r25065 1 1 from cmaptools import getcolormap, truncate_colormap 2 from plot_quiver import plot_quiver3 import numpy as np4 2 try: 5 3 import matplotlib as mpl … … 10 8 except ImportError: 11 9 print("could not import pylab, matplotlib has not been installed, no plotting capabilities enabled") 10 import numpy as np 11 12 from plot_quiver import plot_quiver 12 13 13 14 14 15 def plot_unit(x, y, z, elements, data, is2d, isplanet, datatype, options, fig, axgrid, gridindex): 15 """16 ''' 16 17 PLOT_UNIT - unit plot, display data 17 18 18 19 Usage: 19 plot_unit(x, y, z, elements, data, is2d, isplanet, datatype, options)20 plot_unit(x, y, z, elements, data, is2d, isplanet, datatype, options) 20 21 21 22 See also: PLOTMODEL, PLOT_MANAGER 22 """23 ''' 23 24 #if we are plotting 3d replace the current axis 24 25 if not is2d: … … 228 229 raise ValueError('plot_unit error: 3D node plot not supported yet') 229 230 return 230 231 231 # }}} 232 232 # {{{ plotting P1 Patch (TODO) 233 234 233 elif datatype == 4: 235 234 print('plot_unit message: P1 patch plot not implemented yet') 236 235 return 237 238 236 # }}} 239 237 # {{{ plotting P0 Patch (TODO) 240 241 238 elif datatype == 5: 242 239 print('plot_unit message: P0 patch plot not implemented yet') 243 240 return 244 245 241 # }}} 246 242 else: -
issm/trunk-jpl/src/m/plot/plotmodel.m
r25038 r25065 10 10 11 11 %get number of subplots 12 subplotwidth=ceil(sqrt( options.numberofplots));12 subplotwidth=ceil(sqrt(numberofplots)); 13 13 14 14 %if nlines and ncols specified, then bypass. … … 104 104 end % }}} 105 105 106 %Use zbuffer renderer (s noother colors) and white background106 %Use zbuffer renderer (smoother colors) and white background 107 107 set(f,'Renderer','zbuffer','color',getfieldvalue(options.list{1},'figurebackgroundcolor','w')); 108 108 … … 125 125 end 126 126 else 127 error('plotmodel error message: no output data found. 127 error('plotmodel error message: no output data found.'); 128 128 end -
issm/trunk-jpl/src/m/plot/plotmodel.py
r24269 r25065 1 import numpy as np2 from plotoptions import plotoptions3 from plot_manager import plot_manager4 1 from math import ceil, sqrt 5 2 … … 9 6 except ImportError: 10 7 print("could not import pylab, matplotlib has not been installed, no plotting capabilities enabled") 8 import numpy as np 9 10 from plot_manager import plot_manager 11 from plotoptions import plotoptions 11 12 12 13 13 14 def plotmodel(md, *args): 14 ''' at command prompt, type 'plotdoc()' for additional documentation 15 ''' 16 PLOTMODEL - At command prompt, type 'plotdoc()' for additional 17 documentation. 18 19 TODO: 20 - Fix 'plotdoc()', as it is not currently working. 15 21 ''' 16 22 17 23 #First process options 18 24 options = plotoptions(*args) 19 #get number of subplots 20 subplotwidth = ceil(sqrt(options.numberofplots)) 25 21 26 #Get figure number and number of plots 22 27 figurenumber = options.figurenumber 23 28 numberofplots = options.numberofplots 24 29 25 #get hold 26 hold = options.list[0].getfieldvalue('hold', False) 30 #get number of subplots 31 subplotwidth = ceil(sqrt(numberofplots)) 32 33 # TODO: Check that commenting this out is correct; we do not need a hold 34 # under matplotlib, right? 35 # 36 # #get hold 37 # hold = options.list[0].getfieldvalue('hold', False) 27 38 28 39 #if nrows and ncols specified, then bypass … … 44 55 45 56 #check that nrows and ncols were given at the same time! 46 if n ot nr == nc:47 raise Exception(' error: nrows and ncols need to be specified together, or not at all')57 if nr != nc: 58 raise Exception('plotmodel error message: nrows and ncols need to be specified together, or not at all') 48 59 49 #Go through plots 60 # Go through plots 61 # 62 # NOTE: The following is where Python + matplolib differs substantially in 63 # implementation and inteface from MATLAB. 64 # 65 # Sources: 66 # - https://matplotlib.org/api/_as_gen/mpl_toolkits.axes_grid1.axes_grid.ImageGrid.html 67 # 50 68 if numberofplots: 51 #if plt.fignum_exists(figurenumber):52 # plt.cla()53 54 69 #if figsize specified 55 70 if options.list[0].exist('figsize'): … … 63 78 fig.set_facecolor(backgroundcolor) 64 79 65 translator = {'on': 'each', 66 'off': 'None', 67 'one': 'single'} 68 # options needed to define plot grid 80 # options needed to define plot grid 69 81 plotnum = options.numberofplots 70 82 if plotnum == 1: 71 83 plotnum = None 72 direction = options.list[0].getfieldvalue('direction', 'row') # row, column 73 axes_pad = options.list[0].getfieldvalue('axes_pad', 0.25) 74 add_all = options.list[0].getfieldvalue('add_all', True) # True, False 75 share_all = options.list[0].getfieldvalue('share_all', True) # True, False 76 label_mode = options.list[0].getfieldvalue('label_mode', 'L') # 1, L, all 84 85 # NOTE: The inline comments for each of the following parameters are 86 # taken from https://matplotlib.org/api/_as_gen/mpl_toolkits.axes_grid1.axes_grid.ImageGrid.html 87 # 88 direction = options.list[0].getfieldvalue('direction', 'row') # {"row", "column"}, default: "row" 89 axes_pad = options.list[0].getfieldvalue('axes_pad', 0.25) # float or (float, float), default : 0.02; Padding or (horizonal padding, vertical padding) between axes, in inches 90 add_all = options.list[0].getfieldvalue('add_all', True) # bool, default: True 91 share_all = options.list[0].getfieldvalue('share_all', True) # bool, default: False 92 label_mode = options.list[0].getfieldvalue('label_mode', 'L') # {"L", "1", "all"}, default: "L"; Determines which axes will get tick labels: "L": All axes on the left column get vertical tick labels; all axes on the bottom row get horizontal tick labels;. "1": Only the bottom left axes is labelled. "all": all axes are labelled. 93 94 # Translate MATLAB colorbar mode to matplotlib 95 # 96 # TODO: 97 # - Add 'edge' option (research if there is a corresponding option in 98 # MATLAB)? 99 # 77 100 colorbar = options.list[0].getfieldvalue('colorbar', 'on') # on, off (single) 78 cbar_mode = translator[colorbar]79 cbar_location = options.list[0].getfieldvalue('colorbarpos', 'right') # right, top80 cbar_size = options.list[0].getfieldvalue('colorbarsize', '5%')81 cbar_pad = options.list[0].getfieldvalue('colorbarpad', 0.025) # None or %82 101 83 axgrid = ImageGrid(fig, 111, 84 nrows_ncols=(nrows, ncols), 85 direction=direction, 86 axes_pad=axes_pad, 87 add_all=add_all, 88 share_all=share_all, 89 label_mode=label_mode, 90 cbar_mode=cbar_mode, 91 cbar_location=cbar_location, 92 cbar_size=cbar_size, 93 cbar_pad=cbar_pad) 102 if colorbar == 'on': 103 colorbar = 'each' 104 elif colorbar == 'one': 105 colorbar = 'single' 106 elif colorbar == 'off': 107 colorbar = 'None' 108 else: 109 raise RuntimeError('plotmodel error: colorbar mode \'{}\' is not a valid option'.format(colorbar)) 110 111 cbar_mode = colorbar # {"each", "single", "edge", None }, default: None 112 cbar_location = options.list[0].getfieldvalue('colorbarpos', 'right') # {"left", "right", "bottom", "top"}, default: "right" 113 cbar_pad = options.list[0].getfieldvalue('colorbarpad', 0.025) # float, default: None 114 cbar_size = options.list[0].getfieldvalue('colorbarsize', '5%') # size specification (see Size.from_any), default: "5%" 115 116 # NOTE: Second parameter is: 117 # 118 # rect(float, float, float, float) or int 119 # 120 # The axes position, as a (left, bottom, width, height) tuple or as a 121 # three-digit subplot position code (e.g., "121"). 122 # 123 axgrid = ImageGrid( 124 fig, 125 111, 126 nrows_ncols=(nrows, ncols), 127 direction=direction, 128 axes_pad=axes_pad, 129 add_all=add_all, 130 share_all=share_all, 131 label_mode=label_mode, 132 cbar_mode=cbar_mode, 133 cbar_location=cbar_location, 134 cbar_size=cbar_size, 135 cbar_pad=cbar_pad 136 ) 94 137 95 138 if cbar_mode == 'None': -
issm/trunk-jpl/src/m/qmu/helpers.py
r24894 r25065 1 import numpy as np2 1 from collections import OrderedDict 3 2 from copy import deepcopy 3 4 import numpy as np 4 5 5 6 … … 11 12 class Lstruct(list): 12 13 ''' 13 An empty struct that can be assigned arbitrary attributes 14 but can also be accesed as a list. Eg. x.y = 'hello', x[:] = ['w', 'o', 'r', 'l', 'd'] 15 16 Note that 'x' returns the array and x.__dict__ will only return 17 attributes other than the array 18 19 List-based and struct-based behaviors work normally, however they are referenced 20 as if the other does not exist; len(x) corresponds only to 21 the list component of x, len(x.a) corresponds to x.a, x.__dict__ 22 corresponds only to the non-x-list attributes 23 24 Example uses: 25 26 x = Lstruct(1, 2, 3, 4) -> [1, 2, 3, 4] 27 x.a = 'hello' 28 len(x) -> 4 29 x.append(5) 30 len(x) -> 5 31 x[2] -> 3 32 x.a -> 'hello' 33 print x -> [1, 2, 3, 4, 5] 34 x.__dict__ -> {'a':'hello'} 35 x.b = [6, 7, 8, 9] 36 x.b[-1] -> 9 37 len(x.b) -> 4 38 39 Other valid constructors: 40 x = Lstruct(1, 2, 3, a = 'hello') -> x.a -> 'hello', x -> [1, 2, 3] 41 x = Lstruct(1, 2, 3)(a = 'hello') 42 x = Lstruct([1, 2, 3], x = 'hello') 43 x = Lstruct((1, 2, 3), a = 'hello') 44 45 Credit: https://github.com/Vectorized/Python-Attribute-List 46 ''' 14 An empty struct that can be assigned arbitrary attributes but can also be 15 accesed as a list. Eg. x.y = 'hello', x[:] = ['w', 'o', 'r', 'l', 'd'] 16 17 Note that 'x' returns the array and x.__dict__ will only return attributes 18 other than the array 19 20 List-based and struct-based behaviors work normally, however they are 21 referenced as if the other does not exist; len(x) corresponds only to the 22 list component of x, len(x.a) corresponds to x.a, x.__dict__ corresponds 23 only to the non-x-list attributes 24 25 Examples: 26 27 x = Lstruct(1, 2, 3, 4) -> [1, 2, 3, 4] 28 x.a = 'hello' 29 len(x) -> 4 30 x.append(5) 31 len(x) -> 5 32 x[2] -> 3 33 x.a -> 'hello' 34 print x -> [1, 2, 3, 4, 5] 35 x.__dict__ -> {'a':'hello'} 36 x.b = [6, 7, 8, 9] 37 x.b[-1] -> 9 38 len(x.b) -> 4 39 40 Other valid constructors: 41 x = Lstruct(1, 2, 3, a = 'hello') -> x.a -> 'hello', x -> [1, 2, 3] 42 x = Lstruct(1, 2, 3)(a = 'hello') 43 x = Lstruct([1, 2, 3], x = 'hello') 44 x = Lstruct((1, 2, 3), a = 'hello') 45 46 Sources: 47 -https://github.com/Vectorized/Python-Attribute-List 48 ''' 47 49 48 50 def __new__(self, *args, **kwargs): … … 63 65 class OrderedStruct(object): 64 66 ''' 65 A form of dictionary-like structure that maintains the 66 ordering in which its fields/attributes and their 67 corresponding values were added. 68 69 OrderedDict is a similar device, however this class 70 can be used as an "ordered struct/class" giving 71 it much more flexibility in practice. It is 67 A form of dictionary-like structure that maintains the ordering in which 68 its fields/attributes and their corresponding values were added. 69 70 OrderedDict is a similar device, however this class can be used as an 71 "ordered struct/class" giving it much more flexibility in practice. It is 72 72 also easier to work with fixed valued keys in-code. 73 73 74 Eg:75 OrderedDict: # a bit clumsy to use and look at76 x['y'] = 577 78 OrderedStruct: # nicer to look at, and works the same way79 x.y = 580 OR81 x['y'] = 5 # supports OrderedDict-style usage82 83 Supports: len(x), str(x), for-loop iteration.84 Has methods: x.keys(), x.values(), x.items(), x.iterkeys()85 86 Usage:87 x = OrderedStruct()88 x.y = 589 x.z = 690 OR91 x = OrderedStruct('y', 5, 'z', 6)92 93 # note below that the output fields as iterables are always94 # in the sameorder as the inputs74 Example: 75 OrderedDict: # a bit clumsy to use and look at 76 x['y'] = 5 77 78 OrderedStruct: # nicer to look at, and works the same way 79 x.y = 5 80 OR 81 x['y'] = 5 # supports OrderedDict-style usage 82 83 Supports: len(x), str(x), for-loop iteration. 84 Has methods: x.keys(), x.values(), x.items(), x.iterkeys() 85 86 Usage: 87 x = OrderedStruct() 88 x.y = 5 89 x.z = 6 90 OR 91 x = OrderedStruct('y', 5, 'z', 6) 92 93 note below that the output fields as iterables are always in the same 94 order as the inputs 95 95 96 96 x.keys() -> ['y', 'z'] … … 111 111 ('y', 6) 112 112 113 Note: to access internal fields use dir(x) 114 (input fields will be included, but 115 are not technically internals) 113 Note: to access internal fields use dir(x) (input fields will be included, 114 but are not technically internals) 116 115 ''' 117 116 118 117 def __init__(self, *args): 119 '''Provided either nothing or a series of strings, construct a structure that will, 120 when accessed as a list, return its fields in the same order in which they were provided''' 121 122 # keys and values 118 ''' 119 Provided either nothing or a series of strings, construct a structure 120 that will, when accessed as a list, return its fields in the same order 121 in which they were provided 122 ''' 123 124 # keys and values 123 125 self._k = [] 124 126 self._v = [] … … 185 187 186 188 def __copy__(self): 187 # shallow copy, hard copies of trivial attributes, 188 # references to structures like lists/OrderedDicts 189 # unless redefined as an entirely different structure 189 ''' 190 shallow copy, hard copies of trivial attributes, 191 references to structures like lists/OrderedDicts 192 unless redefined as an entirely different structure 193 ''' 190 194 newInstance = type(self)() 191 195 for k, v in list(self.items()): … … 194 198 195 199 def __deepcopy__(self, memo=None): 196 # hard copy of all attributes 197 # same thing but call deepcopy recursively 198 # technically not how it should be done, 199 # (see https://docs.python.org/2/library/copy.html #copy.deepcopy ) 200 # but will generally work in this case 200 ''' 201 hard copy of all attributes 202 same thing but call deepcopy recursively 203 technically not how it should be done, 204 (see https://docs.python.org/2/library/copy.html #copy.deepcopy ) 205 but will generally work in this case 206 ''' 201 207 newInstance = type(self)() 202 208 for k, v in list(self.items()): … … 212 218 k = self._k.pop(i) 213 219 v = self._v.pop(i) 214 #exec('del self.%s')%(key)220 #exec('del self.%s')%(key) 215 221 return (k, v) 216 222 … … 227 233 def isempty(x): 228 234 ''' 229 returns true if object is + -infinity, NaN, None, '', has length 0, or is an 230 array/matrix composed only of such components (includes mixtures of "empty" types)''' 235 returns true if object is +/-infinity, NaN, None, '', has length 0, or is 236 an array/matrix composed only of such components (includes mixtures of 237 "empty" types) 238 ''' 231 239 232 240 if type(x) in [list, np.ndarray, tuple]: … … 262 270 263 271 def fieldnames(x, ignore_internals=True): 264 '''returns a list of fields of x 265 ignore_internals ignores all fieldnames starting with '_' and is True by default''' 272 ''' 273 returns a list of fields of x 274 ignore_internals ignores all fieldnames starting with '_' and is True by 275 default 276 ''' 266 277 result = list(vars(x).keys()) 267 278 … … 273 284 274 285 def isfield(x, y, ignore_internals=True): 275 '''is y is a field of x? 276 ignore_internals ignores all fieldnames starting with '_' and is True by default''' 286 ''' 287 is y is a field of x? 288 ignore_internals ignores all fieldnames starting with '_' and is True by 289 default 290 ''' 277 291 return str(y) in fieldnames(x, ignore_internals) 278 292 … … 281 295 ''' 282 296 given: "path/path/.../file_name.ext" 283 returns: [path, file_name, ext] (list of strings)''' 297 returns: [path, file_name, ext] (list of strings) 298 ''' 284 299 try: 285 300 a = x[:x.rindex('/')] #path … … 297 312 def fullfile(*args): 298 313 ''' 299 us e:300 301 fullfile(path, path, ... , file_name + ext) 314 usage: 315 fullfile(path, path, ... , file_name + ext) 316 302 317 returns: "path/path/.../file_name.ext" 303 318 … … 305 320 306 321 regarding extensions and the '.': 307 as final arguments ('file.doc') or ('file' + '.doc') will work308 ('final', '.doc'), and the like, will not (you'd get 'final/.doc')309 '''322 as final arguments ('file.doc') or ('file' + '.doc') will work 323 ('final', '.doc'), and the like, will not (you'd get 'final/.doc') 324 ''' 310 325 result = str(args[0]) 311 326 for i in range(len(args[1:])): … … 321 336 ''' 322 337 returns full first line containing s (as a string), or None 338 323 339 Note: will include any newlines or tabs that occur in that line, 324 use str(findline(f, s)).strip() to remove these, str() in case result is None''' 340 use str(findline(f, s)).strip() to remove these, str() in case result is 341 None 342 ''' 325 343 for line in fidi: 326 344 if s in line: … … 331 349 def empty_nd_list(shape, filler=0., as_numpy_ndarray=False): 332 350 ''' 333 returns a python list of the size/shape given (shape must be int or tuple)351 returns a python list of the size/shape given (shape must be int or tuple) 334 352 the list will be filled with the optional second argument 335 353 336 354 filler is 0.0 by default 337 355 338 as_numpy_ndarray will return the result as a numpy.ndarray and is False by default 339 340 Note: the filler must be either None/np.nan/float('NaN'), float/double, or int 341 other numpy and float values such as +/- np.inf will also work 342 343 use: 344 empty_nd_list((5, 5), 0.0) # returns a 5x5 matrix of 0.0's 345 empty_nd_list(5, None) # returns a 5 long array of NaN 346 ''' 356 as_numpy_ndarray will return the result as a numpy.ndarray and is False by 357 default 358 359 Note: the filler must be either None/np.nan/float('NaN'), float/double, or 360 int. other numpy and float values such as +/- np.inf will also work 361 362 Usage: 363 empty_nd_list((5, 5), 0.0) # returns a 5x5 matrix of 0.0's 364 empty_nd_list(5, None) # returns a 5 long array of NaN 365 ''' 347 366 result = np.empty(shape) 348 367 result.fill(filler) -
issm/trunk-jpl/src/m/shp/shpread.m
r22921 r25065 1 1 function Struct=shpread(filename,varargin) 2 %SHPREAD - read a shape file and build a Structure2 %SHPREAD - read a shape file and build a struct 3 3 % 4 % This routine reads a shape file .shp and builds a Structure containing the5 % fields x and y corresponding to the coordinates, one for the filename of6 % the shp file, for the density, for the nodes, and a field closed to7 % indicate if the domain is closed.8 % If this initial shapefile is point only, the fields closed and9 % points are ommited10 % The first argument is the .shp file to be read and the second one (optional)11 % indicates if the last point shall be read (1 to read it, 0 notto).4 % This routine reads a shape file .shp and builds a structure array 5 % containing the fields x and y corresponding to the coordinates, one for the 6 % filename of the shp file, for the density, for the nodes, and a field 7 % closed to indicate if the domain is closed. If this initial shapefile is 8 % point only, the fields closed and points are omitted. 9 % The first argument is the .shp file to be read and the second one 10 % (optional) indicates if the last point shall be read (1 to read it, 0 not 11 % to). 12 12 % 13 % 14 % 13 % Usage: 14 % Struct=shpread(filename) 15 15 % 16 % 17 % 16 % Example: 17 % Struct=shpread('domainoutline.shp') 18 18 % 19 % 19 % See also EXPDOC, EXPWRITEASVERTICES 20 20 21 21 %recover options … … 27 27 end 28 28 29 %initialize number of profile30 count=0;31 32 29 %read shapefile 33 30 shp=shaperead(filename); … … 36 33 fields=fieldnames(shp); 37 34 for i=1:length(shp), 38 if strcmpi(shp(i).Geometry,'Polygon'), 35 if strcmpi(shp(i).Geometry,'Point'), 36 x=shp(i).X'; y=shp(i).Y'; 37 ids=find(isnan(x)); 38 x(ids)=[]; y(ids)=[]; 39 40 Struct(end+1).x=x; 41 Struct(end).y=y; 42 Struct(end).density=1; 43 if isfield(shp,'id'), 44 Struct(end).name=num2str(shp(i).id); 45 else 46 Struct(end).name=''; 47 end 48 for j=1:length(fields), 49 field=fields{j}; 50 if ~(strcmpi(field,'X') | strcmpi(field,'Y') | strcmpi(field,'id')), 51 Struct(end).(field)=shp(i).(field); 52 end 53 end 54 elseif strcmpi(shp(i).Geometry,'Line'), 39 55 x=shp(i).X'; y=shp(i).Y'; 40 56 ids=find(isnan(x)); … … 57 73 end 58 74 end 59 end 60 61 if strcmpi(shp(i).Geometry,'Line'), 75 elseif strcmpi(shp(i).Geometry,'Polygon'), 62 76 x=shp(i).X'; y=shp(i).Y'; 63 77 ids=find(isnan(x)); … … 69 83 Struct(end).density=1; 70 84 Struct(end).closed=1; 71 if isfield(shp,'id'),72 Struct(end).name=num2str(shp(i).id);73 else74 Struct(end).name='';75 end76 for j=1:length(fields),77 field=fields{j};78 if ~(strcmpi(field,'X') | strcmpi(field,'Y') | strcmpi(field,'id')),79 Struct(end).(field)=shp(i).(field);80 end81 end82 end83 84 85 if strcmpi(shp(i).Geometry,'Point'),86 x=shp(i).X'; y=shp(i).Y';87 ids=find(isnan(x));88 x(ids)=[]; y(ids)=[];89 90 Struct(end+1).x=x;91 Struct(end).y=y;92 Struct(end).density=1;93 85 if isfield(shp,'id'), 94 86 Struct(end).name=num2str(shp(i).id); -
issm/trunk-jpl/src/m/shp/shpwrite.m
r22920 r25065 10 10 % See also SHPREAD 11 11 12 13 %initialize number of profile14 count=0;15 16 12 contours=struct([]); 17 13 for i=1:length(shp), … … 22 18 elseif strcmpi(shp(i).Geometry,'Line'), 23 19 contours(i).Geometry='Line'; 20 else, 21 error(['shpwrite error: geometry ' shp(i).Geometry ' not currently supported']); 24 22 end 25 23 contours(i).id=i; … … 27 25 contours(i).Y=shp(i).y; 28 26 end 29 27 30 28 shapewrite(contours,filename); 31 29 end
Note:
See TracChangeset
for help on using the changeset viewer.