DemandsConverter

DemandsConverter instance

The DemandsConverter class instance can be created via the ConverterFactory. Once created it can be used to create demands readers and writers that in turn can be offered to this converter to convert from the reader format to the writer format.

Via its .create_reader(+) and .create_writer(+) methods, the converter can construct readers and writers of supported types. The reader takes a DemandsReaderType while the writer takes a DemandsWriterType to indicate what reader/writer is to be created. The result is an instance of the desired reader/writer. The user then can/should configure the reader/writer based on the available settings. Once configured, the actual conversion can be performed through this converter by providing the created reader/writer to the .convert(+) method.

The user is expected to configure each reader/writers minimum required settings, often involving setting input/output file locations and/or directories for example. For each reader/writer these minimum user configuration actions are clearly indicated. Failing to do so will cause the conversion to fail as information is missing.

Sometimes a reader might require another input component as a prerequisite. For example the TNTP demands reader requires the zoning, which is expected to be made available by providing a TNTPZoningReader upon construction of the TNTP demands reader. In such cases this will be highlighted in the respective create_reader documentation where necessary.

Methods

DemandsConverter exposes the following methods

Name Description
.create_reader(+) Create a new demands reader based on the provided DemandsReaderType
.create_writer(+) Create a new demands writer based on the provided DemandsReaderType
.convert(+) Convert the demands reader’s input into the demands writer’s output format

Properties

N/A

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

ConverterFactory for the converter factory to create other types of converters
DemandsReaderType for the supported demands reader types
DemandsWriterType for the supported demands writer types


.convert(+)

DemandsConverter method

.create_reader(+)

DemandsConverter reader factory method

.create_writer(+)

DemandsConverter writer factory method