Skip to content

Commit

Permalink
Merge pull request #17 from CelsoReyes/RT
Browse files Browse the repository at this point in the history
Merged branch RT
  • Loading branch information
CelsoReyes authored Apr 5, 2019
2 parents db1a28f + 3cfa188 commit fc798f2
Show file tree
Hide file tree
Showing 330 changed files with 10,299 additions and 8,432 deletions.
8 changes: 4 additions & 4 deletions +defaults/general_defaults.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"Directories":{
"output":"./output",
"data":"./eq_data",
"working":"./working"
"output":"../m_zmap_files/output",
"data":"../my_zmap_files/eq_data",
"working":"../my_zmap_files/zmap7/working"
},
"ParallelProcessing":{
"Enable":true,
"Enable":false,
"Threshhold":10000
},
"DebugMode":true,
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ working/lastcatalog.mat


dem/worlddata.zip
dem/chdata.zip
dem/topo_8.2.img
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Clicking on the `see distributions` button will show a few histograms that may h
### Main Map Screen

Once a catalog is loaded, earthquakes will be plotted in the Main Window.
![MainMapScreen](resources/img/ZmapMainWindow_20180216.png)
![MainMapScreen](docs/img/ZmapMainWindow_20180216.png)
This is where most of the work will happen. The screen is divided into several sections. When first presented, all events will be hilighted, and the main map will take up the entirety of the left side of the window.

The plots on the right side of the screen will reflect statistics for the entire catalog.
Expand Down
1 change: 1 addition & 0 deletions docs/tips_en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Reprt an issue with ZMAP|If you experiencing errors or "funny" behavior with ZMA
Reuse your polygon|Polygons can be saved and reloaded, allowing you to select the exact same region for different catalogs.
Cut the catalog to the Mc|You can remove events from the catalog that fall below the Mc directly from the FMD plot. Right click in the plot, and choose "Cut catalog at Mc".|You will have the option to modify the cutoff magnitude before committing.
Save your results|From the "Results", Choose "Save results", and then specify the desired format. Some options:| "Results as ASCII file" : all fields as columns| "bvalgrid object" : all fields and other meta information, best for reevaluating later| "Entire figure" : saves figure| "Results as table" : saves a table of all fields|"X,Y,VAL..." saves only the displayed values in an 3-column table
Print the main window|To create a more printer-friendly main-window figure, choose "Open printable figure" from the Display menu. A figure will be opened with a white background, displaying axes for only the currently selected tabs.
194 changes: 5 additions & 189 deletions importfilters/ascii_imp.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@
if is_old_zmap_style(tb)
tb = from_old_zmap_style(tb);
end
tb = interpretFromTable(tb);

disp(tb(1:min(5,height(tb)),:));

uOutput = ZmapCatalog(tb);
ok=true;
uOutput = ZmapCatalog.from(tb);
ok = true;
end
end

function tf = is_old_zmap_style(tb)
varNames = tb.Properties.VariableNames;
tf = numel(varNames)>=9 && numel(varNames) <=10; % with or without seconds
tf = 9 <= numel(varNames) && numel(varNames) <=10; % with or without seconds
tf = tf && all(startsWith(varNames,'Var')); % no variable specified in file
tf = tf && all(tb.Var1 >=-180 & tb.Var1 <= 180);
tf = tf && all(tb.Var2 >= -90 & tb.Var2 < 90);
tf = tf && all(-180 <= tb.Var1 -180 & tb.Var1 <= 180);
tf = tf && all(-90 <= tb.Var2 -90 & tb.Var2 < 90);
tf = tf && all(0 <= tb.Var9 & tb.Var9 <= 60); % minutes
tf = tf && all(0 <= tb.Var8 & tb.Var8 <= 24); % hours
tf = tf && all(0 <= tb.Var5 & tb.Var5 <= 31); % days
Expand All @@ -50,184 +46,4 @@
'Longitude', 'Latitude', 'Year','Month','Day','Magnitude','Depth','Hours','Minutes','Seconds'};
end

end

