# Path: rlvision/utils.py
# def load_grid_selection(path):
# def process_map_data(path, return_full=False):
# def mask_grid(pos, grid, radius, one_is_free=True):
# def accumulate_map(source_grid, new_grid, one_is_free=True):
# def plot_grid(data, imsize, start=None, pos=None, goal=None, title=None):
# def process_gridworld_data(data_in, imsize):
# def load_mat_data(file_path):
# def find_layout(data, verbose=0):
# def init_h5_db(db_name, save_dir):
# def add_h5_group(group_name, db, db_path=None):
# def add_h5_ds(data, ds_name, db, group_name=None, data_type=np.uint8,
#               renew=False):
# def create_grid_8_dataset(mat_file_path, db_name, save_dir):
# def create_ds_from_splits(mat_file_prefix, db, splits):
# def create_grid_16_dataset(mat_file_prefix, db_name, save_dir, splits=5):
# def create_grid_28_dataset(mat_file_prefix, db_name, save_dir, splits=20):
# def create_grid_40_dataset(mat_file_prefix, db_name, save_dir, splits=100):
# def load_grid8(return_imsize=True):
# def load_grid16(split=None, return_imsize=True):
# def load_grid28(split=None, return_imsize=True):
# def load_grid40(split=None, return_imsize=True):


import os
import numpy as np
import rlvision
from rlvision import utils
"""Load selected grid."""



# load file
file_path = os.path.join(
        rlvision.RLVISION_MODEL, "grid28_paths",
        "grid_28_77_bad.pkl")

grid, gt_path, po_path, goal = utils.load_grid_selection(file_path)

gt = []
for idx in xrange(gt_path.shape[0]):
    gt.append((gt_path[idx, 0], gt_path[idx, 1]))

# plot grid
utils.plot_grid(1-grid, (28, 28),
                start=po_path[0],
                pos=gt[1:],
                goal=goal)

# plot po grid
step_map = np.ones((28, 28))
path = [po_path[0]]
for step in xrange(1, len(po_path)):
    masked_img = utils.mask_grid((path[-1][1], path[-1][0]),
                                 grid, 3, one_is_free=False)

# Path: rlvision/utils.py
# def load_grid_selection(path):
# def process_map_data(path, return_full=False):
# def mask_grid(pos, grid, radius, one_is_free=True):
# def accumulate_map(source_grid, new_grid, one_is_free=True):
# def plot_grid(data, imsize, start=None, pos=None, goal=None, title=None):
# def process_gridworld_data(data_in, imsize):
# def load_mat_data(file_path):
# def find_layout(data, verbose=0):
# def init_h5_db(db_name, save_dir):
# def add_h5_group(group_name, db, db_path=None):
# def add_h5_ds(data, ds_name, db, group_name=None, data_type=np.uint8,
#               renew=False):
# def create_grid_8_dataset(mat_file_path, db_name, save_dir):
# def create_ds_from_splits(mat_file_prefix, db, splits):
# def create_grid_16_dataset(mat_file_prefix, db_name, save_dir, splits=5):
# def create_grid_28_dataset(mat_file_prefix, db_name, save_dir, splits=20):
# def create_grid_40_dataset(mat_file_prefix, db_name, save_dir, splits=100):
# def load_grid8(return_imsize=True):
# def load_grid16(split=None, return_imsize=True):
# def load_grid28(split=None, return_imsize=True):
# def load_grid40(split=None, return_imsize=True):


# Path: rlvision/tests/load_selected_grid.py
import os
import numpy as np
import rlvision
from rlvision import utils

"""Load selected grid."""



# load file
file_path = os.path.join(
        rlvision.RLVISION_MODEL, "grid28_paths",
        "grid_28_77_bad.pkl")

grid, gt_path, po_path, goal = utils.load_grid_selection(file_path)

gt = []
for idx in xrange(gt_path.shape[0]):
    gt.append((gt_path[idx, 0], gt_path[idx, 1]))

# plot grid
utils.plot_grid(1-grid, (28, 28),
                start=po_path[0],
                pos=gt[1:],
                goal=goal)

# plot po grid
step_map = np.ones((28, 28))
path = [po_path[0]]
for step in xrange(1, len(po_path)):
    masked_img = utils.mask_grid((path[-1][1], path[-1][0]),
                                 grid, 3, one_is_free=False)

    step_map = utils.accumulate_map(step_map, masked_img,