Skip to content

Commit

Permalink
try to satisfy checkstyle AND sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
tschlenther committed Sep 30, 2024
1 parent 12642b2 commit 15de3e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,17 @@ public class KelheimOfflineAirPollutionAnalysisByEngineInformation implements MA
@CommandLine.Option(names = "--grid-size", description = "Grid size in meter", defaultValue = "250")
private double gridSize;

private final NumberFormat numberFormat;

//dump out all pollutants. to include only a subset of pollutants, adjust!
static List<Pollutant> pollutants2Output = Arrays.asList(Pollutant.values());

KelheimOfflineAirPollutionAnalysisByEngineInformation(){
numberFormat = NumberFormat.getInstance(Locale.US);
numberFormat.setMaximumFractionDigits(4);
numberFormat.setGroupingUsed(false);
}

@Override
public Integer call() throws Exception {

Expand Down Expand Up @@ -140,7 +147,6 @@ private void process(Config config, Scenario scenario) throws IOException {
// the following is copied from the example and supplemented...
//------------------------------------------------------------------------------


NetworkUtils.writeNetwork(scenario.getNetwork(), output.getPath( "emissionNetwork.xml.gz").toString());

final String eventsFile = input.getEventsPath();
Expand Down Expand Up @@ -301,10 +307,6 @@ private void writeLinkOutput(String linkEmissionAnalysisFile, String linkEmissio

log.info("Writing output...");

NumberFormat nf = NumberFormat.getInstance(Locale.US);
nf.setMaximumFractionDigits(4);
nf.setGroupingUsed(false);

{
//dump link-based output files
File absolutFile = new File(linkEmissionAnalysisFile);
Expand Down Expand Up @@ -340,14 +342,14 @@ private void writeLinkOutput(String linkEmissionAnalysisFile, String linkEmissio
if (link2pollutants.get(linkId).get(pollutant) != null) {
emissionValue = link2pollutants.get(linkId).get(pollutant);
}
absolutWriter.write(";" + nf.format(emissionValue));
absolutWriter.write(";" + numberFormat.format(emissionValue));

double emissionPerM = Double.NaN;
Link link = network.getLinks().get(linkId);
if (link != null) {
emissionPerM = emissionValue / link.getLength();
}
perMeterWriter.write(";" + nf.format(emissionPerM));
perMeterWriter.write(";" + numberFormat.format(emissionPerM));

}
absolutWriter.newLine();
Expand Down Expand Up @@ -435,18 +437,7 @@ private void writeRaster(Network fullNetwork, Network filteredNetwork, Config co
try (CSVPrinter printer = new CSVPrinter(Files.newBufferedWriter(output.getPath("emissions_grid_per_day.xyt.csv")),
CSVFormat.DEFAULT.builder().setCommentMarker('#').build())) {

NumberFormat nf = NumberFormat.getInstance(Locale.US);
nf.setMaximumFractionDigits(4);
nf.setGroupingUsed(false);

String crs = ProjectionUtils.getCRS(fullNetwork);
if (crs == null)
crs = config.network().getInputCRS();
if (crs == null)
crs = config.global().getCoordinateSystem();

// print coordinate system
// printer.printComment(crs);
// printCrsComment(fullNetwork, config, printer);

// print header
printer.print("time");
Expand Down Expand Up @@ -480,7 +471,7 @@ private void writeRaster(Network fullNetwork, Network filteredNetwork, Config co
printer.print(coord.getY());

double value = rasterMap.get(Pollutant.CO2_TOTAL).getValueByIndex(xi, yi);
printer.print(nf.format(value));
printer.print(numberFormat.format(value));

printer.println();
}
Expand Down Expand Up @@ -517,18 +508,7 @@ private void writeTimeDependentRaster(Network fullNetwork, Network filteredNetwo
try (CSVPrinter printer = new CSVPrinter(IOUtils.getBufferedWriter(output.getPath("emissions_grid_per_hour.csv").toString()),
CSVFormat.DEFAULT.builder().setCommentMarker('#').build())) {

NumberFormat nf = NumberFormat.getInstance(Locale.US);
nf.setMaximumFractionDigits(4);
nf.setGroupingUsed(false);

String crs = ProjectionUtils.getCRS(fullNetwork);
if (crs == null)
crs = config.network().getInputCRS();
if (crs == null)
crs = config.global().getCoordinateSystem();

// print coordinate system
// printer.printComment(crs);
// printCrsComment(fullNetwork, config, printer);

// print header
printer.print("time");
Expand Down Expand Up @@ -566,7 +546,7 @@ private void writeTimeDependentRaster(Network fullNetwork, Network filteredNetwo
printer.print(coord.getX());
printer.print(coord.getY());

printer.print(nf.format(value));
printer.print(numberFormat.format(value));

printer.println();
}
Expand All @@ -579,4 +559,15 @@ private void writeTimeDependentRaster(Network fullNetwork, Network filteredNetwo

}

private static void printCrsComment(Network fullNetwork, Config config, CSVPrinter printer) throws IOException {
String crs = ProjectionUtils.getCRS(fullNetwork);
if (crs == null)
crs = config.network().getInputCRS();
if (crs == null)
crs = config.global().getCoordinateSystem();

//print coordinate system
printer.printComment(crs);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.matsim.analysis.postAnalysis.emissions.KelheimOfflineAirPollutionAnalysisByEngineInformation;
import org.matsim.application.prepare.network.CreateGeoJsonNetwork;
import org.matsim.simwrapper.Dashboard;
import org.matsim.simwrapper.Data;
import org.matsim.simwrapper.Header;
import org.matsim.simwrapper.Layout;
import org.matsim.simwrapper.viz.GridMap;
Expand Down

0 comments on commit 15de3e1

Please sign in to comment.