Skip to content

Commit

Permalink
update makefile for next step
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Aug 7, 2024
1 parent c9ca320 commit 516ff99
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 31 deletions.
35 changes: 15 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ input/sumo.net.xml: input/network.osm
--no-internal-links --keep-edges.by-vclass passenger,bicycle\
--remove-edges.by-vclass hov,tram,rail,rail_urban,rail_fast,pedestrian\
--output.original-names --output.street-names\
--proj "+proj=utm +zone=53 +datum=WGS84 +units=m +no_defs"\
--lefthand true
--proj "+proj=utm +zone=53 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"\
--lefthand true\
--osm-files $< -o=$@


input/$V/$N-$V-network.xml.gz:
$(sc) prepare network-from-sumo $(kyoto)/data/Kyoto_Network_C_2021/network_C.net.xml\
input/$V/$N-$V-network.xml.gz: input/sumo.net.xml
$(sc) prepare network-from-sumo $<\
--target-crs $(CRS) --output $@


input/$V/$N-$V-network-with-pt.xml.gz: input/$V/$N-$V-network.xml.gz
# FIXME: Adjust GTFS

Expand Down Expand Up @@ -90,23 +89,20 @@ input/$V/$N-$V-facilities.xml.gz: input/$V/$N-$V-network.xml.gz input/facilities
--output $@

# Static population only contains the home locations
input/$V/$N-static-$V-10pct.plans.xml.gz: $(kyoto)/data/census_kansai_region.csv $(kyoto)/data/kansai-region-epsg4612.gpkg input/facilities.gpkg
$(sc) prepare kyoto-population\
--input $<\
--shp $(word 2,$^) --shp-crs $(CRS)\
--facilities $(word 3,$^) --facilities-attr resident\
input/$V/$N-static-$V-10pct.plans.xml.gz: input/facilities.gpkg
$(sc) prepare kansai-population\
--input $(kyoto)/data/census_kansai_region.csv\
--shp $(kyoto)/data/kansai-region-epsg4612.gpkg --shp-crs $(CRS)\
--facilities $< --facilities-attr resident\
--output $@


# Assigns daily activity chains (without locations)
$p/$N-activities-$V-10pct.plans.xml.gz: input/$V/$N-static-$V-25pct.plans.xml.gz input/$V/$N-$V-facilities.xml.gz input/$V/$N-$V-network.xml.gz
$(sc) prepare activity-sampling --seed 1 --input $< --output $@ --persons src/main/python/table-persons.csv --activities src/main/python/table-activities.csv

$(sc) prepare assign-reference-population --population $@ --output $@\
input/$V/$N-$V-10pct.plans-initial.xml.gz: input/$V/$N-static-$V-10pct.plans.xml.gz input/$V/$N-$V-facilities.xml.gz input/$V/$N-$V-network.xml.gz
$(sc) prepare create-daily-plans --input $< --output $@\
--persons src/main/python/table-persons.csv\
--activities src/main/python/table-activities.csv\
--shp $(germany)/../matsim-berlin/data/SrV/zones/zones.shp\
--shp-crs $(CRS)\
--shp $(kyoto)/data/kansai-region-epsg4612.gpkg --shp-crs $(CRS)\
--facilities $(word 2,$^)\
--network $(word 3,$^)\

Expand All @@ -127,7 +123,6 @@ $p/berlin-initial-$V-10pct.plans.xml.gz: $p/$N-activities-$V-25pct.plans.xml.gz
--samples 0.1 0.03 0.01\


# Aggregated target
# TODO:
#prepare: input/$V/$N-$V-25pct.plans-initial.xml.gz input/$V/$N-$V-network-with-pt.xml.gz
# echo "Done"
# Aggregated target for input plans to calibration
prepare: input/$V/$N-$V-10pct.plans-initial.xml.gz input/$V/$N-$V-network-with-pt.xml.gz
echo "Done"
7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- <version>15.0</version> -->

<!-- PR-labelled release -->
<version>2025.0-PR3350</version>
<version>2025.0-PR3390</version>

<!-- snapshot == not recommended: rather use PR-labelled release!-->
<!-- <version>2025.0-SNAPSHOT</version>-->
Expand Down Expand Up @@ -38,8 +38,7 @@
<repository>
<id>github</id>
<name>GitHub Packages</name>
<!-- FIXME: Update Repo -->
<url>https://maven.pkg.github.com/matsim-scenarios/matsim-template-scenario</url>
<url>https://maven.pkg.github.com/matsim-scenarios/matsim-kyoto</url>
</repository>
</distributionManagement>

