o
    <c                     @   s   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	 d dl
Z
d dlZ
d dlmZ dZdd Zddd	Zd
d Zdd ZdddZedkrMe  dS dS )    N)	RAMP_LIST)readfile	writefile)multitrack_utilitiesa$  example:
  
  gridsearch_ramps_relax.py KokoxiliModelData_AT143_ramped.h5 KokoxiliModel_AT143.h5 mask.h5 --ramp_estimate -s linear -o ramp_noise.h5 --ramp_file ramps.h5 --outdir ./
  
  gridsearch_ramps_relax.py KokoxiliModelData_AT143_ramped.h5 KokoxiliModel_AT143.h5 mask.h5 --outdir ./
  
c                  C   s   t jdt jtd} | jddtdd | jddtdd | jd	dtd
d | jddddd | jdddtdd | jddtddd | jddddd | jddtddd | S ) NzPrepare data for Kite software)descriptionformatter_classepilogObs_file   zObserved data)nargstypehelp
Model_filezModeled datamaskz	Mask filez--ramp_estimatee_ramp
store_truezestimate ramp or not)destactionr   -ssurface_typelinearz5type of surface/ramp to calculated, linear by default)r   defaultchoicesr   -ooutputzoutput name for ramp+noise data)r   r   r   r   --ramp_file	ramp_filezestimated ramp data)r   r   r   --outdiroutdirzoutput file dir)argparseArgumentParserRawTextHelpFormatterEXAMPLEadd_argumentstrr   )parser r&   R/home/exouser/operations/rsmas_insar/tools/MimtPy/mimtpy/gridsearch_ramps_relax.pycreate_parser   s*   
r(   c                 C   s   t  }|j| d}|S )N)args)r(   
parse_args)iargsr%   inpsr&   r&   r'   cmd_line_parse8   s   r-   c                 C   s   | j d }| jd }| j}| jd }| jd }| jd }||d|dd|d|d|d| jd g}t|}t	d| t	d	|  t	d
|  t
j|  ||fS ).subtract forward model data from observed datar   r   z--rampr   z-mr   r   subtract_h5.pyzramp_noise file is: %szestimated ramp file is: %s)r	   r   r   r   r   r   r   museperate_str_byspaceprintmimtpysubtract_h5mainsplit)r,   observed_file	mask_file	ramp_typer   ramp_noise_file
model_filescp_argsr&   r&   r'   calculate_ramp_noise>   s   




$

r=   c                 C   sx   | j d dd d }t| jd | d }t| jd | \}}|| }td|  tj|| jd | |d dS )zLcalculate residual data which is observed data - model data - estimated rampr   Nz_residual.h5zHthe residual file after subtracting model data and estimated ramp is: %s)out_filemetadata)r   r   readr   r2   r   write)r,   r:   r   residual_fileZramp_noise_dataZ	ramp_dataatrresidualr&   r&   r'   calculate_residualQ   s   rF   c           	      C   s   t | }td |jr$td t|\}}td td t||| n;td |jd }|jd }|jd d d d }|jd }||d|d	|jd g}t	
|}td
| tj|  td d S )Nz3--------------------------------------------------
r.   z-calculate residual data with estimating rampsz/calculate residual data without estimating rampr   r>   z_residual_noramp.h5r   r   r/   zfinish!)r-   r2   r   r=   rF   r	   r   r   r   r0   r1   r3   r4   r5   r6   )	r+   r,   r   r:   r7   r8   rC   r;   r<   r&   r&   r'   r5   `   s$   




r5   __main__)N)osr   numpynpmintpymintpy.objectsr   mintpy.utilsr   r   r3   mimtpy.workflowmimtpy.utilsr   r0   r"   r(   r-   r=   rF   r5   __name__r&   r&   r&   r'   <module>   s$   


