Skip to content

Commit

Permalink
woring on subsetting
Browse files Browse the repository at this point in the history
  • Loading branch information
fbielejec committed Jun 10, 2015
1 parent 73d48b4 commit f232063
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 138 deletions.
11 changes: 7 additions & 4 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,18 @@ h3. BAYES FACTORS

h3. PARSING

* -parse -locations /home/filip/Dropbox/JavaProjects/Spread2/data/discrete/H5N1/locationCoordinates_H5N1 -log /home/filip/Dropbox/JavaProjects/Spread2/data/discrete/H5N1/H5N1_HA_discrete_rateMatrix.log -output test_discrete.json
-parse -locations /home/filip/Dropbox/JavaProjects/Spread2/data/discrete/H5N1/locationCoordinates_H5N1 -log /home/filip/Dropbox/JavaProjects/Spread2/data/discrete/H5N1/H5N1_HA_discrete_rateMatrix.log -burnin 10 -output test_discrete.json

h3. RENDERING

* TODO
* use all default settings
-render -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -output test.kml

h4. LINES

* TODO
* TODO: attribute cutoff [bayes factor values]
-render -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -linesSubset bayesFactor -linesCutoff 10 -output test.kml



h1. LICENSE
Expand All @@ -188,7 +191,7 @@ h1. LICENSE
h1. TODO

* Renderers
- alpha channel mapping for lines
- subsetting numerical and factor values
- control arc curvature [0 - 1]
- D3 renderer tool
* Two data modes. dd/mm/yyyy and old origin dates.
Expand Down
File renamed without changes.
60 changes: 60 additions & 0 deletions src/app/Spread2ConsoleApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,21 @@ public class Spread2ConsoleApp {
private static final String TREES = "trees";
private static final String LOCATIONS = "locations";
private static final String LOG = "log";
private static final String BURNIN = "burnin";
private static final String LOCATION_TRAIT = "locationTrait";
private static final String TRAITS = "traits";
private static final String HPD = "hpd";
private static final String INTERVALS = "intervals";
private static final String OUTPUT = "output";
private static final String JSON = "json";

private static final String LINES_SUBSET = "linesSubset";
private static final String LINES_CUTOFF = "linesCutoff";
private static final String LINES_VALUE = "linesValue";

// TODO: polygon cutoffs


private static final String POLYGON_COLOR_MAPPING = "polygoncolormapping";
private static final String POLYGON_COLORS = "polygoncolors";
private static final String POLYGON_COLOR = "polygoncolor";
Expand Down Expand Up @@ -122,6 +130,8 @@ public Spread2ConsoleApp() {

new Arguments.StringOption(LOG, "", "tree file name"),

new Arguments.RealOption(BURNIN, "log file burning in %"),

new Arguments.StringOption(OUTPUT, "", "json output file name")

});
Expand Down Expand Up @@ -217,6 +227,12 @@ public Spread2ConsoleApp() {

new Arguments.StringOption(POLYGON_RADIUS_MAPPING, "" ,"attribute to map radius aesthetic. Only makes sense for polygons with locations."),

new Arguments.StringOption(LINES_SUBSET, "" ,"attribute to select a subset of values above the certain cutoff."),

new Arguments.RealOption(LINES_CUTOFF, "specify cutoff value to create a subset"),

new Arguments.StringOption(LINES_VALUE, "", "specify fixed value to create a subset"),

});

}// END: Constructor
Expand Down Expand Up @@ -475,7 +491,26 @@ public void run(String[] args) {
.getStringOption(OUTPUT);
} // END: option check

if (args2.hasOption(BURNIN)) {

Double burnin = args2
.getRealOption(BURNIN);

if (burnin < 0.0 || burnin > 100.0) {

throw new ArgumentException(
"Burnin outside of [0,100].");

} else {
settings.bayesFactorsSettings.burnin = burnin;
}

} // END: option check

// if (args2.hasOption(BF_CUTOFF)) {
// settings.bayesFactorsSettings.bfcutoff = args2
// .getRealOption(BF_CUTOFF);
// } // END: option check



Expand Down Expand Up @@ -787,6 +822,31 @@ public void run(String[] args) {

}

//---LINES SUBSET---//

