Skip to main content

Recycling Plant Simulator Package

PyPi version Downloads

Quick start

The following code is an example of how to use this package:

import random

from rcplant import *


def user_sorting_function(sensors_output):
    # random identification
    decision = {sensor_id: random.choice(list(Plastic)) for (sensor_id, value) in sensors_output.items()}

    return decision


def main():

    # simulation parameters
    conveyor_length = 1000  # cm
    conveyor_width = 100  # cm
    conveyor_speed = 10  # cm per second
    num_containers = 100
    sensing_zone_location_1 = 500  # cm
    sensors_sampling_frequency = 1  # Hz
    simulation_mode = 'training'

    sensors = [
        Sensor.create(SpectrumType.FTIR, sensing_zone_location_1),
    ]

    conveyor = Conveyor.create(conveyor_speed, conveyor_length, conveyor_width)

    simulator = RPSimulation(
        sorting_function=user_sorting_function,
        num_containers=num_containers,
        sensors=sensors,
        sampling_frequency=sensors_sampling_frequency,
        conveyor=conveyor,
        mode=simulation_mode
    )

    elapsed_time = simulator.run()

    print(f'\nResults for running the simulation in "{simulation_mode}" mode:')

    for item_id, result in simulator.identification_result.items():
        print(result)

    print(f'Total missed containers = {simulator.total_missed}')
    print(f'Total sorted containers = {simulator.total_classified}')
    print(f'Total mistyped containers = {simulator.total_mistyped}')

    print(f'\n{num_containers} containers are processed in {elapsed_time:.2f} seconds')


if __name__ == '__main__':
    main()

You may modify the user_sorting_function function and implement new logic for sorting plastic containers.

API


RPSimulation

class RPSimulation:
    def __init__(
            self,
            sorting_function,
            num_containers: int,
            sensors: List[Sensor],
            sampling_frequency: int,
            conveyor: Conveyor,
            mode: str
    )

A manager class for the recycling plant simulator.

Input parameters:
  • sorting_function : A user-defined function that gets the output of the sensors and identifies the type of plastic, based on the given spectrum.
  • num_containers : Number of input containers needed to be sorted.
  • sensors : An array of sensors.
  • sampling_frequency: The sampling frequency of sensors. Acceptable values: 10, 5, 2, and 1 Hz. In testing mode, increasing the sampling frequency increases added noise to spectrum.
  • conveyor : A user-defined conveyor system.
  • mode: A selector to run the simulation in either training or testing configuration.

RPSimulation.run

def run(self)

A function to run the simulation.

Outputs:
  • RPSimulation.total_missed : Number of missed containers.
  • RPSimulation.classified : Number of classified containers.
  • RPSimulation.mistyped : Number of containers classified incorrectly.
Returns:
  • Amount of time required to process all containers [seconds].

Sensor

class Sensor:
    def __init__(self, sensor_type: SpectrumType, location_cm: int, sensor_id: int = None)

A class to define a new sensor.

Input parameters:
  • location_cm : Location of the sensor [centimeter].
  • sensor_type : Type of the sensor [SpectrumType].
  • sensor_id : Sensor ID, which is used in sorting_function to identify each sensor. If no ID is provided, an ID will be generated based on the number of sensors.

Sensor.create

def create(cls, sensor_type: SpectrumType, location: int, sensor_id: int = None)

A factory method to create a new sensor.

Input parameters:
  • location : Location of the sensor [centimeter].
  • sensor_type : Type of the sensor [SpectrumType].
  • sensor_id : Sensor ID, which is used in sorting_function to identify each sensor. If no ID is provided, an ID will be generated based on the number of sensors.
Returns

Sensor.reset_num

def reset_num(cls)

A class method to reset the number of created sensors. This would be helpful if you also want to reset IDs assigned to newly created sensors.


Sensor.id

@property
def id(self)

Returns Sensor's ID.


Conveyor

class Conveyor:
    def __init__(self, speed_cm_per_second: int, dimension:ConveyorDimension)

A class to define a new conveyor.

Input parameters:
  • speed_cm_per_second : Speed of the conveyor [centimeter per second].
  • dimension : Dimensions of the conveyor in centimeter.

Conveyor.create

def create(cls, speed_cm_per_second: int, length: int, width: int)

A factory method to create a new conveyor.

Input parameters:
  • speed_cm_per_second : Speed of the conveyor [centimeter per second].
  • length : Length of the conveyor in centimeter.
  • width : Width of the conveyor in centimeter.
Returns

Sorting_function

def sorting_function(sensors_output)

A user-defined function that identifies the type of plastic, based on the given spectrum.

Input parameters:
  • sensors_output : A dictionary with sensors information. The keys are the id of each sensor.
{
    sensor.id: {
        'type': type,
        'location': location,
        'spectrum': spectrum,
    }
}
Return value:
decision = {
    sensor_id: plastic_type
}

Plastic

class Plastic(enum.Enum):
    HDPE = 'HDPE'
    LDPE = 'LDPE'
    PP = 'PP'
    PS = 'PS'
    PC = 'PC'
    PVC = 'PVC'
    Polyester = 'Polyester'
    PET = 'PET'
    PU = 'PU'
    Blank = 'background'

An enum for all types of plastics


SpectrumType

class SpectrumType(enum.Enum):
    FTIR = 'FTIR'
    Raman = 'Raman'

An enum for all types of sensors

Release files for rcplant 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rcplant 1.1.3
File Size Uploaded
rcplant-1.1.3.tar.gz 2.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for rcplant 1.1.3
File Interpreter ABI Platform
rcplant-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size:4.5 MB

Release files / rcplant-1.1.3.tar.gz

Download URL rcplant-1.1.3.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
3fd1500dc1361370d9b212c44469a400d47c427f0f6b2875cbaea845b1d663fc
BLAKE2b-256 checksum
How to use checksums
2cbffc946ec77d52b694f0fa7c6c08a4fb015eb493515378766c700e9ab95d02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.10

Release files / rcplant-1.1.3-py3-none-any.whl

Download URL rcplant-1.1.3-py3-none-any.whl
Size 2.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f49ee5c090c017bc44ae15b12fc6a79b30a15742b1efd5812dbb3ad5929a8d18
BLAKE2b-256 checksum
How to use checksums
f03b28a01d597561204e3e51733c40ed4065a9c035ff8aa9648feae650c4641e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.10

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page