def test_stats_dates(): # Winter for 1990 winter_1990 = list( date_sequence(start=to_datetime('1990-06-01'), end=to_datetime('1990-09-01'), step_size='3m', stats_duration='3m')) assert winter_1990 == [(parse('1990-06-01'), parse('1990-09-01'))] # Every winter from 1990 - 1992 three_years_of_winter = list( date_sequence(start=to_datetime('1990-06-01'), end=to_datetime('1992-09-01'), step_size='1y', stats_duration='3m')) assert three_years_of_winter == [ (parse('1990-06-01'), parse('1990-09-01')), (parse('1991-06-01'), parse('1991-09-01')), (parse('1992-06-01'), parse('1992-09-01')) ] # Full years from 1990 - 1994 five_full_years = list( date_sequence(start=to_datetime('1990-01-01'), end=to_datetime('1995'), step_size='1y', stats_duration='1y')) assert five_full_years == [(parse('1990-01-01'), parse('1991-01-01')), (parse('1991-01-01'), parse('1992-01-01')), (parse('1992-01-01'), parse('1993-01-01')), (parse('1993-01-01'), parse('1994-01-01')), (parse('1994-01-01'), parse('1995-01-01'))] # Every season (three months), starting in March, from 1990 until end 1992-02 two_years_of_seasons = list( date_sequence(start=to_datetime('1990-03-01'), end=to_datetime('1992-03'), step_size='3m', stats_duration='3m')) assert len(two_years_of_seasons) == 8 assert two_years_of_seasons == [(parse('1990-03-01'), parse('1990-06-01')), (parse('1990-06-01'), parse('1990-09-01')), (parse('1990-09-01'), parse('1990-12-01')), (parse('1990-12-01'), parse('1991-03-01')), (parse('1991-03-01'), parse('1991-06-01')), (parse('1991-06-01'), parse('1991-09-01')), (parse('1991-09-01'), parse('1991-12-01')), (parse('1991-12-01'), parse('1992-03-01')) ] # Leap year! # Every month from 1990-01 to 1990-06 monthly = list( date_sequence(start=to_datetime('1990-01-01'), end=to_datetime('1990-07-01'), step_size='1m', stats_duration='1m')) assert len(monthly) == 6
def test_date_sequence(start_end, stats_duration, step_size): start, end = start_end sequence = date_sequence(start, end, stats_duration, step_size) assert iter(sequence) == sequence all_ranges = list(sequence) assert all(s < e for s, e in all_ranges)
def main(bounds, base_output_name, load_bounds_from, start_date, end_date, product, measurement, executor, step_size, stats_duration, time_incr, ffmpeg_path, crs): """ Create an mp4 movie file based on datacube data Use only clear pixels, and mosaic over time to produce full frames. Can combine products, specify multiple --product """ if load_bounds_from: crs, (left, bottom, right, top) = bounds_from_file(load_bounds_from) elif bounds: left, bottom, right, top = bounds else: raise click.UsageError('Must specify one of --load-bounds-from or --bounds') tasks = [] for filenum, date_range in enumerate(date_sequence(start_date, end_date, stats_duration, step_size), start=1): filename = "{}_{:03d}_{:%Y-%m-%d}.png".format(base_output_name, filenum, start_date) task = dict(filename=filename, products=product, time=date_range, x=(left, right), y=(top, bottom), crs=crs, measurements=measurement) tasks.append(task) results = [] for task in tasks: result_future = executor.submit(write_mosaic_to_file, **task) results.append(result_future) filenames = [] for result in executor.as_completed(results): filenames.append(executor.result(result)) # Write subtitle file subtitle_filename = "{}.srt".format(base_output_name) write_subtitle_file(tasks, subtitle_filename=subtitle_filename, display_format=SUBTITLE_FORMAT, time_incr=time_incr) # Write video file filenames_pattern = '%s*.png' % base_output_name video_filename = "{}.mp4".format(base_output_name) write_video_file(filenames_pattern, video_filename, subtitle_filename, time_incr=time_incr, ffmpeg_path=ffmpeg_path) click.echo("Finished!")