Expand Down Expand Up @@ -68,7 +67,7 @@
<dependency>
<groupId>com.github.matsim-scenarios</groupId>
<artifactId>matsim-berlin</artifactId>
<version>70c8076e1e</version>
<version>ce81ea226c</version>
</dependency>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@CommandLine.Command(header = ":: Open Kyoto Calibration ::", version = OpenKyotoScenario.VERSION, mixinStandardHelpOptions = true)
@MATSimApplication.Prepare({
MergePopulations.class, CreateKyotoPopulation.class,
MergePopulations.class, CreateKansaiPopulation.class, CreateDailyPlans.class,
ExtractFacilityGeoPkg.class, DownSamplePopulation.class,
CreateNetworkFromSumo.class, CreateTransitScheduleFromGtfs.class,
CleanNetwork.class, CreateMATSimFacilities.class, InitLocationChoice.class, FilterRelevantAgents.class,
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/org/matsim/prepare/population/CreateDailyPlans.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.matsim.prepare.population;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Population;
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.ShpOptions;
import org.matsim.core.population.PopulationUtils;
import org.matsim.core.population.algorithms.ParallelPersonAlgorithmUtils;
import org.matsim.core.population.algorithms.PersonAlgorithm;
import picocli.CommandLine;

import java.nio.file.Path;
import java.util.SplittableRandom;

@CommandLine.Command(
name = "create-daily-plans",
description = "Create daily plans for population."
)
public class CreateDailyPlans implements MATSimAppCommand, PersonAlgorithm {

private static final Logger log = LogManager.getLogger(CreateDailyPlans.class);

@CommandLine.Option(names = "--input", description = "Path to input population.")
private Path input;

@CommandLine.Option(names = "--output", description = "Path to output population", required = true)
private Path output;

@CommandLine.Option(names = "--persons", description = "Path to person table", required = true)
private Path personsPath;

@CommandLine.Option(names = "--activities", description = "Path to activity table", required = true)
private Path activityPath;

@CommandLine.Option(names = "--facilities", description = "Path to facilities file", required = true)
private Path facilityPath;

@CommandLine.Option(names = "--network", description = "Path to network file", required = true)
private Path networkPath;

@CommandLine.Option(names = "--seed", description = "Seed used to sample locations", defaultValue = "1")
private long seed;

@CommandLine.Mixin
private ShpOptions shp;

private ThreadLocal<SplittableRandom> rnd;

public static void main(String[] args) {
new CreateDailyPlans().execute(args);
}

@Override
public Integer call() throws Exception {

if (!shp.isDefined()) {
log.error("Shape file with zones is required.");
return 2;
}

Population population = PopulationUtils.readPopulation(input.toString());

rnd = ThreadLocal.withInitial(() -> new SplittableRandom(seed));

ParallelPersonAlgorithmUtils.run(population, 8, this);

PopulationUtils.writePopulation(population, output.toString());

return 0;
}

@Override
public void run(Person person) {

// TODO: map zones to shape file

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import java.util.*;

@CommandLine.Command(
name = "kyoto-population",
description = "Create synthetic population for kyoto."
name = "kansai-population",
description = "Create synthetic population for kansai region."
)
public class CreateKyotoPopulation implements MATSimAppCommand {
public class CreateKansaiPopulation implements MATSimAppCommand {

private static final NumberFormat FMT = NumberFormat.getInstance(Locale.GERMAN);

Expand All @@ -61,7 +61,7 @@ public class CreateKyotoPopulation implements MATSimAppCommand {
private Population population;

public static void main(String[] args) {
new CreateKyotoPopulation().execute(args);
new CreateKansaiPopulation().execute(args);
}

private static int parseInt(String s) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/python/extract_population_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def trip_filter(df):
df = join_person_with_household(persons, hh)
df = remove_persons_with_invalid_trips(df, trips)

df.to_csv(args.output + "-persons.csv")
df.to_csv(args.output + "-persons.csv", index=False)

print("Written survey csvs with %d persons" % len(df))

activities = create_activities(df, trips, include_person_context=False, cut_groups=False)
activities = create_activities(df, trips, include_person_context=False, use_index_as_pid=False, cut_groups=False)
activities.to_csv(args.output + "-activities.csv", index=False)

0 comments on commit 516ff99

Please sign in to comment.