org.opensha.sha.simulators.eqsim_v04
Class General_EQSIM_Tools

java.lang.Object
  extended by org.opensha.sha.simulators.eqsim_v04.General_EQSIM_Tools

public class General_EQSIM_Tools
extends Object

This class reads and writes various files, as well as doing some analysis of simulator results. Note that this class could extend some class representing the "Container" defined in EQSIM, but it's not clear that generality is necessary. Things to keep in mind: Indexing in the EQSIM files starts from 1, not zero. Therefore, here we refer to their "indices" as IDs to avoid confusion (so IDs here start from 1, but indices here start from zero). Thus, the ID for the ith RectangularElement in rectElementsList equals i+1 (rectElementsList.get(i).getID() = i+1) because the input file has everything in an order of increasing IDs. The same goes for other lists. Note that index for eventList is not necessarily equal to eventID-1 because some events in the input file may not be included (e.g., if Mag = -Inf, which occurs) All units in EQSIM files are SI Note that DAS values are unique only within a fault section (values can start over on the next section) Note that slip rates in EQSIM files are in units of m/s, whereas we convert these to m/yr internally here. We assume the first vertex in each element here is the first on the upper edge (traceFlag=2 if the element is at the top); this is not checked for explicitly.

Author:
field

Field Summary
protected static boolean D
           
static double SECONDS_PER_YEAR
           
 
Constructor Summary
General_EQSIM_Tools(File file)
          This constructor loads the data from an EQSIM_v04 Geometry file
General_EQSIM_Tools(int deformationModelID, boolean aseisReducesArea, double maxDiscretization)
          This constructor makes the list of RectangularElements from a UCERF2 deformation model
General_EQSIM_Tools(String filePathName)
          This constructor loads the data from an EQSIM_v04 Geometry file
General_EQSIM_Tools(String filePathName, int formatType)
          This constructor loads the data from either an EQSIM_v04 Geometry file (formatType=0) or from Steve Ward's format (formatType=1).
General_EQSIM_Tools(URL url)
          This constructor loads the data from an EQSIM_v04 Geometry file
 
Method Summary
 void checkElementSlipRates(String fileNamePrefix, boolean makePlot)
          This compares observed slip rate (from events) with those imposed.
 String checkEventMagnitudes(double magThresh)
          This compares all the computed magnitudes to those given on the input files and writes out the maximum absolute difference.
 String checkFullDDW_rupturing(boolean plotResult, boolean savePlot)
          This looks at what ruptures do and do not rupture all the way down dip (as defined by the isEventSupraSeismogenic(event, Double.NaN) method)
 void checkThatAllEventRecordsHaveSlips()
           
 ArrayList<ArbIncrementalMagFreqDist> computeMagFreqDistByFaultSection(double minMag, double maxMag, int numMag, boolean makeOnePlotWithAll, boolean makeSeparatePlots, boolean savePlots)
           
 ArbIncrementalMagFreqDist computeTotalMagFreqDist(double minMag, double maxMag, int numMag, boolean makePlot, boolean savePlot)
          This computes the total magnitude frequency distribution (with an option to plot the results)
 boolean doesEventUtilizedFault(EQSIM_Event event, int faultID)
          This tells whether the event utilizes any section with the given faultID
 Vertex getClosestVertex(Location loc)
          This returns the vertex that is closest to the given location (although this might not be very close)
 ArrayList<RectangularElement> getElementsList()
          This returns the list of RectangularElement objects
 HashMap<Integer,EQSIM_Event> getEventsHashMap()
          This returns a HashMap of EQSIM_Event objects where the key is the event ID
 ArrayList<EQSIM_Event> getEventsList()
          Note that because some events were filtered out, the index in the returned array list is not neccessariy equal to the eventID minus one (getEventsList().get(index).getID()=1 != index).
static HistogramFunction getNormRI_Distribution(ArrayList<Double> normRI_List, double deltaT)
           
static HeadlessGraphPanel getNormRI_DistributionGraphPanel(ArrayList<Double> normRI_List, String plotTitle)
          This utility returns a graph panel with a histogram of normalized recurrence intervals from normRI_List, along with best-fit BPT, Lognormal, and Weibull distributions.
 int getNumEventsWithElementSlipData()
          This tells whether all events have data on the slip on each element
 double[] getRecurIntervalsForDAS_and_FaultID(double das, int sectID, double magThresh)
          This get the RI for all events that pass below the given DAS & sectID (the way Keith Richards Dinger does it).
 double[] getRecurIntervalsForElement(int elemID, double magThresh)
          For the specified element ID, this computes the intervals between events that have magnitude greater than the given threshold.
