コード例 #1
0
    def read(feed_path: str) -> TransitNetwork:
        """
        Read GTFS feed from folder and TransitNetwork object

        Args:
            feed_path: where to read transit network files from

        Returns: a TransitNetwork object.
        """
        config = default_config()
        feed = ptg.load_feed(feed_path, config=config)
        WranglerLogger.info("Read in transit feed from: {}".format(feed_path))

        updated_config = TransitNetwork.validate_feed(feed, config)

        # Read in each feed so we can write over them
        editable_feed = DotDict()
        for node in updated_config.nodes.keys():
            # Load (initiate Partridge's lazy load)
            editable_feed[node.replace(".txt", "")] = feed.get(node)

        transit_network = TransitNetwork(feed=editable_feed,
                                         config=updated_config)
        transit_network.feed_path = feed_path
        return transit_network
コード例 #2
0
    def __init__(self, path, config=None, view=None, encoding=None):
        self.path = path
        self.is_dir = os.path.isdir(self.path)
        self.config = default_config() if config is None else config
        self.view = {} if view is None else view
        self.zmap = {}
        self.encoding = encoding
        print(encoding)

        assert os.path.isfile(self.path) or self.is_dir, \
            'File or path not found: {}'.format(self.path)

        assert nx.is_directed_acyclic_graph(self.config), \
            'Config must be a DAG'

        roots = {n for n, d in self.config.out_degree() if d == 0}
        for filename, param in self.view.items():
            assert filename in roots, \
                'Filter param given for a non-root node ' \
                'of the config graph: {} {}'.format(filename, param)

        if self.is_dir:
            self._verify_folder_contents()
        else:
            self._verify_zip_contents()
コード例 #3
0
ファイル: test_feed.py プロジェクト: timgates42/partridge
def test_bad_edge_config():
    config = default_config()

    # Remove the `dependencies` key from an edge config
    config.edges["stop_times.txt", "trips.txt"].pop("dependencies")

    feed = Feed(fixture("caltrain-2017-07-24"), config=config)

    with pytest.raises(ValueError, message="Edge missing `dependencies` attribute"):
        feed.stop_times
コード例 #4
0
    def read_feed(feed_path: str = None) -> Tuple[nx.DiGraph, Feed]:
        """
        Read GTFS feed from folder and return a config and Partridge Feed object
        """
        config = geo_config()
        config.nodes["shapes.txt"]["required_columns"] = config.nodes[
            "shapes.txt"]["required_columns"] + ("A", "B", "LINK_ID")

        try:
            feed = ptg.load_feed(feed_path, config=config)
            TransitNetwork.validate_feed(feed, config)

        except KeyError:
            config = default_config()
            config.nodes["shapes.txt"]["required_columns"] = (
                "shape_id",
                "A",
                "B",
                "LINK_ID",
            )

            WranglerLogger.warning(
                "Reducing data requirements for shapes.txt to:",
                config.nodes["shapes.txt"]["required_columns"],
            )
            feed = ptg.load_feed(feed_path, config=config)
            TransitNetwork.validate_feed(feed, config)

        ## todo should be read in as a schema
        WranglerLogger.info(
            "Read %s agencies from %s" %
            (feed.agency.size, os.path.join(feed_path, "agency.txt")))
        WranglerLogger.info("Read %s frequencies from %s" %
                            (feed.frequencies.size,
                             os.path.join(feed_path, "frequencies.txt")))
        WranglerLogger.info(
            "Read %s routes from %s" %
            (feed.routes.size, os.path.join(feed_path, "routes.txt")))
        WranglerLogger.info(
            "Read %s shapes from %s" %
            (feed.shapes.size, os.path.join(feed_path, "shapes.txt")))
        WranglerLogger.info(
            "Read %s stops from %s" %
            (feed.stops.size, os.path.join(feed_path, "stops.txt")))
        WranglerLogger.info(
            "Read %s transfers from %s" %
            (feed.transfers.size, os.path.join(feed_path, "transfers.txt")))
        WranglerLogger.info(
            "Read %s trips from %s" %
            (feed.trips.size, os.path.join(feed_path, "transfers.txt")))

        return config, feed
コード例 #5
0
ファイル: readers.py プロジェクト: cjer/open-bus-explore
def get_filtered_feed(path, filters, config=None):
    '''
    Multi-file feed filtering
    '''
    filter_config = default_config() if config is None else config.copy()
    filter_config = remove_node_attributes(filter_config, 'converters')

    trip_ids = set(raw_feed(path).trips.trip_id)
    for filename, column_filters in filters.items():
        feed = mkfeed(path,
                      config=reroot_graph(filter_config, filename),
                      view={filename: column_filters})
        trip_ids &= set(feed.trips.trip_id)

    return mkfeed(path, config, {'trips.txt': {'trip_id': trip_ids}})
コード例 #6
0
    def read(feed_path: str, fast: bool = False) -> TransitNetwork:
        """
        Read GTFS feed from folder and TransitNetwork object
        """
        config = default_config()
        feed = ptg.load_feed(feed_path, config=config)
        WranglerLogger.info("Read in transit feed from: {}".format(feed_path))
        updated_config = TransitNetwork.validate_feed(feed, config)

        # Read in each feed so we can write over them
        new_feed = DotDict()
        for node in updated_config.nodes.keys():
            # Load (initiate Partridge's lazy load)
            new_feed[node.replace(".txt", "")] = feed.get(node)

        transit_network = TransitNetwork(feed=new_feed, config=updated_config)
        transit_network.feed_path = feed_path
        return transit_network