<jupyter_start><jupyter_text>This notebook provides some examples of visualizations made with FracMan outputs, outside of the normal FracMan capabilities. Many of these visualizations are geospatial and require Geopandas. The best (and by far easier) way to install Geopandas is using Miniconda.https://docs.conda.io/en/latest/miniconda.html<jupyter_code>from pathlib import Path
from typing import Tuple

import geopandas as gpd
import pandas as pd
import numpy as np
from sklearn import linear_model
from shapely.geometry import LineString

from pyfracman.data import clean_columns
from pyfracman.fab import parse_fab_file
from pyfracman.frac_geo import flatten_frac, get_mid_z
from pyfracman.well_geo import (
    load_stage_location,
    load_survey_export, 
    well_surveys_to_linestrings, 
    stage_locs_to_gdf
    )
data_dir = Path(r"C:\Users\scott.mckean\Desktop\spider_plots")
### Load fractures ###
frac_fpath = next(data_dir.rglob("Well_Connected_Fracs_1.fab"))
fracs = parse_fab_file(frac_fpath)

# load fracture properties
prop_df = pd.DataFrame(fracs['prop_list'], columns = fracs['prop_dict'].values(), index=fracs['fid'])
prop_df.index.set_names('fid', inplace=True)

# load fracture geometry and flatten to 2D at midpoint of frac plane
frac_linestrings = list(map(flatten_frac, fracs['fracs']))
frac_mid_z = list(map(get_mid_z, fracs['fracs']))
frac_gdf = gpd.GeoDataFrame(prop_df, geometry=frac_linestrings)
### load stages and surveys ###
# load surveys and convert to linestrings
surveys = pd.concat(
    [load_survey_export(well_path) for well_path in data_dir.glob("*_well.txt")]
)
survey_linestrings = well_surveys_to_linestrings(surveys)

# load stage locations and convert to GDF with points and linestring
stage_locs = pd.concat(
    [load_stage_location(well_path) for well_path in data_dir.glob("*_intervals.txt")]
)
stage_gdf = stage_locs_to_gdf(stage_locs)
def get_fracture_set_stats(fpath: Path, set_name: str, set_alias: str) -> pd.DataFrame:
    """Parse a connection export from FracMan to get the Fracture set statistics

    Args:
        fpath (Path): file path
        set_name (str): name of fracture set to summarize

    Returns:
        pd.DataFrame: Dataframe with statistics
    """
    conn = pd.read_csv(fpath, delim_whitespace=True).rename(columns={"Set_Name":"FractureSet"})
    conn.columns = clean_columns(conn.columns)
    
    # get set ids
    set_ids = conn.query("fractureset == @set_name").groupby('object')['fracid'].apply(list)
    set_ids.name = set_alias + "_ids"

    # get set counts
    set_ct = conn.query("fractureset == @set_name").groupby('object').count().iloc[:,0]
    set_ct.name = set_alias + "_count"

    # get stage counts
    stages = conn.groupby("object").count().reset_index().rename(columns={'FractureSet':'interactions'})
    stages['stage_no'] = stages.object.str.split("_").str[-1]
    stages['well'] = stages.object.str.split("_").str[-3]
    stages = (stages[['stage_no','well','object']]
        .merge(set_ids, left_on='object', right_index=True)
        .merge(set_ct, left_on='object', right_index=True)
        )
### load results ###
stage_dfs = []
for conn_fpath in data_dir.rglob("*_Connections.txt"):
    
conn.query("object == 'StageConnection_A6_Stage_1'")
stages
set_a_ids
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
survey_linestrings.plot(ax = ax)
frac_gdf.plot(ax = ax, color='r')
stage_gdf.set_geometry('stg_line').plot(ax = ax, color='k')
ax.set_aspect('equal')
plt.xlim(-250, 2000)
plt.ylim(-1250, 1000)
plt.show()
# Load results
# Make plot
# Make spider plot
# Redo histograms<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12141280353200883, 'fraction_numerical': 0.006070640176600441, 'mean_word_length': 5.186006825938566, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '320002', 'license': 'MIT', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1259, 'n_words': 283, 'path': 'examples/geospatial_viz.ipynb', 'repo_name': 'ScottHMcKean/pyfracman', 'size': '3624'}