static ArrayList<EvenlyDiscretizedFunc> getRenewalModelFunctionFitsToDist(EvenlyDiscretizedFunc dist)
           
 int getSectionIndexForVertex(Vertex vertex)
          This returns the section index (not ID) for the given vertex, assuming there is only one section for each vertex (exception is thrown if not) (not efficient)
 ArrayList<String> getSectionsNameList()
           
 double getSimulationDuration()
           
static double getSimulationDuration(List<EQSIM_Event> events)
           
 double getSimulationDurationYears()
           
static double getSimulationDurationYears(List<EQSIM_Event> events)
           
 boolean isEventSupraSeismogenic(EQSIM_Event event, double magThresh)
          This tells whether the given event is a supra-seismogenic rupture.
static void main(String[] args)
           
 void mkElementsFromUCERF2_DefMod(int deformationModelID, boolean aseisReducesArea, double maxDiscretization)
          This makes the elements from a UCERF2 deformation model
 void mkFigsForUCERF3_ProjPlanRepot(String dirNameForSavingFiles, double magThresh)
           
 void oldTests(String dirNameForSavingFiles, double magThresh)
          This is no longer used or needed?
 boolean plotAveNormSlipAlongRupture(Double magThresh, boolean savePlot)
          This plot the average normalized slip along ruptures
 void plotNormRecurIntsForAllSurfaceElements(double magThresh, boolean savePlot)
          This plots a histogram of normalized recurrence intervals for all surface elements (normalized by the average interval at each element).
