diff --git a/build.gradle b/build.gradle index 91dfaae6..9b05590b 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ apply from: '../opensha/build-common.gradle' dependencies { - api "ghsc:nshmp-lib:1.4.11" + api "ghsc:nshmp-lib:1.4.26" implementation 'org.apache.pdfbox:pdfbox:2.0.6' implementation 'org.apache.commons:commons-collections4:4.1' diff --git a/src/main/java/scratch/kevin/nshm23/LogicTreeBranchAverageWriter.java b/src/main/java/scratch/kevin/nshm23/LogicTreeBranchAverageWriter.java index 78bb24f4..8b92eb46 100644 --- a/src/main/java/scratch/kevin/nshm23/LogicTreeBranchAverageWriter.java +++ b/src/main/java/scratch/kevin/nshm23/LogicTreeBranchAverageWriter.java @@ -23,6 +23,7 @@ import org.opensha.commons.logicTree.LogicTreeLevel; import org.opensha.commons.logicTree.LogicTreeNode; import org.opensha.commons.util.ExceptionUtils; +import org.opensha.commons.util.ExecutorUtils; import org.opensha.commons.util.modules.OpenSHA_Module; import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution; import org.opensha.sha.earthquake.faultSysSolution.modules.BranchAverageableModule; @@ -262,9 +263,7 @@ public static void main(String[] args) throws IOException { // this dicates how far ahead we will read in solutions, needs to be > asyncThreads to make use of parallel // reading, but should be small enough soas to not use too much memory storing to-be-processed solutions int maxTasks = Integer.min(asyncThreads * 2, asyncThreads + 2); - ExecutorService exec = new ThreadPoolExecutor(asyncThreads, asyncThreads, - 0L, TimeUnit.MILLISECONDS, - new ArrayBlockingQueue(maxTasks), new ThreadPoolExecutor.CallerRunsPolicy()); + ExecutorService exec = ExecutorUtils.newBlockingThreadPool(asyncThreads, maxTasks); int count = 0; List> futures = new ArrayList<>(); diff --git a/src/main/java/scratch/kevin/nshm23/MPJ_LogicTreeInversionRunnerScriptWriter.java b/src/main/java/scratch/kevin/nshm23/MPJ_LogicTreeInversionRunnerScriptWriter.java index 6247821c..da34a01f 100644 --- a/src/main/java/scratch/kevin/nshm23/MPJ_LogicTreeInversionRunnerScriptWriter.java +++ b/src/main/java/scratch/kevin/nshm23/MPJ_LogicTreeInversionRunnerScriptWriter.java @@ -50,6 +50,7 @@ import org.opensha.sha.earthquake.faultSysSolution.inversion.sa.params.CoolingScheduleType; import org.opensha.sha.earthquake.faultSysSolution.inversion.sa.params.GenerationFunctionType; import org.opensha.sha.earthquake.faultSysSolution.inversion.sa.params.NonnegativityConstraintType; +import org.opensha.sha.earthquake.faultSysSolution.modules.GridSourceProvider; import org.opensha.sha.earthquake.faultSysSolution.reports.ReportPageGen.PlotLevel; import org.opensha.sha.earthquake.faultSysSolution.util.TrueMeanSolutionCreator; import org.opensha.sha.earthquake.rupForecastImpl.nshm23.NSHM23_InvConfigFactory; @@ -154,8 +155,8 @@ public static void main(String[] args) throws IOException { List> individualRandomLevels = new ArrayList<>(); int samplingBranchCountMultiplier = 1; -// String dirName = new SimpleDateFormat("yyyy_MM_dd").format(new Date()); - String dirName = "2024_02_02"; + String dirName = new SimpleDateFormat("yyyy_MM_dd").format(new Date()); +// String dirName = "2024_02_02"; String dirSuffix = null; /* @@ -247,390 +248,204 @@ public static void main(String[] args) throws IOException { * NSHM23 logic tree * TODO (this is a just a marker to find this part quickly, not an actual todo) */ -// List> levels = NSHM23_U3_HybridLogicTreeBranch.levels; -// dirName += "-nshm23_u3_hybrid_branches"; -// double avgNumRups = 325000; - - List> levels = NSHM23_LogicTreeBranch.levelsOnFault; - dirName += "-nshm23_branches"; - double avgNumRups = 600000; - - dirSuffix = "-gridded_rebuild"; - -// List> levels = NSHM18_LogicTreeBranch.levels; -// dirName += "-nshm18_branches-wc_94"; -// double avgNumRups = 500000; - -// List> levels = NSHM18_LogicTreeBranch.levelsNewScale; -// dirName += "-nshm18_branches-new_scale"; -// double avgNumRups = 500000; - -// levels = new ArrayList<>(levels); -// for (int i=levels.size(); --i>=0;) -// if (levels.get(i).getType().isAssignableFrom(ShawSegmentationModels.class) -// || levels.get(i).getType().isAssignableFrom(NSHM23_SegmentationModels.class) -// || levels.get(i).getType().isAssignableFrom(SegmentationMFD_Adjustment.class) -// || levels.get(i).getType().isAssignableFrom(DistDependSegShift.class)) -// levels.remove(i); -// dirName += "-no_seg"; -//// levels.add(NSHM23_LogicTreeBranch.RUPS_THROUGH_CREEPING); -//// dirName += "-creep_branches"; -//// levels.add(NSHM23_LogicTreeBranch.MAX_DIST); -//// dirName += "-strict_cutoff_seg"; strictSeg = true; - - -// dirName += "-pre_zero_slip_parent_fix"; -// dirName += "-reweight_seg_2_3_4"; - -// levels = new ArrayList<>(levels); -// int origSize = levels.size(); -// for (int i=levels.size(); --i>=0;) -// if (levels.get(i).getType().isAssignableFrom(ScalingRelationships.class)) -// levels.remove(i); -// Preconditions.checkState(levels.size() < origSize); -// levels.add(NSHM23_LogicTreeBranch.SCALE); -// dirName += "-new_scale_rels"; -// dirName += "-full_set"; - - Class factoryClass = NSHM23_InvConfigFactory.class; - -// Class factoryClass = NSHM23_InvConfigFactory.MFDUncert0p1.class; -// dirName += "-mfd_uncert_0p1"; - -// Class factoryClass = NSHM23_InvConfigFactory.ConstantSlipRateStdDev0p1.class; -// dirName += "-const_slip_sd_0p1"; - -// Class factoryClass = NSHM23_InvConfigFactory.ConstantSlipRateStdDev0p2.class; -// dirName += "-const_slip_sd_0p2"; - -// Class factoryClass = NSHM23_InvConfigFactory.FullSysInv.class; -// dirName += "-full_sys_inv"; - -// Class factoryClass = NSHM23_InvConfigFactory.ClusterSpecific.class; -// dirName += "-cluster_specific_inversion"; - -// Class factoryClass = NSHM23_InvConfigFactory.SegWeight100.class; -// dirName += "-seg_weight_100"; - -// Class factoryClass = NSHM23_InvConfigFactory.SegWeight1000.class; -// dirName += "-seg_weight_1000"; - -// Class factoryClass = NSHM23_InvConfigFactory.SegWeight10000.class; -// dirName += "-seg_weight_10000"; - -// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevWeightAdjust.class; -// dirName += "-no_reweight_use_prev"; - -// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevWeightAdjustFullSys.class; -// dirName += "-full_sys_inv-no_reweight_use_prev"; - -// Class factoryClass = NSHM23_InvConfigFactory.HardcodedOrigWeights.class; -// dirName += "-no_reweight_use_orig"; - -// Class factoryClass = NSHM23_InvConfigFactory.HardcodedOrigWeightsFullSys.class; -// dirName += "-full_sys_inv-no_reweight_use_orig"; - -// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevAvgWeights.class; -// dirName += "-no_reweight_use_prev_avg"; - -// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevAvgWeightsFullSys.class; -// dirName += "-full_sys_inv-no_reweight_use_prev_avg"; - -// Class factoryClass = NSHM23_InvConfigFactory.NoPaleoParkfield.class; -// dirName += "-no_paleo_parkfield"; - -// Class factoryClass = NSHM23_InvConfigFactory.NoMFDScaleAdjust.class; -// dirName += "-no_scale_adj_mfds"; - -// Class factoryClass = NSHM23_InvConfigFactory.NoIncompatibleDataAdjust.class; -// dirName += "-no_mfd_sigma_data_adj"; - -// Class factoryClass = NSHM23_InvConfigFactory.ScaleLowerDepth1p3.class; -// dirName += "-scaleLowerDepth1.3"; - -// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevAsInitial.class; -// dirName += "-prev_as_initial"; - -// Class factoryClass = NSHM23_InvConfigFactory.NoAvg.class; -// dirName += "-no_avg"; - -// Class factoryClass = NSHM23_InvConfigFactory.ForceNewPaleo.class; -// dirName += "-new_paleo"; - -// Class factoryClass = NSHM23_InvConfigFactory.NewScaleUseOrigWidths.class; -// dirName += "-use_orig_widths"; - - // also set nonzero weights! -// Class factoryClass = NSHM23_InvConfigFactory.ForceWideSegBranches.class; -// dirName += "-wide_seg_branches"; - -// Class factoryClass = NSHM23_InvConfigFactory.ForceNoGhostTransient.class; -// dirName += "-no_ghost_trans"; - -// Class factoryClass = NSHM23_InvConfigFactory.ScaleSurfSlipUseActualWidths.class; -// dirName += "-surf_slip_use_actual_w"; - -// Class factoryClass = NSHM23_InvConfigFactory.RemoveIsolatedFaults.class; -// dirName += "-remove_isolated_faults"; - -// Class factoryClass = NSHM23_InvConfigFactory.RemoveProxyFaults.class; -// dirName += "-remove_proxy_faults"; - -// Class factoryClass = NSHM23_InvConfigFactory.NoPaleoSlip.class; -// dirName += "-no_paleo_slip"; - -// Class factoryClass = NSHM23_InvConfigFactory.PaleoSlipInequality.class; -// dirName += "-paleo_slip_ineq"; - -// Class factoryClass = NSHM23_InvConfigFactory.TenThousandItersPerRup.class; -// dirName += "-10000ip"; - -// Class factoryClass = NSHM23_InvConfigFactory.DM_OriginalWeights.class; -// dirName += "-dm_orig_weights"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; - -// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierlMinimizationWeights.class; -// dirName += "-dm_outlier_minimize_weights"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = false; - -// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierReplacementYc2p0.class; -// dirName += "-dm_outlier_sub_yc_2"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; - -// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierReplacementYc3p5.class; -// dirName += "-dm_outlier_sub_yc_3p5"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; - -// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierReplacementYc5p0.class; -// dirName += "-dm_outlier_sub_yc_5"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; - -// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierLogReplacementYc2p0.class; -// dirName += "-dm_outlier_log_sub_yc_2"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; - -// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierLogReplacementYc3p5.class; -// dirName += "-dm_outlier_log_sub_yc_3p5"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; - -// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierLogReplacementYc5p0.class; -// dirName += "-dm_outlier_log_sub_yc_5"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; - -// Class factoryClass = NSHM23_InvConfigFactory.SegModelLimitMaxLen.class; -// dirName += "-seg_limit_max_length"; - -// Class factoryClass = NSHM23_InvConfigFactory.SlipRateStdDevCeil0p1.class; -// dirName += "-slip_rate_sd_ceil_0p1"; - -// Class factoryClass = NSHM23_InvConfigFactory.SegModelMaxLen600.class; -// dirName += "-seg_limit_max_length_600"; - -// Class factoryClass = NSHM23_InvConfigFactory.SparseGRDontSpreadSingleToMulti.class; -// dirName += "-sparse_gr_dont_spread_single_multi"; - -// Class factoryClass = NSHM23_InvConfigFactory.ModDepthGV08.class; -// dirName += "-gv_08_mod_depth"; - -// Class factoryClass = NSHM23_InvConfigFactory.OrigDraftScaling.class; -// dirName += "-orig_draft_scaling"; - -// Class factoryClass = NSHM23_InvConfigFactory.ModScalingAdd4p3.class; -// dirName += "-mod_scaling"; - -// Class factoryClass = NSHM23_InvConfigFactory.NSHM18_UseU3Paleo.class; -// dirName += "-u3_paleo"; - -// Class factoryClass = NSHM23_InvConfigFactory.ModPitasPointDDW.class; -// dirName += "-mod_pitas_ddw"; - -// Class factoryClass = DefModSamplingEnabledInvConfig.ConnDistB0p5MidSegCorr.class; -// dirName += "-dm_sampling"; -// individualRandomLevels.add(new RandomDefModSampleLevel()); - -// Class factoryClass = DefModSamplingEnabledInvConfig.ConnDistB0p5MidSegCorrCapSigma.class; -// dirName += "-dm_sampling_cap_sigma"; -// individualRandomLevels.add(new RandomDefModSampleLevel()); - - if (!factoryClass.equals(NSHM23_InvConfigFactory.class)) { - // try instantiate it to make sure we get any static modifiers that might change branch weights - try { - System.out.println("Instantiating factory class: "+factoryClass.getName()); - factoryClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - e.printStackTrace(); - } - } - -// levels = new ArrayList<>(levels); -// boolean randB = true; -// boolean randSeg = true; -// int origSize = levels.size(); -// for (int i=levels.size(); --i>=0;) { -// if (randB && SupraSeisBValues.class.isAssignableFrom(levels.get(i).getType())) -// levels.remove(i); -// if (randSeg && SegmentationModelBranchNode.class.isAssignableFrom(levels.get(i).getType())) -// levels.remove(i); -// } -// Preconditions.checkState(levels.size() < origSize); -// if (randB) { -// samplingBranchCountMultiplier *= 5; // there were originally 5 each -// dirName += "-randB"; -// individualRandomLevels.add(new RandomBValSampler.Level()); -// } -// if (randSeg) { -// samplingBranchCountMultiplier *= 5; // there were originally 5 each -// dirName += "-randSeg"; -// individualRandomLevels.add(new RandomSegModelSampler.Level()); -// } - -// dirName += "-mini_one_fifth"; -// samplingBranchCountMultiplier /= 5; - -// dirName += "-u3_perturb"; -// extraArgs.add("--perturb "+GenerationFunctionType.UNIFORM_0p001.name()); -// dirName += "-exp_perturb"; -// extraArgs.add("--perturb "+GenerationFunctionType.EXPONENTIAL_SCALE.name()); -// dirName += "-limit_zeros"; -// extraArgs.add("--non-negativity "+NonnegativityConstraintType.LIMIT_ZERO_RATES.name()); -// dirName += "-classic_sa"; -// extraArgs.add("--cooling-schedule "+CoolingScheduleType.CLASSICAL_SA.name()); - -// levels = new ArrayList<>(levels); -// levels.add(NSHM23_LogicTreeBranch.SINGLE_STATES); -// dirName += "-single_state"; - -// dirName += "-mod_west_valley_ddw"; - -// dirName += "-mod_dm_weights"; - - forceHazardGridSpacing = 0.1; - - forceRequiredNonzeroWeight = true; - LogicTreeNode[] required = { - // FAULT MODELS -// FaultModels.FM3_1, -// FaultModels.FM3_2, -// NSHM18_FaultModels.NSHM18_WUS_NoCA, -// NSHM18_FaultModels.NSHM18_WUS_PlusU3_FM_3p1, -// NSHM23_FaultModels.FM_v1p4, -// NSHM23_FaultModels.FM_v2, - NSHM23_FaultModels.WUS_FM_v3, -// PRVI25_FaultModels.PRVI_FM_INITIAL, - -// // SINGLE STATE -// NSHM23_SingleStates.NM, -// NSHM23_SingleStates.UT, - - // RUPTURE SETS -// RupturePlausibilityModels.COULOMB, // default -// RupturePlausibilityModels.COULOMB_5km, -// RupturePlausibilityModels.AZIMUTHAL, -// RupturePlausibilityModels.SEGMENTED, -// RupturePlausibilityModels.UCERF3, -// RupturePlausibilityModels.UCERF3_REDUCED, - - // DEFORMATION MODELS -// U3_UncertAddDeformationModels.U3_ZENG, -// U3_UncertAddDeformationModels.U3_MEAN, -// NSHM18_DeformationModels.BRANCH_AVERAGED, -// NSHM23_DeformationModels.AVERAGE, -// NSHM23_DeformationModels.GEOLOGIC, -// NSHM23_DeformationModels.EVANS, -// NSHM23_DeformationModels.MEDIAN, - - // SCALING RELATIONSHIPS -// ScalingRelationships.SHAW_2009_MOD, -// ScalingRelationships.MEAN_UCERF3, -// NSHM23_ScalingRelationships.AVERAGE, -// NSHM23_ScalingRelationships.LOGA_C4p2_SQRT_LEN, -// NSHM23_ScalingRelationships.WIDTH_LIMITED_CSD, - - // SLIP ALONG RUPTURE -// NSHM23_SlipAlongRuptureModels.UNIFORM, -// NSHM23_SlipAlongRuptureModels.TAPERED, -// SlipAlongRuptureModels.UNIFORM, -// SlipAlongRuptureModels.TAPERED, - - // SUB-SECT CONSTRAINT -// SubSectConstraintModels.TOT_NUCL_RATE, // default -// SubSectConstraintModels.NUCL_MFD, - - // SUB-SEIS MO REDUCTION -// SubSeisMoRateReductions.SUB_B_1, -// SubSeisMoRateReductions.NONE, // default -// SubSeisMoRateReductions.SYSTEM_AVG, -// SubSeisMoRateReductions.SYSTEM_AVG_SUB_B_1, - - // SUPRA-SEIS-B -// SupraSeisBValues.B_0p5, -// SupraSeisBValues.AVERAGE, - - // PALEO UNCERT -// NSHM23_PaleoUncertainties.EVEN_FIT, - - // SEGMENTATION -// SegmentationModels.SHAW_R0_3, -// NSHM23_SegmentationModels.AVERAGE, -// NSHM23_SegmentationModels.MID, -// NSHM23_SegmentationModels.CLASSIC, -// NSHM23_SegmentationModels.CLASSIC_FULL, - - // SEG-SHIFT -// DistDependSegShift.NONE, -// DistDependSegShift.ONE_KM, -// DistDependSegShift.TWO_KM, -// DistDependSegShift.THREE_KM, - - // SEG ADJUSTMENT -// SegmentationMFD_Adjustment.NONE, -// SegmentationMFD_Adjustment.JUMP_PROB_THRESHOLD_AVG, -// SegmentationMFD_Adjustment.REL_GR_THRESHOLD_AVG_SINGLE_ITER, -// SegmentationMFD_Adjustment.REL_GR_THRESHOLD_AVG, // default -// SegmentationMFD_Adjustment.CAPPED_REDIST, -// SegmentationMFD_Adjustment.CAPPED_REDIST_SELF_CONTAINED, -// SegmentationMFD_Adjustment.GREEDY, -// SegmentationMFD_Adjustment.GREEDY_SELF_CONTAINED, -// SegmentationMFD_Adjustment.JUMP_PROB_THRESHOLD_AVG_MATCH_STRICT, - - // CREEPING SECTION -// RupsThroughCreepingSect.INCLUDE, -// RupsThroughCreepingSect.EXCLUDE, - }; -// LogicTreeNode[] required = { FaultModels.FM3_1, SubSeisMoRateReductionNode.SYSTEM_AVG }; -// LogicTreeNode[] required = { FaultModels.FM3_1, SubSeisMoRateReductionNode.FAULT_SPECIFIC }; -// Class sortBy = SubSectConstraintModels.class; - Class sortBy = NSHM23_SegmentationModels.class; - /* - * END NSHM23 logic tree - */ - - /* - * PRVI25 logic tree - * TODO (this is a just a marker to find this part quickly, not an actual todo) - */ -// List> levels = PRVI25_LogicTreeBranch.levelsOnFault; -// dirName += "-prvi25_crustal_branches"; -// double avgNumRups = 50000; +//// List> levels = NSHM23_U3_HybridLogicTreeBranch.levels; +//// dirName += "-nshm23_u3_hybrid_branches"; +//// double avgNumRups = 325000; // -// // random DM sampling -// levels = new ArrayList<>(levels); -// int origNumLevels = levels.size(); -// for (int i=levels.size(); --i>=0;) -// if (levels.get(i).getNodes().get(0) instanceof PRVI25_CrustalDeformationModels) -// levels.remove(i); -// Preconditions.checkState(levels.size() == origNumLevels -1); -// individualRandomLevels.add(new PRVI25_CrustalRandomlySampledDeformationModelLevel()); -// samplingBranchCountMultiplier = 5; // 5 for each branch -// dirName += "-dmSample"; -// if (samplingBranchCountMultiplier > 1) -// dirName += samplingBranchCountMultiplier+"x"; -// -//// List> levels = PRVI25_LogicTreeBranch.levelsSubduction; -//// dirName += "-prvi25_subduction_branches"; -//// double avgNumRups = 10000; -//// gmpe = null; +// List> levels = NSHM23_LogicTreeBranch.levelsOnFault; +// dirName += "-nshm23_branches"; +// double avgNumRups = 600000; +// +// dirSuffix = "-gridded_rebuild"; +// +//// List> levels = NSHM18_LogicTreeBranch.levels; +//// dirName += "-nshm18_branches-wc_94"; +//// double avgNumRups = 500000; +// +//// List> levels = NSHM18_LogicTreeBranch.levelsNewScale; +//// dirName += "-nshm18_branches-new_scale"; +//// double avgNumRups = 500000; +// +//// levels = new ArrayList<>(levels); +//// for (int i=levels.size(); --i>=0;) +//// if (levels.get(i).getType().isAssignableFrom(ShawSegmentationModels.class) +//// || levels.get(i).getType().isAssignableFrom(NSHM23_SegmentationModels.class) +//// || levels.get(i).getType().isAssignableFrom(SegmentationMFD_Adjustment.class) +//// || levels.get(i).getType().isAssignableFrom(DistDependSegShift.class)) +//// levels.remove(i); +//// dirName += "-no_seg"; +////// levels.add(NSHM23_LogicTreeBranch.RUPS_THROUGH_CREEPING); +////// dirName += "-creep_branches"; +////// levels.add(NSHM23_LogicTreeBranch.MAX_DIST); +////// dirName += "-strict_cutoff_seg"; strictSeg = true; +// +// +//// dirName += "-pre_zero_slip_parent_fix"; +//// dirName += "-reweight_seg_2_3_4"; // //// levels = new ArrayList<>(levels); -//// levels.add(NSHM23_LogicTreeBranch.SUB_SECT_CONSTR); +//// int origSize = levels.size(); +//// for (int i=levels.size(); --i>=0;) +//// if (levels.get(i).getType().isAssignableFrom(ScalingRelationships.class)) +//// levels.remove(i); +//// Preconditions.checkState(levels.size() < origSize); +//// levels.add(NSHM23_LogicTreeBranch.SCALE); +//// dirName += "-new_scale_rels"; +//// dirName += "-full_set"; +// +// Class factoryClass = NSHM23_InvConfigFactory.class; +// +//// Class factoryClass = NSHM23_InvConfigFactory.MFDUncert0p1.class; +//// dirName += "-mfd_uncert_0p1"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ConstantSlipRateStdDev0p1.class; +//// dirName += "-const_slip_sd_0p1"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ConstantSlipRateStdDev0p2.class; +//// dirName += "-const_slip_sd_0p2"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.FullSysInv.class; +//// dirName += "-full_sys_inv"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ClusterSpecific.class; +//// dirName += "-cluster_specific_inversion"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.SegWeight100.class; +//// dirName += "-seg_weight_100"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.SegWeight1000.class; +//// dirName += "-seg_weight_1000"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.SegWeight10000.class; +//// dirName += "-seg_weight_10000"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevWeightAdjust.class; +//// dirName += "-no_reweight_use_prev"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevWeightAdjustFullSys.class; +//// dirName += "-full_sys_inv-no_reweight_use_prev"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.HardcodedOrigWeights.class; +//// dirName += "-no_reweight_use_orig"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.HardcodedOrigWeightsFullSys.class; +//// dirName += "-full_sys_inv-no_reweight_use_orig"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevAvgWeights.class; +//// dirName += "-no_reweight_use_prev_avg"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevAvgWeightsFullSys.class; +//// dirName += "-full_sys_inv-no_reweight_use_prev_avg"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.NoPaleoParkfield.class; +//// dirName += "-no_paleo_parkfield"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.NoMFDScaleAdjust.class; +//// dirName += "-no_scale_adj_mfds"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.NoIncompatibleDataAdjust.class; +//// dirName += "-no_mfd_sigma_data_adj"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ScaleLowerDepth1p3.class; +//// dirName += "-scaleLowerDepth1.3"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.HardcodedPrevAsInitial.class; +//// dirName += "-prev_as_initial"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.NoAvg.class; +//// dirName += "-no_avg"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ForceNewPaleo.class; +//// dirName += "-new_paleo"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.NewScaleUseOrigWidths.class; +//// dirName += "-use_orig_widths"; +// +// // also set nonzero weights! +//// Class factoryClass = NSHM23_InvConfigFactory.ForceWideSegBranches.class; +//// dirName += "-wide_seg_branches"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ForceNoGhostTransient.class; +//// dirName += "-no_ghost_trans"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ScaleSurfSlipUseActualWidths.class; +//// dirName += "-surf_slip_use_actual_w"; // -//// dirName += "-proxyGriddedTests"; +//// Class factoryClass = NSHM23_InvConfigFactory.RemoveIsolatedFaults.class; +//// dirName += "-remove_isolated_faults"; // -// Class factoryClass = PRVI25_InvConfigFactory.class; +//// Class factoryClass = NSHM23_InvConfigFactory.RemoveProxyFaults.class; +//// dirName += "-remove_proxy_faults"; // -// if (!factoryClass.equals(PRVI25_InvConfigFactory.class)) { +//// Class factoryClass = NSHM23_InvConfigFactory.NoPaleoSlip.class; +//// dirName += "-no_paleo_slip"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.PaleoSlipInequality.class; +//// dirName += "-paleo_slip_ineq"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.TenThousandItersPerRup.class; +//// dirName += "-10000ip"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.DM_OriginalWeights.class; +//// dirName += "-dm_orig_weights"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; +// +//// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierlMinimizationWeights.class; +//// dirName += "-dm_outlier_minimize_weights"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = false; +// +//// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierReplacementYc2p0.class; +//// dirName += "-dm_outlier_sub_yc_2"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; +// +//// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierReplacementYc3p5.class; +//// dirName += "-dm_outlier_sub_yc_3p5"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; +// +//// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierReplacementYc5p0.class; +//// dirName += "-dm_outlier_sub_yc_5"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; +// +//// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierLogReplacementYc2p0.class; +//// dirName += "-dm_outlier_log_sub_yc_2"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; +// +//// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierLogReplacementYc3p5.class; +//// dirName += "-dm_outlier_log_sub_yc_3p5"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; +// +//// Class factoryClass = NSHM23_InvConfigFactory.DM_OutlierLogReplacementYc5p0.class; +//// dirName += "-dm_outlier_log_sub_yc_5"; NSHM23_DeformationModels.ORIGINAL_WEIGHTS = true; +// +//// Class factoryClass = NSHM23_InvConfigFactory.SegModelLimitMaxLen.class; +//// dirName += "-seg_limit_max_length"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.SlipRateStdDevCeil0p1.class; +//// dirName += "-slip_rate_sd_ceil_0p1"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.SegModelMaxLen600.class; +//// dirName += "-seg_limit_max_length_600"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.SparseGRDontSpreadSingleToMulti.class; +//// dirName += "-sparse_gr_dont_spread_single_multi"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ModDepthGV08.class; +//// dirName += "-gv_08_mod_depth"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.OrigDraftScaling.class; +//// dirName += "-orig_draft_scaling"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ModScalingAdd4p3.class; +//// dirName += "-mod_scaling"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.NSHM18_UseU3Paleo.class; +//// dirName += "-u3_paleo"; +// +//// Class factoryClass = NSHM23_InvConfigFactory.ModPitasPointDDW.class; +//// dirName += "-mod_pitas_ddw"; +// +//// Class factoryClass = DefModSamplingEnabledInvConfig.ConnDistB0p5MidSegCorr.class; +//// dirName += "-dm_sampling"; +//// individualRandomLevels.add(new RandomDefModSampleLevel()); +// +//// Class factoryClass = DefModSamplingEnabledInvConfig.ConnDistB0p5MidSegCorrCapSigma.class; +//// dirName += "-dm_sampling_cap_sigma"; +//// individualRandomLevels.add(new RandomDefModSampleLevel()); +// +// if (!factoryClass.equals(NSHM23_InvConfigFactory.class)) { // // try instantiate it to make sure we get any static modifiers that might change branch weights // try { // System.out.println("Instantiating factory class: "+factoryClass.getName()); @@ -640,40 +455,227 @@ public static void main(String[] args) throws IOException { // } // } // +//// levels = new ArrayList<>(levels); +//// boolean randB = true; +//// boolean randSeg = true; +//// int origSize = levels.size(); +//// for (int i=levels.size(); --i>=0;) { +//// if (randB && SupraSeisBValues.class.isAssignableFrom(levels.get(i).getType())) +//// levels.remove(i); +//// if (randSeg && SegmentationModelBranchNode.class.isAssignableFrom(levels.get(i).getType())) +//// levels.remove(i); +//// } +//// Preconditions.checkState(levels.size() < origSize); +//// if (randB) { +//// samplingBranchCountMultiplier *= 5; // there were originally 5 each +//// dirName += "-randB"; +//// individualRandomLevels.add(new RandomBValSampler.Level()); +//// } +//// if (randSeg) { +//// samplingBranchCountMultiplier *= 5; // there were originally 5 each +//// dirName += "-randSeg"; +//// individualRandomLevels.add(new RandomSegModelSampler.Level()); +//// } +// +//// dirName += "-mini_one_fifth"; +//// samplingBranchCountMultiplier /= 5; +// +//// dirName += "-u3_perturb"; +//// extraArgs.add("--perturb "+GenerationFunctionType.UNIFORM_0p001.name()); +//// dirName += "-exp_perturb"; +//// extraArgs.add("--perturb "+GenerationFunctionType.EXPONENTIAL_SCALE.name()); +//// dirName += "-limit_zeros"; +//// extraArgs.add("--non-negativity "+NonnegativityConstraintType.LIMIT_ZERO_RATES.name()); +//// dirName += "-classic_sa"; +//// extraArgs.add("--cooling-schedule "+CoolingScheduleType.CLASSICAL_SA.name()); +// +//// levels = new ArrayList<>(levels); +//// levels.add(NSHM23_LogicTreeBranch.SINGLE_STATES); +//// dirName += "-single_state"; +// +//// dirName += "-mod_west_valley_ddw"; +// +//// dirName += "-mod_dm_weights"; +// // forceHazardGridSpacing = 0.1; // // forceRequiredNonzeroWeight = true; // LogicTreeNode[] required = { // // FAULT MODELS -//// PRVI25_CrustalFaultModels.PRVI_FM_INITIAL, -//// PRVI25_SubductionFaultModels.PRVI_SUB_FM_INITIAL, +//// FaultModels.FM3_1, +//// FaultModels.FM3_2, +//// NSHM18_FaultModels.NSHM18_WUS_NoCA, +//// NSHM18_FaultModels.NSHM18_WUS_PlusU3_FM_3p1, +//// NSHM23_FaultModels.FM_v1p4, +//// NSHM23_FaultModels.FM_v2, +// NSHM23_FaultModels.WUS_FM_v3, +//// PRVI25_FaultModels.PRVI_FM_INITIAL, +// +//// // SINGLE STATE +//// NSHM23_SingleStates.NM, +//// NSHM23_SingleStates.UT, // // // RUPTURE SETS //// RupturePlausibilityModels.COULOMB, // default //// RupturePlausibilityModels.COULOMB_5km, +//// RupturePlausibilityModels.AZIMUTHAL, +//// RupturePlausibilityModels.SEGMENTED, +//// RupturePlausibilityModels.UCERF3, +//// RupturePlausibilityModels.UCERF3_REDUCED, // // // DEFORMATION MODELS -//// PRVI25_CrustalDeformationModels.GEOLOGIC, +//// U3_UncertAddDeformationModels.U3_ZENG, +//// U3_UncertAddDeformationModels.U3_MEAN, +//// NSHM18_DeformationModels.BRANCH_AVERAGED, +//// NSHM23_DeformationModels.AVERAGE, +//// NSHM23_DeformationModels.GEOLOGIC, +//// NSHM23_DeformationModels.EVANS, +//// NSHM23_DeformationModels.MEDIAN, // // // SCALING RELATIONSHIPS +//// ScalingRelationships.SHAW_2009_MOD, +//// ScalingRelationships.MEAN_UCERF3, +//// NSHM23_ScalingRelationships.AVERAGE, +//// NSHM23_ScalingRelationships.LOGA_C4p2_SQRT_LEN, +//// NSHM23_ScalingRelationships.WIDTH_LIMITED_CSD, +// +// // SLIP ALONG RUPTURE +//// NSHM23_SlipAlongRuptureModels.UNIFORM, +//// NSHM23_SlipAlongRuptureModels.TAPERED, +//// SlipAlongRuptureModels.UNIFORM, +//// SlipAlongRuptureModels.TAPERED, // // // SUB-SECT CONSTRAINT //// SubSectConstraintModels.TOT_NUCL_RATE, // default //// SubSectConstraintModels.NUCL_MFD, // +// // SUB-SEIS MO REDUCTION +//// SubSeisMoRateReductions.SUB_B_1, +//// SubSeisMoRateReductions.NONE, // default +//// SubSeisMoRateReductions.SYSTEM_AVG, +//// SubSeisMoRateReductions.SYSTEM_AVG_SUB_B_1, +// // // SUPRA-SEIS-B //// SupraSeisBValues.B_0p5, //// SupraSeisBValues.AVERAGE, // +// // PALEO UNCERT +//// NSHM23_PaleoUncertainties.EVEN_FIT, +// // // SEGMENTATION +//// SegmentationModels.SHAW_R0_3, //// NSHM23_SegmentationModels.AVERAGE, //// NSHM23_SegmentationModels.MID, //// NSHM23_SegmentationModels.CLASSIC, +//// NSHM23_SegmentationModels.CLASSIC_FULL, +// +// // SEG-SHIFT +//// DistDependSegShift.NONE, +//// DistDependSegShift.ONE_KM, +//// DistDependSegShift.TWO_KM, +//// DistDependSegShift.THREE_KM, +// +// // SEG ADJUSTMENT +//// SegmentationMFD_Adjustment.NONE, +//// SegmentationMFD_Adjustment.JUMP_PROB_THRESHOLD_AVG, +//// SegmentationMFD_Adjustment.REL_GR_THRESHOLD_AVG_SINGLE_ITER, +//// SegmentationMFD_Adjustment.REL_GR_THRESHOLD_AVG, // default +//// SegmentationMFD_Adjustment.CAPPED_REDIST, +//// SegmentationMFD_Adjustment.CAPPED_REDIST_SELF_CONTAINED, +//// SegmentationMFD_Adjustment.GREEDY, +//// SegmentationMFD_Adjustment.GREEDY_SELF_CONTAINED, +//// SegmentationMFD_Adjustment.JUMP_PROB_THRESHOLD_AVG_MATCH_STRICT, +// +// // CREEPING SECTION +//// RupsThroughCreepingSect.INCLUDE, +//// RupsThroughCreepingSect.EXCLUDE, // }; //// LogicTreeNode[] required = { FaultModels.FM3_1, SubSeisMoRateReductionNode.SYSTEM_AVG }; //// LogicTreeNode[] required = { FaultModels.FM3_1, SubSeisMoRateReductionNode.FAULT_SPECIFIC }; //// Class sortBy = SubSectConstraintModels.class; // Class sortBy = NSHM23_SegmentationModels.class; + /* + * END NSHM23 logic tree + */ + + /* + * PRVI25 logic tree + * TODO (this is a just a marker to find this part quickly, not an actual todo) + */ + List> levels = PRVI25_LogicTreeBranch.levelsOnFault; + dirName += "-prvi25_crustal_branches"; + double avgNumRups = 50000; + + // random DM sampling + levels = new ArrayList<>(levels); + int origNumLevels = levels.size(); + for (int i=levels.size(); --i>=0;) + if (levels.get(i).getNodes().get(0) instanceof PRVI25_CrustalDeformationModels) + levels.remove(i); + Preconditions.checkState(levels.size() == origNumLevels -1); + individualRandomLevels.add(new PRVI25_CrustalRandomlySampledDeformationModelLevel()); + samplingBranchCountMultiplier = 5; // 5 for each branch + dirName += "-dmSample"; + if (samplingBranchCountMultiplier > 1) + dirName += samplingBranchCountMultiplier+"x"; + +// List> levels = PRVI25_LogicTreeBranch.levelsSubduction; +// dirName += "-prvi25_subduction_branches"; +// double avgNumRups = 10000; + + gmpe = null; + +// levels = new ArrayList<>(levels); +// levels.add(NSHM23_LogicTreeBranch.SUB_SECT_CONSTR); + +// dirName += "-proxyGriddedTests"; + + Class factoryClass = PRVI25_InvConfigFactory.class; + + if (!factoryClass.equals(PRVI25_InvConfigFactory.class)) { + // try instantiate it to make sure we get any static modifiers that might change branch weights + try { + System.out.println("Instantiating factory class: "+factoryClass.getName()); + factoryClass.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + forceHazardGridSpacing = 0.1; + + forceRequiredNonzeroWeight = true; + LogicTreeNode[] required = { + // FAULT MODELS +// PRVI25_CrustalFaultModels.PRVI_FM_INITIAL, +// PRVI25_SubductionFaultModels.PRVI_SUB_FM_INITIAL, + + // RUPTURE SETS +// RupturePlausibilityModels.COULOMB, // default +// RupturePlausibilityModels.COULOMB_5km, + + // DEFORMATION MODELS +// PRVI25_CrustalDeformationModels.GEOLOGIC, + + // SCALING RELATIONSHIPS + + // SUB-SECT CONSTRAINT +// SubSectConstraintModels.TOT_NUCL_RATE, // default +// SubSectConstraintModels.NUCL_MFD, + + // SUPRA-SEIS-B +// SupraSeisBValues.B_0p5, +// SupraSeisBValues.AVERAGE, + + // SEGMENTATION +// NSHM23_SegmentationModels.AVERAGE, +// NSHM23_SegmentationModels.MID, +// NSHM23_SegmentationModels.CLASSIC, + }; +// LogicTreeNode[] required = { FaultModels.FM3_1, SubSeisMoRateReductionNode.SYSTEM_AVG }; +// LogicTreeNode[] required = { FaultModels.FM3_1, SubSeisMoRateReductionNode.FAULT_SPECIFIC }; +// Class sortBy = SubSectConstraintModels.class; + Class sortBy = NSHM23_SegmentationModels.class; /* * END PRVI25 logic tree */ @@ -972,6 +974,9 @@ else if (mpjWrite instanceof FastMPJShellScriptWriter) boolean griddedJob = GridSourceProviderFactory.class.isAssignableFrom(factoryClass); if (griddedJob) { + boolean allLevelsAffected = true; + for (LogicTreeLevel level : levels) + allLevelsAffected &= GridSourceProvider.affectedByLevel(level); argz = "--factory '"+factoryClass.getName()+"'"; // surround in single quotes to escape $'s argz += " --logic-tree "+ltPath; argz += " --sol-dir "+resultsPath; @@ -979,6 +984,13 @@ else if (mpjWrite instanceof FastMPJShellScriptWriter) String randLTPath = dirPath+"/logic_tree_full_gridded_sampled.json"; argz += " --write-full-tree "+fullLTPath; argz += " --write-rand-tree "+randLTPath+" --num-samples-per-sol 5"; + String onlyLTPath; + if (allLevelsAffected) { + onlyLTPath = fullLTPath; + } else { + onlyLTPath = dirPath+"/logic_tree_full_gridded_for_only_calc.json"; + argz += " --write-only-tree "+onlyLTPath; + } // boolean averageOnly = logicTree.size() > 400; // if (averageOnly) argz += " --average-only"; @@ -1001,7 +1013,7 @@ else if (mpjWrite instanceof FastMPJShellScriptWriter) pbsWrite.writeScript(new File(localDir, "true_mean_builder.slurm"), script, mins, 1, remoteTotalThreads, queue); // now add hazard calc jobs with gridded - for (int i=0; i<4; i++) { + for (int i=0; i<5; i++) { int myNodes = nodes; // for (boolean avgGridded : new boolean[] {true, false}) { File jobFile; @@ -1015,8 +1027,6 @@ else if (mpjWrite instanceof FastMPJShellScriptWriter) argz += " --external-grid-prov "+dirPath+"/"+griddedBAName; jobFile = new File(localDir, "batch_hazard_avg_gridded.slurm"); } else if (i == 1) { -// if (averageOnly) -// continue; argz = "--input-file "+resultsPath; argz += " --logic-tree "+fullLTPath; argz += " --output-file "+resultsPath+"_hazard_full_gridded.zip"; @@ -1028,8 +1038,6 @@ else if (mpjWrite instanceof FastMPJShellScriptWriter) jobFile = new File(localDir, "batch_hazard_full_gridded.slurm"); myNodes = origNodes; } else if (i == 2) { -// if (averageOnly) -// continue; argz = "--input-file "+resultsPath; argz += " --logic-tree "+randLTPath; argz += " --output-file "+resultsPath+"_hazard_full_gridded_sampled.zip"; @@ -1039,6 +1047,16 @@ else if (mpjWrite instanceof FastMPJShellScriptWriter) argz += " --quick-grid-calc"; jobFile = new File(localDir, "batch_hazard_full_gridded_sampled.slurm"); myNodes = origNodes; + } else if (i == 3) { + argz = "--input-file "+resultsPath; + argz += " --logic-tree "+onlyLTPath; + argz += " --output-file "+resultsPath+"_hazard_full_gridded_only.zip"; + argz += " --output-dir "+resultsPath+"_full_gridded"; + argz += " --combine-with-dir "+resultsPath; + argz += " --gridded-seis ONLY"; + argz += " --quick-grid-calc"; + jobFile = new File(localDir, "batch_hazard_full_gridded_only.slurm"); + myNodes = origNodes; } else { argz = "--input-file "+resultsPath+"_gridded_branches.zip"; argz += " --output-file "+resultsPath+"_hazard_gridded_only.zip"; diff --git a/src/main/java/scratch/kevin/prvi25/CrustalSubductionLogicTreeCombine.java b/src/main/java/scratch/kevin/prvi25/CrustalSubductionLogicTreeCombine.java index 243e06bb..e905a37a 100644 --- a/src/main/java/scratch/kevin/prvi25/CrustalSubductionLogicTreeCombine.java +++ b/src/main/java/scratch/kevin/prvi25/CrustalSubductionLogicTreeCombine.java @@ -63,23 +63,37 @@ public static void main(String[] args) throws IOException { if (cmd.hasOption("gridded-seis")) bgOp = IncludeBackgroundOption.valueOf(cmd.getOptionValue("gridded-seis")); + LogicTree crustalLT; SolutionLogicTree crustalSLT; + LogicTree subductionLT; SolutionLogicTree subductionSLT; if (cmd.hasOption("logic-tree-file-name")) { String logicTreeFileName = cmd.getOptionValue("logic-tree-file-name"); File crustalLogicTreefile = new File(crustalDir, logicTreeFileName); - LogicTree crustalTree = LogicTree.read(crustalLogicTreefile); + crustalLT = LogicTree.read(crustalLogicTreefile); File subductionLogicTreeFile = new File(subductionDir, logicTreeFileName); - LogicTree subductionTree = LogicTree.read(subductionLogicTreeFile); - crustalSLT = SolutionLogicTree.load(new File(crustalDir, resultsFileName), crustalTree); - subductionSLT = SolutionLogicTree.load(new File(subductionDir, resultsFileName), subductionTree); + subductionLT = LogicTree.read(subductionLogicTreeFile); + File crustalSLTFile = new File(crustalDir, resultsFileName); + if (crustalSLTFile.exists()) + crustalSLT = SolutionLogicTree.load(crustalSLTFile, crustalLT); + else + crustalSLT = null; + File subductionSLTFile = new File(subductionDir, resultsFileName); + if (subductionSLTFile.exists()) + subductionSLT = SolutionLogicTree.load(subductionSLTFile, subductionLT); + else + subductionSLT = null; } else { crustalSLT = SolutionLogicTree.load(new File(crustalDir, resultsFileName)); + crustalLT = crustalSLT.getLogicTree(); subductionSLT = SolutionLogicTree.load(new File(subductionDir, resultsFileName)); + subductionLT = subductionSLT.getLogicTree(); } - crustalSLT.setVerbose(false); - subductionSLT.setVerbose(false); + if (crustalSLT != null) + crustalSLT.setVerbose(false); + if (subductionSLT != null) + subductionSLT.setVerbose(false); GriddedRegion gridReg = loadGridReg(new File(crustalDir, gridRegFileName)); Preconditions.checkState(gridReg.equals(loadGridReg(new File(subductionDir, gridRegFileName))), @@ -91,35 +105,67 @@ public static void main(String[] args) throws IOException { else if (bgOp == IncludeBackgroundOption.EXCLUDE) outputHazardFileName = "results_hazard.zip"; else if (bgOp == IncludeBackgroundOption.INCLUDE) - outputHazardFileName = "results_hazard_gridded.zip"; + outputHazardFileName = "results_hazard_full_gridded.zip"; else if (bgOp == IncludeBackgroundOption.ONLY) outputHazardFileName = "results_hazard_gridded_only.zip"; else throw new IllegalStateException(); - File resultsOutputFile = cmd.hasOption("disable-write-results") ? null : new File(outputDir, resultsFileName); - +// CrustalSubductionLogicTreeCombine combiner = new CrustalSubductionLogicTreeCombine( +// crustalLT, crustalSLT, new File(crustalDir, hazardDirName), bgOp, +// subductionLT, subductionSLT, new File(subductionDir, hazardDirName), bgOp, +// resultsOutputFile, +// new File(outputDir, outputHazardFileName), gridReg); CrustalSubductionLogicTreeCombine combiner = new CrustalSubductionLogicTreeCombine( - crustalSLT, new File(crustalDir, hazardDirName), bgOp, - subductionSLT, new File(subductionDir, hazardDirName), bgOp, - resultsOutputFile, - new File(outputDir, outputHazardFileName), gridReg); + crustalLT, subductionLT); + + if (!cmd.hasOption("disable-write-results")) { + File resultsOutputFile = new File(outputDir, resultsFileName); + Preconditions.checkNotNull(crustalSLT); + Preconditions.checkNotNull(subductionSLT); + combiner.setWriteSLTs(crustalSLT, subductionSLT, resultsOutputFile); + } + + combiner.setCombineHazardMaps(new File(crustalDir, hazardDirName), bgOp, + new File(subductionDir, hazardDirName), bgOp, new File(outputDir, outputHazardFileName), gridReg); + + long treeSize = (long)crustalLT.size()*(long)subductionLT.size(); + if (cmd.hasOption("pre-samples")) { + // more memory efficient pre-sampling version + int samples = Integer.parseInt(cmd.getOptionValue("pre-samples")); + long seed = cmd.hasOption("rand-seed") ? Long.parseLong(cmd.getOptionValue("rand-seed")) : treeSize*(long)samples; + combiner.pairwiseSampleTree(samples, seed); + } if (cmd.hasOption("samples")) { int samples = Integer.parseInt(cmd.getOptionValue("samples")); - int treeSize = combiner.getCombTree().size(); if (samples < treeSize) { - long seed = cmd.hasOption("rand-seed") ? Long.parseLong(cmd.getOptionValue("rand-seed")) : (long)treeSize*(long)samples; + long seed = cmd.hasOption("rand-seed") ? Long.parseLong(cmd.getOptionValue("rand-seed")) : treeSize*(long)samples; combiner.sampleTree(samples, seed); } } - combiner.build(); + LogicTree combTree = combiner.getCombTree(); + File treeOutputFile; + if (cmd.hasOption("logic-tree-file-name")) + treeOutputFile = new File(outputDir, cmd.getOptionValue("logic-tree-file-name")); + else + treeOutputFile = new File(outputDir, "logic_tree_"+bgOp.name()+".json"); + combTree.write(treeOutputFile); + + try { + combiner.build(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } } public static Options createOptions() { Options ops = new Options(); - + + ops.addOption(null, "pre-samples", true, "Number of pre-samples to draw. This is more memory efficient and doesn't require " + + "instantiating the entire tree in memory first."); ops.addOption(null, "samples", true, "Number of samples to draw"); ops.addOption(null, "rand-seed", true, "Random seed for use when sampling"); ops.addOption(null, "gridded-seis", true, "Gridded seismicity option. One of " @@ -134,11 +180,8 @@ public static Options createOptions() { return ops; } - public CrustalSubductionLogicTreeCombine(SolutionLogicTree outerSLT, File outerHazardDir, - IncludeBackgroundOption outerBGOp, SolutionLogicTree innerSLT, File innerHazardDir, - IncludeBackgroundOption innerBGOp, File outputSLTFile, File outputHazardFile, GriddedRegion gridReg) { - super(outerSLT, outerHazardDir, outerBGOp, innerSLT, innerHazardDir, innerBGOp, outputSLTFile, outputHazardFile, - gridReg); + public CrustalSubductionLogicTreeCombine(LogicTree outerLT, LogicTree innerLT) { + super(outerLT, innerLT); } private static GriddedRegion loadGridReg(File regFile) throws IOException { @@ -212,8 +255,8 @@ protected boolean isSerializeGridded() { } @Override - protected boolean canSkipLevel(LogicTreeLevel level, boolean inner) { - return false; + protected List> getCommonLevels() { + return List.of(); } } diff --git a/src/main/java/scratch/kevin/prvi25/GMMLogicTreeWriter.java b/src/main/java/scratch/kevin/prvi25/GMMLogicTreeWriter.java index 8a37ca32..cee8c30a 100644 --- a/src/main/java/scratch/kevin/prvi25/GMMLogicTreeWriter.java +++ b/src/main/java/scratch/kevin/prvi25/GMMLogicTreeWriter.java @@ -5,110 +5,262 @@ import java.util.ArrayList; import java.util.List; -import org.opensha.commons.logicTree.AffectsNone; +import org.opensha.commons.data.CSVFile; +import org.opensha.commons.data.Site; +import org.opensha.commons.geo.GriddedRegion; +import org.opensha.commons.geo.Location; +import org.opensha.commons.geo.json.Feature; +import org.opensha.commons.hpc.JavaShellScriptWriter; +import org.opensha.commons.hpc.mpj.FastMPJShellScriptWriter; +import org.opensha.commons.hpc.mpj.MPJExpressShellScriptWriter; +import org.opensha.commons.hpc.mpj.NoMPJSingleNodeShellScriptWriter; +import org.opensha.commons.hpc.pbs.BatchScriptWriter; +import org.opensha.commons.hpc.pbs.USC_CARC_ScriptWriter; import org.opensha.commons.logicTree.LogicTree; import org.opensha.commons.logicTree.LogicTreeBranch; import org.opensha.commons.logicTree.LogicTreeLevel; -import org.opensha.commons.logicTree.LogicTreeLevel.EnumBackedLevel; import org.opensha.commons.logicTree.LogicTreeNode; -import org.opensha.sha.imr.AttenRelSupplier; -import org.opensha.sha.imr.attenRelImpl.nshmp.NSHMP_AttenRelSupplier; -import org.opensha.sha.imr.logicTree.ScalarIMRsLogicTreeNode; -import org.opensha.sha.imr.logicTree.ScalarIMR_ParamsLogicTreeNode; +import org.opensha.sha.earthquake.faultSysSolution.hazard.mpj.MPJ_LogicTreeHazardCalc; +import org.opensha.sha.earthquake.faultSysSolution.hazard.mpj.MPJ_SiteLogicTreeHazardCurveCalc; +import org.opensha.sha.earthquake.param.IncludeBackgroundOption; +import org.opensha.sha.earthquake.rupForecastImpl.prvi25.logicTree.PRVI25_CrustalFaultModels; +import org.opensha.sha.earthquake.rupForecastImpl.prvi25.logicTree.PRVI25_LogicTreeBranch; +import org.opensha.sha.earthquake.rupForecastImpl.prvi25.util.PRVI25_RegionLoader; import com.google.common.base.Preconditions; -import gov.usgs.earthquake.nshmp.gmm.Gmm; +import edu.usc.kmilner.mpj.taskDispatch.MPJTaskCalculator; public class GMMLogicTreeWriter { public static void main(String[] args) throws IOException { - File sourceDir = new File("/home/kevin/OpenSHA/nshm23/batch_inversions/2024_07_01-prvi25_crustal_branches-dmSample5x"); - File outputDir = new File("/home/kevin/OpenSHA/nshm23/batch_inversions/2024_07_01-prvi25_crustal_branches-dmSample5x-gmTreeCalcs"); + File baseDir = new File("/home/kevin/OpenSHA/nshm23/batch_inversions"); - LogicTree tree = LogicTree.read(new File(sourceDir, "logic_tree.json")); - System.out.println("Read "+tree.size()+" branches"); + String jobSuffix = ""; + String outputSuffix = ""; + String forceInputFileName = null; + String logicTreeOutputName = null; + boolean combineOnly = false; - EnumBackedLevel gmmLevel = new EnumBackedLevel<>("GMM", "GMM", NGAW2_Node.class); +// GriddedRegion gridReg = new GriddedRegion(PRVI25_RegionLoader.loadPRVI_ModelBroad(), 0.1, GriddedRegion.ANCHOR_0_0); + GriddedRegion gridReg = new GriddedRegion(PRVI25_RegionLoader.loadPRVI_MapExtents(), 0.025, GriddedRegion.ANCHOR_0_0); + System.out.println("Region has "+gridReg.getNodeCount()+" nodes"); - System.out.println("GMM level check worked? "+isGMMLevel(gmmLevel)); + /* + * Active crustal + */ + List> gmmLevels = PRVI25_LogicTreeBranch.levelsCrustalGMM; + File sourceDir = new File(baseDir, "2024_08_16-prvi25_crustal_branches-dmSample5x"); + File outputDir = new File(baseDir, sourceDir.getName()+"-gmTreeCalcs"); + // supra-seis only +// File sourceTreeFile = new File(sourceDir, "logic_tree.json"); +// int mins = 1440; +// IncludeBackgroundOption bgOp = IncludeBackgroundOption.EXCLUDE; + // including gridded + int mins = 1440*5; +// File sourceTreeFile = new File(sourceDir, "logic_tree_full_gridded.json"); + File sourceTreeFile = new File(sourceDir, "logic_tree_full_gridded_sampled.json"); jobSuffix = "_sampled"; + IncludeBackgroundOption bgOp = IncludeBackgroundOption.INCLUDE; + + /* + * Interface + */ +// List> gmmLevels = PRVI25_LogicTreeBranch.levelsInterfaceGMM; +// File sourceDir = new File(baseDir, "2024_08_16-prvi25_subduction_branches"); +// File outputDir = new File(baseDir, sourceDir.getName()+"-gmTreeCalcs"); +//// // supra-seis only +//// File sourceTreeFile = new File(sourceDir, "logic_tree.json"); +//// int mins = 1440; +//// IncludeBackgroundOption bgOp = IncludeBackgroundOption.EXCLUDE; +// // interface gridded only +//// int mins = 1440; +//// File sourceTreeFile = new File(sourceDir, "logic_tree_gridded_only.json"); +//// logicTreeOutputName = "logic_tree_gridded_interface_only.json"; +//// IncludeBackgroundOption bgOp = IncludeBackgroundOption.ONLY; +//// forceInputFileName = "results_gridded_branches_interface_only.zip"; +//// jobSuffix = "_interface"; +//// outputSuffix = jobSuffix; +// // interface both (combine only) +// combineOnly = true; +// int mins = 1440; +// forceInputFileName = "results_full_gridded_interface_only.zip"; +// File sourceTreeFile = new File(sourceDir, "logic_tree_full_gridded.json"); +// logicTreeOutputName = "logic_tree_full_gridded_interface_only.json"; +// IncludeBackgroundOption bgOp = IncludeBackgroundOption.INCLUDE; +// jobSuffix = "_interface"; +// outputSuffix = jobSuffix; + + /* + * Slab + */ +// List> gmmLevels = PRVI25_LogicTreeBranch.levelsSlabGMM; +// File sourceDir = new File(baseDir, "2024_08_16-prvi25_subduction_branches"); +// File outputDir = new File(baseDir, sourceDir.getName()+"-gmTreeCalcs"); +// // always slab gridded only +// int mins = 1440; +// File sourceTreeFile = new File(sourceDir, "logic_tree_gridded_only.json"); +// logicTreeOutputName = "logic_tree_gridded_slab_only.json"; +// IncludeBackgroundOption bgOp = IncludeBackgroundOption.ONLY; +// forceInputFileName = "results_gridded_branches_slab_only.zip"; +// jobSuffix = "_slab"; +// outputSuffix = jobSuffix; + + LogicTree erfTree = LogicTree.read(sourceTreeFile); + System.out.println("Read "+erfTree.size()+" ERF branches"); + + LogicTree gmmTree = LogicTree.buildExhaustive(gmmLevels, true); + System.out.println("Built "+gmmTree.size()+" GMM branches"); + + Preconditions.checkState(outputDir.exists() || outputDir.mkdir()); + + File gridRegFile = new File(outputDir, "gridded_region.geojson"); + Feature.write(gridReg.toFeature(), gridRegFile); List> combLevels = new ArrayList<>(); - combLevels.addAll(tree.getLevels()); - combLevels.add(gmmLevel); + combLevels.addAll(erfTree.getLevels()); + combLevels.addAll(gmmLevels); - List> combBranches = new ArrayList<>(); + List> combBranches = new ArrayList<>(erfTree.size()*gmmTree.size()); - for (LogicTreeBranch branch : tree) { - for (NGAW2_Node gmmNode : NGAW2_Node.values()) { + for (LogicTreeBranch branch : erfTree) { + for (LogicTreeBranch gmmBranch : gmmTree) { LogicTreeBranch combBranch = new LogicTreeBranch<>(combLevels); for (LogicTreeNode node : branch) combBranch.setValue(node); - combBranch.setValue(gmmNode); + for (LogicTreeNode node : gmmBranch) + combBranch.setValue(node); combBranches.add(combBranch); } } + LogicTree logicTree = LogicTree.fromExisting(combLevels, combBranches); - Preconditions.checkState(outputDir.exists() || outputDir.mkdir()); - LogicTree combTree = LogicTree.fromExisting(combLevels, combBranches); - combTree.write(new File(outputDir, "logic_tree.json")); - System.out.println("Write "+combTree.size()+" branches"); - - combTree = LogicTree.read(new File(outputDir, "logic_tree.json")); - - LogicTreeBranch prevBranch = null; - for (int i=0; i branch = combTree.getBranch(i); - if (prevBranch != null) { - boolean onlyGmmDifferent = true; - for (int l=0; l level) { - return ScalarIMRsLogicTreeNode.class.isAssignableFrom(level.getType()) || - ScalarIMR_ParamsLogicTreeNode.class.isAssignableFrom(level.getType()); - } - - @AffectsNone - public static enum NGAW2_Node implements ScalarIMRsLogicTreeNode.Single { - ASK(Gmm.ASK_14_BASE), - BSSA(Gmm.BSSA_14_BASE), - CB(Gmm.CB_14_BASE), - CY(Gmm.CY_14_BASE); - - private Gmm gmm; - - private NGAW2_Node(Gmm gmm) { - this.gmm = gmm; - } - - @Override - public double getNodeWeight(LogicTreeBranch fullBranch) { - return 1d; - } - - @Override - public String getFilePrefix() { - return gmm.name(); + File localLogicTree = new File(outputDir, logicTreeOutputName == null ? sourceTreeFile.getName() : logicTreeOutputName); + logicTree.write(localLogicTree); + System.out.println("Wrote "+logicTree.size()+" branches"); + + String dirName = outputDir.getName(); + File localDir = outputDir; + + File remoteMainDir = new File("/project/scec_608/kmilner/nshm23/batch_inversions"); + int remoteTotalThreads = 20; + int remoteTotalMemGB = 50; + String queue = "scec"; + int nodes = 36; +// JavaShellScriptWriter mpjWrite = new MPJExpressShellScriptWriter( +// USC_CARC_ScriptWriter.JAVA_BIN, remoteTotalMemGB*1024, null, USC_CARC_ScriptWriter.MPJ_HOME); + JavaShellScriptWriter mpjWrite = new FastMPJShellScriptWriter( + USC_CARC_ScriptWriter.JAVA_BIN, remoteTotalMemGB*1024, null, USC_CARC_ScriptWriter.FMPJ_HOME); +// JavaShellScriptWriter mpjWrite = new NoMPJSingleNodeShellScriptWriter(USC_CARC_ScriptWriter.JAVA_BIN, +// remoteTotalMemGB*1024, null); nodes = 1; remoteInversionsPerBundle = 2; + BatchScriptWriter pbsWrite = new USC_CARC_ScriptWriter(); + + mpjWrite.setEnvVar("MAIN_DIR", remoteMainDir.getAbsolutePath()); + String mainDirPath = "$MAIN_DIR"; + mpjWrite.setEnvVar("DIR", mainDirPath+"/"+dirName); + String dirPath = "$DIR"; + mpjWrite.setEnvVar("ORIG_DIR", mainDirPath+"/"+sourceDir.getName()); + String origDirPath = "$ORIG_DIR"; + + List classpath = new ArrayList<>(); + classpath.add(new File(dirPath+"/opensha-dev-all.jar")); + if (mpjWrite instanceof NoMPJSingleNodeShellScriptWriter) + classpath.add(new File("/project/scec_608/kmilner/git/opensha/lib/mpj-0.38.jar")); + + mpjWrite.setClasspath(classpath); + if (mpjWrite instanceof MPJExpressShellScriptWriter) + ((MPJExpressShellScriptWriter)mpjWrite).setUseLaunchWrapper(true); + else if (mpjWrite instanceof FastMPJShellScriptWriter) + ((FastMPJShellScriptWriter)mpjWrite).setUseLaunchWrapper(true); + + String mapScriptName = "batch_hazard_"+bgOp.name()+jobSuffix+".slurm"; + String siteScriptName = "batch_hazard_sites_"+bgOp.name()+jobSuffix+".slurm"; + + // now write hazard map script + String inputFileName; + if (forceInputFileName != null) + inputFileName = origDirPath+"/"+forceInputFileName; // use supplied + else if (bgOp == IncludeBackgroundOption.EXCLUDE) + inputFileName = origDirPath+"/results.zip"; // use the zip file + else + inputFileName = origDirPath+"/results"; // use the results dir + String argz = "--input-file "+inputFileName; + + String outputDirName, outputFilePrefix; + if (bgOp == IncludeBackgroundOption.INCLUDE) { + argz += " --combine-with-dir "+dirPath+"/results"; + argz += " --combine-with-dir "+dirPath+"/results_gridded_only"+outputSuffix; + outputDirName = "results_full_gridded"; + outputFilePrefix = outputDirName; + } else if (bgOp == IncludeBackgroundOption.ONLY) { + outputDirName = "results_gridded_only"; + outputFilePrefix = outputDirName; + } else { + outputDirName = "results"; + outputFilePrefix = "results_hazard"; } - - @Override - public AttenRelSupplier getSupplier() { - return new NSHMP_AttenRelSupplier(gmm, false); + argz += " --output-dir "+dirPath+"/"+outputDirName+outputSuffix; + argz += " --output-file "+dirPath+"/"+outputFilePrefix+outputSuffix+".zip"; + argz += " --gridded-seis "+bgOp.name(); + String logicTreePath = dirPath+"/"+localLogicTree.getName(); + argz += " --logic-tree "+logicTreePath; + if (bgOp == IncludeBackgroundOption.ONLY || bgOp == IncludeBackgroundOption.INCLUDE) + argz += " --quick-grid-calc"; + if (combineOnly) + argz += " --combine-only"; + argz += " --region "+dirPath+"/"+gridRegFile.getName(); + argz += " "+MPJTaskCalculator.argumentBuilder().exactDispatch(1).threads(remoteTotalThreads).build(); + List script = mpjWrite.buildScript(MPJ_LogicTreeHazardCalc.class.getName(), argz); + pbsWrite.writeScript(new File(localDir, mapScriptName), script, mins, nodes, remoteTotalThreads, queue); + + // now write hazard curve script + CSVFile csv = CSVFile.readStream(PRVI25_CrustalFaultModels.class.getResourceAsStream("/data/erf/prvi25/sites/prvi_sites.csv"), true); + List sites = new ArrayList<>(); + for (int row=1; row(true); + csv.addLine("Name", "Latitude", "Longitude"); + for (Site site : sites) + csv.addLine(site.getName(), site.getLocation().lat+"", site.getLocation().lon+""); + File localSitesFile = new File(localDir, "hazard_sites.csv"); + csv.writeToFile(localSitesFile); + argz = "--input-file "+inputFileName; + argz += " --logic-tree "+logicTreePath; + argz += " --output-dir "+dirPath+"/"+outputFilePrefix+"_sites"+outputSuffix; + argz += " --sites-file "+dirPath+"/"+localSitesFile.getName(); + argz += " --gridded-seis "+bgOp.name(); + argz += " "+MPJTaskCalculator.argumentBuilder().minDispatch(1).maxDispatch(10).threads(remoteTotalThreads).build(); + script = mpjWrite.buildScript(MPJ_SiteLogicTreeHazardCurveCalc.class.getName(), argz); + pbsWrite.writeScript(new File(localDir, siteScriptName), script, mins, nodes, remoteTotalThreads, queue); + +// combTree = LogicTree.read(new File(outputDir, "logic_tree.json")); +// +// LogicTreeBranch prevBranch = null; +// for (int i=0; i branch = combTree.getBranch(i); +// if (prevBranch != null) { +// boolean onlyGmmDifferent = true; +// for (int l=0; l level) { +// return ScalarIMRsLogicTreeNode.class.isAssignableFrom(level.getType()) || +// ScalarIMR_ParamsLogicTreeNode.class.isAssignableFrom(level.getType()); +// } } diff --git a/src/main/java/scratch/kevin/prvi25/InterfaceSlabSLT_Splitter.java b/src/main/java/scratch/kevin/prvi25/InterfaceSlabSLT_Splitter.java new file mode 100644 index 00000000..a92a231a --- /dev/null +++ b/src/main/java/scratch/kevin/prvi25/InterfaceSlabSLT_Splitter.java @@ -0,0 +1,115 @@ +package scratch.kevin.prvi25; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.opensha.commons.logicTree.LogicTree; +import org.opensha.commons.logicTree.LogicTreeBranch; +import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution; +import org.opensha.sha.earthquake.faultSysSolution.modules.GridSourceList; +import org.opensha.sha.earthquake.faultSysSolution.modules.GridSourceList.GriddedRupture; +import org.opensha.sha.earthquake.faultSysSolution.modules.SolutionLogicTree; +import org.opensha.sha.util.TectonicRegionType; + +import com.google.common.base.Preconditions; + +public class InterfaceSlabSLT_Splitter { + + public static void main(String[] args) throws IOException { + File dir; + boolean griddedOnly; + + if (args.length == 1 && args[0].equals("--hardcoded")) { + System.out.println("HARDCODED"); + File baseDir = new File("/home/kevin/OpenSHA/nshm23/batch_inversions"); + dir = new File(baseDir, "2024_08_16-prvi25_subduction_branches"); + griddedOnly = true; + } else if (args.length == 2) { + dir = new File(args[0]); + griddedOnly = Boolean.parseBoolean(args[1]); + + } else { + throw new IllegalArgumentException("USAGE: "); + } + System.out.println("Input directory: "+dir.getAbsolutePath()); + System.out.println("Gridded only? "+griddedOnly); + Preconditions.checkState(dir.exists()); + + if (griddedOnly) { + File intputFile = new File(dir, "results_gridded_branches.zip"); + File slabOutputFile = new File(dir, "results_gridded_branches_slab_only.zip"); + File interfaceOutputFile = new File(dir, "results_gridded_branches_interface_only.zip"); + + SolutionLogicTree slt = SolutionLogicTree.load(intputFile); + LogicTree tree = slt.getLogicTree(); + + SolutionLogicTree.FileBuilder slabWriter = new SolutionLogicTree.FileBuilder(slabOutputFile); + SolutionLogicTree.FileBuilder interfaceWriter = new SolutionLogicTree.FileBuilder(interfaceOutputFile); + // we'll manually write them + slabWriter.setSerializeGridded(false); + interfaceWriter.setSerializeGridded(false); + for (int b=0; b branch = tree.getBranch(b); + System.out.println("Processing "+b+"/"+tree.size()+": "+branch); + FaultSystemSolution sol = slt.forBranch(branch); + GridSourceList gridSources = sol.requireModule(GridSourceList.class); + + List> slabRupturesList = new ArrayList<>(gridSources.getNumLocations()); + List> interfaceRupturesList = new ArrayList<>(gridSources.getNumLocations()); + + for (int l=0; l tree = LogicTree.read(new File(dir, "logic_tree_full_gridded.json")); + + SolutionLogicTree slt = new SolutionLogicTree.ResultsDirReader(intputDir, tree); + + SolutionLogicTree.FileBuilder interfaceWriter = new SolutionLogicTree.FileBuilder(outputFile); + // we'll manually write them + interfaceWriter.setSerializeGridded(false); + for (int b=0; b branch = tree.getBranch(b); + System.out.println("Processing "+b+"/"+tree.size()+": "+branch); + FaultSystemSolution sol = slt.forBranch(branch); + GridSourceList gridSources = (GridSourceList)sol.getGridSourceProvider(); + + List> interfaceRupturesList = new ArrayList<>(gridSources.getNumLocations()); + + for (int l=0; l"); + ModuleContainer.VERBOSE_DEFAULT = false; + File hazardDir = new File(args[0]); + Preconditions.checkState(hazardDir.exists(), "Directory doesn't exist: %s", hazardDir.getAbsolutePath()); + + LogicTree interfaceTree = LogicTree.read(new File(hazardDir, "logic_tree_full_gridded_interface_only.json")); + LogicTree slabTree = LogicTree.read(new File(hazardDir, "logic_tree_gridded_slab_only.json")); + + File interfaceHazardMapDir = new File(hazardDir, "results_full_gridded_interface"); + File slabHazardMapDir = new File(hazardDir, "results_gridded_only_slab"); + + File outputDir = new File(hazardDir, "results_full_gridded"); + GriddedRegion gridReg = loadGridReg(new File(hazardDir, "gridded_region.geojson")); + + SubductionInterfaceSlabHazardLogicTreeCombine combiner = new SubductionInterfaceSlabHazardLogicTreeCombine( + interfaceTree, slabTree); + + if (cmd.hasOption("disable-preload")) + combiner.setPreloadInnerCurves(false); + + if (!cmd.hasOption("no-maps") && interfaceHazardMapDir.exists()) { + System.out.println("Will combine hazard maps"); + combiner.setCombineHazardMaps(interfaceHazardMapDir, IncludeBackgroundOption.INCLUDE, slabHazardMapDir, + IncludeBackgroundOption.ONLY, outputDir, gridReg); + } + + File interfaceHazardSitesFile = new File(hazardDir, "results_full_gridded_sites_interface.zip"); + File slabHazardSitesFile = new File(hazardDir, "results_gridded_only_sites_slab.zip"); + + if (!cmd.hasOption("no-curves") && interfaceHazardSitesFile.exists()) { + System.out.println("Will combine hazard sites"); + File sitesOutputFile = new File(hazardDir, "results_full_gridded_sites"); + combiner.setCombineHazardCurves(interfaceHazardSitesFile, slabHazardSitesFile, sitesOutputFile); + } + + System.out.println(); + List> commonLevels = combiner.getCommonLevels(); + System.out.println("Interface tree has "+interfaceTree.size()+" branches; Levels:"); + for (LogicTreeLevel level : interfaceTree.getLevels()) + System.out.println("\t"+level.getName()+" (common="+commonLevels.contains(level)+")"); + System.out.println("Slab tree has "+slabTree.size()+" branches; Levels:"); + for (LogicTreeLevel level : slabTree.getLevels()) + System.out.println("\t"+level.getName()+" (common="+commonLevels.contains(level)+")"); + System.out.println("Raw tree product is "+(interfaceTree.size()*slabTree.size())); + System.out.println(); + + if (cmd.hasOption("samples")) { + int samples = Integer.parseInt(cmd.getOptionValue("samples")); + if (cmd.hasOption("rand-seed")) + combiner.sampleTree(samples, Long.parseLong(cmd.getOptionValue("rand-seed"))); + else + combiner.sampleTree(samples); + } + + combiner.getCombTree().write(new File(hazardDir, "logic_tree_full_gridded.json")); + + try { + combiner.build(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + + public SubductionInterfaceSlabHazardLogicTreeCombine(LogicTree interfaceTree, LogicTree slabTree) { + super(interfaceTree, slabTree); +// super(interfaceTree, interfaceHazardDir, IncludeBackgroundOption.INCLUDE, +// slabTree, slabHazardDir, IncludeBackgroundOption.ONLY, +// outputHazardFile, gridReg); + } + + public static Options createOptions() { + Options ops = new Options(); + + ops.addOption(null, "samples", true, "Number of samples to draw"); + ops.addOption(null, "rand-seed", true, "Random seed for use when sampling"); + ops.addOption(null, "disable-preload", false, "Flag to disable pre-loading of slab hazard curves (to quickly get to the build loop)"); + ops.addOption(null, "no-maps", false, "Flag to disable combining hazard maps"); + ops.addOption(null, "no-curves", false, "Flag to disable combining site hazard curves"); + + return ops; + } + + private static GriddedRegion loadGridReg(File regFile) throws IOException { + Preconditions.checkState(regFile.exists(), "Supplied region file doesn't exist: %s", regFile.getAbsolutePath()); + if (regFile.getName().toLowerCase().endsWith(".zip")) { + // it's a zip file, assume it's a prior hazard calc + ZipFile zip = new ZipFile(regFile); + ZipEntry regEntry = zip.getEntry(MPJ_LogicTreeHazardCalc.GRID_REGION_ENTRY_NAME); + System.out.println("Reading gridded region from zip file: "+regEntry.getName()); + BufferedReader bRead = new BufferedReader(new InputStreamReader(zip.getInputStream(regEntry))); + GriddedRegion region = GriddedRegion.fromFeature(Feature.read(bRead)); + zip.close(); + return region; + } else { + Feature feature = Feature.read(regFile); + return GriddedRegion.fromFeature(feature); + } + } + + private static void remapTree(LogicTree tree, Map, LogicTreeLevel> levelRemaps, + Map nodeRemaps, String nameAdd, String shortNameAdd) { + for (LogicTreeLevel level : tree.getLevels()) { + if (ScalarIMR_ParamsLogicTreeNode.class.isAssignableFrom(level.getType())) { + // need to remap + String name = level.getName(); + List modNodes = new ArrayList<>(); + for (LogicTreeNode node : level.getNodes()) { + FileBackedNode modNode = new FileBackedNode(nameAdd+" "+node.getName(), node.getShortName(), + node.getNodeWeight(null), shortNameAdd+node.getFilePrefix()); + modNodes.add(modNode); + nodeRemaps.put(node, modNode); + } + FileBackedLevel modLevel = new FileBackedLevel(nameAdd+" "+name, shortNameAdd+level.getShortName(), modNodes); + modLevel.setAffected(level.getAffected(), level.getNotAffected(), false); + levelRemaps.put(level, modLevel); + } else { + // don't need to remap + levelRemaps.put(level, level); + for (LogicTreeNode node : level.getNodes()) + nodeRemaps.put(node, node); + } + } + } + + @Override + protected void remapOuterTree(LogicTree tree, Map, LogicTreeLevel> levelRemaps, + Map nodeRemaps) { + remapTree(tree, levelRemaps, nodeRemaps, "Interface", ""); + } + + @Override + protected void remapInnerTree(LogicTree tree, Map, LogicTreeLevel> levelRemaps, + Map nodeRemaps) { + remapTree(tree, levelRemaps, nodeRemaps, "Slab", ""); + } + + @Override + protected boolean doesOuterSupplySols() { + return false; + } + + @Override + protected boolean doesInnerSupplySols() { + return false; + } + + @Override + protected boolean isSerializeGridded() { + return false; + } + + @Override + protected List> getCommonLevels() { + List> commonLevels = new ArrayList<>(); + for (LogicTreeLevel level : getInnerTree().getLevels()) { + // everything is common except GMM branches + if (!ScalarIMRsLogicTreeNode.class.isAssignableFrom(level.getType()) + && !ScalarIMR_ParamsLogicTreeNode.class.isAssignableFrom(level.getType())) + commonLevels.add(level); + } + return commonLevels; + } + +} diff --git a/src/main/java/scratch/kevin/ucerf3/BayAreaUpdatedProbsCalc.java b/src/main/java/scratch/kevin/ucerf3/BayAreaUpdatedProbsCalc.java index 083f8008..1a16bbda 100644 --- a/src/main/java/scratch/kevin/ucerf3/BayAreaUpdatedProbsCalc.java +++ b/src/main/java/scratch/kevin/ucerf3/BayAreaUpdatedProbsCalc.java @@ -40,12 +40,18 @@ public class BayAreaUpdatedProbsCalc { static Map> loadFaultParentSectMappings() { Map> map = new HashMap<>(); - map.put("San Andreas", List.of(654, 655, 657, 658)); - map.put("Hayward-Rodgers Creek", List.of(637, 638, 639, 651)); - map.put("Calaveras", List.of(601, 602, 603, 621)); - map.put("Concord", List.of(635, 636, 711, 713, 2, 622, 623, 640, 677)); - map.put("San Gregorio", List.of(660, 661)); - map.put("Maacama", List.of(644)); +// map.put("San Andreas", List.of(654, 655, 657, 658)); +// map.put("Hayward-Rodgers Creek", List.of(637, 638, 639, 651)); +// map.put("Calaveras", List.of(601, 602, 603, 621)); +// map.put("Concord", List.of(635, 636, 711, 713, 2, 622, 623, 640, 677)); +// map.put("San Gregorio", List.of(660, 661)); +// map.put("Maacama", List.of(644)); + // these aren't bay area, but from Ruth's 8/15/24 e-mail + map.put("SAF Creeping", List.of(658)); + map.put("SAF Parkfield", List.of(32)); + map.put("Imperial", List.of(97)); + map.put("Superstition Hills", List.of(98)); + map.put("S. SAF", List.of(285, 300, 287, 286, 301, 282, 283, 284, 295)); return map; } @@ -55,7 +61,8 @@ public static void main(String[] args) throws IOException { // int year = 2014; int duration = 30; - File outputDir = new File("/home/kevin/OpenSHA/UCERF3/bay_area_updated_probs"); +// File outputDir = new File("/home/kevin/OpenSHA/UCERF3/bay_area_updated_probs"); + File outputDir = new File("/tmp/ruth_probs"); Preconditions.checkState(outputDir.exists() || outputDir.mkdir()); double[] minMags = {6.7, 7, 7.5}; @@ -67,7 +74,10 @@ public static void main(String[] args) throws IOException { MeanUCERF3 erf = new MeanUCERF3(); erf.setPreset(presets[0]); - Region reg = new CaliforniaRegions.SF_BOX(); +// String regName = "Bay Area Region"; +// Region reg = new CaliforniaRegions.SF_BOX(); + String regName = null; + Region reg = null; Map> faultIDs = loadFaultParentSectMappings(); List faultsSorted = new ArrayList<>(); @@ -77,7 +87,7 @@ public static void main(String[] args) throws IOException { Map faultProbs = new HashMap<>(); for (String faultName : faultsSorted) faultProbs.put(faultName, new double[minMags.length]); - double[] regProbs = new double[minMags.length]; + double[] regProbs = reg == null ? new double[minMags.length] : null; DecimalFormat pDF = new DecimalFormat("0.00%"); @@ -115,9 +125,12 @@ public static void main(String[] args) throws IOException { List faultRupMappings = new ArrayList<>(); - List> regionalRupProbs = new ArrayList<>(); - for (int m=0; m()); + List> regionalRupProbs = null; + if (reg != null) { + regionalRupProbs = new ArrayList<>(); + for (int m=0; m()); + } List>> faultRupProbs = new ArrayList<>(); for (String faultName : faultsSorted) { @@ -137,7 +150,7 @@ public static void main(String[] args) throws IOException { } } - double[] rupsInRegion = rupSet.getFractRupsInsideRegion(reg, false); + double[] rupsInRegion = reg == null ? null : rupSet.getFractRupsInsideRegion(reg, false); double minMinMag = StatUtils.min(minMags); @@ -147,9 +160,6 @@ public static void main(String[] args) throws IOException { if (sourceID < numFSS) { // fault-based int rupIndex = erf.getFltSysRupIndexForSource(sourceID); - if (rupsInRegion[rupIndex] == 0d) - // not in region - continue; // see if it matches any of our faults for (int i=0; i= (float)minMags[m]) - regionalRupProbs.get(m).add(rup.getProbability()); + if (reg != null) { + // if we're here, it's contained + for (ProbEqkRupture rup : source) { + double mag = rup.getMag(); + if (mag < minMinMag) + continue; + for (int m=0; m= (float)minMags[m]) + regionalRupProbs.get(m).add(rup.getProbability()); + } } } @@ -185,9 +200,11 @@ public static void main(String[] args) throws IOException { System.out.println("Probabilities for "+presets[p]+", "+covs[c]); for (int m=0; m="+(float)minMags[m]); - double regProb = FaultSysSolutionERF_Calc.calcSummedProbs(regionalRupProbs.get(m)); - System.out.println("Region:\t"+pDF.format(regProb)); - regProbs[m] += weight*regProb; + if (reg != null) { + double regProb = FaultSysSolutionERF_Calc.calcSummedProbs(regionalRupProbs.get(m)); + System.out.println("Region:\t"+pDF.format(regProb)); + regProbs[m] += weight*regProb; + } for (int i=0; i="+(float)minMag); csv.addLine(header); - List regLine = new ArrayList<>(); - regLine.add("Bay Area Region"); - for (int m=0; m regLine = new ArrayList<>(); + regLine.add(regName); + for (int m=0; m line = new ArrayList<>(); diff --git a/src/main/java/scratch/kevin/ucerf3/PureScratch.java b/src/main/java/scratch/kevin/ucerf3/PureScratch.java index 6527264f..02ced96a 100644 --- a/src/main/java/scratch/kevin/ucerf3/PureScratch.java +++ b/src/main/java/scratch/kevin/ucerf3/PureScratch.java @@ -8,7 +8,9 @@ import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.ObjectOutputStream; +import java.io.StringReader; import java.nio.file.Path; import java.text.DecimalFormat; import java.util.ArrayList; @@ -23,6 +25,9 @@ import java.util.Random; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.apache.commons.math3.distribution.LogNormalDistribution; import org.apache.commons.math3.distribution.NormalDistribution; @@ -97,6 +102,7 @@ import org.opensha.sha.earthquake.faultSysSolution.FaultSystemSolution; import org.opensha.sha.earthquake.faultSysSolution.RupSetDeformationModel; import org.opensha.sha.earthquake.faultSysSolution.RupSetFaultModel; +import org.opensha.sha.earthquake.faultSysSolution.hazard.mpj.MPJ_LogicTreeHazardCalc; import org.opensha.sha.earthquake.faultSysSolution.modules.BranchAveragingOrder; import org.opensha.sha.earthquake.faultSysSolution.modules.BranchParentSectParticMFDs; import org.opensha.sha.earthquake.faultSysSolution.modules.BranchRegionalMFDs; @@ -156,6 +162,8 @@ import org.opensha.sha.earthquake.rupForecastImpl.prvi25.gridded.PRVI25_GridSourceBuilder; import org.opensha.sha.earthquake.rupForecastImpl.prvi25.logicTree.PRVI25_CrustalDeformationModels; import org.opensha.sha.earthquake.rupForecastImpl.prvi25.logicTree.PRVI25_CrustalFaultModels; +import org.opensha.sha.earthquake.rupForecastImpl.prvi25.logicTree.PRVI25_CrustalGMMs; +import org.opensha.sha.earthquake.rupForecastImpl.prvi25.logicTree.PRVI25_LogicTreeBranch; import org.opensha.sha.earthquake.rupForecastImpl.prvi25.logicTree.PRVI25_RegionalSeismicity; import org.opensha.sha.earthquake.rupForecastImpl.prvi25.util.PRVI25_RegionLoader; import org.opensha.sha.earthquake.rupForecastImpl.prvi25.util.PRVI25_RegionLoader.SeismicityRegions; @@ -165,7 +173,11 @@ import org.opensha.sha.gui.infoTools.IMT_Info; import org.opensha.sha.imr.AttenRelRef; import org.opensha.sha.imr.ScalarIMR; +import org.opensha.sha.imr.attenRelImpl.nshmp.NSHMP_GMM_Wrapper; +import org.opensha.sha.imr.attenRelImpl.nshmp.util.NSHMP_GMM_Branch; +import org.opensha.sha.imr.attenRelImpl.nshmp.util.NSHMP_GMM_EpistemicBranchLevel; import org.opensha.sha.imr.param.IntensityMeasureParams.PGA_Param; +import org.opensha.sha.imr.param.OtherParams.TectonicRegionTypeParam; import org.opensha.sha.imr.param.SiteParams.DepthTo1pt0kmPerSecParam; import org.opensha.sha.imr.param.SiteParams.Vs30_Param; import org.opensha.sha.magdist.GutenbergRichterMagFreqDist; @@ -185,6 +197,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import gov.usgs.earthquake.nshmp.gmm.Gmm; import gov.usgs.earthquake.nshmp.mfd.Mfd.Properties.GutenbergRichter; import gov.usgs.earthquake.nshmp.model.NshmErf; import gov.usgs.earthquake.nshmp.model.NshmSurface; @@ -2674,13 +2687,82 @@ private static void test320() throws IOException { } } + private static void test321() throws IOException { +// NSHMP_GMM_EpistemicBranchLevel level = new NSHMP_GMM_EpistemicBranchLevel( +// NSHMP_GMM_EpistemicBranchLevel.buildNodes(Gmm.USGS_PRVI_ACTIVE_CRUST, "Active", true), "Crustal GMM", "CrustalGMM"); +// System.out.println("Level name: "+level.getName()); +// System.out.println("Level short name: "+level.getShortName()); +// for (NSHMP_GMM_Branch branch : level.getNodes()) { +// System.out.println(branch.getName()); +// System.out.println("\tshortName="+branch.getShortName()); +// System.out.println("\tfileName="+branch.getFilePrefix()); +// System.out.println("\tweight="+branch.getNodeWeight(null)); +// +// System.out.println("\ttrt="+branch.getTectonicRegion()); +// ScalarIMR gmm = branch.get(); +// System.out.println("\tgmmName="+gmm.getName()); +// System.out.println("\tgmmShortName="+gmm.getShortName()); +// System.out.println("\tgmmTRT="+gmm.getParameter(TectonicRegionTypeParam.NAME).getValue()); +// System.out.println("\tgmmFilter="+((NSHMP_GMM_Wrapper)gmm).getGroundMotionTreeFilter()); +// } + + LogicTree tree = LogicTree.buildExhaustive(PRVI25_LogicTreeBranch.levelsCrustalGMM, true); + String json = tree.getJSON(); + System.out.println(json); + System.out.println("Reading from JSON"); + tree = LogicTree.read(new StringReader(json)); + String json2 = tree.getJSON(); + System.out.println("Making sure deserialized produces the same JSON"); + Preconditions.checkState(json.equals(json2)); + System.out.println("All good!"); + + for (LogicTreeBranch branch : tree) { + Map> suppliers = MPJ_LogicTreeHazardCalc.getGMM_Suppliers(branch, null); + System.out.println(branch+", weight="+branch.getBranchWeight()); + for (TectonicRegionType trt : suppliers.keySet()) { + System.out.println("\tTRT: "+trt); + NSHMP_GMM_Wrapper gmm = (NSHMP_GMM_Wrapper)suppliers.get(trt).get(); + System.out.println("\tGMM: "+gmm.getName()+" ["+gmm.getShortName()+"]"); + System.out.println("\tFilter: "+gmm.getGroundMotionTreeFilter()); + } + } + } + + private static void test322() throws IOException { + LogicTree tree = LogicTree.read(new File("/home/kevin/OpenSHA/nshm23/batch_inversions/" + + "2024_08_15-prvi25_subduction_branches/logic_tree.json")); + for (LogicTreeLevel level : tree.getLevels()) + System.out.println(level.getName()+" affects gridded? "+GridSourceProvider.affectedByLevel(level)); + } + + private static void test323() throws IOException { + File[] files = { + new File("/project/scec_608/kmilner/nshm23/batch_inversions/2024_08_15-prvi25_subduction_branches-gmTreeCalcs/results_hazard.zip"), + new File("/project/scec_608/kmilner/nshm23/batch_inversions/2024_08_15-prvi25_subduction_branches-gmTreeCalcs/results_full_gridded_interface.zip"), + new File("/project/scec_608/kmilner/nshm23/batch_inversions/2024_08_15-prvi25_subduction_branches-gmTreeCalcs/results_gridded_only_interface.zip"), + new File("/project/scec_608/kmilner/nshm23/batch_inversions/2024_08_15-prvi25_subduction_branches-gmTreeCalcs/results_gridded_only_slab.zip"), + new File("/project/scec_608/kmilner/nshm23/batch_inversions/2024_08_05-prvi25_crustal_branches-dmSample5x-gmTreeCalcs/results_full_gridded_hazard.zip") + }; + + for (File file : files) { + System.out.println(file.getAbsolutePath()); + ZipFile zip = new ZipFile(file); + ZipEntry entry = zip.getEntry(MPJ_LogicTreeHazardCalc.GRID_REGION_ENTRY_NAME); + Feature feature = Feature.read(new BufferedReader(new InputStreamReader(zip.getInputStream(entry)))); + GriddedRegion gridReg = GriddedRegion.fromFeature(feature); + System.out.println("\t"+gridReg.getNodeCount()+" nodes"); + System.out.println("\tfist: "+gridReg.getLocation(0)); + System.out.println("\tlast: "+gridReg.getLocation(gridReg.getNodeCount()-1)); + } + } + /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { try { - test320(); + test323(); } catch (Throwable t) { t.printStackTrace(); System.exit(1);