# Path: s2p/common.py
# def remove(target):
# def garbage_cleanup():
# def tmpfile(ext=''):
# def run(cmd, env=os.environ):
# def mkdir_p(path):
# def shellquote(s):
# def matrix_translation(x, y):
# def image_size_gdal(im):
# def gdal_read_as_array_with_nans(im):
# def image_zoom_out_morpho(im, f):
# def rasterio_write(path, array, profile={}, tags={}):
# def image_apply_homography(out, im, H, w, h):
# def image_qauto(im, out=None):
# def points_apply_homography(H, pts):
# def bounding_box2D(pts):
# def image_crop_gdal(im, x, y, w, h, out=None):
# def run_binary_on_list_of_points(points, binary, option=None, env_var=None):
# def get_rectangle_coordinates(im):
# def get_roi_coordinates(img, preview):
# def cargarse_basura(inputf, outputf):
# def print_elapsed_time(since_first_call=False):
# class RunFailure(Exception):


import os
import json
import argparse
import s2p
from s2p import common
        vrt_basename = vrt_basename[:-3]+'vrt'
    elif output_format !='vrt':
        print('Error: only vrt or tif extension is allowed for output image.')
        return

    vrt_name = os.path.join(outfile_dirname,vrt_basename)

    # Read the tiles file
    tiles = s2p.read_tiles(tiles_file)

    print(str(len(tiles))+' tiles found')

    # Compute the global extent of the output image
    (min_x,max_x,min_y,max_y) = global_extent(tiles)

    print('Global extent: [%i,%i]x[%i,%i]'%(min_x,max_x,min_y,max_y))

    # Now, write all row vrts
    print("Writing row vrt files "+vrt_basename)
    vrt_row = write_row_vrts(tiles,sub_img,vrt_basename,min_x,max_x)

    # Finally, write main vrt
    print('Writing '+vrt_name)
    write_main_vrt(vrt_row,vrt_name,min_x,max_x,min_y,max_y)

    # If Output format is tif, convert vrt file to tif
    if output_format == 'tif':
        print('Converting vrt to tif ...')
        common.run(('gdal_translate -ot Float32 -co TILED=YES -co'
                    ' BIGTIFF=IF_NEEDED %s %s'

# Path: s2p/common.py
# def remove(target):
# def garbage_cleanup():
# def tmpfile(ext=''):
# def run(cmd, env=os.environ):
# def mkdir_p(path):
# def shellquote(s):
# def matrix_translation(x, y):
# def image_size_gdal(im):
# def gdal_read_as_array_with_nans(im):
# def image_zoom_out_morpho(im, f):
# def rasterio_write(path, array, profile={}, tags={}):
# def image_apply_homography(out, im, H, w, h):
# def image_qauto(im, out=None):
# def points_apply_homography(H, pts):
# def bounding_box2D(pts):
# def image_crop_gdal(im, x, y, w, h, out=None):
# def run_binary_on_list_of_points(points, binary, option=None, env_var=None):
# def get_rectangle_coordinates(im):
# def get_roi_coordinates(img, preview):
# def cargarse_basura(inputf, outputf):
# def print_elapsed_time(since_first_call=False):
# class RunFailure(Exception):


# Path: utils/s2p_mosaic.py
import os
import json
import argparse
import s2p
from s2p import common

        vrt_basename = vrt_basename[:-3]+'vrt'
    elif output_format !='vrt':
        print('Error: only vrt or tif extension is allowed for output image.')
        return

    vrt_name = os.path.join(outfile_dirname,vrt_basename)

    # Read the tiles file
    tiles = s2p.read_tiles(tiles_file)

    print(str(len(tiles))+' tiles found')

    # Compute the global extent of the output image
    (min_x,max_x,min_y,max_y) = global_extent(tiles)

    print('Global extent: [%i,%i]x[%i,%i]'%(min_x,max_x,min_y,max_y))

    # Now, write all row vrts
    print("Writing row vrt files "+vrt_basename)
    vrt_row = write_row_vrts(tiles,sub_img,vrt_basename,min_x,max_x)

    # Finally, write main vrt
    print('Writing '+vrt_name)
    write_main_vrt(vrt_row,vrt_name,min_x,max_x,min_y,max_y)

    # If Output format is tif, convert vrt file to tif
    if output_format == 'tif':
        print('Converting vrt to tif ...')
        common.run(('gdal_translate -ot Float32 -co TILED=YES -co'
                    ' BIGTIFF=IF_NEEDED %s %s'

                    %(common.shellquote(vrt_name),common.shellquote(outfile))))