Skip to content

Commit

Permalink
update that should bring this working into agreement with gitlab
Browse files Browse the repository at this point in the history
When this was imported to GitHub, I had to mess with the history and remove huge dem files because they could not be uploaded.  One file was turned into a zip to make it comply with the 100MB limit, while others were never added to begin with.

This commit includes the summary at the end of the following:

Date:   Fri Aug 31 09:06:53 2018 +0200

    * got rid of unwanted data file

Date:   Wed Aug 29 13:58:05 2018 +0200

    * added way to check sample sleection

    maybe should have this work in bg any time the sampling has changed?

Date:   Wed Aug 29 12:48:28 2018 +0200

    * Deleting the result tab also deletes the sampling line

Date:   Wed Aug 29 12:07:41 2018 +0200

    * added helptext ability that helps each ZmapFunction be self-documenting
    also made it an option to iniialize functions using the ZmapMainWindow.
    For example:
    ```
    zmw = ZmapMainWindow
    bv = XYfun.bvalgrid(zmw,'DelayProcessing,true,'InteractiveMode',false)
    bv.helptext('-all')
    ```

Date:   Tue Aug 28 16:13:08 2018 +0200

    * started making additional panes aware of map window
    selections will hide and show depending upon the window.

Date:   Tue Aug 28 15:39:24 2018 +0200

    * fixed radius sampling
    fixed bug introduced a few commits ago to the catalog distance calculations
    other small fixes

Date:   Tue Aug 28 14:41:17 2018 +0200

    * bpvalgrid now functions with MyPvalClass
    Calculation logic may not be right, but at least one can now reasonably look at the code to figure out what may be wrong.

Date:   Tue Aug 28 11:10:58 2018 +0200

    * made the ploop_c_and_p_calcs from MyPvalClass readable
    can't guarantee correctness, but at least now there's a chance to understand what its doing

Date:   Mon Aug 27 17:55:50 2018 +0200

    * major (probably very broken)

    options updated
    consolidating pvalue code
    streamlined and improved event selection code
    continued adding testing code
    disabled new UI dialog boxes due to java error. They were great because they provided automated testing, but they seem to break with the way that I'm using  checkboxes (?!?!?)

Date:   Wed Aug 22 11:04:09 2018 +0200

    * removed autoradius, added copyfields
    added a copyfields function to encapsulate some repeating code.
    removed the autoradius feature, since it was poorly conceived, broken, and ill defined.

Date:   Tue Aug 21 15:56:11 2018 +0200

    * finally created EventSelectionParameters
    and am in process of wiring it up.  This breaks out functionality from EventSelectionChoice, and provides a clean way to do selections, regardless of distance units.
  • Loading branch information
CelsoReyes committed Aug 31, 2018
1 parent f9d89b8 commit 2bd0ba9
Show file tree
Hide file tree
Showing 96 changed files with 3,902 additions and 2,271 deletions.
8 changes: 4 additions & 4 deletions +defaults/sampling_defaults.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"NumNearbyEvents":150,
"NumClosestEvents":150,
"UseNumNearbyEvents":true,
"RadiusKm":10,
"MaxSampleRadius":10,
"DistanceUnits":"kilometer",
"UseEventsInRadius":false,
"WeightByDistance":false,
"maxRadiusKm":null
"WeightByDistance":false
}
14 changes: 7 additions & 7 deletions ZmapAnalysisPkg.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
%
% obj = ZmapAnalysisPkg([], catalog, eventparams, grid, shape) all values are provided as
% objects of the correct type. CATALOG should be some sort of ZmapCatalog. EVENTPARAMS
% should be a struct containing details on how to choose evnets
% should be an EventSelectionParameters object containing details on how to choose events
%
% obj = ZmapAnalysisPkg(s, catalogField, eventField, gridField, shapeField) retrieve all
% values from the structure or object "s".
Expand All @@ -23,10 +23,7 @@
% can only be set in constructor

Catalog % a ZMapCatalog. Do not change this catalog directly
% EVENTSEL is a structure containing one or more fields used to map a catalog onto a grid point:
% NumNearbyEvents, RadiusKm, UseNumNearbyEvents, UseEventsInRadius
% maxRadiusKm, requiredNumEvents
EventSel
EventSel EventSelectionParameters
Grid % ZmapGrid used to sample at points in space
Shape % Shape used to mask a catalog

Expand Down Expand Up @@ -57,14 +54,17 @@
end

