
    Zf                     n    d dl Z d dlmZ dZdZd
dZd
dZd
dZedk(  r ee j                  d	d        yy)    N)create_argument_parsera  template
## if both yx and lalo are specified, use lalo option unless a) no lookup file AND b) dataset is in radar coord
mintpy.subset.yx       = auto    #[1800:2000,700:800 / no], auto for no
mintpy.subset.lalo     = auto    #[31.5:32.5,130.5:131.0 / no], auto for no
au  example:
  subset.py inputs/ifgramStack.h5 -y 400  1500 -x 200   600
  subset.py geo_velocity.h5       -l 30.5 30.8 -L 130.3 130.9
  subset.py velocity.h5   --lat 25.894 25.896  --lon -80.124 -80.122
  subset.py 030405_090801.unw     -t SinabungT495F50AlosA.template
  subset.py demLat*.dem.wgs84 --lat 32.5 33.0 --lon 130.2 130.6 -o srtm1.h5

  # subset to the same coverage as the reference file
  subset.py geo_incidence.h5 -r subset_geo_velocity.h5

  # multiple files input
  subset.py *velocity*.h5 timeseries*.h5  -y 400 1500  -x 200 600
  subset.py geometryRadar.h5 slcStack.h5  --lat 25.894 25.896  --lon -80.124 -80.122

  # crop to larger area with custom fill value
  subset.py geo_velocity.h5 -l 32.2 33.5  --outfill-nan
  subset.py Mask.h5 -x 500 3500 --outfill 0

  # "tight" subset for geocoded lookup table larger than data file
  subset.py geomap_4rlks.trans --tight
c           
         d}t         dz   t        z   }t        j                  d      d   }t	        |||||       }|j                  ddd	       |j                  d
dddt        dd       |j                  ddddt        dd       |j                  dddddt        dd       |j                  ddddd t        dd!       |j                  d"d#d$d%&       |j                  d'd(d)*       |j                  d+d,d-.       |j                  d/d0t        d12       |j                  d3d4d5d6&       |j                  d7d8      }|j                  d9d:d;&       |S )<Nz#Generate a subset from file/dataset
.)synopsisdescriptionepilog
subparsersfile+zFile(s) to subset/crop)nargshelpz-xz--sub-xz
--subset-xsubset_x   z.subset range in x/cross-track/column direction)desttyper   r   z-yz--sub-yz
--subset-ysubset_yz+subset range in y/along-track/row directionz-lz--latz	--sub-latz--subset-lat
subset_latzsubset range in latitudez-Lz--lonz	--sub-lonz--subset-lon
subset_lonzsubset range in column

z-tz
--templatetemplate_filez}template file with subset setting.  i.e. 
mintpy.subset.yx    = 300:800,1000:3500
mintpy.subset.lalo  = 30.2:30.5,130.1:131.3)r   r   z-rz--referencez9reference file, subset to the same lalo as reference file)r   z--tight
store_truezsubset geomap_*.trans file based on non-zero values.
For geocoded file(s) onlyA convenient way to get rid of extra wide space due to "too large" DEM.

)actionr   z	--outfill
fill_valuezyfill subset area out of data coverage with input value. i.e. 
np.nan, 0, 1000, ... 
By default, it's None for no-outfill.)r   r   r   z-oz--outputoutfilezloutput file name
add prefix "sub_" if input/output files are in the same directory;
same filename otherwise.DatasetszpCreate a subset of entire dataset in radar using y/x or lat/lon option
Including *.trans and *.dem in geo coord.z--lookuplookup_filezcalculate bounding box in geo/radar coord from input radar/geo subset range
using transformation file, i.e. geomap_4rlks.trans
All input radar coord file should be same size/coverage; same for all geo coord files.)	TEMPLATEEXAMPLE__name__splitr   add_argumentintfloatadd_argument_group)r   r   r
   nameparser
dset_groups         J/home/exouser/operations/rsmas_insar/tools/MintPy/src/mintpy/cli/subset.pycreate_parserr*   *   s   4H_w&F>>#r"D#xXfQ[]F c0HI Y|*3VWM  O
Y|*3VWJ  L
g{N"!2L  N
g{N"!2N  P lK  L mX  Z
	,k  l ,UE  F
 jy8  9
 **:,WXJ J]"z  { M    c                 H   t               }|j                  |       }ddlm} |j	                  |j
                        }t        |      dk(  rt        d|j
                   d      ||_        t        |j
                        dkD  r|j                  rd |_        t        d       |S )N)argsr   )utils1zNO file found in: !   z:WARNING: disable --output option for multiple input files.)
r*   
parse_argsmintpy.utilsr.   get_file_listr   lenFileNotFoundErrorr   print)iargsr'   inpsutflists        r)   cmd_line_parser;   ]   s    _F%(D * TYY'E
5zQ"4TYYKq ABBDI 499~dllJKKr+   c                     t        |       }ddlm}m}  ||      }|j                  D ]+  }t        d        ||t        |      |j                         - y )Nr   )read_aux_subset2inpssubset_filez------------------------------)out_file)r;   mintpy.subsetr=   r>   r   r6   varsr   )r7   r8   r=   r>   fnames        r)   mainrC   t   sL    % D @  %D >fE4:=>r+   __main__r0   )N)
sysmintpy.utils.arg_utilsr   r   r   r*   r;   rC   r    argv r+   r)   <module>rI      sL     9,0f.>  z!" r+   