original_docstring: 
      Mosaics all images in every subfolder in the parent folder. Writes output to the parent folder. Also generates derivatives
  
      Args:
          parent: the parent directory
          cut_fol: where to copy cuts to (defunct)
          shpf: shapefile to cut with (defunct)
          spatial_ref: EPSG code
          path_to_gdal: the path to you GDAL bin
  
      Returns:
          None
  
      
docstring: Mosaics all images in every subfolder in the parent folder. Writes output to the parent folder. Also generates derivatives
docstring_tokens: Mosaics all images in every subfolder in the parent folder . Writes output to the parent folder . Also generates derivatives
code: def mosaic_folders(parent, cut_fol, shpf, spatial_ref, path_to_gdal=r'C:\OSGeo4W64\bin'):
      """
      Mosaics all images in every subfolder in the parent folder. Writes output to the parent folder. Also generates derivatives
  
      Args:
          parent: the parent directory
          cut_fol: where to copy cuts to (defunct)
          shpf: shapefile to cut with (defunct)
          spatial_ref: EPSG code
          path_to_gdal: the path to you GDAL bin
  
      Returns:
          None
  
      """
      wd = os.getcwd()
      subs = [f.name for f in os.scandir(parent) if f.is_dir()]
  
      if not isinstance(subs, list):
          subs = [subs]
      n_subs = len(subs)
  
      start = time.time()
      for i,sub in enumerate(subs):
          intermediate1 = time.time()
          print(f'Mosaicing {sub}')
  
          current = os.path.join(parent,sub)
          os.chdir(current)
          files = os.listdir()
          pairs = []
          out_loc = os.path.join(parent,f'{sub}.tif')
  
          if not os.path.exists(out_loc):
              try:
                  for j, f in enumerate(files):
                      os.rename(f, f'{j}.tif')
                      pairs.append((f, f'{j}.tif'))
  
                  wild = glob.glob('*.tif')
                  files_string = " ".join(wild)
                  gdal_merge = os.path.join(path_to_gdal, 'gdal_merge.py')
  
                  mosaic_command = f"{gdal_merge} -o {out_loc} -a_nodata -9999 -of gtiff " + files_string
                  print(f'Run mosaic command: {mosaic_command}')
                  os.system(mosaic_command)
  
                  """
                  #add spatial ref
                  gdal_edit = os.path.join(path_to_gdal, 'gdal_edit.py')
                  edit_command = f'{gdal_edit} -a_srs EPSG:{spatial_ref} {out_loc}'
                  print(f'Run edit command: {edit_command}')
                  os.system(edit_command)
  
                  # calculate stats
                  stat_command = f'gdalinfo -stats {out_loc}'
                  print(f'Run stats command: {stat_command}')
                  os.system(stat_command)
                  """
  
                  for previous, current in pairs:
                      os.rename(current, previous)
  
              except KeyboardInterrupt:
                  print(f'Keyboard interruption. Repairing file names before termination.')
                  for previous, current in pairs:
                      os.rename(current, previous)
          else:
              print(f'{out_loc} exists. Skipping mosaic....')
  
          intermediate2 = time.time()
          intermediate_elap = round(intermediate2-intermediate1, 2) # in seconds
          running_time = round(intermediate2-start, 2)/60 # in minutes
          frac_progress = (i+1)/n_subs
          estimated_total_time = round(running_time*(1/frac_progress) - running_time, 2)
  
          print(f'Processing time: {intermediate_elap} seconds. Folder {i+1} of {n_subs} complete. Estimated time remaining: '
                f'{estimated_total_time} minutes')
  
  
      big_derivs(parent)
  
      messed_up_dighe_ref = os.path.join(parent, 'dighe.tif.aux.xml')
      #print(messed_up_dighe_ref)
      if os.path.exists(messed_up_dighe_ref):
          os.remove(messed_up_dighe_ref)
  
      calc_stats_and_ref(parent, spatial_ref, path_to_gdal)
  
      final = time.time()
      elap = round(final-start, 2)
      print(f'FINISHED. Elapsed time: {elap/60} minutes')
      os.chdir(wd)
