Skip to content

MTCRoadwayNetwork

models.mtc_network.MTCRoadwayNetwork

Bases: RoadwayNetwork

MTC-specific roadway network with additional validation.

Extends RoadwayNetwork to enforce MTC-specific schema requirements including county, jurisdiction, and mtc_facility_type fields.

Parameters:

Name Type Description Default
nodes_df

GeoDataFrame of roadway nodes

None
links_df

GeoDataFrame of roadway links

None
shapes_df

GeoDataFrame of roadway shapes (optional)

None
validate_mtc bool

If True, validates against MTC schemas (default: True)

True
**kwargs

Additional arguments passed to RoadwayNetwork

{}
Example
from mtc_wrangler.models.mtc_network import MTCRoadwayNetwork

# Load a network with MTC validation
net = MTCRoadwayNetwork.read(
    link_file="links.geojson",
    node_file="nodes.geojson",
    validate_mtc=True
)

# Access network data
print(net.links_df[['model_link_id', 'county', 'jurisdiction']])
Source code in models/mtc_network.py
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
class MTCRoadwayNetwork(RoadwayNetwork):
    """MTC-specific roadway network with additional validation.

    Extends RoadwayNetwork to enforce MTC-specific schema requirements including
    county, jurisdiction, and mtc_facility_type fields.

    Args:
        nodes_df: GeoDataFrame of roadway nodes
        links_df: GeoDataFrame of roadway links
        shapes_df: GeoDataFrame of roadway shapes (optional)
        validate_mtc: If True, validates against MTC schemas (default: True)
        **kwargs: Additional arguments passed to RoadwayNetwork

    Example:
        ```python
        from mtc_wrangler.models.mtc_network import MTCRoadwayNetwork

        # Load a network with MTC validation
        net = MTCRoadwayNetwork.read(
            link_file="links.geojson",
            node_file="nodes.geojson",
            validate_mtc=True
        )

        # Access network data
        print(net.links_df[['model_link_id', 'county', 'jurisdiction']])
        ```
    """

    def __init__(
        self,
        nodes_df=None,
        links_df=None,
        shapes_df=None,
        validate_mtc: bool = True,
        **kwargs
    ):
        """Initialize MTC Roadway Network with optional MTC-specific validation."""
        # Initialize parent RoadwayNetwork
        super().__init__(
            nodes_df=nodes_df,
            links_df=links_df,
            shapes_df=shapes_df,
            **kwargs
        )

        # Apply MTC-specific validation if requested
        if validate_mtc:
            self.validate()

    def validate(self):
        """Validate network against MTC-specific schemas.

        This method can be called explicitly to validate the network after
        modifications have been made to the dataframes.

        Example:
            ```python
            # Modify network
            net.links_df['county'] = 'Alameda'

            # Validate changes
            net.validate()
            ```
        """
        WranglerLogger.debug("MTCRoadwayNetwork.validate() called")
        self.links_df = validate_df_to_model(self.links_df, MTCRoadLinksTable)
        self.nodes_df = validate_df_to_model(self.nodes_df, MTCRoadNodesTable)

    @classmethod
    def read(
        cls,
        link_file: Union[str, Path],
        node_file: Union[str, Path],
        shape_file: Optional[Union[str, Path]] = None,
        validate_mtc: bool = True,
        **kwargs
    ) -> "MTCRoadwayNetwork":
        """Read network from files with MTC validation.

        Args:
            link_file: Path to links file (GeoJSON, shapefile, etc.)
            node_file: Path to nodes file (GeoJSON, shapefile, etc.)
            shape_file: Optional path to shapes file
            validate_mtc: If True, validates against MTC schemas (default: True)
            **kwargs: Additional arguments passed to parent read method

        Returns:
            MTCRoadwayNetwork instance

        Example:
            ```python
            net = MTCRoadwayNetwork.read(
                link_file="data/links.geojson",
                node_file="data/nodes.geojson",
                validate_mtc=True
            )
            ```
        """
        # Use parent class read method
        network = RoadwayNetwork.read(
            link_file=link_file,
            node_file=node_file,
            shape_file=shape_file,
            **kwargs
        )

        # Convert to MTCRoadwayNetwork
        mtc_network = cls(
            nodes_df=network.nodes_df,
            links_df=network.links_df,
            shapes_df=network.shapes_df,
            validate_mtc=validate_mtc,
            **{k: v for k, v in network.__dict__.items()
               if k not in ['nodes_df', 'links_df', 'shapes_df']}
        )

        return mtc_network

    def write(
        self,
        out_dir: Union[str, Path],
        validate_mtc: bool = True,
        **kwargs
    ):
        """Write network to files with optional MTC validation.

        Args:
            out_dir: Output directory for network files
            validate_mtc: If True, validates against MTC schemas before writing
            **kwargs: Additional arguments passed to parent write method

        Example:
            ```python
            net.write("output/network", validate_mtc=True)
            ```
        """
        # Validate before writing if requested
        if validate_mtc:
            self.validate()

        # Use parent write method
        super().write(out_dir=out_dir, **kwargs)

