Skip to content

Commit

Permalink
230808 Ver 4.0.2: Better PS forward model + GUI changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sedysen committed Aug 8, 2023
1 parent fb27a1f commit feec920
Show file tree
Hide file tree
Showing 15 changed files with 478 additions and 321 deletions.
2 changes: 1 addition & 1 deletion src/BackwordCompatible_ginput.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%% 2017A - 2018B
if (2017.1 <= MRelease) && (MRelease <= 2018.2)
% Solve the 2017 issue by using the 2018B ginput version
[xx,yy] = sam2018b_ginput(N, haxis);
[xx,yy] = SAM_2018b_ginput(N, haxis);
return
end

Expand Down
Binary file added src/BodyWavesForwardModel.p
Binary file not shown.
3 changes: 1 addition & 2 deletions src/Pfiles__INTERNAL_VARIABLES.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

%% INFO
P.appname_3D = 'OpenHVSR-3D Inversion (BETA)';%% Note: the "3D" in P.appname is used to recognize dimensionality
P.appversion_3D = 'v4.0.1';
P.appversion_3D = '4.0.2';

%% Data shown
P.isshown.id = 0;% Id of dataset shown in inversion
Expand Down Expand Up @@ -111,4 +111,3 @@
%

%%

2 changes: 1 addition & 1 deletion src/SAM_smooth.m → src/SAM_2018a_smooth.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [c,ww] = SAM_smooth(varargin)
function [c,ww] = SAM_2018a_smooth(varargin)
%SMOOTH Smooth data.
% Z = SMOOTH(Y) smooths data Y using a 5-point moving average.
%
Expand Down
File renamed without changes.
169 changes: 169 additions & 0 deletions src/SAM_2022b_griddata3.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
function w = SAM_griddata3(x,y,z,v,xi,yi,zi,method,options)
%GRIDDATA3 Data gridding and hyper-surface fitting for 3-dimensional data.
%
% GRIDDATA3 will be removed in a future release. Use TriScatteredInterp instead.
%
% W = GRIDDATA3(X,Y,Z,V,XI,YI,ZI) fits a hyper-surface of the form
% W = F(X,Y,Z) to the data in the (usually) nonuniformly-spaced vectors
% (X,Y,Z,V). GRIDDATA3 interpolates this hyper-surface at the points
% specified by (XI,YI,ZI) to produce W.
%
% (XI,YI,ZI) is usually a uniform grid (as produced by MESHGRID) and is
% where GRIDDATA3 gets its name.
%
% [...] = GRIDDATA3(X,Y,Z,V,XI,YI,ZI,METHOD) where METHOD is one of
% 'linear' - Tessellation-based linear interpolation (default)
% 'nearest' - Nearest neighbor interpolation
%
% defines the type of surface fit to the data.
% All the methods are based on a Delaunay triangulation of the data.
% If METHOD is [], then the default 'linear' method will be used.
%
% [...] = GRIDDATA3(X,Y,Z,V,XI,YI,ZI,METHOD,OPTIONS) specifies a cell
% array of strings OPTIONS that were previously used by Qhull.
% Qhull-specific OPTIONS are no longer required and are currently ignored.
%
% Example:
% x = 2*rand(5000,1)-1; y = 2*rand(5000,1)-1; z = 2*rand(5000,1)-1;
% v = x.^2 + y.^2 + z.^2;
% d = -0.8:0.05:0.8;
% [xi,yi,zi] = meshgrid(d,d,d);
% w = griddata3(x,y,z,v,xi,yi,zi);
% Since it is difficult to visualize 4D data sets, use isosurface at 0.8:
% p = patch(isosurface(xi,yi,zi,w,0.8));
% isonormals(xi,yi,zi,w,p);
% set(p,'FaceColor','blue','EdgeColor','none');
% view(3), axis equal, axis off, camlight, lighting phong
%
% Class support for inputs X,Y,Z,V,XI,YI,ZI: double
%
% See also TriScatteredInterp, DelaunayTri, GRIDDATAN, DELAUNAYN, MESHGRID.

% Copyright 1984-2009 The MathWorks, Inc.
% $Revision: 1.11.4.11 $ $Date: 2009/09/03 05:25:18 $

