o
    |Ne!                     @   s   d dl Z d dlmZ d dlmZ d dlmZm	Z	 d dl
T d dlmZmZ d dlmZmZmZmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZ d d
lmZmZ d dlmZmZ d dl m!Z! d dl"m#Z#m$Z$ d dl%Z%dd Z&dd Z'dS )    N)readfile	writefile)*)
prep_slice
plot_slice)reference_pointasc_desc2horz_vert	save_gdalmask)get_file_names)prepend_scratchdir_if_neededfind_nearest_start_end_date)get_data_typesave_gbis_plotdata)plot_shaded_relief)modify_colormapadd_colorbar)get_earthquakesnormalize_earthquake_times)get_gps)generate_view_velocity_cmdgenerate_view_ifgram_cmdc                 C   s  d| _ d| _d| _d| _dtjv rtdd | _ntdd | _td| j | jd	 | _	| jd
 | _
| j}| j
}| j}| j}| j}| j}| j}i }|dksS|dkr|D ]~}	t|	}
t|
\}}}}}|dd}t||\}}| d| d| d| }dg|  }t|}| d| }t|  | d| d| d| }t|  |r| d|d  d|d  }t|  |rt|||| ||d||< qUn^|dkr'|D ]I}	t|	}
t|
\}}}}}tj|dd\}}|dd}tj |||d |r| d|d  d|d  }t|  |d  |d  d||< qn|d!kr3||d||< |dkrpi }tt|d \}}}}}tt|d \}}}}}| d"| }t!|  ||d|d#< ||d|d$< |S )%Nz0 10Zplasma_rg?ZGPSDIRz/data
SCRATCHDIRz/MaunaLoa/MLtry/datazrun_prepare: inps.gps_dir:z/GPS_BenBrooks_03-05full.txtz
/demGeo.h5velocityhorzvertzvelocity.h5ztemporalCoherence.tifz --start-date z --end-date z
 --output ztimeseries2velocity.pyz# --dset temporalCoherence --output z --mask z --mask-vmin z --outfile z --lat r   z --lon    )
start_dateend_datestepZstep20210306)ZdatasetName)Zout_fileZmetadatazmintpy.timeFunc.stepDateshaded-relief zup.h5zhz.h5)"depth_range	cmap_nameexclude_beginningexclude_endosenvirongetenvgps_dirprintgps_list_filedem_filedata_dir	plot_typereference_lalo	mask_vminflag_save_gbisperiodr   r   replacer   split
subprocessZcheck_outputr	   mainr
   r   r   r   readr   writer   )inpsr,   r+   r-   r.   r/   r0   r1   	data_dictdirwork_dirZeos_fileqZout_geo_vel_fileZtemp_coh_filer   r   cmdoutputZgeo_vel_fileZgeo_geometry_fileZout_dirZgeo_stepatrZout_geo_step_fileZout_geo_vel_file0Zout_geo_vel_file1 r@   K/home/exouser/operations/rsmas_insar/tools/PlotData/src/prepare_and_plot.pyrun_prepare   s   





rB   c           4      C   s6  |j }|j}|j}|j}|j}|j}|j}|j}	|j}
|j	}|j
}|j}|j}|j}|j}|j}|j}|j}|jd }|jd }|j}|j}|j}|j}t| dkrgtjddddgd\}}t|jd |_ntjddgd\}}|g}t|  D ]\}\}}|	dks|	d	ks|	d
ks|	dkr|	dks|	d	ks|	dkrt||}n
|	d
krttt |}t!|\} }!}"t"|| | |!|"\}#}$}%}&n|	dkrt#|| ||d t$|}'|| %|'d |d  d |d   |
rt&j'|
dd}(|| j(|(d d d df |(d d d df dddd |rUt)|||})t*|)||}*t+|||dd}+|)j,d dksB|| j-|)d |)d d|)d d  |*|+dd t|  dksUt.|| |+||d  |rt/|||||||j
\},}-}.}/}0}1}2|||||||f || j0|-|.|/|0|d!d"}3|| j1|3d#d$|d% |2d&d'd!d(|id)	 qzt2  d S )*Nr   r            )Zfigsizegffffff?r   r   Zifgramr   r   )plot_boxz: r   z - r   T)Z
squeeze_meZLllhZblackZdashed)colorZ	linestyleZ	linewidthF)r"   r#   r$   showZ	LongitudeZLatitudeZ	Magnitude   g?)sccmapalpha)ZaxrL   r   r   Zblue)ZscalerG   g     pcgR3@
   Ndatasize)ZlabelposZcoordinatesrG   Zfontproperties)3r,   r(   r*   r+   rF   flag_seismicityflag_gpsr-   	line_filegps_scale_facgps_key_lengthgps_unitunit	font_sizer.   r/   vlimr0   r1   r!   r"   r#   r$   lenpltZsubplotsint	enumerateitemsr   r   r;   Zdate12r   r   r   r   Z	set_titlesioZloadmatZplotr   r   r   shapeZscatterr   r   ZquiverZ	quiverkeyrH   )4r9   r8   r,   r(   r*   r+   rF   rR   rS   r-   rT   rU   rV   rW   rX   rY   r.   r/   rZ   r0   r   r   r!   r"   r#   r$   ZfigZaxesifiledictr=   rP   r?   Ztmp_inpsZq0Zq1Zq2Zq3Z	data_typelinesZ	events_dfZ
norm_timesrL   gpsZlonZlatUVZZquiver_labelZquivr@   r@   rA   run_plotn   sz   

 &8.$rj   )(r%   Zmatplotlib.pyplotZpyplotr\   Zscipy.ioior`   Zmintpy.utilsr   r   Zmintpy.defaults.plotZmintpy.viewr   r   Z
mintpy.clir   r   r	   r
   Zhelper_functionsr   r   r   r   r   Zplot_functionsr   r   r   Z
seismicityr   r   rf   r   Zinsarr   r   r4   rB   rj   r@   r@   r@   rA   <module>   s$   U