__init__(nodes_df=None, links_df=None, shapes_df=None, validate_mtc: bool = True, **kwargs)

Initialize MTC Roadway Network with optional MTC-specific validation.

Source code in models/mtc_network.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def __init__(
    self,
    nodes_df=None,
    links_df=None,
    shapes_df=None,
    validate_mtc: bool = True,
    **kwargs
):
    """Initialize MTC Roadway Network with optional MTC-specific validation."""
    # Initialize parent RoadwayNetwork
    super().__init__(
        nodes_df=nodes_df,
        links_df=links_df,
        shapes_df=shapes_df,
        **kwargs
    )

    # Apply MTC-specific validation if requested
    if validate_mtc:
        self.validate()

validate()

Validate network against MTC-specific schemas.

This method can be called explicitly to validate the network after modifications have been made to the dataframes.

Example
# Modify network
net.links_df['county'] = 'Alameda'

# Validate changes
net.validate()
Source code in models/mtc_network.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def validate(self):
    """Validate network against MTC-specific schemas.

    This method can be called explicitly to validate the network after
    modifications have been made to the dataframes.

    Example:
        ```python
        # Modify network
        net.links_df['county'] = 'Alameda'

        # Validate changes
        net.validate()
        ```
    """
    WranglerLogger.debug("MTCRoadwayNetwork.validate() called")
    self.links_df = validate_df_to_model(self.links_df, MTCRoadLinksTable)
    self.nodes_df = validate_df_to_model(self.nodes_df, MTCRoadNodesTable)

read(link_file: Union[str, Path], node_file: Union[str, Path], shape_file: Optional[Union[str, Path]] = None, validate_mtc: bool = True, **kwargs) -> MTCRoadwayNetwork classmethod

Read network from files with MTC validation.

Parameters:

Name Type Description Default
link_file Union[str, Path]

Path to links file (GeoJSON, shapefile, etc.)

required
node_file Union[str, Path]

Path to nodes file (GeoJSON, shapefile, etc.)

required
shape_file Optional[Union[str, Path]]

Optional path to shapes file

None
validate_mtc bool

If True, validates against MTC schemas (default: True)

True
**kwargs

Additional arguments passed to parent read method

{}

Returns:

Type Description
MTCRoadwayNetwork

MTCRoadwayNetwork instance

Example
net = MTCRoadwayNetwork.read(
    link_file="data/links.geojson",
    node_file="data/nodes.geojson",
    validate_mtc=True
)
Source code in models/mtc_network.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@classmethod
def read(
    cls,
    link_file: Union[str, Path],
    node_file: Union[str, Path],
    shape_file: Optional[Union[str, Path]] = None,
    validate_mtc: bool = True,
    **kwargs
) -> "MTCRoadwayNetwork":
    """Read network from files with MTC validation.

    Args:
        link_file: Path to links file (GeoJSON, shapefile, etc.)
        node_file: Path to nodes file (GeoJSON, shapefile, etc.)
        shape_file: Optional path to shapes file
        validate_mtc: If True, validates against MTC schemas (default: True)
        **kwargs: Additional arguments passed to parent read method

    Returns:
        MTCRoadwayNetwork instance

    Example:
        ```python
        net = MTCRoadwayNetwork.read(
            link_file="data/links.geojson",
            node_file="data/nodes.geojson",
            validate_mtc=True
        )
        ```
    """
    # Use parent class read method
    network = RoadwayNetwork.read(
        link_file=link_file,
        node_file=node_file,
        shape_file=shape_file,
        **kwargs
    )

    # Convert to MTCRoadwayNetwork
    mtc_network = cls(
        nodes_df=network.nodes_df,
        links_df=network.links_df,
        shapes_df=network.shapes_df,
        validate_mtc=validate_mtc,
        **{k: v for k, v in network.__dict__.items()
           if k not in ['nodes_df', 'links_df', 'shapes_df']}
    )

    return mtc_network

write(out_dir: Union[str, Path], validate_mtc: bool = True, **kwargs)

Write network to files with optional MTC validation.

Parameters:

Name Type Description Default
out_dir Union[str, Path]

Output directory for network files

required
validate_mtc bool

If True, validates against MTC schemas before writing

True
**kwargs

Additional arguments passed to parent write method

{}
Example
net.write("output/network", validate_mtc=True)
Source code in models/mtc_network.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def write(
    self,
    out_dir: Union[str, Path],
    validate_mtc: bool = True,
    **kwargs
):
    """Write network to files with optional MTC validation.

    Args:
        out_dir: Output directory for network files
        validate_mtc: If True, validates against MTC schemas before writing
        **kwargs: Additional arguments passed to parent write method

    Example:
        ```python
        net.write("output/network", validate_mtc=True)
        ```
    """
    # Validate before writing if requested
    if validate_mtc:
        self.validate()

    # Use parent write method
    super().write(out_dir=out_dir, **kwargs)