if nargin < 7
error('MATLAB:griddata3:NotEnoughInputs', 'Needs at least 7 inputs.');
end
if ( nargin == 7 || isempty(method) )
method = 'linear';
elseif ~strncmpi(method,'l',1) && ~strncmpi(method,'n',1)
error('MATLAB:griddata3:InvalidMethod',...
'METHOD must be one of ''linear'', or ''nearest''.');
end
if nargin == 9
if ~iscellstr(options)
error('MATLAB:griddata3:OptsNotStringCell',...
'OPTIONS should be cell array of strings.');
end
opt = options;
else
opt = [];
end

if ndims(x) > 3 || ndims(y) > 3 || ndims(z) > 3 || ndims(xi) > 3 || ndims(yi) > 3 || ndims(zi) > 3
error('MATLAB:griddata3:HigherDimArray',...
'X,Y,Z and XI,YI,ZI cannot be arrays of dimension greater than three.');
end

x = x(:); y=y(:); z=z(:); v = v(:);
m = length(x);
if m < 3, error('MATLAB:griddata3:NotEnoughPts','Not enough unique sample points specified.'); end
if m ~= length(y) || m ~= length(z) || m ~= length(v)
error('MATLAB:griddata3:InputSizeMismatch',...
'X,Y,Z,V must all have the same size.');
end

X = [x y z];

% Sort (x,y,z) so duplicate points can be averaged before passing to delaunay

