Skip to content

Commit

Permalink
Updated ISO phoenix model to work with changes for #53
Browse files Browse the repository at this point in the history
  • Loading branch information
dhixsingh committed Sep 13, 2018
1 parent 0ad621d commit 8ea4e50
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 15 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<!-- Phoenix start time in HH:MM format; used to calculate absolute values for hour_spot and hour_burnt -->
<opt id="ignitionHHMM">00:00</opt>
<!-- Phoenix fire GeoJSON file -->
<opt id="fireGeoJson">scenarios/mount-alexander-shire/bradford-newstead-fire-crossing-400/scenario_fire.json</opt>
<opt id="fireGeoJson">scenarios/mount-alexander-shire/bradford-newstead-fire-crossing-400/20160420_MtAlexShire_FDI100_Iso_epsg28355.json</opt>
<!-- Phoenix smoke (embers) GeoJSON file -->
<opt id="smokeGeoJson"></opt>
</model>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<!-- Phoenix start time in HH:MM format; used to calculate absolute values for hour_spot and hour_burnt -->
<opt id="ignitionHHMM">00:00</opt>
<!-- Phoenix fire GeoJSON file -->
<opt id="fireGeoJson">scenarios/mount-alexander-shire/maldon-100-with-emergency-vehicles/scenario_fire.json</opt>
<opt id="fireGeoJson">scenarios/mount-alexander-shire/maldon-100-with-emergency-vehicles/20160420_MtAlexShire_FDI100_Iso_epsg28355.json</opt>
<!-- Phoenix smoke (embers) GeoJSON file -->
<opt id="smokeGeoJson"></opt>
</model>
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scenarios/surf-coast-shire/otways-300/ees.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<!-- Phoenix start time in HH:MM format; used to calculate absolute values for hour_spot and hour_burnt -->
<opt id="ignitionHHMM">00:00</opt>
<!-- Phoenix fire GeoJSON file -->
<opt id="fireGeoJson">scenarios/surf-coast-shire/otways-300/scenario_fire.json</opt>
<opt id="fireGeoJson">scenarios/surf-coast-shire/otways-300/Anglesea_evac_test_ffdi104_phx5_2016data_minsup_fh2017_Iso_epsg32754.json</opt>
<!-- Phoenix smoke (embers) GeoJSON file -->
<opt id="smokeGeoJson"></opt>
</model>
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scenarios/surf-coast-shire/torquay-3000/ees.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<!-- Phoenix start time in HH:MM format; used to calculate absolute values for hour_spot and hour_burnt -->
<opt id="ignitionHHMM">00:00</opt>
<!-- Phoenix fire GeoJSON file -->
<opt id="fireGeoJson">scenarios/surf-coast-shire/torquay-3000/scenario_fire.json</opt>
<opt id="fireGeoJson">scenarios/surf-coast-shire/torquay-3000/Anglesea_evac_test_ffdi104_phx5_2016data_minsup_fh2017_Iso_epsg32754.json</opt>
<!-- Phoenix smoke (embers) GeoJSON file -->
<opt id="smokeGeoJson"></opt>
</model>
Expand Down
54 changes: 43 additions & 11 deletions src/main/java/io/github/agentsoz/ees/PhoenixFireModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
import java.text.SimpleDateFormat;
import java.util.*;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.PrecisionModel;
import com.vividsolutions.jts.precision.GeometryPrecisionReducer;
import io.github.agentsoz.util.Time;
import io.github.agentsoz.util.evac.PerceptList;
import org.geotools.geometry.jts.GeometryBuilder;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand All @@ -41,7 +45,7 @@
import io.github.agentsoz.dataInterface.DataServer;
import io.github.agentsoz.dataInterface.DataSource;

