|
| 1 | +package scratch.ned.NGA_W2_FlatFileAnalysis; |
| 2 | + |
| 3 | +import java.awt.Color; |
| 4 | +import java.io.File; |
| 5 | +import java.io.IOException; |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.util.Collections; |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.List; |
| 10 | +import java.util.TreeSet; |
| 11 | + |
| 12 | +import org.opensha.commons.data.CSVFile; |
| 13 | +import org.opensha.commons.geo.Location; |
| 14 | +import org.opensha.commons.geo.LocationList; |
| 15 | +import org.opensha.commons.geo.LocationUtils; |
| 16 | +import org.opensha.commons.mapping.gmt.elements.GMT_CPT_Files; |
| 17 | +import org.opensha.commons.util.cpt.CPT; |
| 18 | + |
| 19 | +import scratch.UCERF3.analysis.FaultBasedMapGen; |
| 20 | + |
| 21 | +public class makeSrcSiteKML_File { |
| 22 | + |
| 23 | + public static void main(String[] args) { |
| 24 | + |
| 25 | + // read csv rate file |
| 26 | + String csvPath = "/Users/field/Library/CloudStorage/OneDrive-DOI/Field_Other/MiscDocs/test.csv"; |
| 27 | + double minMagThresh=4; |
| 28 | + double maxMagThresh=9; |
| 29 | + double maxDist = 100; |
| 30 | + |
| 31 | + File saveDir = new File("TEST_DIR_HERE"); |
| 32 | + if(!saveDir.exists()) saveDir.mkdir(); |
| 33 | + |
| 34 | + File file = new File(csvPath); |
| 35 | + CSVFile<String> csvFile=null; |
| 36 | + try { |
| 37 | + csvFile = CSVFile.readFile(file, true); |
| 38 | + } catch (IOException e) { |
| 39 | + e.printStackTrace(); |
| 40 | + } |
| 41 | + |
| 42 | +// CPT cpt = new CPT(minMagThresh, maxMagThresh, Color.BLUE, Color.RED); |
| 43 | + CPT cpt = new CPT(4.0, 9.0, Color.BLACK, Color.BLUE, Color.GREEN, Color.ORANGE, Color.RED, Color.MAGENTA); |
| 44 | +// GMT_CPT_Files cptFile = GMT_CPT_Files.MAX_SPECTRUM; |
| 45 | +// CPT cpt=null; |
| 46 | +// try { |
| 47 | +// cpt = cptFile.instance(); |
| 48 | +// } catch (IOException e1) { |
| 49 | +// e1.printStackTrace(); |
| 50 | +// } |
| 51 | +// cpt.rescale(4, 9); |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + // sort file rows by mag |
| 56 | +// ArrayList<Integer> csvRowIndicesSortedByMag = new ArrayList<Integer>(); |
| 57 | +// double deltaMag = 0.25; |
| 58 | +// for(double curMag=minMagThresh; curMag<maxMagThresh; curMag+=deltaMag) { |
| 59 | +// for(int i=1; i<csvFile.getNumRows(); i++) { |
| 60 | +// double mag = csvFile.getDouble(i, 2); |
| 61 | +// if(mag>=curMag && mag<curMag+deltaMag) |
| 62 | +// csvRowIndicesSortedByMag.add(i); |
| 63 | +// } |
| 64 | +// } |
| 65 | +//// Collections.reverse(csvRowIndicesSortedByMag); |
| 66 | +// System.out.println(csvFile.getDouble(csvRowIndicesSortedByMag.get(0), 2)); |
| 67 | +// System.out.println(csvFile.getDouble(csvRowIndicesSortedByMag.get(csvRowIndicesSortedByMag.size()-1), 2)); |
| 68 | + |
| 69 | + for(double magMid=5; magMid<8.25; magMid+=1.0) { |
| 70 | + double minMag = magMid-0.5; |
| 71 | + double maxMag = magMid+0.5; |
| 72 | + |
| 73 | + List<LocationList> pathList = new ArrayList<LocationList>(); |
| 74 | + List<String> pathNameList = new ArrayList<String>(); |
| 75 | + List<Double> magList = new ArrayList<Double>(); |
| 76 | + int numPaths=0; |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + for(int i=1; i<csvFile.getNumRows(); i++) { |
| 81 | + double mag = csvFile.getDouble(i, 2); |
| 82 | + if(mag<minMag || mag>=maxMag) |
| 83 | + continue; |
| 84 | + String qkName = csvFile.get(i, 0); |
| 85 | + String stationName = csvFile.get(i, 1); |
| 86 | + if(mag >= minMagThresh && mag <= maxMagThresh) { |
| 87 | + double hypoLat = csvFile.getDouble(i, 3); |
| 88 | + double hypoLon = csvFile.getDouble(i, 4); |
| 89 | + double hypoDepth = csvFile.getDouble(i, 5); |
| 90 | + double stationLat = csvFile.getDouble(i, 6); |
| 91 | + double stationLon = csvFile.getDouble(i, 7); |
| 92 | + String pathName = qkName+"-->"+stationName; |
| 93 | + |
| 94 | + if(hypoLat>90 || hypoLat<-90) { |
| 95 | + System.out.println("SKIPPING: hypoLat="+hypoLat+"\tfor "+pathName); |
| 96 | + continue; |
| 97 | + } |
| 98 | + if(stationLat>90 || stationLat<-90) { |
| 99 | + System.out.println("SKIPPING: stationLat="+stationLat+"\tfor "+pathName); |
| 100 | + continue; |
| 101 | + } |
| 102 | + |
| 103 | + if(hypoLon>360 || hypoLon<-360) { |
| 104 | + System.out.println("SKIPPING: hypoLon="+hypoLon+"\tfor "+pathName); |
| 105 | + continue; |
| 106 | + } |
| 107 | + if(stationLon>360 || stationLon<-360) { |
| 108 | + System.out.println("SKIPPING: stationLon="+stationLon+"\tfor "+pathName); |
| 109 | + continue; |
| 110 | + } |
| 111 | + |
| 112 | + Location hypoLoc = new Location(hypoLat,hypoLon); |
| 113 | + Location stationLoc = new Location(stationLat,stationLon); |
| 114 | + |
| 115 | + if(LocationUtils.horzDistance(hypoLoc, stationLoc)> maxDist) |
| 116 | + continue;; |
| 117 | + |
| 118 | + |
| 119 | + LocationList locList = new LocationList(); |
| 120 | + locList.add(hypoLoc); |
| 121 | + locList.add(stationLoc); |
| 122 | + |
| 123 | + |
| 124 | + pathList.add(locList); |
| 125 | + pathNameList.add(pathName); |
| 126 | + magList.add(mag); |
| 127 | + |
| 128 | + numPaths+=1; |
| 129 | + // System.out.println(pathName+"\t"+mag); |
| 130 | + } |
| 131 | + } |
| 132 | + System.out.println("numPaths="+numPaths+" for magMid="+magMid); |
| 133 | + |
| 134 | + double[] magArray = new double[magList.size()]; |
| 135 | + for(int i=0;i<magList.size();i++) |
| 136 | + magArray[i] = magList.get(i); |
| 137 | + |
| 138 | + |
| 139 | + String prefix = "testFileHere_"+magMid; |
| 140 | + boolean skipNans = true; |
| 141 | + int numColorBins=20; |
| 142 | + int lineWidth=2; |
| 143 | + String name = "magMid_"+magMid; |
| 144 | + |
| 145 | + // scratch.UCERF3.analysis.FaultBasedMapGen.makeFaultKML(CPT, List<LocationList>, double[], File, String, boolean, int, int, String, List<String>) |
| 146 | + try { |
| 147 | + FaultBasedMapGen.makeFaultKML(cpt, pathList, magArray,saveDir, prefix, skipNans, numColorBins, |
| 148 | + lineWidth, name, pathNameList); |
| 149 | + } catch (IOException e) { |
| 150 | + // TODO Auto-generated catch block |
| 151 | + e.printStackTrace(); |
| 152 | + } |
| 153 | + |
| 154 | + |
| 155 | + } |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | +// public static void makeFaultKML(CPT cpt, List<LocationList> faults, double[] values, |
| 160 | +// File saveDir, String prefix, boolean skipNans, int numColorBins, int lineWidth, |
| 161 | +// String name, List<String> descriptions) |
| 162 | + |
| 163 | + } |
| 164 | + |
| 165 | +} |
0 commit comments