methods(Static)
function obj = fromGlobal(catname)
function obj = fromGlobal(catname,polyg)
% FROMGLOBAL create the package from the Zmap Globals, using the catalog specified
%
% obj = ZMAPANALYSISPKG.FROMGLOBAL(catname)
%
% see also ZMAPDATA, ZMAPGLOBAL
ZG=ZmapGlobal.Data;
obj=ZmapAnalysisPkg(ZG, catname, 'GridSelector', 'Grid', 'selection_shape');
if ~exist('polyg','var')
polyg = ShapeGeneral;
end
obj = ZmapAnalysisPkg([], ZG.(catname), ZG.GridSelector, ZG.Grid, polyg);
end
end
end
3 changes: 3 additions & 0 deletions moveable_item.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ function moveable_item(h, updateFcn, doneFcn, varargin)
end

% modify based on unmatched varargin values
COPY = copyfields(COPY, p.Unmatched);
%{
fn=fieldnames(p.Unmatched);
for i=1:numel(fn)
COPY.(fn{i})=p.Unmatched.(fn{i});
end
%}

ARCLEN=nan; % used when latitude aware
AZ=nan; %used when latitude aware
Expand Down
24 changes: 4 additions & 20 deletions src/+XYZfun/bgrid3dB.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,11 @@
zdlg=ZmapDialog(); %h, okevent
zdlg.AddHeader('Grid Input Parameters');
zdlg.AddPopup('mc_choice','Mc Estimation Option:',labelList2,5,'Magnitude of completion option')
zdlg.AddEventSelector('evsel',ni,R,50);
obj.AddDialogOption(zdlg,'EventSelector');
zdlg.AddGridSpacing('gridopt',.1,'deg',.1,'deg',5,'km')
zdlg.AddEdit('minz','Shallowest Boundary [km]',min(ZG.primeCatalog.Depth),'Shallowest boundary');
zdlg.AddEdit('maxz','Deepest Boundary [km]',max(ZG.primeCatalog.Depth),'Deepest boundary');
[res, pressedOk]=zdlg.Create('b-value 3D Grid');
if ~pressedOk
return
end
obj.mc_choice=res.mc_choice;
% NOTE: this used to write back to ZG
obj.ni=res.evsel.NumNearbyEvents;
obj.R=res.evsel.RadiusKm;
useRadius=res.evsel.UseEventsInRadius;
dx=res.gridopt.dx;
dy=res.gridopt.dy;
dz=res.gridopt.dz;
z1=res.minz;
z2=res.maxz;

obj.Calculate();

zdlg.AddEdit('minz','Shallowest Boundary [km]',min(ZG.primeCatalog.Depth),'Shallowest boundary'); %z1
zdlg.AddEdit('maxz','Deepest Boundary [km]',max(ZG.primeCatalog.Depth),'Deepest boundary'); %z2
zdlg.Create('Name', 'b-value 3D Grid','WriteToObj',obj,'OkFcn',@obj.doIt);
end

% get the grid-size interactively and
Expand Down
10 changes: 1 addition & 9 deletions src/+XYZfun/zgrid3d.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,9 @@ function InteractiveSetup(obj)
zdlg = ZmapDialog();

zdlg.AddHeader('Choose stuff');
[res,okPressed] = zdlg.Create('3D Z-Value Parameters');
if ~okPressed
return
end
obj.SetValuesFromDialog(res);
obj.doIt()
zdlg.Create('Name', '3D Z-Value Parameters','WriteToObj',obj,'OkFcn',@obj.doIt);
end

function SetValuesFromDialog(obj, res)
% called when the dialog's OK button is pressed
end

function results=Calculate(obj)
% once the properties have been set, either by the constructor or by interactive_setup
Expand Down
45 changes: 13 additions & 32 deletions src/+XYfun/bdepth_ratio.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
bottomzone_ceiling = 7; % Top of BOTTOM zone
bottomzone_floor = 15; % Bottom of BOTTOM zone
fBinning = 0.1; % magnitude bins
Nmin = 50;
mc_choice McMethods = McMethods.MaxCurvature % magnitude of completion method
useAutoMcomp McAutoEstimate = true
end
Expand Down Expand Up @@ -39,7 +38,9 @@

ParameterableProperties = ["topzone_ceiling" "topzone_floor"....
"bottomzone_ceiling" "bottomzone_floor"...
"fBinning" "Nmin" "mc_choice" "useAutoMcomp"];
"fBinning" "NodeMinEventCount" "mc_choice" "useAutoMcomp"];

