Changeset 21828
- Timestamp:
- 07/20/17 04:16:12 (8 years ago)
- Location:
- issm/trunk-jpl/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp
r17207 r21828 6 6 #include "../../shared/shared.h" 7 7 8 void InterpFromMeshToGridx(double** px_m,double** py_m,double** pgriddata,double* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh, int data_length, double xmin,double ymax,double xposting,double yposting,int nlines,int ncols,double default_value) { 9 10 /*Output*/ 11 double* griddata=NULL; 12 double* x_grid=NULL; 13 double* y_grid=NULL; 8 void InterpFromMeshToGridx(double** pgriddata,double* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh,int data_length,double* x_grid,double* y_grid,int nlines,int ncols,double default_value){ 14 9 15 10 /*Intermediary*/ 16 int i,j ,n;11 int i,j; 17 12 int i1,i2,j1,j2; 18 13 int interpolation_type; 19 bool debug;20 int xflip,yflip;21 14 double area; 22 15 double area_1,area_2,area_3; … … 28 21 29 22 /*some checks*/ 30 if (nels<1 || nods<3 || nlines<1 || ncols<1 || xposting==0 || yposting==0){ 31 _error_("nothing to be done according to the mesh given in input"); 32 } 23 if(nels<1 || nods<3 || nlines<2 || ncols<2) _error_("nothing to be done according to the mesh given in input"); 33 24 34 25 /*figure out what kind of interpolation is needed*/ 35 if (data_length==nods){ 36 interpolation_type=1; 37 } 38 else if (data_length==nels){ 39 interpolation_type=2; 40 } 41 else{ 42 _error_("length of vector data not supported yet. It should be of length (number of nodes) or (number of elements)!"); 43 } 26 if(data_length==nods) interpolation_type=1; 27 else if(data_length==nels) interpolation_type=2; 28 else _error_("length of vector data not supported yet. It should be of length (number of nodes) or (number of elements)!"); 44 29 45 30 /*First, allocate pointers: */ 46 griddata=xNewZeroInit<double>(nlines*ncols); 47 x_grid=xNewZeroInit<double>(ncols); 48 y_grid=xNewZeroInit<double>(nlines); 31 double* griddata=xNewZeroInit<double>(nlines*ncols); 49 32 50 33 /*Set debug to 1 if there are lots of elements*/ 51 debug=(bool)((double)ncols*nlines*nels >= 5*pow(10.,10.));34 bool debug=(bool)((double)ncols*nlines*nels >= 5.e10); 52 35 53 36 /*Initialize coordintes and griddata*/ 54 for(i=0;i<nlines;i++){ 55 for(j=0;j<ncols; j++){ 56 griddata[i*ncols+j]=default_value; 57 } 58 } 37 for(i=0;i<nlines;i++) for(j=0;j<ncols; j++) griddata[i*ncols+j]=default_value; 38 59 39 /*figure out if x or y are flipped*/ 60 if (xposting<0) xflip=1;61 else xflip=0;62 if ( yposting<0) yflip=1;63 else yflip=0;40 bool xflip = false; 41 bool yflip = false; 42 if (x_grid[1]-x_grid[0]<0) xflip=true; 43 if (y_grid[1]-y_grid[0]<0) yflip=true; 64 44 65 /*Get extreme coordinates of the grid*/ 66 if (xflip){ 67 for(i=0;i<ncols; i++) x_grid[ncols-1-i] = xmin - xposting*i; 45 /*Get min/max coordinates of the grid*/ 46 double xposting = x_grid[1]-x_grid[0]; 47 double yposting = y_grid[1]-y_grid[0]; 48 if(xflip){ 68 49 x_grid_min=x_grid[ncols-1]; 69 50 x_grid_max=x_grid[0]; 70 51 } 71 52 else{ 72 for(i=0;i<ncols; i++) x_grid[i]= xmin + xposting*i;73 53 x_grid_min=x_grid[0]; 74 54 x_grid_max=x_grid[ncols-1]; 75 55 } 76 if (yflip){ 77 for(i=0;i<nlines;i++) y_grid[i] = ymax + yposting*i; 56 if(yflip){ 78 57 y_grid_min=y_grid[nlines-1]; 79 58 y_grid_max=y_grid[0]; 80 59 } 81 60 else{ 82 for(i=0;i<nlines;i++) y_grid[nlines-1-i]= ymax - yposting*i;83 61 y_grid_min=y_grid[0]; 84 62 y_grid_max=y_grid[nlines-1]; … … 86 64 87 65 /*Loop over the elements*/ 88 for (n=0;n<nels;n++){66 for(int n=0;n<nels;n++){ 89 67 90 68 /*display current iteration*/ 91 if 69 if(debug && fmod((double)n,(double)100)==0) 92 70 _printf_("\r interpolation progress: "<<setw(6)<<setprecision(2)<<double(n)/double(nels)*100<<"% "); 93 71 … … 95 73 x_tria_min=x_mesh[(int)index_mesh[3*n+0]-1]; x_tria_max=x_tria_min; 96 74 y_tria_min=y_mesh[(int)index_mesh[3*n+0]-1]; y_tria_max=y_tria_min; 97 for 75 for(i=1;i<3;i++){ 98 76 if(x_mesh[(int)index_mesh[3*n+i]-1]<x_tria_min) x_tria_min=x_mesh[(int)index_mesh[3*n+i]-1]; 99 77 if(x_mesh[(int)index_mesh[3*n+i]-1]>x_tria_max) x_tria_max=x_mesh[(int)index_mesh[3*n+i]-1]; … … 103 81 104 82 /*if the current triangle is not in the grid, continue*/ 105 if 83 if( (x_tria_min>x_grid_max) || (x_tria_max<x_grid_min) || (y_tria_min>y_grid_max) || (y_tria_max<y_grid_min) ) continue; 106 84 107 85 /*Get indices i and j that form a square around the currant triangle*/ 108 if 86 if(yflip){ 109 87 i1=max(0, (int)floor((y_tria_max-y_grid_max)/yposting)-1); 110 88 i2=min(nlines-1,(int)ceil((y_tria_min-y_grid_max)/yposting)); … … 114 92 i2=min(nlines-1,(int)ceil((y_tria_max-y_grid_min)/yposting)); 115 93 } 116 if 94 if(xflip){ 117 95 j1=max(0, (int)floor((x_tria_max-x_grid_max)/xposting)-1); 118 96 j2=min(ncols-1,(int)ceil((x_tria_min-x_grid_max)/xposting)); … … 130 108 131 109 /*Go through x_grid and y_grid and interpolate if necessary*/ 132 for 110 for(i=i1;i<=i2;i++){ 133 111 134 112 //exit if y not between y_tria_min and y_tria_max … … 147 125 - (y_mesh[(int)index_mesh[3*n+0]-1]-y_mesh[(int)index_mesh[3*n+2]-1])*(x_grid[j]-x_mesh[(int)index_mesh[3*n+2]-1]))/area; 148 126 /*Get third area coordinate = 1-area1-area2*/ 149 area_3=1 -area_1-area_2;127 area_3=1.-area_1-area_2; 150 128 151 129 /*is the current point in the current element?*/ 152 if 130 if(area_1>-10e-12 && area_2>-10e-12 && area_3>-10e-12){ 153 131 154 132 /*Yes ! compute the value on the point*/ 155 if 133 if(interpolation_type==1){ 156 134 /*nodal interpolation*/ 157 135 data_value=area_1*data_mesh[(int)index_mesh[3*n+0]-1]+area_2*data_mesh[(int)index_mesh[3*n+1]-1]+area_3*data_mesh[(int)index_mesh[3*n+2]-1]; … … 169 147 } 170 148 } 171 if (debug) 172 _printf_("\r interpolation progress: "<<fixed<<setw(6)<<setprecision(2)<<100.<<"% \n"); 149 if(debug) _printf_("\r interpolation progress: "<<fixed<<setw(6)<<setprecision(2)<<100.<<"% \n"); 173 150 174 151 /*Assign output pointers:*/ 175 152 *pgriddata=griddata; 176 *px_m=x_grid;177 *py_m=y_grid;178 153 } -
issm/trunk-jpl/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.h
r9242 r21828 8 8 #include "../../toolkits/toolkits.h" 9 9 10 void InterpFromMeshToGridx(double** p x_m,double** py_m,double** pgriddata,double* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh, int data_length, double xmin,double ymax,double xposting,double yposting,int nlines,int ncols,double default_value);10 void InterpFromMeshToGridx(double** pgriddata,double* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh,int data_length,double* x_grid,double* y_grid,int nlines,int ncols,double default_value); 11 11 12 12 #endif /* _INTERPFROMMESHTOGRIDX_H */ -
issm/trunk-jpl/src/m/kml/kmlimagesc.m
r13007 r21828 46 46 47 47 %figure out nlines and ncols in our image 48 nlines=(maxlat-minlat)/posting;49 ncols=(maxlong-minlong)/posting;48 x_m = minlong:posting:maxlong; 49 y_m = minlat:posting:maxlat; 50 50 51 51 %regrid to lat,long grid 52 [x_m,y_m,field]=InterpFromMeshToGrid(md.mesh.elements,md.mesh.long,md.mesh.lat,field,minlong,maxlat,posting,posting,nlines,ncols,NaN);52 field=InterpFromMeshToGrid(md.mesh.elements,md.mesh.long,md.mesh.lat,field,x_m,y_m,NaN); 53 53 field=flipud(field); 54 54 -
issm/trunk-jpl/src/m/miscellaneous/diagnostics.m
r21455 r21828 46 46 yposting=getfieldvalue(options,'velposting',500); 47 47 48 xmin=min(md.mesh.x); ymax=max(md.mesh.y); 49 ncols=(max(md.mesh.x)-min(md.mesh.x))/xposting+1; 50 nlines=(max(md.mesh.y)-min(md.mesh.y))/yposting+1; 48 xm=min(md.mesh.x):posting:max(md.mesh.x); 49 ym=min(md.mesh.y):posting:max(md.mesh.y); 51 50 52 [xm,ym,vel]=InterpFromMeshToGrid(md.mesh.elements,md.mesh.x,md.mesh.y,vel,xmin,ymax,xposting,yposting,nlines,ncols,0);51 vel=InterpFromMeshToGrid(md.mesh.elements,md.mesh.x,md.mesh.y,vel,xm,ym,0.); 53 52 vel=uint16(flipud(vel)); 54 53 -
issm/trunk-jpl/src/m/modules/InterpFromMeshToGrid.m
r20875 r21828 1 function [x_m,y_m,griddata] = InterpFromMeshToGrid(index,x,y,data,xmin,ymax,xposting,yposting,nlines,ncols,default_value);1 function grid = InterpFromMeshToGrid(index,x,y,data,xgrid,ygrid,default_value); 2 2 %INTERPFROMMESHTOGRID - Interpolation of a data defined on a mesh onto a grid 3 % 4 % Usage: 5 % grid = InterpFromMeshToGrid(index,x,y,data,xgrid,ygrid,default_value) 3 6 % 4 7 % This function is a multi-threaded mex file that interpolates a field defined on a triangular … … 8 11 % meshdata: vertex values of data to be interpolated 9 12 % 10 % x min,ymax,posting,nlines,ncols:parameters that define the grid11 % default_value: 13 % xgrid,ygrid: parameters that define the grid 14 % default_value: value of points located out of the mesh 12 15 13 16 % Check usage 14 if nargin~= 1117 if nargin~=7 15 18 help InterpFromMeshToGrid 16 19 error('Wrong usage (see above)'); … … 18 21 19 22 % Call mex module 20 [x_m,y_m,griddata] = InterpFromMeshToGrid_matlab(index,x,y,data,xmin,ymax,xposting,yposting,nlines,ncols,default_value);23 grid = InterpFromMeshToGrid_matlab(index,x,y,data,xgrid,ygrid,default_value); -
issm/trunk-jpl/src/m/modules/InterpFromMeshToGrid.py
r20909 r21828 1 1 from InterpFromMeshToGrid_python import InterpFromMeshToGrid_python 2 2 3 def InterpFromMeshToGrid(index,x,y,data,x min,ymax,xposting,yposting,nlines,ncols,default_value):3 def InterpFromMeshToGrid(index,x,y,data,xgrid,ygrid,default_value): 4 4 """ 5 5 INTERPFROMMESHTOGRID - Interpolation of a data defined on a mesh onto a grid … … 11 11 meshdata: vertex values of data to be interpolated 12 12 13 x min,ymax,posting,nlines,ncols: parameters that define the grid13 xgrid,ygrid,: parameters that define the grid 14 14 default_value: value of points located out of the mesh 15 15 """ 16 16 # Call mex module 17 x_m,y_m,griddata=InterpFromMeshToGrid_python(index,x,y,data,xmin,ymax,xposting,yposting,nlines,ncols,default_value)17 grid=InterpFromMeshToGrid_python(index,x,y,data,xgrid,ygrid,default_value) 18 18 # Return 19 return x_m,y_m,griddate19 return grid -
issm/trunk-jpl/src/m/plot/kmlgridded.m
r14195 r21828 25 25 26 26 %Interpolating data on grid 27 [x_m y_m data_grid]=InterpFromMeshToGrid(elements,x,y,data,xlim(1),ylim(2),post,post,round(diff(ylim)/post),round(diff(xlim)/post),NaN); 27 x_m = xlim(1):post:xlim(2); 28 y_m = ylim(1):post:ylim(2); 29 data_grid=InterpFromMeshToGrid(elements,x,y,data,x_m,y_m,NaN); 28 30 if size(data_grid,1)<3 | size(data_grid,2)<3, 29 31 error('data_grid size too small, check posting and units'); -
issm/trunk-jpl/src/m/plot/plot_googlemaps.m
r20834 r21828 62 62 %Prepare grid 63 63 if size(md.radaroverlay.x,1)==1 | size(md.radaroverlay.x,2)==1, 64 xmin=min(md.radaroverlay.x); 65 ymax=max(md.radaroverlay.y); 66 xspacing=md.radaroverlay.x(2)-md.radaroverlay.x(1); 67 yspacing=md.radaroverlay.y(2)-md.radaroverlay.y(1); 68 nlines=length(md.radaroverlay.y); 69 ncols =length(md.radaroverlay.x); 70 [x_m y_m data_grid]=InterpFromMeshToGrid(elements,x/getfieldvalue(options,'unit',1),y/getfieldvalue(options,'unit',1),... 71 data,xmin,ymax,xspacing,yspacing,nlines,ncols,NaN); 64 x_m = md.radaroverlay.x; 65 y_m = md.radaroverlay.y; 66 data_grid=InterpFromMeshToGrid(elements,x/getfieldvalue(options,'unit',1),y/getfieldvalue(options,'unit',1),data,x_m,y_m,NaN); 72 67 else 73 68 X = md.radaroverlay.x; -
issm/trunk-jpl/src/m/plot/plot_gridded.m
r21240 r21828 23 23 24 24 %Interpolating data on grid 25 [x_m y_m data_grid]=InterpFromMeshToGrid(elements,x,y,data,xlim(1),ylim(2),postx,posty,round(diff(ylim)/posty),round(diff(xlim)/postx),NaN); 25 x_m = xlim(1):postx:xlim(2); 26 y_m = ylim(1):posty:ylim(2); 27 data_grid=InterpFromMeshToGrid(elements,x,y,data,x_m,y_m,NaN); 26 28 data_grid_save = data_grid; 27 29 if size(data_grid,1)<3 | size(data_grid,2)<3, -
issm/trunk-jpl/src/m/plot/plot_overlay.m
r21783 r21828 58 58 59 59 %InterpFromMeshToGrid 60 xmin=min(md.radaroverlay.x);61 ymax=max(md.radaroverlay.y);62 xspacing=(max(md.radaroverlay.x)-min(md.radaroverlay.x))/(length(md.radaroverlay.x) -1);63 yspacing=(max(md.radaroverlay.y)-min(md.radaroverlay.y))/(length(md.radaroverlay.y) -1);64 if(md.radaroverlay.x(end)-md.radaroverlay.x(1)<0)65 xspacing= -xspacing;66 end67 if(md.radaroverlay.y(end)-md.radaroverlay.y(1)<0)68 yspacing= -yspacing;69 end70 nlines=length(md.radaroverlay.y);71 ncols =length(md.radaroverlay.x);72 60 disp('Interpolating data on grid...'); 61 x_m = md.radaroverlay.x; 62 y_m = md.radaroverlay.y; 73 63 if radaronly, 74 x_m=xmin:xspacing:xmin+ncols*xspacing; 75 y_m=ymax-nlines*yspacing:yspacing:ymax; 76 data_grid=NaN*ones(nlines,ncols); 64 data_grid=NaN(size(radar)); 77 65 else 78 [x_m y_m data_grid]=InterpFromMeshToGrid(elements,x/getfieldvalue(options,'unit',1),y/getfieldvalue(options,'unit',1),... 79 data,xmin,ymax,xspacing,yspacing,nlines,ncols,NaN); 66 data_grid=InterpFromMeshToGrid(elements,x/getfieldvalue(options,'unit',1),y/getfieldvalue(options,'unit',1),data,x_m,y_m,NaN); 80 67 end 81 68 … … 152 139 153 140 %Plot: 154 imagesc( md.radaroverlay.x*getfieldvalue(options,'unit',1),md.radaroverlay.y*getfieldvalue(options,'unit',1),image_rgb);set(gca,'YDir','normal');141 imagesc(x_m*getfieldvalue(options,'unit',1),y_m*getfieldvalue(options,'unit',1),image_rgb);set(gca,'YDir','normal'); 155 142 156 143 %last step: mesh overlay? -
issm/trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.cpp
r20877 r21828 12 12 _printf0_("\n"); 13 13 _printf0_(" Usage:\n"); 14 _printf0_(" [x_m,y_m,griddata]=InterpFromMeshToGrid(index,x,y,data,xmin,ymax,xposting,yposting,nlines,ncols,default_value)\n");14 _printf0_(" grid=InterpFromMeshToGrid(index,x,y,data,x_grid,y_grid,default_value)\n"); 15 15 _printf0_("\n"); 16 16 _printf0_(" index,x,y: delaunay triangulation defining the mesh.\n"); 17 17 _printf0_(" meshdata: vertex values of data to be interpolated.\n"); 18 _printf0_(" x min,ymax,posting,nlines,ncols: parameters that define the grid\n");18 _printf0_(" xgrid,ygrid: parameters that define the grid\n"); 19 19 _printf0_(" default_value: value of points located out of the mesh.\n"); 20 20 _printf0_("\n"); … … 22 22 WRAPPER(InterpFromMeshToGrid_python){ 23 23 24 /*input datasets:*/24 /*inputs */ 25 25 double* index=NULL; 26 int nel;27 26 double* x=NULL; 28 int nods;29 27 double* y=NULL; 28 int nel,nods; 30 29 double* meshdata=NULL; 31 30 int meshdata_length; 32 double xmin; 33 double ymax; 34 double xposting; 35 double yposting; 36 int nlines,ncols; 31 double* xgrid=NULL; 32 double* ygrid=NULL; 33 int nlines,ncols,test; 37 34 double default_value; 38 35 39 /* output datasets:*/36 /* outputs */ 40 37 double* griddata=NULL; 41 double* x_m=NULL;42 double* y_m=NULL;43 38 44 39 /*Boot module: */ … … 51 46 52 47 /*Input datasets: */ 53 FetchData(&index,&nel,NULL,INDEX); 54 FetchData(&x,&nods,NULL,X); 55 FetchData(&y,NULL,NULL,Y); 56 FetchData(&meshdata,&meshdata_length,NULL,MESHDATA); 57 FetchData(&xmin,XMIN); 58 FetchData(&ymax,YMAX); 59 FetchData(&xposting,XPOSTING); 60 FetchData(&yposting,YPOSTING); 61 FetchData(&nlines,NLINES); 62 FetchData(&ncols,NCOLS); 48 FetchData(&index,&nel,&test,INDEX); 49 if(test!=3) _error_("size not supported yet"); 50 FetchData(&x,&nods,X); 51 FetchData(&y,&test,Y); 52 if(test!=nods) _error_("size not supported yet"); 53 FetchData(&meshdata,&meshdata_length,MESHDATA); 54 FetchData(&xgrid,&ncols,XGRID); 55 FetchData(&ygrid,&nlines,YGRID); 63 56 FetchData(&default_value,DEFAULTVALUE); 64 57 65 58 /*Call core of computation: */ 66 InterpFromMeshToGridx(& x_m,&y_m,&griddata,index,x,y,nods,nel,meshdata,meshdata_length,xmin,ymax,xposting,yposting,nlines,ncols,default_value);59 InterpFromMeshToGridx(&griddata,index,x,y,nods,nel,meshdata,meshdata_length,xgrid,ygrid,nlines,ncols,default_value); 67 60 68 61 /*Write results: */ 69 WriteData(XM,x_m,ncols);70 WriteData(YM,y_m,nlines);71 62 WriteData(GRIDDATA,griddata,nlines,ncols); 72 63 … … 77 68 xDelete<double>(meshdata); 78 69 xDelete<double>(griddata); 79 xDelete<double>(x _m);80 xDelete<double>(y _m);70 xDelete<double>(xgrid); 71 xDelete<double>(ygrid); 81 72 82 73 /*end module: */ -
issm/trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.h
r21086 r21828 33 33 #define Y prhs[2] 34 34 #define MESHDATA prhs[3] 35 #define XMIN prhs[4] 36 #define YMAX prhs[5] 37 #define XPOSTING prhs[6] 38 #define YPOSTING prhs[7] 39 #define NLINES prhs[8] 40 #define NCOLS prhs[9] 41 #define DEFAULTVALUE prhs[10] 35 #define XGRID prhs[4] 36 #define YGRID prhs[5] 37 #define DEFAULTVALUE prhs[6] 42 38 /* serial output macros: */ 43 #define XM (mxArray**)&plhs[0] 44 #define YM (mxArray**)&plhs[1] 45 #define GRIDDATA (mxArray**)&plhs[2] 39 #define GRIDDATA (mxArray**)&plhs[0] 46 40 #endif 47 41 … … 52 46 #define Y PyTuple_GetItem(args,2) 53 47 #define MESHDATA PyTuple_GetItem(args,3) 54 #define XMIN PyTuple_GetItem(args,4) 55 #define YMAX PyTuple_GetItem(args,5) 56 #define XPOSTING PyTuple_GetItem(args,6) 57 #define YPOSTING PyTuple_GetItem(args,7) 58 #define NLINES PyTuple_GetItem(args,8) 59 #define NCOLS PyTuple_GetItem(args,9) 48 #define XGRID PyTuple_GetItem(args,4) 49 #define YGRID PyTuple_GetItem(args,5) 60 50 #define DEFAULTVALUE PyTuple_GetItem(args,10) 61 51 /* serial output macros: */ 62 #define XM output,0 63 #define YM output,1 64 #define GRIDDATA output,2 52 #define GRIDDATA output,0 65 53 #endif 66 54 67 55 /* serial arg counts: */ 68 56 #undef NLHS 69 #define NLHS 357 #define NLHS 1 70 58 #undef NRHS 71 #define NRHS 1159 #define NRHS 7 72 60 73 61 #endif /* _INTERPFROMMESHTOGRID_H*/
Note:
See TracChangeset
for help on using the changeset viewer.