function tb = interpretFromTable(tb)
Candidates.Latitude = "^lat.*";
Candidates.Longitude = "^lon.*";
Candidates.Depth = "^dep.*";
Candidates.Magnitude = ["^mag$","^mags$","^magnitude$","^magnitudes$"];
Candidates.Date = "^date.";

Candidates.DecYear = "^decyear";
Candidates.JulianDay = ["^julian.*","^jday"];
Candidates.Time = "^time.";
Candidates.Year = ["^yr\w?", "^year\w?"];
Candidates.Month = ["^month", "^mo"];
Candidates.Day = "^day";
Candidates.Hour = ["^hr\w?","^hour"];
Candidates.Minute = ["^mi","^min","^minute."];
Candidates.Second = ["^sec","^second\w?"];

Candidates.MagnitudeType = ["^magnitudetype$","^magtype$"];
Candidates.Dip = "^dip";
Candidates.DipDirection = "^dipd.*";
Candidates.Rake = "^rake";
Candidates.MomentTensor = "^momenttensor";

fn = fieldnames(Candidates);
tbNames = lower( tb.Properties.VariableNames );
for i=1:numel(fn)
thisfield = fn{i};
for j=1:numel(Candidates.(thisfield))
thisExp = Candidates.(thisfield)(j);
mask = ~ cellfun(@isempty, regexp(tbNames, Candidates.(thisfield)(j), 'once') );
if any(mask)
if thisfield == "Depth"
s=split(tb.Properties.VariableNames(mask),["_","/"]);
for q=2:numel(s)
try
unit = validateLengthUnit(s{q});
tb.Properties.VariableUnits(mask)={unit};
catch
do_nothing();
end
end
end
tb.Properties.VariableNames(mask)={thisfield};
break
end
end
end
tb(isnan(tb.Longitude),:)=[]; % dump comments
tb.Date = munge_dates(tb) + munge_times(tb);
keepFields = {'Date','Latitude','Longitude','Magnitude','Depth',...
'MagnitudeType','Rake','Dip','DipDirection','MomentTensor'};
theoreticalOnlyFields = fn(~ismember(fn, keepFields));
vn = tb.Properties.VariableNames;
toRemove = vn(~ismember(vn,keepFields'));
tb(:,toRemove)=[];
end

function d = add_duration(d, transFcn, values)
if isnumeric(values)
d = d + transFcn(values);
elseif isduration(values)
d=d+values;
else
error('choked on duration..unknown type');
end
end
function d = munge_times(tb)
vn = tb.Properties.VariableNames;
tidx = (vn=="Time");
if any(tidx) && ~isduration(tb.Time)
fmt = timestr_to_fmt(tb.Time(1));

dt= datetime(tb.Time, 'InputFormat',fmt);
% fmt includes full date, but keep only time part
d = dt - datetime(dt.Year, dt.Month, dt.Day); % now it is a duration
return
elseif any(tidx) && isduration(tb.Time)
d =tb.Time;
return
end

d = years(zeros(height(tb),1));
if any(vn == "Hour")
d = add_duration(d, @hours, tb.Hour);
end
if any(vn == "Minute")
d = add_duration(d, @minutes, tb.Minute);
end
if any(vn == "Second")
d = add_duration(d, @seconds, tb.Second);
end

end

function dt = munge_dates(tb)
vn = tb.Properties.VariableNames;
if any(vn == "DecYear")
disp('decyear detected')
yelapsed = years(tb.DecYear); %duration
dt = datetime(0,0,0) + yelapsed;

else
if any(vn == "Time") && ~isduration(tb.Time(1))
fmt = timestr_to_fmt(tb.Time(1));
if fmt(1)=='y'
dt = datetime(tb.Time, 'InputFormat',fmt);
% fmt includes full date, but keep only time part
dt = datetime(dt.Year, dt.Month, dt.Day); % now it is just the base datetime

if all(dt.Month)==0 || all(dt.Day)==0
% continue
else
return
end
end
end
if any(vn == "Year")
yy = tb.Year;
else
yy = zeros(height(tb),1);
end
if any(vn == "Month")
mm = tb.Month;
else
mm = zeros(height(tb),1);
end
if any(vn == "Day")
dd = tb.Day;
else
dd = zeros(height(tb),1);
end
dt = datetime(yy, mm, dd);
end
end


function fmt = timestr_to_fmt(val)
% look at format for the date
if iscell(val); val=val{1};end
hasDatePart = all(ismember(val(1:4),'1234567890')); %assume 4 digit year.
hasTimePart = any(ismember(val,':')); % time

if ~hasDatePart
date_format = '';
elseif ismember('/',val)
date_format = 'yyyy/MM/dd';
else
date_format = 'yyyy-MM-dd'; %FDSN date standard
end

if ~hasTimePart
time_format = '';
elseif ismember('.',val)

% look at format for time

seconds_precision = length(val) - strfind(val,'.') - double(endsWith(val,'Z'));

time_format = 'HH:mm:ss.';
time_format(1, end+1:end+seconds_precision)='S';
else
time_format ='HH:mm:ss';
end

if endsWith(val,'Z')
time_format = [time_format, '''Z'''];
end

% look at separator between date & time fields
if ~hasDatePart
fmt = time_format;
elseif ~hasTimePart
fmt = date_format;
elseif ismember('T', val) % FDSN date standard
fmt=[date_format, '''T''', time_format];
else
fmt=[date_format, ' ', time_format];
end
end
29 changes: 10 additions & 19 deletions importfilters/import_fdsn_event.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,15 @@
ok=false;
case "BadRequest"
disp(resp.Body.Data)

numbers= double(regexp(extractBefore(resp.Body.Data,'Request:'),'\d\d\d+','match'));
% first number is the error, so ignore it.
numbers(1)=[];
% second number is
% as of 2018-12-14, USGS returns this result when limit is exceeded. these depend on the error message wording
maxSearchLimit = double(extractBefore(extractAfter(resp.Body.Data,'exceeds search limit of '),'.'));
nFound = double(extractBefore(extractAfter(resp.Body.Data,'exceeds search limit of '),'.'));
maxSearchLimit = min(numbers);
nFound = max(numbers);
if ~ismissing(maxSearchLimit)
warning("maximum number of events [%d] exceeded. atttempting to limit results", maxSearchLimit);
warning("maximum number of events [%d] exceeded. attempting to limit results", maxSearchLimit);
% try again, in chunks of maxSearchLimit
disp('* trying again while limiting results')
[resp, ok] = get_in_chunks(myuri, maxSearchLimit, nFound);
Expand Down Expand Up @@ -196,7 +199,7 @@
% spacing in header line is not guaranteed

if isempty(data)
uOutput = ZmapCatalog('nodata');
uOutput = ZmapCatalog('Name','nodata');
ok=false;
return
end
Expand Down Expand Up @@ -252,7 +255,7 @@
for j=1:length(conversionDetails)
tb.(conversionDetails{j,3}) = mData{midx(conversionDetails{j,1})};
end
uOutput = ZmapCatalog(tb);
uOutput = ZmapCatalog.from(tb);

%%

Expand Down Expand Up @@ -343,18 +346,6 @@
,'ConnectTimeout',30 ... % in seconds
);
[resp,req,hist] = request.send(U,options,consumer);
%{
% if there is an error, it would be shown in hist.Response.Body.Data
ss=strsplit(string(resp.Body.Data),newline)';
numel(ss)
%%
f=fopen('junkk.dat','w');
fprintf(f,"%s",resp.Body.Data); %resp.Body.Payload
fclose(f);
%%
ZG.primeCatalog = import_fdsn_event(1,'junk.dat')
% ZmapMainWindow(ZG.primeCatalog)
%}

end

2 changes: 1 addition & 1 deletion importfilters/import_gismo_catalog.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
catalog.mag,...
catalog.magtype,...
'VariableNames',{'Date','Latitude','Longitude','Depth','Magnitude','MagnitudeType'});
uOutput=ZmapCatalog(tb);
uOutput=ZmapCatalog.from(tb);

uOutput.Name=inputname(2);

Expand Down
Loading

0 comments on commit fc798f2

Please sign in to comment.