From 3986b356948b088bb8841a8fb0573da850241e4e Mon Sep 17 00:00:00 2001 From: sime94 Date: Tue, 20 Aug 2024 17:00:34 +0200 Subject: [PATCH] class LausitzSimWrapperRunner for running RAM intense noise analysis separately after sim --- .../dashboards/LausitzSimWrapperRunner.java | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java diff --git a/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java b/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java new file mode 100644 index 0000000..bb61bda --- /dev/null +++ b/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java @@ -0,0 +1,104 @@ +/* *********************************************************************** * + * project: org.matsim.* + * Controler.java + * * + * *********************************************************************** * + * * + * copyright : (C) 2007 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ + +package org.matsim.dashboards; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.matsim.application.ApplicationUtils; +import org.matsim.application.MATSimAppCommand; +import org.matsim.application.options.ShpOptions; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.simwrapper.Dashboard; +import org.matsim.simwrapper.SimWrapper; +import org.matsim.simwrapper.SimWrapperConfigGroup; +import org.matsim.simwrapper.dashboard.NoiseDashboard; +import picocli.CommandLine; + +import java.io.IOException; +import java.io.InterruptedIOException; +import java.nio.file.Path; +import java.util.List; + +@CommandLine.Command( + name = "simwrapper", + description = "Run additional analysis and create SimWrapper dashboard for existing run output." +) +final class LausitzSimWrapperRunner implements MATSimAppCommand { + + private static final Logger log = LogManager.getLogger(LausitzSimWrapperRunner.class); + + @CommandLine.Parameters(arity = "1..*", description = "Path to run output directories for which dashboards are to be generated.") + private List inputPaths; + + @CommandLine.Mixin + private final ShpOptions shp = new ShpOptions(); + + @CommandLine.Option(names = "--noise", defaultValue = "false", description = "create noise dashboard") + private boolean noise; + + + private LausitzSimWrapperRunner(){ + } + + @Override + public Integer call() throws Exception { + + if (!noise){ + throw new IllegalArgumentException("you have not configured any dashboard to be created! Please use command line parameters!"); + } + + for (Path runDirectory : inputPaths) { + log.info("Running on {}", runDirectory); + + Path configPath = ApplicationUtils.matchInput("config.xml", runDirectory); + Config config = ConfigUtils.loadConfig(configPath.toString()); + SimWrapper sw = SimWrapper.create(config); + + SimWrapperConfigGroup simwrapperCfg = ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class); + if (shp.isDefined()){ + simwrapperCfg.defaultParams().shp = shp.getShapeFile(); + } + //skip default dashboards + simwrapperCfg.defaultDashboards = SimWrapperConfigGroup.Mode.disabled; + + //add dashboards according to command line parameters +// TODO: if more dashboards are to be added here, we need to check if noise==true before adding noise dashboard here + sw.addDashboard(Dashboard.customize(new NoiseDashboard()).context("noise")); + + + try { + sw.generate(runDirectory, true); + sw.run(runDirectory); + } catch (IOException e) { + throw new InterruptedIOException(); + } + } + + return 0; + } + + public static void main(String[] args) { + new LausitzSimWrapperRunner().execute(args); + + } + +}