o
    /BfZ                     @   s~   d Z ddlT ddlmZ ddlZddlZddlZddl	Z
ddlZdd Zdd Zd	d
 Zdd Zdd Zedkr=e  dS dS )a  Analyze arbors

This file contains functions for analyzing arbors to create the Pareto 
front.

This file requires `pandas` to be installed.

This file can also be imported as a module and contains the following
functions:
    * write_front - creates a file containing columns of alpha, wiring cost, and conduction delay
    * get_pareto_front - returns a list containing wiring_costs and conduction_delays
    * analyze_arbors -
    * write_scaling_dists - 
    * main - the main function of the file

This file can also be called on its own with arguments `--analyze` 
to run `analyze_arbors()` and `--scaling` to run `write_scaling_dists()`.

    )*)read_arbor_fullNc           
      C   sx   | j d }td||f d$}|d t|||D ]\}}}	|d|||	f  qW d    d S 1 s5w   Y  d S )N
arbor name	%s/%s.csvwz%alpha, wiring cost, conduction delay
z%f, %f, %f
)graphopenwritezip)
Goutdiralphaswiring_costsconduction_delaysfnamefalphawiringdelay r   l/home/dh_an3skk/arjun-chandrasekhar-teaching.com/tomato/backend/backend_plant_architecture/analyze_arbors.pywrite_front   s   

"r   c                 C   st   |t  }d|| jd f }tj|r&tj|dd}t|d t|d fS t	| |\}}t
| |||| ||fS )a  Gets the wiring costs and condution delays for the Pareto front.
    If the file already exists it just reads the file. If it does not,
    it will use `pareto_front()` from `pareto_functions.py` to calculate
    the needed information and then write the file using `write_front()` and
    finally returns the wiring costs and conduction delays.

    Parameters
    ----------
    G : graph(?) #TODO: maybe figure out what exactly G is? 
                 #      Could just do type print later for it.
        The graph information of the arbor (maybe)
    alphas : alpha numbers (?)
        Used to create the Pareto front if file doesn't already exist.

    Returns
    -------
    list
        a list of wiring costs and conduction delays
    r   r   Tskipinitialspacezwiring costzconduction delay)PARETO_FRONTS_DIRr   ospathexistspdread_csvlistpfpareto_frontr   )r   r   
pathPrefixr   r   dfr   r   r   r   r   get_pareto_front$   s   r%   c                 C   
  t }d| t  }tj| }g }|s tj|dd}t|d }t|dV}|r-|	d t
| t D ]>}|ds<q4|d|v rDq4td t| t|| }|jd }	t||| \}
}t|||
|\}}|	d	|	||f  q4W d    d S 1 s~w   Y  d S )
Nz%s/arbor_stats.csvTr   r   az9arbor name, pareto front distance, pareto front location
.csvz'analyzing arbors from analyze_arbors.py%s, %f, %f
)DEFAULT_ALPHASSTATISTICS_DIRr   r   r   r   r   r    r   r	   listdirRECONSTRUCTIONS_DIRendswithstripprintr   r   r%   r!   arbor_dist_locr#   r   r   
first_timeprev_arborsr$   r   arbor_fnamer   
arbor_namer   r   distr   r   r   r   analyze_arborsB   s0   



"r8   c                 C   r&   )
Nz%s/scaling_distances.csvTr   r   r'   zIarbor name, pareto front scaling distance, pareto front scaling location
r(   z0writing scaling distances from analyze_arbors.pyr)   )r*   r+   r   r   r   r   r   r    r   r	   r,   r-   r.   r/   r0   r   r   r%   r!   arbor_dist_loc_scaler2   r   r   r   write_scaling_distsa   s0   



"r:   c                  C   sL   t  } | jddd | jddd |  }|jrt  |jr$t  d S d S )Nz	--analyze
store_true)actionz	--scaling)argparseArgumentParseradd_argument
parse_argsanalyzer8   scalingr:   )parserargsr   r   r   main   s   
rE   __main__)__doc__new_constantsread_arbor_reconstructionr   pareto_functionsr!   numpynpr   pandasr   r=   r   r%   r8   r:   rE   __name__r   r   r   r   <module>   s      