References="";
end

methods
Expand All @@ -58,39 +59,19 @@
function InteractiveSetup(obj)

% get two time periods, along with grid and event parameters
zdlg=ZmapDialog([]);
zdlg=ZmapDialog();
zdlg.AddMcAutoEstimateCheckbox('useAutoMcomp', obj.useAutoMcomp);
zdlg.AddMcMethodDropdown('mc_choice', obj.mc_choice);
zdlg.AddHeader('Please define two Depth ranges to compare');
zdlg.AddEdit('top_of_top','TOP zone ceiling [km]', obj.topzone_ceiling,'');
zdlg.AddEdit('bottom_of_top','TOP zone floor [km]', obj.topzone_floor,'');
zdlg.AddEdit('top_of_bottom','BOTTOM zone ceiling [km]', obj.bottomzone_ceiling,'');
zdlg.AddEdit('bottom_of_bottom','BOTTOM zone floor [km]', obj.bottomzone_floor,'');
zdlg.AddEdit('Nmin','Min. No. of events > Mc', obj.Nmin,...
'Min # events greater than magnitude of completeness (Mc)');
zdlg.AddEventSelector('evsel', obj.EventSelector)
[res,okPressed]=zdlg.Create('Depth Ratio Grid input parameters');
if ~okPressed
return
end

obj.SetValuesFromDialog(res)

obj.doIt()
end

function SetValuesFromDialog(obj, res)
obj.useAutoMcomp = res.useAutoMcomp;
obj.mc_choice = res.mc_choice;
obj.topzone_ceiling = res.top_of_top;
obj.topzone_floor = res.bottom_of_top;
obj.bottomzone_ceiling = res.top_of_bottom;
obj.bottomzone_floor = res.bottom_of_bottom;
obj.Nmin = res.Nmin;
obj.EventSelector = res.evsel;
zdlg.AddEdit('topzone_ceiling','TOP zone ceiling [km]', obj.topzone_ceiling,'');
zdlg.AddEdit('topzone_floor','TOP zone floor [km]', obj.topzone_floor,'');
zdlg.AddEdit('bottomzone_ceiling','BOTTOM zone ceiling [km]', obj.bottomzone_ceiling,'');
zdlg.AddEdit('bottomzone_floor','BOTTOM zone floor [km]', obj.bottomzone_floor,'');
obj.AddDialogOption(zdlg, 'NodeMinEventCount');
obj.AddDialogOption(zdlg,'EventSelector');
zdlg.Create('Name', 'Depth Ratio Grid input parameters','WriteToObj',obj,'OkFcn',@obj.doIt);
end


function modifyGlobals(obj)
obj.ZG.bvg = obj.Result.values;
end
Expand Down Expand Up @@ -145,7 +126,7 @@ function modifyGlobals(obj)



if length(topb) < obj.Nmin || length(botb) < obj.Nmin
if length(topb) < obj.NodeMinEventCount || length(botb) < obj.NodeMinEventCount

[Mc_valueTop] = mcCalculator(topb);
[Mc_valueBot] = mcCalculator(botb);
Expand Down Expand Up @@ -180,7 +161,7 @@ function modifyGlobals(obj)
% where mycat is already the subset value
idx = mycat.Magnitude >= magco-0.05;
n=sum(idx);
if sum(idx) >= obj.Nmin
if sum(idx) >= obj.NodeMinEventCount
[bv, magco, ~, av] = bvalca3(mycat.Magnitude(idx), McAutoEstimate.manual, b_overall); %not automatic estimate of Mcomp
bv2 = bvalca3(mycat.Magnitude(idx), McAutoEstimate.auto); % automatic estimate of Mcomp
else
Expand Down
84 changes: 36 additions & 48 deletions src/+XYfun/bpvalgrid.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
classdef bpvalgrid < ZmapHGridFunction
% calculate P values on X-Y grid
properties
CO = 0 % omori c parameter with sign dictating whether it is constant or not
valeg2 = 2 % omori c parameter
minpe = nan % min goodness percentage
c_initial double = 2 % omori c parameter
use_const_c logical = false
minpe double = nan % min goodness percentage
mc_choice McMethods = McMethods.MaxCurvature % magnitude of completion method
wt_auto LSWeightingAutoEstimate = true
mc_auto McAutoEstimate = true
main_event ZmapCatalog
end
properties(Constant)
PlotTag = 'bpvalgrid';
Expand All @@ -22,9 +23,9 @@
'p_value', 'p-value', '';... 11: pv
'pstd', 'p-val std', '';... 12: pstd
'c_value', 'c in days', '';... 14 cv
'mmav', 'mmav', '';... mmav
'mmav', 'R&J a-value (unadjusted, untrusted)', '';... mmav, untrusted
'k_value', 'kv', '';... kv
'mbv', 'mbv', '';... mbv
'mbv', 'R&J b-value (unadjusted, untrusted)', '';... mbv, untrusted
'deltaB', 'difference in b', '';...
'dM', 'Magnitude range map (Mmax - Mcomp)', ''...
}, 'VariableNames', {'Names','Descriptions','Units'})
Expand All @@ -33,7 +34,8 @@
'b_value_std_maxlikelihood','a_value', ...
'stan', 'power_fit', 'p_value', 'pstd',...
'c_value', 'mmav', 'k_value', 'mbv'};
ParameterableProperties = ["CO" "valeg2" "minpe" "mc_choice"];
ParameterableProperties = ["c_initial", "use_const_c", "minpe", "mc_choice", "main_event"];
References="";
end
methods
function obj=bpvalgrid(zap, varargin)
Expand Down Expand Up @@ -67,48 +69,21 @@ function InteractiveSetup(obj)

