.create_reader(+)

DemandsConverter reader factory method
Description

The factory method that allows you to create (manufacture) demands reader instances of a chosen type. Currently, the following options are supported:

Since demands (od trips) rely on an underlying zoning system, it is required to configure the zoning that is deemed compatible with the demands to be parsed. to do so, both for TNTP as well as PLANit, a ZoningReader instance needs to be provided which carries this configuration, see Example on what this might look like.

To complicate matters, a zoning reader in turn relies on a network, therefore the ZoningReader may require a network reader as input. We might simplify this in future releases, but for now it is required to provide this cascade of readers to be able to convert demands in PLANit.

Each demands reader can be configured further via its settings, where each reader exposes different settings depending on its type.

Signature

.create_reader(demands_reader_type: DemandsReaderType, ref_zoning_reader: ZoningReaderWrapper)

with

Parameter Type Unit Compulsory Description
demands_reader_type DemandsReaderType.<enum> None YES Type of demands reader to create
ref_zoning_reader ZoningReaderWrapper None YES The zoning reader to extract compatible zoning from

Return type

DemandsReader implementation

Example 1

from planit import *

# create a demands converter
planit_instance = Planit()
demands_converter = planit_instance.converter_factory.create(ConverterType.DEMANDS)

# TNTP demands reader requires compatible zones. These can be configured via a TNTP zoning reader
# For this example, it is assumed this has been configured already (see ZoningConverter to see how to do this)
tntp_zoning_reader # a presumed configured TNTP zoning reader

# example TNTP demands reader        
tntp_dem_reader = demands_converter.create_reader(DemandsReaderType.TNTP, tntp_zoning_reader)
tntp_dem_settings = tntp_dem_reader.settings
tntp_dem_settings.set_demand_file_location(DEMAND_FILE_PATH)
tntp_dem_settings.set_start_time_since_midnight(8.0, TimeUnits.HOURS)
tntp_dem_settings.set_time_period_duration(1.0, TimeUnits.HOURS)

# example PLANit demands writer
planit_writer = demand_converter.create_writer(DemandsWriterType.PLANIT)
planit_writer.settings.set_output_directory("<path_to_output_dir>")
planit_writer.settings.set_country("<country_name>")

# perform conversion
demands_converter.convert(tntp_dem_reader, planit_writer)

See also

DemandsReaderType.<enum> for the various demands reader types available
TntpDemandsReader for more information on the TNTP demands reader
PlanitDemandsReader for more information on the PLANit demands reader

Source code

Class DemandsConverter in converter.py