Beispiel #1
0
def generate_from_inc(output_dir_name, inc_file, colormapobject):
    basename = os.path.basename(inc_file).replace('_', '')[:4]
    output_file = os.path.join(output_dir_name, basename + "{:04d}.png")

    inc = flshinc.Flsh(inc_file, one_per_hour=True)
    classes = inc.get_classes()
    geo_transform = inc.geo_transform()

    for i, (timestamp, grid) in enumerate(inc):
        real_filename = output_file.format(i)

        flshinc.save_grid_to_image(grid, real_filename, classes,
                                   colormapobject, geo_transform)

    return i + 1, basename
Beispiel #2
0
def process_flsh(flsh_path):
    flsh = flshinc.Flsh(flsh_path, one_per_hour=True)
    geo_transform = flsh.geo_transform()

    calculated_inundations = []

    for timestamp, grid in flsh:
        total_inundation_volume, total_inundated_area = (
            calculate_inundation_and_area(grid, geo_transform[1]))
        calculated_inundations.append({
            'timestamp': timestamp,
            'inundation_volume': total_inundation_volume,
            'inundated_area': total_inundated_area
        })
    flsh.f.close()
    del flsh

    return json.dumps(calculated_inundations)
def animation_from_inc(inc_file, output_dir, maxwaterdepth_geotransform,
                       use_to_compute_arrival_times, startmoment_hours):
    """Save each grid as a geotiff dataset so that images can be
    quickly created on the fly from it."""
    fls = flshinc.Flsh(inc_file,
                       one_per_hour=True,
                       mutate=False,
                       helper_geotransform=maxwaterdepth_geotransform)
    logger.debug("Generating animation from {}".format(inc_file))

    geotransform = fls.geo_transform()

    maxvalue = None

    gridta_gridtd_recorder = GridtaGridtdRecorder(output_dir, geotransform,
                                                  startmoment_hours)

    for i, (timestamp, array) in enumerate(fls):
        filename = b'dataset{:04d}.tiff'.format(i)
        filepath = os.path.join(output_dir, filename)
        logger.debug("Writing {}.".format(filepath))
        if i == 0:
            maxvalue = np.amax(array)
        else:
            maxvalue = max(maxvalue, np.amax(array))

        gridta_gridtd_recorder.register(i, array)

        save_to_tiff(filepath, array, geotransform)

    rows, cols = array.shape

    animation = pyramidmodels.Animation.objects.create(
        frames=i + 1,
        cols=cols,
        rows=rows,
        geotransform={'geotransform': geotransform},
        basedir=output_dir,
        maxvalue=maxvalue)

    if use_to_compute_arrival_times:
        gridta_gridtd_recorder.save()

    return animation