def main(args): """ Test input and pass to appropriate functions """ ### Produce output specified try: image_ds = gdal.Open(args["image"], gdal.GA_ReadOnly) except: logger.error("Could not open example image for reading") raise band_names = None if args["class"]: raster, band_names = get_classification( args["date"], args["results"], image_ds, after=args["after"], before=args["before"], qa=args["qa"], pred_proba=args["pred_proba"], ) elif args["coef"]: raster, band_names = get_coefficients( args["date"], args["results"], image_ds, args["bands"], args["coefs"], use_robust=args["use_robust"], amplitude=args["amplitude"], after=args["after"], before=args["before"], qa=args["qa"], ndv=args["ndv"], ) elif args["predict"]: raster, band_names = get_prediction( args["date"], args["results"], image_ds, args["bands"], use_robust=args["use_robust"], after=args["after"], before=args["before"], qa=args["qa"], ndv=args["ndv"], ) elif args["pheno"]: raster, band_names = get_phenology( args["date"], args["results"], image_ds, after=args["after"], before=args["before"], qa=args["qa"], ndv=args["ndv"], ) write_output(raster, args["output"], image_ds, args["gdal_frmt"], args["ndv"], band_names) image_ds = None
def main(args): """ Test input and pass to appropriate functions """ ### Produce output specified try: image_ds = gdal.Open(args['image'], gdal.GA_ReadOnly) except: logger.error('Could not open example image for reading') raise band_names = None if args['class']: raster, band_names = get_classification(args['date'], args['results'], image_ds, after=args['after'], before=args['before'], qa=args['qa'], pred_proba=args['pred_proba']) elif args['coef']: raster, band_names = get_coefficients(args['date'], args['results'], image_ds, args['bands'], args['coefs'], use_robust=args['use_robust'], amplitude=args['amplitude'], after=args['after'], before=args['before'], qa=args['qa'], ndv=args['ndv']) elif args['predict']: raster, band_names = get_prediction(args['date'], args['results'], image_ds, args['bands'], use_robust=args['use_robust'], after=args['after'], before=args['before'], qa=args['qa'], ndv=args['ndv']) elif args['pheno']: raster, band_names = get_phenology(args['date'], args['results'], image_ds, after=args['after'], before=args['before'], qa=args['qa'], ndv=args['ndv']) write_output(raster, args['output'], image_ds, args['gdal_frmt'], args['ndv'], band_names) image_ds = None
def changemap(ctx, map_type, start_date, end_date, output, root, result, image, date_frmt, ndv, gdal_frmt, out_date_frmt, warn_on_empty, magnitude): """ Examples: TODO """ gdal_frmt = str(gdal_frmt) # GDAL GetDriverByName doesn't work on Unicode frmt = '%Y%j' start_txt, end_txt = start_date.strftime(frmt), end_date.strftime(frmt) start_date, end_date = start_date.toordinal(), end_date.toordinal() try: image_ds = gdal.Open(image, gdal.GA_ReadOnly) except: logger.error('Could not open example image for reading') raise if map_type in ('first', 'last'): changemap, magnitudemap, magnitude_indices = get_datechangemap( start_date, end_date, result, image_ds, first=map_type == 'first', out_format=out_date_frmt, magnitude=magnitude, ndv=ndv, pattern=_result_record ) band_names = ['ChangeDate_s{s}-e{e}'.format(s=start_txt, e=end_txt)] write_output(changemap, output, image_ds, gdal_frmt, ndv, band_names=band_names) if magnitudemap is not None: band_names = (['Magnitude Index {}'.format(i) for i in magnitude_indices]) name, ext = os.path.splitext(output) output = name + '_mag' + ext write_output(magnitudemap, output, image_ds, gdal_frmt, ndv, band_names=band_names) elif map_type == 'num': changemap = get_numchangemap( start_date, end_date, result, image_ds, ndv=ndv, pattern=_result_record ) band_names = ['NumChanges_s{s}-e{e}'.format(s=start_txt, e=end_txt)] write_output(changemap, output, image_ds, gdal_frmt, ndv, band_names=band_names) image_ds = None
def main(args): """ Make change maps from parsed user inputs """ ### Make map try: image_ds = gdal.Open(args['image'], gdal.GA_ReadOnly) except: logger.error('Could not open example image for reading') raise start_txt = dt.fromordinal(args['start']).strftime('%Y%j') end_txt = dt.fromordinal(args['end']).strftime('%Y%j') # Make map of date of change if args['first'] or args['last']: changemap, magnitudemap, magnitude_indices = get_datechangemap( args['start'], args['end'], args['results'], image_ds, first=args['first'], out_format=args['out_format'], magnitude=args['magnitude'], ndv=args['ndv'], pattern=_result_record ) band_names = ['ChangeDate_s{s}-e{e}'.format(s=start_txt, e=end_txt)] write_output(changemap, args['output'], image_ds, args['gdal_frmt'], args['ndv'], band_names=band_names) if magnitudemap is not None: band_names = (['Magnitude Index ' + str(i) for i in magnitude_indices]) name, ext = os.path.splitext(args['output']) output = name + '_mag' + ext write_output(magnitudemap, output, image_ds, args['gdal_frmt'], args['ndv'], band_names=band_names) elif args['num']: changemap = get_numchangemap( args['start'], args['end'], args['results'], image_ds, ndv=args['ndv'], pattern=_result_record ) band_names = ['NumChanges_s{s}-e{e}'.format(s=start_txt, e=end_txt)] write_output(changemap, args['output'], image_ds, args['gdal_frmt'], args['ndv'], band_names=band_names) image_ds = None
def main(args): """ Make change maps from parsed user inputs """ ### Make map try: image_ds = gdal.Open(args['image'], gdal.GA_ReadOnly) except: logger.error('Could not open example image for reading') raise start_txt = dt.fromordinal(args['start']).strftime('%Y%j') end_txt = dt.fromordinal(args['end']).strftime('%Y%j') # Make map of date of change if args['first'] or args['last']: changemap, magnitudemap, magnitude_indices = get_datechangemap( args['start'], args['end'], args['results'], image_ds, first=args['first'], out_format=args['out_format'], magnitude=args['magnitude'], ndv=args['ndv'], pattern=_result_record) band_names = ['ChangeDate_s{s}-e{e}'.format(s=start_txt, e=end_txt)] write_output(changemap, args['output'], image_ds, args['gdal_frmt'], args['ndv'], band_names=band_names) if magnitudemap is not None: band_names = ([ 'Magnitude Index ' + str(i) for i in magnitude_indices ]) name, ext = os.path.splitext(args['output']) output = name + '_mag' + ext write_output(magnitudemap, output, image_ds, args['gdal_frmt'], args['ndv'], band_names=band_names) elif args['num']: changemap = get_numchangemap(args['start'], args['end'], args['results'], image_ds, ndv=args['ndv'], pattern=_result_record) band_names = ['NumChanges_s{s}-e{e}'.format(s=start_txt, e=end_txt)] write_output(changemap, args['output'], image_ds, args['gdal_frmt'], args['ndv'], band_names=band_names) image_ds = None
def map(ctx, map_type, date, output, root, result, image, date_frmt, ndv, gdal_frmt, warn_on_empty, band, coef, after, before, qa, refit_prefix, amplitude, predict_proba): """ Map types: coef, predict, class, pheno \b Map QA flags: - 1 => before - 2 => after - 3 => intersect \b Examples: > yatsm map --coef intercept --coef slope \ ... --band 3 --band 4 --band 5 --ndv -9999 \ ... coef 2000-01-01 coef_map.gtif > yatsm map -c intercept -c slope -b 3 -b 4 -b 5 --ndv -9999 \ ... coef 2000-01-01 coef_map.gtif > yatsm map --date "%Y-%j" predict 2000-001 prediction.gtif > yatsm map --result "YATSM_new" --after class 2000-01-01 LCmap.gtif Notes: - Image predictions will not use categorical information in timeseries models. """ try: image_ds = gdal.Open(image, gdal.GA_ReadOnly) except: logger.error('Could not open example image for reading') raise date = date.toordinal() # Append underscore to prefix if not included if refit_prefix and not refit_prefix.endswith('_'): refit_prefix += '_' band_names = None if map_type == 'class': raster, band_names = get_classification( date, result, image_ds, after=after, before=before, qa=qa, pred_proba=predict_proba ) elif map_type == 'coef': raster, band_names = get_coefficients( date, result, image_ds, band, coef, prefix=refit_prefix, amplitude=amplitude, after=after, before=before, qa=qa, ndv=ndv ) elif map_type == 'predict': raster, band_names = get_prediction( date, result, image_ds, band, prefix=refit_prefix, after=after, before=before, qa=qa, ndv=ndv ) elif map_type == 'pheno': raster, band_names = get_phenology( date, result, image_ds, after=after, before=before, qa=qa, ndv=ndv) write_output(raster, output, image_ds, gdal_frmt, ndv, band_names) image_ds = None