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mZ d dlm	Z	m
Z
mZ d dlmZmZ dZdd ZdddZd	d
 ZdddZedkrIe  dS dS )    N)gdal
gdal_arrayosr)readfile	writefilezexample:
    H5UNW_to_geotiff.py /data/lxr/insarlab/SCRATCHDIR/BalochistanSenAT/ERA/geo_velocity_msk_mosaic.h5 --outdir /data/lxr/insarlab/SCRATCHDIR/BalochistanSenAT/ERA/ --unit radian --output geo_velocity_msk_mosaic.tif
c                  C   sd   t jdt jtd} | jddtdd | jddd	td
d | jdddtdd | jdddtdd | S )NzAGenerate *.tiff file with WGS projection based *.h5 / *.unw files)descriptionformatter_classepiloginput_HDFEOS   zdirectory stored *.he5 files. 
)nargstypehelpz--unitunit?z8the unit of input data.Make transefer for m and radian.
)destr   r   r   z--outdiroutdirzoutput directory.
z--outputoutputzoutput file name.
)argparseArgumentParserRawTextHelpFormatterEXAMPLEadd_argumentstr)parser r   L/home/exouser/operations/rsmas_insar/tools/MimtPy/mimtpy/H5UNW_to_geotiff.pycreate_parser   s   r   c                 C   s   t  }|j| d}|S )N)args)r   
parse_args)iargsr   inpsr   r   r   cmd_line_parse&   s   r"   c                 C   sf  | j d }| jd }|| jd  }td|  t|}t|d }| jdks/td |}n&| jd dkr;|d }n| jd dkrUt|d }d	||  d
t	j
  d }t|d }t|d }	t	|\}
}t|d }d	t|d  }||d|	d| g}td|||
dtj}|| t }|d ||  |d| |  td dS )Ztransferr   zoutput tiff file name : %sNonezusing the orgianl unit of inputmd   radian
WAVELENGTH   X_FIRSTY_FIRSTX_STEPY_STEPGTiffr   i  zfinish conversion!N)r
   r   r   printr   read_attributereadr   floatnppishaper   GetDriverByNameCreateGDT_Float32SetGeoTransformr   SpatialReferenceImportFromEPSGSetProjectionExportToWktGetRasterBand
WriteArray
FlushCache)r!   fnameZoutput_path
output_tifatrdatadisp
wavelengthxminymaxnrowsncolsxresyresgeotransformrastersrsr   r   r   hdf_to_geotif,   s8   






rP   c                 C   s   t | }t| d S N)r"   rP   )iagrsr!   r   r   r   mainV   s   rS   __main__rQ   )sysr   osrenumpyr3   scipy.ioioosgeor   r   r   mintpy.utilsr   r   r   r   r"   rP   rS   __name__r   r   r   r   <module>   s    

*