[X, ind] = sortrows(X);
v = v(ind);
ind = all(diff(X)'==0);
if any(ind)
warning('MATLAB:griddata3:DuplicateDataPoints',['Duplicate x data points ' ...
'detected: using average of the v values.']);
ind = [0 ind];
ind1 = diff(ind);
fs = find(ind1==1);
fe = find(ind1==-1);
if fs(end) == length(ind1) % add an extra term if the last one start at end
fe = [fe fs(end)+1];
end

for i = 1 : length(fs)
% averaging v values
v(fe(i)) = mean(v(fs(i):fe(i)));
end
X = X(~ind(2:end),:);
v = v(~ind(2:end));
end

if size(X,1) < 3
error('MATLAB:griddata3:NotEnoughSamplePts',...
'Not enough unique sample points specified.');
end

%warning('MATLAB:griddata3:DeprecatedFunction',...
% 'GRIDDATA3 will be removed in a future release. Use TriScatteredInterp instead.');

switch lower(method(1)),
case 'l'
w = linear(X,v,[xi(:) yi(:) zi(:)]);
case 'n'
w = nearest(X,v,[xi(:) yi(:) zi(:)]);
otherwise
error('MATLAB:griddata3:UnknownMethod', 'Unknown method.');
end
w = reshape(w,size(xi));



%------------------------------------------------------------
function vi = linear(x,v,xi)
%LINEAR Triangle-based linear interpolation

% Reference: David F. Watson, "Contouring: A guide
% to the analysis and display of spacial data", Pergamon, 1994.

dt = DelaunayTri(x);
scopedWarnOff = warning('off', 'MATLAB:TriRep:EmptyTri3DWarnId');
restoreWarnOff = onCleanup(@()warning(scopedWarnOff));
dtt = dt.Triangulation;
if isempty(dtt)
error('MATLAB:griddata3:EmptyTriangulation','Error computing Delaunay triangulation. The sample datapoints may be coplanar or collinear.');
end


if(isreal(v))
F = TriScatteredInterp(dt,v);
vi = F(xi);
else
vre = real(v);
vim = imag(v);
F = TriScatteredInterp(dt,vre);
vire = F(xi);
F.V = vim;
viim = F(xi);
vi = complex(vire,viim);
end

%------------------------------------------------------------
function vi = nearest(x,v,xi)
%NEAREST Triangle-based nearest neightbor interpolation

% Reference: David F. Watson, "Contouring: A guide
% to the analysis and display of spacial data", Pergamon, 1994.

dt = DelaunayTri(x);
scopedWarnOff = warning('off', 'MATLAB:TriRep:EmptyTri3DWarnId');
restoreWarnOff = onCleanup(@()warning(scopedWarnOff));
dtt = dt.Triangulation;
if isempty(dtt)
error('MATLAB:griddata3:EmptyTriangulation','Error computing Delaunay triangulation. The sample datapoints may be coplanar or collinear.');
end
k = dt.nearestNeighbor(xi);
vi = k;
d = find(isfinite(k));
vi(d) = v(k(d));
43 changes: 28 additions & 15 deletions src/START_OpenHVSR.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
%% University Of Ferrara (Italy)
%% - User Interface
%% - Montecarlo inversion
%%
%% TESTED MATLAB CONFIGURATIONS: (started tracking on August 2, 2023)
% OpenHVSR --- MATLAB
% 4.0.2 --- R2022b 64-bit (glnxa64)
%%
%%
%% Project Evolution
%% Date:
Expand All @@ -24,19 +29,26 @@
%% December 5, 2017 Minor Bugfix: linspace. (not affecting functionality)
%% September 27, 2018 Files with different frequency scales are now accepted
%% October 2, 2018 smooth.m (curve fittin toolbox) included as SAM_smooth.m
%% November 18, 2018 modifies curve and slope terms management in the energy function
%% NEW move-over suggestionss
%% NEW test-function in model_manager for surface-waves
%% April 4, 2019 New version 4.0.0 (Beta)
%% NEW main tab showing the survey map
%% NEW multiple profiles definition
%% NEW terrain elevation in profiles
%% August 10, 2020 2D profile revision
%% September 10, 2020 Improved the View Menu.
%% Solved a minor issue with color_axis variable.
%% Improved image production
%% Changed behavior of "Refresh" button
%% November 18, 2018 modifies curve and slope terms management in the energy function
% NEW move-over suggestionss
% NEW test-function in model_manager for surface-waves
%% April 4, 2019 New version 4.0.0 (Beta)
% NEW main tab showing the survey map
% NEW multiple profiles definition
% NEW terrain elevation in profiles
%% August 10, 2020 2D profile revision
%% September 10, 2020 Improved the View Menu.
% Solved a minor issue with color_axis variable.
% Improved image production
% Changed behavior of "Refresh" button
%% January 27,2021 fixed backword compatibility R2016b: (gimput)
%% August 02, 2023 TESTED AND WORKING ON MATLAB 2022b
% - name change: sam_ginput.m >> SAM_2018b_ginput.m
% - name change: sam_smooth.m >> SAM_2018a_smooth.m
% - name change: as_Samuel.m >> BodyWavesForwardModel.p
% - implemented memory preallocation in
% BodyWavesForwardModel, for efficiency
% - created SAM_2022b_griddata3.m from griddata3.m
%%
%%
%%
Expand All @@ -54,8 +66,8 @@
%% -----------------------------------------------------------------------
enable_menu = 0;
%% -----------------------------------------------------------------------
mode = '2D';%% only 2D (better for 2-D profiles)
mode = '3D';%%
mode = '3D'; %% 3D is enable by default.
% mode = '2D';%% uncomment this line to stat in 2D mode (better for 2-D profiles)
%% -----------------------------------------------------------------------
%% some settings
fontsizeis = 15;
Expand All @@ -80,7 +92,8 @@
gui_2D_210127(enable_menu,fontsizeis);% routine for 2D geometry
end
if strcmp(mode,'3D')
gui_3D_210127();% routine for 3D geometry
% gui_3D_210127();% routine for 3D geometry
gui_3D_230802();% routine for 3D geometry
end


Expand Down
5 changes: 3 additions & 2 deletions src/SparseDtata_XYZD_to_3D.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
Z = reshape( Z, L,1);
D = reshape( D, L,1);

VM = griddata3( X, Y, Z, D, XM,YM,ZM, 'nearest');
% VM = griddata3( X, Y, Z, D, XM,YM,ZM, 'nearest');
VM = SAM_2022b_griddata3( X, Y, Z, D, XM,YM,ZM, 'nearest');
VM = smooth3(VM,'box',5);
correct_for_surface(meshed_surface);
trim_edges();
Expand Down Expand Up @@ -76,7 +77,7 @@
ylim([min(surface_locations(:,2)), max(surface_locations(:,2))]); hold off
%zlim([min(surface_locations(:,3)), max(surface_locations(:,3))]); hold on
hold off
fprintf('done')
%fprintf('done')


%% SUBFUNCTIONS
Expand Down
Loading

0 comments on commit feec920

Please sign in to comment.