public class PhoenixFireModule implements DataSource<SortedMap<Double, Double[][]>> {
public class PhoenixFireModule implements DataSource<Geometry> {

private final Logger logger = LoggerFactory.getLogger(PhoenixFireModule.class);

Expand All @@ -55,19 +59,19 @@ public class PhoenixFireModule implements DataSource<SortedMap<Double, Double[][
private DataServer dataServer = null;
private JSONObject json = null;
private double lastUpdateTimeInMinutes = -1;
private TreeMap<Double, Double[][]> fire;
private TreeMap<Double, Geometry> fire;
private Time.TimestepUnit timestepUnit = Time.TimestepUnit.SECONDS;
private double evacStartInSeconds = 0.0;
private boolean fireAlertSent = true;

public PhoenixFireModule(boolean sendFireAlertOnFireStart) {

fire = new TreeMap<Double, Double[][]>();
fire = new TreeMap<>();
fireAlertSent = !sendFireAlertOnFireStart;
}

public PhoenixFireModule(Map<String, String> opts, DataServer dataServer) {
fire = new TreeMap<Double, Double[][]>();
fire = new TreeMap<>();
this.dataServer = dataServer;
parse(opts);
}
Expand Down Expand Up @@ -130,14 +134,16 @@ public void loadGeoJson(String file) throws FileNotFoundException, IOException,
cal.setTime(date);
double minutes = 60*cal.get(Calendar.HOUR_OF_DAY) + cal.get(Calendar.MINUTE);
//double minutes = (double) properties.get("MINUTES");
fire.put(minutes, coordinates);
fire.put(minutes, getGeometryFromCoords(coordinates));
}
}

@Override
public SortedMap<Double, Double[][]> sendData(double timestep, String dataType) {

public Geometry sendData(double timestep, String dataType) {
Geometry geometry = null;
double time = Time.convertTime(timestep, timestepUnit, Time.TimestepUnit.MINUTES);
SortedMap<Double, Double[][]> shapes = fire.subMap(lastUpdateTimeInMinutes, time);
SortedMap<Double, Geometry> shapes = fire.subMap(lastUpdateTimeInMinutes, time);
// if evac start time was explicitly set, then send alert at that time
// irrespective of when the fire actually starts
if (!fireAlertSent && evacStartInSeconds > 0.0 && timestep >= evacStartInSeconds) {
Expand All @@ -151,7 +157,9 @@ public SortedMap<Double, Double[][]> sendData(double timestep, String dataType)
logger.info("step {} ({} mins): sending fire alert!!", String.format("%.0f", timestep), String.format("%.0f", time));
dataServer.publish(PerceptList.FIRE_ALERT, null);
}
dataServer.publish(PerceptList.FIRE_DATA, shapes);
geometry = getGeometry(shapes);
logger.info("sending {} : {}", PerceptList.FIRE_DATA, geometry);
dataServer.publish(PerceptList.FIRE_DATA, geometry);
}

// Setting 'lastUpdateTimeInMinutes = time' below will mean that only the new fire shapes since the
Expand All @@ -160,14 +168,38 @@ public SortedMap<Double, Double[][]> sendData(double timestep, String dataType)
// So instead, we send all the shapes up until now. This ensures that the state of the fire
// in the model will always be a union of all shapes from the start of fire.
// To send all shapes, just disable the lastUpdateTimeInMinutes update below
// lastUpdateTimeInMinutes = time;
lastUpdateTimeInMinutes = time;

Double nextTime = fire.higherKey(time);
if (nextTime != null) {
dataServer.registerTimedUpdate(PerceptList.FIRE, this, Time.convertTime(nextTime, Time.TimestepUnit.MINUTES, timestepUnit));
}
logger.info("sending {} data: {}", PerceptList.FIRE, shapes);
return shapes;
return geometry;
}

private Geometry getGeometry(SortedMap<Double, Geometry> shapes) {
Geometry polygon = null;
if (shapes != null && !shapes.isEmpty()) {
for (Geometry shape : shapes.values()) {
// Fix for JTS #288 requires reduction to floating.
// https://github.com/locationtech/jts/issues/288#issuecomment-396647804
polygon = (polygon==null) ?
shape :
GeometryPrecisionReducer.reduce(polygon.union(shape),new PrecisionModel(PrecisionModel.FLOATING));
}
}
return polygon;
}

private Geometry getGeometryFromCoords(Double[][] pairs) {
int i = 0;
double[] flatarray = new double[pairs.length*2];
int o = 0;
for (Double[] pair : pairs) {
flatarray[i++] = pair[0];
flatarray[i++] = pair[1];
}
return new GeometryBuilder().polygon(flatarray);
}

public void setDataServer(DataServer dataServer) {
Expand Down

0 comments on commit 8ea4e50

Please sign in to comment.