yatsm.utils module

yatsm.utils.copy_dict_filter_key(d, regex)[source]

Copy a dict recursively, but only if key doesn’t match regex pattern

yatsm.utils.csvfile_to_dataframe(input_file, date_format='%Y%j')[source]

Return sorted filenames of images from input text file

Parameters:
  • input_file – text file of dates and files
  • date_format – format of dates in file
Returns:

pd.DataFrame of dates, sensor IDs, and filenames

Return type:

pd.DataFrame

yatsm.utils.date2index(dates, d)[source]

Returns index of sorted array dates containing the date d

Parameters:
  • dates – array of dates (or numbers really) in sorted order
  • d – number to search for
Returns:

index of dates containing value d

Return type:

int

yatsm.utils.distribute_jobs(job_number, total_jobs, n, interlaced=True)[source]

Assign job_number out of total_jobs a subset of n tasks

Parameters:
  • job_number – 0-indexed processor to distribute jobs to
  • total_jobs – total number of processors running jobs
  • n – number of tasks (e.g., lines in image, regions in segment)
  • interlaced – interlace job assignment (default: True)
Returns:

np.ndarray of task IDs to be processed

Return type:

np.ndarray

Raises:

ValueError – raise error if job_number and total_jobs specified result in no jobs being assinged (happens if job_number and total_jobs are both 1)

yatsm.utils.find_results(location, pattern)[source]

Create list of result files and return sorted

Parameters:
  • location – directory location to search
  • pattern – glob style search pattern for results
Returns:

list of file paths for results found

Return type:

results (list)

yatsm.utils.get_image_IDs(filenames)[source]

Returns image IDs for each filename (basename of dirname of file)

Parameters:filenames – filenames to return image IDs for
Returns:image IDs for each file in filenames
Return type:list
yatsm.utils.get_output_name(dataset_config, line)[source]

Returns output name for specified config and line number

Parameters:
  • dataset_config – configuration information about the dataset
  • line – line of the dataset for output
Returns:

output filename

Return type:

filename (str)

yatsm.utils.is_integer(s)[source]

Returns True if s is an integer

yatsm.utils.iter_records(records, warn_on_empty=False, yield_filename=False)[source]

Iterates over records, returning result NumPy array

Parameters:
  • records – List containing filenames of results
  • warn_on_empty – Log warning if result contained no result records (default: False)
  • yield_filename – Yield the filename and the record
Yields:

np.ndarray or tuple – Result saved in record and the filename, if desired

yatsm.utils.write_output(raster, output, image_ds, gdal_frmt, ndv, band_names=None)[source]

Write raster to output file