zdlg.AddMcAutoEstimateCheckbox('mc_auto', obj.mc_auto);

zdlg.AddEdit('c_val', 'omori c parameter', obj.valeg2,...
' input parameter (varying)');
zdlg.AddCheckbox('use_const_c','fixed c', obj.CO<0, {'const_c'},...
'keep the Omori C parameter fixed');
zdlg.AddEdit('const_c', 'omori c parameter', obj.valeg2,...
'C-parameter parameter (fixed)');
zdlg.AddEdit('minpe', 'min goodness %', obj.minpe,...
'Minimum goodness of fit (percentage)');
zdlg.AddCheckbox('use_const_c', 'fixed c', obj.use_const_c,[], 'keep the Omori C parameter fixed');
zdlg.AddEdit('c_initial', 'initial omori c parameter', obj.c_initial, 'C-parameter parameter');
zdlg.AddEdit('minpe', 'min goodness %', obj.minpe, 'Minimum goodness of fit (percentage)');
obj.AddDialogOption(zdlg,'EventSelector');
obj.AddDialogOption(zdlg,'NodeMinEventCount');

zdlg.AddEventSelector('evsel', obj.EventSelector);
% zdlg.AddEdit('Mmin','minMag', nan, 'Minimum magnitude');
% FIXME min number of events should be the number > Mc

[res, okpressed]=zdlg.Create('B P val grid');
if ~okpressed
return
end

obj.SetValuesFromDialog(res);
obj.doIt();
end

function SetValuesFromDialog(obj, res)
obj.mc_choice = res.mc_choice;
obj.mc_auto = res.mc_auto;
obj.valeg2=res.c_val;
obj.minpe=res.minpe;
obj.EventSelector=res.evsel;
if res.use_const_c
obj.CO=res.const_c;
obj.valeg2 = -obj.valeg2; %duplicating original inputs
else
obj.CO=0;
end
zdlg.Create('Name', 'B P val grid','WriteToObj',obj,'OkFcn', @obj.doIt);
end

function results=Calculate(obj)
%In the following line, the program selgp.m is called, which creates a rectangular grid from which then selects,
%on the basis of the vector ll, the points within the selected poligon.

ZG=ZmapGlobal.Data;
Nmin = obj.EventSelector.requiredNumEvents;
Nmin = obj.NodeMinEventCount;
minThreshMag = min(obj.RawCatalog.Magnitude);

% get the grid parameter
Expand Down Expand Up @@ -137,21 +112,29 @@ function SetValuesFromDialog(obj, res)
overall_b_value = bv;
ZG.overall_b_value = bv;

%
mpvc = MyPvalClass;
mpvc.MinThreshMag = minThreshMag;
mpvc = mpvc.setMainEvent(mainshock);
mpvc.c_initial = obj.c_initial;
mpvc.UseConstantC = obj.use_const_c;

%
mycalcmethods= {@calcguts_opt1,...
@calcguts_opt2,...
@calcguts_opt3,...
@calcguts_opt4,...
@calcguts_opt5};
calculation_function = mycalcmethods{obj.mc_choice};

% calculate at all points
obj.gridCalculations(calculation_function);

