o
    	\nf_                     @   s   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mZ d dl	m
  mZ dZdZdd ZG dd	 d	Zd
d Zdd ZdS )    N)convert_from_path)message_rsmaszexamples:
    create_html.py MaunaLoaSenDT87/mintpy_5_20/pic
    create_html.py unittestGalapagosSenDT128/miaplpy_SN_201606_201608/network_single_reference/pic
zCCreates index.html file to display images in the mintpy/pic folder.c                  C   s.   t jttt jd} | jdtdd |  }|S )N)descriptionepilogformatter_classdirzmintpy/pic directory path)typehelp)argparseArgumentParserDESCRIPTIONEXAMPLERawTextHelpFormatteradd_argumentstr
parse_args)parserinps r   :/home/exouser/operations/rsmas_insar/minsar/create_html.pycreate_parser   s   r   c                   @   s   e Zd Zdd ZdS )Inpsc                 C   s
   || _ d S )N)Zcustom_template_file)selftemplate_filer   r   r   __init__&   s   
zInps.__init__N)__name__
__module____qualname__r   r   r   r   r   r   %   s    r   c              	      s   t d|  dd t| D }dd |D }dd |D }dd |D }t|  |D ]&}t|}t|D ]\}}tjtj|d }	|	 d}
|	|
d	 q5q+d
d t| D }dd |D }|slt d t
  g d  fdd}|j|d t| d |d  }t|}z|jd }W n   d}Y |d dd }d}|d| d7 }d| v r|d| d7 }|D ]}
d|
 d}d|
 d|
 d|
 d}||| 7 }qd }d| d}t d!t  t|d"}||d# |  d$ 7 }W d    n	1 sw   Y  |D ]}d%| d}d| d&}||| 7 }q|D ]+}d| d}t|d"}||d# |  d$ 7 }W d    n	1 sEw   Y  q |d'7 }tj| d(}t|d)}|| W d    n	1 smw   Y  t|}t d*|  d S )+NzDIRECTORY_PATH:c                 S      g | ]}|  d r|qS )).png.pdf.kmz	.templatelowerendswith.0filer   r   r   
<listcomp>+       zbuild_html.<locals>.<listcomp>c                 S   r   )r    r#   r&   r   r   r   r)   ,   r*   c                 S   r   )r!   r#   r&   r   r   r   r)   -   r*   c                 S   r   )r"   r#   r&   r   r   r   r)   .   r*   r   r   ZPNGc                 S   r   ))r   r    r"   r#   r&   r   r   r   r)   <   r*   c                 S   r   )r   r#   r&   r   r   r   r)   =   r*   z.No PNG files found in the specified directory.)zgeo_velocity.pngzgeo_temporalCoherence.pngzgeo_maskTempCoh.pngzgeo_avgSpatialCoh.pngznetwork.pngzcoherenceHistory.pngzcoherenceMatrix.pngzrms_timeseries*.pngztemporalCoherence.pngzmaskTempCoh.pngzavgSpatialCoh.pngzmaskConnComp.pngznumTriNonzeroIntAmbiguity.pngznumInvIfgram.pngzvelocity.pngzgeometryRadar.pngzcoherence_?.pngzcoherence_??.pngzunwrapPhase_wrap_?.pngzunwrapPhase_wrap_??.pngzunwrapPhase_?.pngzunwrapPhase_??.pngzconnectComponent_?.pngzconnectComponent_??.pngztimeseries_*_wrap10_?.pngzgeo_timeseries_*_wrap10_?.pngc                    sV   t  D ] \}}t| |r$td| }|rt| nd}||f  S qt dfS )Nz\d+r   )	enumeratefnmatchresearchintgrouplen)filenameipatternmatchZnumberZpreferred_orderr   r   sort_keyQ   s   zbuild_html.<locals>.sort_key)key/z"miaplpy.interferograms.networkTypeZsingle_reference.z<html><body>z  <h1>z</h1>
Zmiaplpyz  <h2>network: z</h2>
z  <h2>z	<a href="z"><img src="z" alt="z" width="500"></a><br>zreference_date.txtzQQ cwd:rz<pre>
z</pre>
z<h2>z" download>Download file.</a>
z</body></html>
z
index.htmlwzHTML file created: 
)printoslistdirchdirr   r+   pathsplitextbasenameZsaveexitsortr   putilsZcreate_or_update_templatetemplatesplitgetcwdopenreadjoinwriter   &insert_environment_variables_into_path)Zdirectory_pathZ	file_listZ	pdf_filesZ	kmz_filesZtemplate_filesZpdf_fileZimagesr3   Zimage	base_nameZpng_fileZ	png_filesr7   r   Znetwork_typeZproject_nameZhtml_contentZ
header_tagZimg_tagZtxt_filer(   Zkmz_fileZdownload_linkr   Zhtml_file_pathZ	html_filer   r6   r   
build_html)   sx   





rP   c                 C   s0   t j| jst  d | j | _t| j d S )Nr9   )r>   rA   isabsr   rI   rP   )r   r   r   r   create_html   s   
rR   )r>   sysr
   r-   r,   Z	pdf2imager   minsar.objectsr   Zminsar.utils.process_utilitiesZutilsZprocess_utilitiesrF   r   r   r   r   rP   rR   r   r   r   r   <module>   s   d