code_tokens: def mosaic_folders ( parent , cut_fol , shpf , spatial_ref , path_to_gdal = r'C:\OSGeo4W64\bin' ) : wd = os . getcwd ( ) subs = [ f . name for f in os . scandir ( parent ) if f . is_dir ( ) ] if not isinstance ( subs , list ) : subs = [ subs ] n_subs = len ( subs ) start = time . time ( ) for i , sub in enumerate ( subs ) : intermediate1 = time . time ( ) print ( f'Mosaicing {sub}' ) current = os . path . join ( parent , sub ) os . chdir ( current ) files = os . listdir ( ) pairs = [ ] out_loc = os . path . join ( parent , f'{sub}.tif' ) if not os . path . exists ( out_loc ) : try : for j , f in enumerate ( files ) : os . rename ( f , f'{j}.tif' ) pairs . append ( ( f , f'{j}.tif' ) ) wild = glob . glob ( '*.tif' ) files_string = " " . join ( wild ) gdal_merge = os . path . join ( path_to_gdal , 'gdal_merge.py' ) mosaic_command = f"{gdal_merge} -o {out_loc} -a_nodata -9999 -of gtiff " + files_string print ( f'Run mosaic command: {mosaic_command}' ) os . system ( mosaic_command ) """
                  #add spatial ref
                  gdal_edit = os.path.join(path_to_gdal, 'gdal_edit.py')
                  edit_command = f'{gdal_edit} -a_srs EPSG:{spatial_ref} {out_loc}'
                  print(f'Run edit command: {edit_command}')
                  os.system(edit_command)
  
                  # calculate stats
                  stat_command = f'gdalinfo -stats {out_loc}'
                  print(f'Run stats command: {stat_command}')
                  os.system(stat_command)
                  """ for previous , current in pairs : os . rename ( current , previous ) except KeyboardInterrupt : print ( f'Keyboard interruption. Repairing file names before termination.' ) for previous , current in pairs : os . rename ( current , previous ) else : print ( f'{out_loc} exists. Skipping mosaic....' ) intermediate2 = time . time ( ) intermediate_elap = round ( intermediate2 - intermediate1 , 2 ) running_time = round ( intermediate2 - start , 2 ) / 60 frac_progress = ( i + 1 ) / n_subs estimated_total_time = round ( running_time * ( 1 / frac_progress ) - running_time , 2 ) print ( f'Processing time: {intermediate_elap} seconds. Folder {i+1} of {n_subs} complete. Estimated time remaining: ' f'{estimated_total_time} minutes' ) big_derivs ( parent ) messed_up_dighe_ref = os . path . join ( parent , 'dighe.tif.aux.xml' ) if os . path . exists ( messed_up_dighe_ref ) : os . remove ( messed_up_dighe_ref ) calc_stats_and_ref ( parent , spatial_ref , path_to_gdal ) final = time . time ( ) elap = round ( final - start , 2 ) print ( f'FINISHED. Elapsed time: {elap/60} minutes' ) os . chdir ( wd )
short_docstring: Mosaics all images in every subfolder in the parent folder.
short_docstring_tokens: Mosaics all images in every subfolder in the parent folder .
comment: """
      Mosaics all images in every subfolder in the parent folder. Writes output to the parent folder. Also generates derivatives
  
      Args:
          parent: the parent directory
          cut_fol: where to copy cuts to (defunct)
          shpf: shapefile to cut with (defunct)
          spatial_ref: EPSG code
          path_to_gdal: the path to you GDAL bin
  
      Returns:
          None
  
      """$SEP$"""
                  #add spatial ref
                  gdal_edit = os.path.join(path_to_gdal, 'gdal_edit.py')
                  edit_command = f'{gdal_edit} -a_srs EPSG:{spatial_ref} {out_loc}'
                  print(f'Run edit command: {edit_command}')
                  os.system(edit_command)
  
                  # calculate stats
                  stat_command = f'gdalinfo -stats {out_loc}'
                  print(f'Run stats command: {stat_command}')
                  os.system(stat_command)
                  """$SEP$# in seconds$SEP$# in minutes$SEP$#print(messed_up_dighe_ref)