% prepare output to dektop
obj.Result.minpe = obj.minpe; %min goodness of fit (%)
obj.Result.minpe = obj.minpe; %min goodness of fit (%)

% ADDITIONAL VALUES
obj.Result.values.dM = obj.Result.values.max_mag - obj.Result.values.Mc_value;
obj.Result.values.dM = obj.Result.values.max_mag - obj.Result.values.Mc_value;
obj.Result.values.deltaB = obj.Result.values.b_value_wls - obj.Result.values.b_value_maxlikelihood;

if nargout
Expand All @@ -174,8 +157,9 @@ function SetValuesFromDialog(obj, res)
[bv, magco, stan, av] = bvalca3(b.Magnitude,McAutoEstimate.auto);
maxcat = b.subset(b.Magnitude >= magco-0.05);
if maxcat.Count >= Nmin
mpvc = mpvc.setEvents(maxcat);
[bv2, stan2] = calc_bmemag(maxcat.Magnitude, 0.1);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mypval2m(maxcat.Date,maxcat.Magnitude,'days',obj.valeg2,obj.CO,minThreshMag);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mpvc.mypval2m();

bpvg = [bv magco bv2 stan2 av stan nan pv pstd cv mmav kv mbv];
else
Expand All @@ -186,8 +170,9 @@ function SetValuesFromDialog(obj, res)
function bpvg = calcguts_opt2(b)
[bv, magco, stan, av] = bvalca3(b.Magnitude, McAutoEstimate.manual);
[bv2, stan2] = calc_bmemag(b.Magnitude, 0.1);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mypval2m(b.Date,b.Magnitude,'days',obj.valeg2,obj.CO,minThreshMag);
%[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mypval2m(b.Date(l),b.Magnitude(l),'days',obj.valeg2,obj.CO,minThreshMag);

mpvc = mpvc.setEvents(b);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mpvc.mypval2m();

bpvg = [bv magco bv2 stan2 av stan nan pv pstd cv mmav kv mbv];
end
Expand All @@ -197,9 +182,10 @@ function SetValuesFromDialog(obj, res)
maxcat = b.subset(b.Magnitude >= Mc90-0.05);
magco = Mc90;
if maxcat.Count >= Nmin
mpvc = mpvc.setEvents(maxcat);
[bv, ~, stan, av] = bvalca3(maxcat.Magnitude, McAutoEstimate.manual, overall_b_value );
[bv2, stan2] = calc_bmemag(maxcat.Magnitude,0.1);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mypval2m(maxcat.Date,maxcat.Magnitude,'days',obj.valeg2,obj.CO,minThreshMag);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mpvc.mypval2m();
bpvg = [bv magco bv2 stan2 av stan prf pv pstd cv mmav kv mbv];
else
bpvg = nan(1,numel(obj.CalcFields));
Expand All @@ -211,9 +197,10 @@ function SetValuesFromDialog(obj, res)
maxcat= b.subset(b.Magnitude >= Mc95-0.05);
magco = Mc95;
if maxcat.Count >= Nmin
mpvc = mpvc.setEvents(maxcat);
[bv, ~, stan, av] = bvalca3(maxcat.Magnitude, McAutoEstimate.manual);
[bv2, stan2] = calc_bmemag(maxcat.Magnitude,0.1);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mypval2m(maxcat.Date,maxcat.Magnitude,'days',obj.valeg2,obj.CO,minThreshMag);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mpvc.mypval2m();

bpvg = [bv magco bv2 stan2 av stan prf pv pstd cv mmav kv mbv];
else
Expand All @@ -232,9 +219,10 @@ function SetValuesFromDialog(obj, res)
end
maxcat= b.subset(b.Magnitude >= magco-0.05);
if maxcat.Count >= Nmin
mpvc = mpvc.setEvents(maxcat);
[bv, ~, stan, av] = bvalca3(maxcat.Magnitude, McAutoEstimate.manual);
[bv2, stan2] = calc_bmemag(maxcat.Magnitude,0.1);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mypval2m(maxcat.Date, maxcat.Magnitude, 'days' ,obj.valeg2,obj.CO,minThreshMag);
[pv, pstd, cv, ~, kv, ~, mmav, mbv] = mpvc.mypval2m();
bpvg = [bv magco bv2 stan2 av stan prf pv pstd cv mmav kv mbv];
else
bpvg = nan(1,numel(obj.CalcFields));
Expand Down
Loading

0 comments on commit 2bd0ba9

Please sign in to comment.