static GraphWindow plotNormRI_Distribution(ArrayList<Double> normRI_List, String plotTitle, double bptAperForComparison)
          This utility plots the histogram of normalized recurrence intervals from normRI_List, along with best-fit BPT, Lognormal, and Weibull distributions.
 void plotRecurIntervalsForElement(double[] intervals, boolean savePlot, String locName, String infoString)
           
 boolean plotRecurIntervalsForNearestLoc(Location loc, double magThresh, boolean savePlot, String locName, String infoString)
          This quits and returns false if the loc is not within 5 km of a vertex.
 void plotSAF_EventsAlongStrikeVsTime(double magThresh, int maxNumEvents)
           
 void plotScalingRelationships(boolean savePlotsToFile)
          This plots slip versus length, mag versus area, and mag versus length.
 void plotYearlyEventRates()
          This plots yearly event rates
 String printMinAndMaxElementArea()
           
 void randomizeEventTimes()
          This replaces all the event times with a random value sampled between the first and last original event time using a uniform distribution.
 void read_EQSIMv04_EventsFile(File file)
           
 void read_EQSIMv04_EventsFile(File file, Collection<RuptureIdentifier> rupIdens)
           
 void read_EQSIMv04_EventsFile(String filePathName)
           
 void read_EQSIMv04_EventsFile(String filePathName, Collection<RuptureIdentifier> rupIdens)
           
 void read_EQSIMv04_EventsFile(URL url)
           
 void read_EQSIMv04_EventsFile(URL url, Collection<RuptureIdentifier> rupIdens)
           
 void setDirNameForSavingFiles(String dirNameForSavingFiles)
          This sets the directory name for files that are saved
 void testDistanceAlong()
          This tests the EQSIM_Event.getDistAlongRupForElements() for a few ruptures, and assuming the "eqs.ALLCAL2_RSQSim_sigma0.5-5_b=0.015.barall" input file is used (event indices are set by hand).
 void testElementAreas()
          This tests whether element areas agree between gridded surface and that computed by RectangularElement
 void testTemp()
           
 String testTimePredictability(double supraSeisMagThresh, boolean saveStuff, Integer testElementID, boolean plotSectionResults)
          This method evaluates Ned's average time- and slip-predictability in various ways.
 void writeDAS_ForVertices()
           
 void writeEventsThatInvolveMultSections()
           
 void writeRI_COV_forAllSurfaceElements(double magThresh, String fileName)
           
 void writeSectionNamesEtc()
          This writes out the section index, ID (index+1), name, and fault ID to a file called "simulatorSectionNamesEtc.txt"
 void writeTo_EQSIM_V04_GeometryFile(String fileName, ArrayList<String> infoLines, String titleLine, String author, String date)
          The creates a EQSIM V04 Geometry file for the given instance.
 void writeToWardFile(String fileName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

D

protected static final boolean D
See Also:
Constant Field Values

SECONDS_PER_YEAR

public static final double SECONDS_PER_YEAR
See Also:
Constant Field Values
Constructor Detail

General_EQSIM_Tools

public General_EQSIM_Tools(int deformationModelID,
                           boolean aseisReducesArea,
                           double maxDiscretization)
This constructor makes the list of RectangularElements from a UCERF2 deformation model

Parameters:
deformationModelID - - D2.1 = 82; D2.2 = 83; D2.3 = 84; D2.4 = 85; D2.5 = 86; D2.6 = 87
aseisReducesArea - - whether or not to reduce area (otherwise reduces slip rate?)
maxDiscretization - - the maximum element size

General_EQSIM_Tools

public General_EQSIM_Tools(String filePathName)
This constructor loads the data from an EQSIM_v04 Geometry file

Parameters:
filePathName - - full path and file name

General_EQSIM_Tools

public General_EQSIM_Tools(String filePathName,
                           int formatType)
This constructor loads the data from either an EQSIM_v04 Geometry file (formatType=0) or from Steve Ward's format (formatType=1).

Parameters:
filePathName - - full path and file name
formatType - - set as 0 for EQSIM_v04 Geometry file or 1 for Steve Ward's format

General_EQSIM_Tools

public General_EQSIM_Tools(File file)
                    throws IOException
This constructor loads the data from an EQSIM_v04 Geometry file

Parameters:
url - - full URL path name
Throws:
IOException

General_EQSIM_Tools

public General_EQSIM_Tools(URL url)
This constructor loads the data from an EQSIM_v04 Geometry file

Parameters:
url - - full URL path name
Method Detail

getSectionsNameList

public ArrayList<String> getSectionsNameList()

read_EQSIMv04_EventsFile

public void read_EQSIMv04_EventsFile(URL url)
                              throws IOException
Throws:
IOException

read_EQSIMv04_EventsFile

public void read_EQSIMv04_EventsFile(URL url,
                                     Collection<RuptureIdentifier> rupIdens)
                              throws IOException
Throws:
IOException

read_EQSIMv04_EventsFile

public void read_EQSIMv04_EventsFile(File file)
                              throws IOException
Throws:
IOException

read_EQSIMv04_EventsFile

public void read_EQSIMv04_EventsFile(File file,
                                     Collection<RuptureIdentifier> rupIdens)
                              throws IOException
Throws:
IOException

read_EQSIMv04_EventsFile

public void read_EQSIMv04_EventsFile(String filePathName)
                              throws FileNotFoundException,
                                     IOException
Throws:
FileNotFoundException
IOException

read_EQSIMv04_EventsFile

public void read_EQSIMv04_EventsFile(String filePathName,
                                     Collection<RuptureIdentifier> rupIdens)
                              throws FileNotFoundException,
                                     IOException
Throws:
FileNotFoundException
IOException

isEventSupraSeismogenic

public boolean isEventSupraSeismogenic(EQSIM_Event event,
                                       double magThresh)
This tells whether the given event is a supra-seismogenic rupture. If magThresh is not NaN, this returns true if event mag is >= magThresh If magThresh is NaN, this returns true sqrt(rupArea) >= (aveFaultDownDipWidth-1.5 km), where the 1.5 km buffer is half an element width.

Parameters:
event -
magThresh - - set as Double.NaN to use down-dip-width
Returns:

getElementsList

public ArrayList<RectangularElement> getElementsList()
This returns the list of RectangularElement objects

Returns:

printMinAndMaxElementArea

public String printMinAndMaxElementArea()

testElementAreas

public void testElementAreas()
This tests whether element areas agree between gridded surface and that computed by RectangularElement


testDistanceAlong

public void testDistanceAlong()
This tests the EQSIM_Event.getDistAlongRupForElements() for a few ruptures, and assuming the "eqs.ALLCAL2_RSQSim_sigma0.5-5_b=0.015.barall" input file is used (event indices are set by hand). The data file was loaded into Igor and plotted to confirm the distance along rupture looked good (but note ambiguities when ruptures fork).


mkElementsFromUCERF2_DefMod

public void mkElementsFromUCERF2_DefMod(int deformationModelID,
                                        boolean aseisReducesArea,
                                        double maxDiscretization)
This makes the elements from a UCERF2 deformation model

Parameters:
deformationModelID - - D2.1 = 82; D2.2 = 83; D2.3 = 84; D2.4 = 85; D2.5 = 86; D2.6 = 87
aseisReducesArea - - whether or not to reduce area (otherwise reduces slip rate?)
maxDiscretization - - the maximum element size

writeToWardFile

public void writeToWardFile(String fileName)
                     throws IOException
Throws:
IOException

writeTo_EQSIM_V04_GeometryFile

public void writeTo_EQSIM_V04_GeometryFile(String fileName,
                                           ArrayList<String> infoLines,
                                           String titleLine,
                                           String author,
                                           String date)
                                    throws IOException
The creates a EQSIM V04 Geometry file for the given instance.

Parameters:
fileName -
infoLines - - each line here should NOT end with a new line char "\n" (this will be added)
titleLine -
author -
date -
Throws:
IOException

computeTotalMagFreqDist

public ArbIncrementalMagFreqDist computeTotalMagFreqDist(double minMag,
                                                         double maxMag,
                                                         int numMag,
                                                         boolean makePlot,
                                                         boolean savePlot)
This computes the total magnitude frequency distribution (with an option to plot the results)

Returns:

computeMagFreqDistByFaultSection

public ArrayList<ArbIncrementalMagFreqDist> computeMagFreqDistByFaultSection(double minMag,
                                                                             double maxMag,
                                                                             int numMag,
                                                                             boolean makeOnePlotWithAll,
                                                                             boolean makeSeparatePlots,
                                                                             boolean savePlots)
Parameters:
minMag -
maxMag -
numMag -
makeOnePlotWithAll - - plot all incremental dists in one graph
makeSeparatePlots - - make separate plots of incremental and cumulative distributions
Returns:

getNumEventsWithElementSlipData

public int getNumEventsWithElementSlipData()
This tells whether all events have data on the slip on each element

Returns:

getEventsList

public ArrayList<EQSIM_Event> getEventsList()
Note that because some events were filtered out, the index in the returned array list is not neccessariy equal to the eventID minus one (getEventsList().get(index).getID()=1 != index).

Returns:

getEventsHashMap

public HashMap<Integer,EQSIM_Event> getEventsHashMap()
This returns a HashMap of EQSIM_Event objects where the key is the event ID

Returns:

randomizeEventTimes

public void randomizeEventTimes()
This replaces all the event times with a random value sampled between the first and last original event time using a uniform distribution.


plotYearlyEventRates

public void plotYearlyEventRates()
This plots yearly event rates


plotSAF_EventsAlongStrikeVsTime

public void plotSAF_EventsAlongStrikeVsTime(double magThresh,
                                            int maxNumEvents)

getNormRI_Distribution

public static HistogramFunction getNormRI_Distribution(ArrayList<Double> normRI_List,
                                                       double deltaT)

getRenewalModelFunctionFitsToDist

public static ArrayList<EvenlyDiscretizedFunc> getRenewalModelFunctionFitsToDist(EvenlyDiscretizedFunc dist)

getNormRI_DistributionGraphPanel

public static HeadlessGraphPanel getNormRI_DistributionGraphPanel(ArrayList<Double> normRI_List,
                                                                  String plotTitle)
This utility returns a graph panel with a histogram of normalized recurrence intervals from normRI_List, along with best-fit BPT, Lognormal, and Weibull distributions. * This is an alternative version of plotNormRI_Distribution(*)

Parameters:
normRI_List -
plotTitle -

plotNormRI_Distribution

public static GraphWindow plotNormRI_Distribution(ArrayList<Double> normRI_List,
                                                  String plotTitle,
                                                  double bptAperForComparison)
This utility plots the histogram of normalized recurrence intervals from normRI_List, along with best-fit BPT, Lognormal, and Weibull distributions. Use the returned object if you want to save to a file. This is an alternative version of getNormRI_DistributionGraphPanel(*)

Parameters:
normRI_List -
plotTitle -
bptAperForComparison - - this will add a BPT dist with mean=1 and given aper for comparison (set as Double.NaN if not desired)

testTemp

public void testTemp()

testTimePredictability

public String testTimePredictability(double supraSeisMagThresh,
                                     boolean saveStuff,
                                     Integer testElementID,
                                     boolean plotSectionResults)
This method evaluates Ned's average time- and slip-predictability in various ways.

Parameters:
supraSeisMagThresh - - threshold defining supra-seismogenic rupture (if Double.NaN sqrt(area)>fltDDW will be used)
saveStuff -
testElementID - - set null if not wanted
Returns:
info string

checkThatAllEventRecordsHaveSlips

public void checkThatAllEventRecordsHaveSlips()

checkEventMagnitudes

public String checkEventMagnitudes(double magThresh)
This compares all the computed magnitudes to those given on the input files and writes out the maximum absolute difference.


writeEventsThatInvolveMultSections

public void writeEventsThatInvolveMultSections()

getSimulationDuration

public double getSimulationDuration()
Returns:
simulation duration in seconds

getSimulationDuration

public static double getSimulationDuration(List<EQSIM_Event> events)

getSimulationDurationYears

public double getSimulationDurationYears()
Returns:
simulation duration in years

getSimulationDurationYears

public static double getSimulationDurationYears(List<EQSIM_Event> events)
Returns:
simulation duration in years

checkElementSlipRates

public void checkElementSlipRates(String fileNamePrefix,
                                  boolean makePlot)
This compares observed slip rate (from events) with those imposed. This writes out the correlation coefficient to System, and optionally makes a plot, and optionally saves the plot and data to a file.

Parameters:
fileNamePrefix - - set as null to not write the data out.

plotAveNormSlipAlongRupture

public boolean plotAveNormSlipAlongRupture(Double magThresh,
                                           boolean savePlot)
This plot the average normalized slip along ruptures

Parameters:
magThresh - - Double.NaN for supra seismogenic This returns false if the plot can't be made (e.g., ViscoSim has some problem with event.getNormDistAlongRupForElements())
savePlot -

plotScalingRelationships

public void plotScalingRelationships(boolean savePlotsToFile)
This plots slip versus length, mag versus area, and mag versus length.


getRecurIntervalsForElement

public double[] getRecurIntervalsForElement(int elemID,
                                            double magThresh)
For the specified element ID, this computes the intervals between events that have magnitude greater than the given threshold.

Parameters:
elemID -
magThresh - - set as Double.NaN to use sqrt(area)>aveFaultDDW instead
Returns:

writeRI_COV_forAllSurfaceElements

public void writeRI_COV_forAllSurfaceElements(double magThresh,
                                              String fileName)

writeDAS_ForVertices

public void writeDAS_ForVertices()

writeSectionNamesEtc

public void writeSectionNamesEtc()
This writes out the section index, ID (index+1), name, and fault ID to a file called "simulatorSectionNamesEtc.txt"


plotNormRecurIntsForAllSurfaceElements

public void plotNormRecurIntsForAllSurfaceElements(double magThresh,
                                                   boolean savePlot)
This plots a histogram of normalized recurrence intervals for all surface elements (normalized by the average interval at each element). Note that the surface element doesn't need to slip, but rather any element below it.

Parameters:
magThresh -

plotRecurIntervalsForNearestLoc

public boolean plotRecurIntervalsForNearestLoc(Location loc,
                                               double magThresh,
                                               boolean savePlot,
                                               String locName,
                                               String infoString)
This quits and returns false if the loc is not within 5 km of a vertex.

Parameters:
loc -
magThresh -
savePlot -
locName -
infoString -

plotRecurIntervalsForElement

public void plotRecurIntervalsForElement(double[] intervals,
                                         boolean savePlot,
                                         String locName,
                                         String infoString)

getClosestVertex

public Vertex getClosestVertex(Location loc)
This returns the vertex that is closest to the given location (although this might not be very close)

Parameters:
loc -
Returns:

getSectionIndexForVertex

public int getSectionIndexForVertex(Vertex vertex)
This returns the section index (not ID) for the given vertex, assuming there is only one section for each vertex (exception is thrown if not) (not efficient)

Parameters:
vertex -
Returns:

getRecurIntervalsForDAS_and_FaultID

public double[] getRecurIntervalsForDAS_and_FaultID(double das,
                                                    int sectID,
                                                    double magThresh)
This get the RI for all events that pass below the given DAS & sectID (the way Keith Richards Dinger does it). This returns null if there are not more than two event times

Parameters:
das - - in meters!
sectID - - id of fault section (not index!)
magThresh -
Returns:

oldTests

public void oldTests(String dirNameForSavingFiles,
                     double magThresh)
This is no longer used or needed?

Parameters:
dirNameForSavingFiles -
magThresh -

checkFullDDW_rupturing

public String checkFullDDW_rupturing(boolean plotResult,
                                     boolean savePlot)
This looks at what ruptures do and do not rupture all the way down dip (as defined by the isEventSupraSeismogenic(event, Double.NaN) method)


setDirNameForSavingFiles

public void setDirNameForSavingFiles(String dirNameForSavingFiles)
This sets the directory name for files that are saved

Parameters:
dirNameForSavingFiles -

mkFigsForUCERF3_ProjPlanRepot

public void mkFigsForUCERF3_ProjPlanRepot(String dirNameForSavingFiles,
                                          double magThresh)

doesEventUtilizedFault

public boolean doesEventUtilizedFault(EQSIM_Event event,
                                      int faultID)
This tells whether the event utilizes any section with the given faultID

Parameters:
faultID -
Returns:

main

public static void main(String[] args)
                 throws FileNotFoundException,
                        IOException
Parameters:
args -
Throws:
IOException
FileNotFoundException