Skip to content

Commit

Permalink
Initial changes to new oberlausitz-dresden scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Dec 16, 2024
1 parent 7cf3fea commit e9b3207
Show file tree
Hide file tree
Showing 15 changed files with 1,080 additions and 63 deletions.
72 changes: 38 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

N := template
N := oberlausitz-dresden
V := v1.0
CRS := EPSG:25832

Expand Down Expand Up @@ -103,51 +103,55 @@ input/freight-trips.xml.gz: input/$V/$N-$V-network.xml.gz
--shp ../shared-svn/projects/$N/data/shp/$N.shp --shp-crs $(CRS)\
--output $@

input/$V/prepare-25pct.plans.xml.gz:
input/$V/prepare-100pct.plans.xml.gz:
$(sc) prepare trajectory-to-plans\
--name prepare --sample-size 0.25 --output input/$V\
--population ../shared-svn/projects/$N/matsim-input-files/population.xml.gz\
--attributes ../shared-svn/projects/$N/matsim-input-files/personAttributes.xml.gz

$(sc) prepare resolve-grid-coords\
input/$V/prepare-25pct.plans.xml.gz\
--input-crs $(CRS)\
--grid-resolution 300\
--landuse ../matsim-leipzig/scenarios/input/landuse/landuse.shp\
--output $@
--name prepare --sample-size 1 --output input/$V\
--population ../shared-svn/projects/matsim-$N/data/snz/20241129_Teilmodell_Hoyerswerda/Teilmodell/populationATA.xml.gz\
--attributes ../shared-svn/projects/matsim-$N/data/snz/20241129_Teilmodell_Hoyerswerda/Teilmodell/personAttributesATA.xml.gz

input/$V/$N-$V-25pct.plans-initial.xml.gz: input/freight-trips.xml.gz input/$V/$N-$V-network.xml.gz input/$V/prepare-25pct.plans.xml.gz
$(sc) prepare generate-short-distance-trips\
--population input/$V/prepare-25pct.plans.xml.gz\
--input-crs $(CRS)\
--shp ../shared-svn/projects/$N/data/shp/$N.shp --shp-crs $(CRS)\
--num-trips 111111 # FIXME
# $(sc) prepare resolve-grid-coords\
# input/$V/prepare-25pct.plans.xml.gz\
# --input-crs $(CRS)\
# --grid-resolution 300\
# --landuse ../matsim-leipzig/scenarios/input/landuse/landuse.shp\
# --output $@

$(sc) prepare adjust-activity-to-link-distances input/$V/prepare-25pct.plans-with-trips.xml.gz\
--shp ../shared-svn/projects/$N/data/shp/$N.shp --shp-crs $(CRS)\
--scale 1.15\
--input-crs $(CRS)\
--network input/$V/$N-$V-network.xml.gz\
--output input/$V/prepare-25pct.plans-adj.xml.gz
input/$V/$N-$V-100pct.plans-initial.xml.gz: input/$V/prepare-100pct.plans.xml.gz

# Use direct input for now
cp $< $@

# $(sc) prepare generate-short-distance-trips\
# --population input/$V/prepare-25pct.plans.xml.gz\
# --input-crs $(CRS)\
# --shp ../shared-svn/projects/$N/data/shp/$N.shp --shp-crs $(CRS)\
# --num-trips 111111 # FIXME

# $(sc) prepare adjust-activity-to-link-distances input/$V/prepare-25pct.plans-with-trips.xml.gz\
# --shp ../shared-svn/projects/$N/data/shp/$N.shp --shp-crs $(CRS)\
# --scale 1.15\
# --input-crs $(CRS)\
# --network input/$V/$N-$V-network.xml.gz\
# --output input/$V/prepare-25pct.plans-adj.xml.gz

$(sc) prepare xy-to-links --network input/$V/$N-$V-network.xml.gz --input input/$V/prepare-25pct.plans-adj.xml.gz --output $@
# $(sc) prepare xy-to-links --network input/$V/$N-$V-network.xml.gz --input input/$V/prepare-25pct.plans-adj.xml.gz --output $@

$(sc) prepare fix-subtour-modes --input $@ --output $@
# $(sc) prepare fix-subtour-modes --input $@ --output $@

$(sc) prepare merge-populations $@ $< --output $@
# $(sc) prepare merge-populations $@ $< --output $@

$(sc) prepare extract-home-coordinates $@ --csv input/$V/$N-$V-homes.csv
# $(sc) prepare extract-home-coordinates $@ --csv input/$V/$N-$V-homes.csv

