o
    <c                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ	 d dl
Z
d dlZd dlZd dlmZmZmZ d dlmZ dZdd ZdddZd	d
 ZdddZedkrWe  dS dS )    N)readfile	writefileutils)multitrack_utilitiesa  example:
  generate_horzvert.py $SCRATCHDIR/BalochistanSenAT/velocity/BalochistanSenAT.h5 $SCRATCHDIR/BalochistanSenDT/velocity/BalochistanSenDT.h5 --bbox 26.0 27.5 63.5 66.0 --outdir ./ 
  generate_horzvert.py $SCRATCHDIR/BalochistanSenAT/velocity/BalochistanSenAT.h5 $SCRATCHDIR/BalochistanSenDT/velocity/BalochistanSenDT.h5 --bbox 26.0 27.5 63.5 66.0 --reference_point 27.5 64.8 --azimuth 15 --outname hz.h5 up.h5 --outdir ./
c                  C   s   t jdt jtd} | jdddd | jddtd	d
dd | jddtddd | jddtddd | jddtdddgdd | jddtdd d | S )!Nz)Generate horizontal and vertical datafile)descriptionformatter_classepilogDataSet   zascending or descending files
)nargshelpz--bboxSNWE   )SNWEzBounding box of area to be geocoded.
Include the uppler left corner of the first pixel    and the lower right corner of the last pixel)desttyper   metavarr   z--reference_pointref_poi*zreset reference point)r   r   r   r   z	--azimuthazimuthg     V@zazimuth angle in degree (clockwise) of the direction of the horizontal movement
default is 90.0 for E-W component, assuming no N-S displacement.
i.e. azimuth angle of strike-slip fault

)r   r   defaultr   z	--outnameoutnamezhorz.h5zvert.h5z7output file name for vertical and horizontal components)r   r   r   r   r   --outdiroutdir   zoutput directory)argparseArgumentParserRawTextHelpFormatterEXAMPLEadd_argumentfloatstr)parser r&   M/home/exouser/operations/rsmas_insar/tools/MimtPy/mimtpy/generate_horzvert.pycreate_parser   s*   r(   c                 C   s   t  }|j| d}|S )N)args)r(   
parse_args)iargsr%   inpsr&   r&   r'   cmd_line_parse5   s   r-   c                 C   sT  | j d }| j d }tj|d dd }tj|d dd }| jd }| j}|r|d }|d }td tt	d|d|d|g}	|	dkrRt
d| t|\}
}||d	< ||d
< tj|
||d tt	d|d|d|g}	|	dkrt
d| t|\}}||d	< ||d
< tj|||d td| t| | j}td d| d }tt	d|d|dd d|dd d|g tt	d|d|dd d|dd d|g}	|	dkrt
dtd d| d }tt	d|d|dd d|dd d|g tt	d|d|dd d|dd d|g}	|	dkr*t
d| j}| j}|d }|d }td tt	d||dt|d||g tt	d||dt|d||g}	|	dkrht
d|d|d|dd d g}t	|}td| tj|  |d|d|dd d g}t	|}td| tj|  dS ) z&generate horzontal and vertical files.r   r   .z7
changing ascending and descending data reference pointzreference_point.pyz-lz-Lz+error when runing reference_point.py for %sREF_LATREF_LON)out_filemetadataz
go to the output dir {}z
subset ascending dataZsubset_z.h5z	subset.pyr
   r   z-oz!error when subset ascending data!z
subset descending dataz"error when subset descending data!z
 runing asc_desc2horz_vert.pyzasc_desc2horz_vert.pyz--azz)error when running asc_desc2horz_vert.py!r   z--outputz.tiffz
H5UNW_to_geotiff.pyN)r	   ospathsplitr   r   printsystemmuseperate_str_byspace	Exceptionr   readr   writeformatchdirr   r   r   r$   mimtpyH5UNW_to_geotiffmain)r,   Zdataset_ascZdataset_desZfile_ascZfile_desr   Zrefpoi_laloZ
refpoi_latZ
refpoi_loncompletion_statusZasc_dataZasc_atrZdes_dataZdes_atrr   Zsub_file_ascZsub_file_desr   r   Z	horz_nameZ	vert_nameZ	scp_args2r&   r&   r'   horzvert;   sr   



.0.0
"$




rC   c                 C   s   t | }t| t| d S N)r-   r6   rC   )r+   r,   r&   r&   r'   rA      s   rA   __main__rD   )r3   r   stringshutilnumpynpreZscipy.ioiosiomintpyr?   mimtpy.workflowmintpy.utilsr   r   r   utmimtpy.utilsr   r8   r!   r(   r-   rC   rA   __name__r&   r&   r&   r'   <module>   s(   

V
