Ejemplo n.º 1
0
def post_process_detailed_3di(full_path):
    """
    Make detailed images using a 0.5m height map.
    """
    print 'post processing %s...' % full_path
    data = Data(full_path)  # NetCDF data

    # TODO: Find out which AHN tiles

    for timestep in range(data.num_timesteps):
        print('Working on timestep %d...' % timestep)

        ma_3di = data.to_masked_array(data.depth, timestep)
        ds_3di = to_dataset(ma_3di, data.geotransform)
        # testing
        ahn_indices = models.AhnIndex.get_ahn_indices(ds_3di)
        print ahn_indices
        for ahn_index in ahn_indices:
            print 'reading ahn data... %s' % ahn_index
            ahn_index.get_ds()

        filename_base = '_step%d' % timestep

        cdict = {
            'red': ((0.0, 51./256, 51./256),
                    (0.5, 237./256, 237./256),
                    (1.0, 83./256, 83./256)),
            'green': ((0.0, 114./256, 114./256),
                      (0.5, 245./256, 245./256),
                      (1.0, 83./256, 83./256)),
            'blue': ((0.0, 54./256, 54./256),
                     (0.5, 170./256, 170./256),
                     (1.0, 83./256, 83./256)),
            }
        colormap = mpl.colors.LinearSegmentedColormap('something', cdict, N=1024)

        min_value, max_value = 0.0, 4.0
        normalize = mpl.colors.Normalize(vmin=min_value, vmax=max_value)
        rgba = colormap(normalize(ma_3di), bytes=True)
        #rgba[:,:,3] = np.where(rgba[:,:,0], 153 , 0)

        Image.fromarray(rgba).save(filename_base + '.png', 'PNG')
Ejemplo n.º 2
0
def post_process_3di(full_path):
    """
    Simple version: do not use AHN tiles to do the calculation

    This method is quite fast, but the result has squares.
    """
    print 'post processing %s...' % full_path
    data = Data(full_path)  # NetCDF data
    #process_3di_nc(full_path)

    # TODO: Find out which AHN tiles

    for timestep in range(data.num_timesteps):
        print('Working on timestep %d...' % timestep)

        ma_3di = data.to_masked_array(data.depth, timestep)
        ds_3di = to_dataset(ma_3di, data.geotransform)
        # testing
        #print ', '.join([i.bladnr for i in get_ahn_indices(ds_3di)])

        filename_base = '_step%d' % timestep

        cdict = {
            'red': ((0.0, 51./256, 51./256),
                    (0.5, 237./256, 237./256),
                    (1.0, 83./256, 83./256)),
            'green': ((0.0, 114./256, 114./256),
                      (0.5, 245./256, 245./256),
                      (1.0, 83./256, 83./256)),
            'blue': ((0.0, 54./256, 54./256),
                     (0.5, 170./256, 170./256),
                     (1.0, 83./256, 83./256)),
            }
        colormap = mpl.colors.LinearSegmentedColormap('something', cdict, N=1024)

        min_value, max_value = 0.0, 4.0
        normalize = mpl.colors.Normalize(vmin=min_value, vmax=max_value)
        rgba = colormap(normalize(ma_3di), bytes=True)
        #rgba[:,:,3] = np.where(rgba[:,:,0], 153 , 0)

        Image.fromarray(rgba).save(filename_base + '.png', 'PNG')