$(sc) prepare downsample-population $@\
--sample-size 0.25\
--samples 0.1 0.01\
# $(sc) prepare downsample-population $@\
# --sample-size 0.25\
# --samples 0.1 0.01\

check: input/$V/$N-$V-25pct.plans-initial.xml.gz
check: input/$V/$N-$V-100pct.plans-initial.xml.gz
$(sc) analysis check-population $<\
--input-crs $(CRS)\
--shp ../shared-svn/projects/$N/data/shp/$N.shp --shp-crs $(CRS)
--shp ../shared-svn/projects/matsim-$N/data/snz/20241129_Teilmodell_Hoyerswerda/Teilmodell/UG.shp/UG.shp --shp-crs $(CRS)

# Aggregated target
prepare: input/$V/$N-$V-25pct.plans-initial.xml.gz input/$V/$N-$V-network-with-pt.xml.gz
prepare: input/$V/$N-$V-100pct.plans-initial.xml.gz input/$V/$N-$V-network-with-pt.xml.gz
echo "Done"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The MATSim Open Template Scenario
# The MATSim Oberlausitz/Dresden Scenario

![Build Status](https://github.com/matsim-scenarios/matsim-scenario-template/workflows/build/badge.svg?branch=main)
![license](https://img.shields.io/github/license/matsim-scenarios/matsim-scenario-template.svg)
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

<modelVersion>4.0.0</modelVersion>
<groupId>com.github.matsim-scenarios</groupId>
<artifactId>matsim-template</artifactId>
<artifactId>matsim-oberlausitz-dresden</artifactId>
<version>1.x-SNAPSHOT</version>

<name>MATSim Template Model</name>
<description>A transport model of template</description>
<name>MATSim Oberlausitz/Dresden Model</name>
<description>A transport model of the Oberlausitz region including Dresden city</description>

<properties>
<!-- FIXME: change main class -->
<main.class>org.matsim.run.RunTemplateScenario</main.class>
<main.class>org.matsim.run.OberlausitzDresdenScenario</main.class>

<!-- Don't modify, will use the same version as parent -->
<matsim.version>${project.parent.version}</matsim.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.matsim.application.prepare.population.*;
import org.matsim.application.prepare.pt.CreateTransitScheduleFromGtfs;
import org.matsim.core.config.Config;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.config.groups.VspExperimentalConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
Expand All @@ -23,7 +23,7 @@
import javax.annotation.Nullable;
import java.util.List;

@CommandLine.Command(header = ":: Open Template Scenario ::", version = RunTemplateScenario.VERSION, mixinStandardHelpOptions = true)
@CommandLine.Command(header = ":: Oberlausitz/Dresden Scenario ::", version = OberlausitzDresdenScenario.VERSION, mixinStandardHelpOptions = true)
@MATSimApplication.Prepare({
CreateNetworkFromSumo.class, CreateTransitScheduleFromGtfs.class, TrajectoryToPlans.class, GenerateShortDistanceTrips.class,
MergePopulations.class, ExtractRelevantFreightTrips.class, DownSamplePopulation.class, ExtractHomeCoordinates.class,
Expand All @@ -33,25 +33,25 @@
LinkStats.class, CheckPopulation.class
})
// FIXME: Rename scenario
public class RunTemplateScenario extends MATSimApplication {
public class OberlausitzDresdenScenario extends MATSimApplication {

static final String VERSION = "1.0";

@CommandLine.Mixin
private final SampleOptions sample = new SampleOptions(25, 10, 1);


public RunTemplateScenario(@Nullable Config config) {
public OberlausitzDresdenScenario(@Nullable Config config) {
super(config);
}

// FIXME: update config path
public RunTemplateScenario() {
public OberlausitzDresdenScenario() {
super(String.format("input/v%s/template-v%s-25pct.config.xml", VERSION, VERSION));
}

public static void main(String[] args) {
MATSimApplication.run(RunTemplateScenario.class, args);
MATSimApplication.run(OberlausitzDresdenScenario.class, args);
}

@Nullable
Expand All @@ -64,38 +64,38 @@ protected Config prepareConfig(Config config) {

for (String act : List.of("home", "restaurant", "other", "visit", "errands", "accomp_other", "accomp_children",
"educ_higher", "educ_secondary", "educ_primary", "educ_tertiary", "educ_kiga", "educ_other")) {
config.planCalcScore()
.addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams(act + "_" + ii).setTypicalDuration(ii));
config.scoring()
.addActivityParams(new ScoringConfigGroup.ActivityParams(act + "_" + ii).setTypicalDuration(ii));
}

config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("work_" + ii).setTypicalDuration(ii)
config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("work_" + ii).setTypicalDuration(ii)
.setOpeningTime(6. * 3600.).setClosingTime(20. * 3600.));
config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("business_" + ii).setTypicalDuration(ii)
config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("business_" + ii).setTypicalDuration(ii)
.setOpeningTime(6. * 3600.).setClosingTime(20. * 3600.));
config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("leisure_" + ii).setTypicalDuration(ii)
config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("leisure_" + ii).setTypicalDuration(ii)
.setOpeningTime(9. * 3600.).setClosingTime(27. * 3600.));

config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("shop_daily_" + ii).setTypicalDuration(ii)
config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("shop_daily_" + ii).setTypicalDuration(ii)
.setOpeningTime(8. * 3600.).setClosingTime(20. * 3600.));
config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("shop_other_" + ii).setTypicalDuration(ii)
config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("shop_other_" + ii).setTypicalDuration(ii)
.setOpeningTime(8. * 3600.).setClosingTime(20. * 3600.));
}