if(renderArguments.hasOption(LINES_SUBSET)) {

settings.kmlRendererSettings.linesSubset = renderArguments.getStringOption(LINES_SUBSET);

if(renderArguments.hasOption(LINES_CUTOFF)) {

settings.kmlRendererSettings.linesCutoff = renderArguments.getRealOption(LINES_CUTOFF);

} else if(renderArguments.hasOption(LINES_VALUE)) {

//TODO: this should work for both real value and a factor
settings.kmlRendererSettings.linesValue = renderArguments.getStringOption(LINES_VALUE);

} else {

gracefullyExit("Can't create a subset from these options!", renderArguments, null);

}

}




} catch (ArgumentException e) {
gracefullyExit(e.getMessage(), renderArguments, e);
Expand Down
17 changes: 13 additions & 4 deletions src/data/structure/Layer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class Layer {
private final String id;
private final String description;
private final List<Polygon> polygons;

private final List<Line> lines;
private boolean hasPolygons;

public Layer(String id, //
String description, //
Expand All @@ -19,14 +19,19 @@ public Layer(String id, //

super();


this.hasPolygons = true;
this.polygons = new ArrayList<Polygon>();
this.lines = new ArrayList<Line>();

this.lines.addAll(lines);
if(polygons != null) {
this.polygons.addAll(polygons);
}

if (polygons != null) {
this.polygons.addAll(polygons);
} else {
this.hasPolygons = false;
}

this.id = id;
this.description = description;

Expand All @@ -36,6 +41,10 @@ public List<Line> getLines() {
return lines;
}

public boolean hasPolygons() {
return hasPolygons;
}

public List<Polygon> getPolygons() {
return polygons;
}
Expand Down
66 changes: 31 additions & 35 deletions src/parsers/BayesFactorLinesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import utils.Trait;
import utils.Utils;

import data.structure.Coordinate;
import data.structure.Line;
import data.structure.Location;
Expand All @@ -16,79 +15,76 @@ public class BayesFactorLinesParser {

private static final String BAYES_FACTOR = "bayesFactor";
private static final String POSTERIOR_PROBABILITY = "posteriorProbability";

private LinkedList<Location> locationsList;

private LinkedList<Location> locationsList;
private LinkedList<String> from;
private LinkedList<String> to;
LinkedList<Double> bayesFactors;
LinkedList<Double> posteriorProbabilities;



private LinkedList<Double> bayesFactors;
private LinkedList<Double> posteriorProbabilities;

public BayesFactorLinesParser(LinkedList<Location> locationsList, //
LinkedList<String> from, //
LinkedList<String> to, //
LinkedList<Double> bayesFactors, //
LinkedList<Double> posteriorProbabilities //
) {
) {

this.locationsList = locationsList;
this.from = from;
this.to = to;
this.bayesFactors = bayesFactors;
this.posteriorProbabilities = posteriorProbabilities;
}//END: Constructor

}// END: Constructor

public LinkedList<Line> parseLines() throws LocationNotFoundException {

LinkedList<Line> linesList = new LinkedList<Line>();
Location dummy;
int n = from.size();
for(int i = 0; i < n; i++) {

dummy = new Location(from.get(i), "", new Coordinate(0.0, 0.0), null);

int n = bayesFactors.size();
for (int i = 0; i < n; i++) {

dummy = new Location(from.get(i), "", new Coordinate(0.0, 0.0),
null);
int fromLocationIndex = Integer.MAX_VALUE;
if(locationsList.contains(dummy)) {
if (locationsList.contains(dummy)) {
fromLocationIndex = locationsList.indexOf(dummy);
} else {
throw new LocationNotFoundException(dummy);
}




dummy = new Location(to.get(i), "", new Coordinate(0.0, 0.0), null);
int toLocationIndex = Integer.MAX_VALUE;
if(locationsList.contains(dummy)) {
if (locationsList.contains(dummy)) {
toLocationIndex = locationsList.indexOf(dummy);
} else {
throw new LocationNotFoundException(dummy);
}



Location fromLocation = locationsList.get(fromLocationIndex);
Location toLocation = locationsList.get(toLocationIndex);

Map<String, Trait> attributes = new LinkedHashMap<String, Trait>();

Double bayesFactor = bayesFactors.get(i);
Trait bayesFactorTrait = new Trait(bayesFactor);
attributes.put(BAYES_FACTOR, bayesFactorTrait);

Double posteriorProbability = posteriorProbabilities.get(i);
Trait posteriorProbabilityTrait = new Trait(posteriorProbability);
attributes.put(POSTERIOR_PROBABILITY, posteriorProbabilityTrait);

Double distance = Utils.rhumbDistance(fromLocation.getCoordinate(), toLocation.getCoordinate());
Trait distanceTrait = new Trait(distance);
attributes.put(Utils.DISTANCE, distanceTrait);

Line line = new Line(fromLocation, toLocation, 0.0, 0.0, attributes);
linesList.add(line);

}//END: i loop



}// END: i loop

return linesList;
}//END: parseLines
}// END: parseLines

}//END: class
}// END: class
Loading

0 comments on commit f232063

Please sign in to comment.