コード例 #1
0
def save_azimuth_bin_data(network: Network, other_results_path: Path,
                          loc_hash: str):
    """
    Save azimuth bin data from a Network.
    """
    trace_bins, _, _ = network.plot_trace_azimuth()
    branch_bins, _, _ = network.plot_branch_azimuth()
    trace_bin_df, branch_bin_df = bins_to_dataframes(trace_bins, branch_bins)
    utils.save_csv(trace_bin_df, other_results_path / f"trace_{loc_hash}.csv")
    utils.save_csv(branch_bin_df,
                   other_results_path / f"branch_{loc_hash}.csv")
コード例 #2
0
def test_plaifiny_rose_plot_manual():
    """
    Test plainify_rose_plot.
    """
    network = Network(
        trace_gdf=tests.flato_traces_gdf(),
        area_gdf=tests.flato_area_gdf(),
        snap_threshold=0.001,
        determine_branches_nodes=False,
        truncate_traces=True,
    )

    _, fig, ax = network.plot_trace_azimuth()
    network_scripts.plainify_rose_plot(fig, ax)
コード例 #3
0
def plot_and_save_azimuths(network: Network, other_results_path: Path,
                           name: str):
    """
    Plot azimuth rose plots and save them.
    """
    _, fig, ax = network.plot_trace_azimuth()
    # save normal version
    fig.savefig(other_results_path / f"{name}_trace_azimuths.svg",
                bbox_inches="tight")
    # Make plain version
    plainify_rose_plot(fig, ax)
    # Save plain version
    fig.savefig(
        other_results_path / f"{name}_trace_azimuths_plain.svg",
        bbox_inches="tight",
        transparent=True,
    )
    # Branch version
    _, fig, _ = network.plot_branch_azimuth()
    fig.savefig(other_results_path / f"{name}_branch_azimuths.svg",
                bbox_inches="tight")
コード例 #4
0
def network(
    trace_file: Path = typer.Argument(...,
                                      exists=True,
                                      dir_okay=False,
                                      help=TRACE_FILE_HELP),
    area_file: Path = typer.Argument(...,
                                     exists=True,
                                     dir_okay=False,
                                     help=AREA_FILE_HELP),
    snap_threshold: float = typer.Option(0.001, help=SNAP_THRESHOLD_HELP),
    determine_branches_nodes: bool = typer.Option(
        True,
        help=
        "Whether to determine branches and nodes as part of analysis. Recommended.",
    ),
    name: Optional[str] = typer.Option(
        None,
        help="Name for Network. Used when saving outputs and as plot titles."),
    circular_target_area: bool = typer.Option(
        False, help="Is/are target area(s) circles?"),
    truncate_traces: bool = typer.Option(
        True,
        help="Whether to cut traces at target area boundary. Recommended."),
    censoring_area: Optional[Path] = typer.Option(
        None,
        help=
        "Path to area data that delineates censored areas within target areas.",
    ),
    branches_output: Optional[Path] = typer.Option(
        None, help="Where to save branch data."),
    nodes_output: Optional[Path] = typer.Option(
        None, help="Where to save node data."),
    general_output: Optional[Path] = typer.Option(
        None,
        help="Where to save general network analysis outputs e.g. plots."),
    parameters_output: Optional[Path] = typer.Option(
        None, help="Where to save numerical parameter data from analysis."),
):
    """
    Analyze the geometry and topology of trace network.
    """
    network_name = name if name is not None else area_file.stem
    console = Console()

    console.print(
        Text.assemble("Performing network analysis of ",
                      (network_name, "bold green"), "."))

    network = Network(
        trace_gdf=read_geofile(trace_file),
        area_gdf=read_geofile(area_file),
        snap_threshold=snap_threshold,
        determine_branches_nodes=determine_branches_nodes,
        name=network_name,
        circular_target_area=circular_target_area,
        truncate_traces=truncate_traces,
        censoring_area=read_geofile(censoring_area)
        if censoring_area is not None else gpd.GeoDataFrame(),
    )
    (
        general_output_path,
        branches_output_path,
        nodes_output_path,
        parameters_output_path,
    ) = default_network_output_paths(
        network_name=network_name,
        general_output=general_output,
        branches_output=branches_output,
        nodes_output=nodes_output,
        parameters_output=parameters_output,
    )
    # Save branches and nodes
    console.print(
        Text.assemble(
            "Saving branches to ",
            (str(branches_output_path), "bold green"),
            " and nodes to ",
            (str(nodes_output_path), "bold green"),
            ".",
        ))
    network.branch_gdf.to_file(branches_output_path, driver="GPKG")
    network.node_gdf.to_file(nodes_output_path, driver="GPKG")

    console.print(rich_table_from_parameters(network.parameters))

    pd.DataFrame([network.numerical_network_description()
                  ]).to_csv(parameters_output_path)

    console.print(
        Text.assemble(
            "Saving extensive network parameter csv to path:\n",
            (str(parameters_output_path), "bold green"),
        ))

    # Plot ternary XYI-node proportion plot
    fig, _, _ = network.plot_xyi()
    save_fig(fig=fig, results_dir=general_output_path, name="xyi_ternary_plot")

    # Plot ternary branch proportion plot
    fig, _, _ = network.plot_branch()
    save_fig(fig=fig,
             results_dir=general_output_path,
             name="branch_ternary_plot")

    # Plot trace azimuth rose plot
    _, fig, _ = network.plot_trace_azimuth()
    save_fig(fig=fig, results_dir=general_output_path, name="trace_azimuth")

    # Plot trace length distribution plot
    _, fig, _ = network.plot_trace_lengths()
    save_fig(fig=fig,
             results_dir=general_output_path,
             name="trace_length_distribution")