config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("car interaction").setTypicalDuration(60));
config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("other").setTypicalDuration(600 * 3));
config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("car interaction").setTypicalDuration(60));
config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("other").setTypicalDuration(600 * 3));

config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("freight_start").setTypicalDuration(60 * 15));
config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("freight_end").setTypicalDuration(60 * 15));
config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("freight_start").setTypicalDuration(60 * 15));
config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("freight_end").setTypicalDuration(60 * 15));

config.controler().setOutputDirectory(sample.adjustName(config.controler().getOutputDirectory()));
config.controller().setOutputDirectory(sample.adjustName(config.controller().getOutputDirectory()));
config.plans().setInputFile(sample.adjustName(config.plans().getInputFile()));
config.controler().setRunId(sample.adjustName(config.controler().getRunId()));
config.controller().setRunId(sample.adjustName(config.controller().getRunId()));

config.qsim().setFlowCapFactor(sample.getSize() / 100.0);
config.qsim().setStorageCapFactor(sample.getSize() / 100.0);

config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.abort);
config.plansCalcRoute().setAccessEgressType(PlansCalcRouteConfigGroup.AccessEgressType.accessEgressModeToLink);
config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink);

// TODO: Config options

Expand Down
51 changes: 51 additions & 0 deletions src/main/python/create_ref.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import geopandas as gpd
import numpy as np
import pandas as pd
from matsim.scenariogen.data import run_create_ref_data
from matsim.scenariogen.data.preparation import calc_needed_short_distance_trips, cut

CRS = "EPSG:25832"


def person_filter(df):
""" Filter person that are relevant for the calibration."""

df = gpd.GeoDataFrame(df, geometry=gpd.GeoSeries.from_wkt(df.geom, crs="EPSG:4326").to_crs(CRS))
df = gpd.sjoin(df, region, how="inner", predicate="intersects")

# Groups will be shown on the dashboard
df["age"] = cut(df.age, [0, 12, 18, 25, 35, 66, np.inf])

# Only weekdays Monday through Thursday are considered, with persons present in their home region
return df[df.present_on_day & (df.reporting_day <= 4)]


def trip_filter(df):
# All modes, expect for "other" are considered
return df[df.main_mode != "other"]


if __name__ == "__main__":

# Defines the study area
region = gpd.read_file("../../../../shared-svn/projects/matsim-oberlausitz-dresden/data/snz/20241129_Teilmodell_Hoyerswerda/Teilmodell/UG.shp").to_crs(CRS)

# This contains the path to the MiD 2017 data with the highest resolution
# See https://daten.clearingstelle-verkehr.de/279/ for more information, the data is not included in this repository
r = run_create_ref_data.create(
# this is the MID2017 dataset, it is not available in svn as it has to be encrypted
"/Volumes/Untitled/B3_Lokal-Datensatzpaket/CSV",
person_filter, trip_filter,
run_create_ref_data.InvalidHandling.REMOVE_TRIPS,
ref_groups=["age", "economic_status"]
)

print("Filtered %s persons" % len(r.persons))
print("Filtered %s trips" % len(r.trips))

print(r.share)

print(r.trips.groupby("dist_group").agg(n=("main_mode", "count")) / len(r.trips))
Loading

0 comments on commit e9b3207

Please sign in to comment.