# Path: ldif/util/base_util.py
# ENVIRONMENT = 'EXTERNAL'
#   FS = StandardFileSystem()
#   LOG = SimpleLog()
# class FileSystem(abc.ABC):
# class StandardFileSystem(FileSystem):
# class Log(abc.ABC):
# class SimpleLog(Log):
#   def open(self, filename, mode):
#   def mkdir(self, path, exist_ok=False):
#   def makedirs(self, path, exist_ok=False):
#   def glob(self, path):
#   def exists(self, path):
#   def cp(self, from_path, to_path):
#   def rm(self, path):
#   def mkdir(self, path, exist_ok=False):
#   def makedirs(self, path, exist_ok=False):
#   def open(self, *args):
#   def glob(self, *args):
#   def exists(self, *args):
#   def cp(self, *args):
#   def rm(self, *args):
#   def log(self, msg, level='info'):
#   def levels(self):
#   def level_index(self, level):
#   def __init__(self):
#   def log(self, msg, level='info'):
#   def verbose(self, msg):
#   def info(self, msg):
#   def warning(self, msg):
#   def error(self, msg):
#   def set_level(self, level):
# 
# Path: ldif/util/mesh_util.py
# def serialize(mesh):
# def deserialize(mesh_str):
# def remove_small_components(mesh, min_volume=5e-05):


import os
import pickle
import struct
import numpy as np
import pandas as pd
from PIL import Image
from ldif.util import base_util
from ldif.util import mesh_util
  if p[-4:] != '.npy':
    raise ValueError(f'Expected .npy ending for file {p}.')
  with base_util.FS.open(p, 'rb') as f:
    arr = np.load(f)
  return arr


def read_txt_to_np(p):
  with base_util.FS.open(p, 'rt') as f:
    return np.loadtxt(f)


def read_py2_pkl(p):
  if p[-4:] != '.pkl':
    raise ValueError(f'Expected .pkl ending for file {p}.')
  with base_util.FS.open(p, 'rb') as f:
    # pkl = dict(np.load(f, allow_pickle=True))
    pkl = pickle.load(f, encoding='latin1')
  return pkl


def write_mesh(path, mesh):
  mesh_str = mesh_util.serialize(mesh)
  with base_util.FS.open(path, 'wb') as f:
    f.write(mesh_str)


def read_mesh(path):
  with base_util.FS.open(path, 'rb') as f:
    mesh_str = f.read()

# Path: ldif/util/base_util.py
# ENVIRONMENT = 'EXTERNAL'
#   FS = StandardFileSystem()
#   LOG = SimpleLog()
# class FileSystem(abc.ABC):
# class StandardFileSystem(FileSystem):
# class Log(abc.ABC):
# class SimpleLog(Log):
#   def open(self, filename, mode):
#   def mkdir(self, path, exist_ok=False):
#   def makedirs(self, path, exist_ok=False):
#   def glob(self, path):
#   def exists(self, path):
#   def cp(self, from_path, to_path):
#   def rm(self, path):
#   def mkdir(self, path, exist_ok=False):
#   def makedirs(self, path, exist_ok=False):
#   def open(self, *args):
#   def glob(self, *args):
#   def exists(self, *args):
#   def cp(self, *args):
#   def rm(self, *args):
#   def log(self, msg, level='info'):
#   def levels(self):
#   def level_index(self, level):
#   def __init__(self):
#   def log(self, msg, level='info'):
#   def verbose(self, msg):
#   def info(self, msg):
#   def warning(self, msg):
#   def error(self, msg):
#   def set_level(self, level):
# 
# Path: ldif/util/mesh_util.py
# def serialize(mesh):
# def deserialize(mesh_str):
# def remove_small_components(mesh, min_volume=5e-05):


# Path: ldif/util/file_util.py
import os
import pickle
import struct
import numpy as np
import pandas as pd
from PIL import Image
from ldif.util import base_util
from ldif.util import mesh_util

  if p[-4:] != '.npy':
    raise ValueError(f'Expected .npy ending for file {p}.')
  with base_util.FS.open(p, 'rb') as f:
    arr = np.load(f)
  return arr


def read_txt_to_np(p):
  with base_util.FS.open(p, 'rt') as f:
    return np.loadtxt(f)


def read_py2_pkl(p):
  if p[-4:] != '.pkl':
    raise ValueError(f'Expected .pkl ending for file {p}.')
  with base_util.FS.open(p, 'rb') as f:
    # pkl = dict(np.load(f, allow_pickle=True))
    pkl = pickle.load(f, encoding='latin1')
  return pkl


def write_mesh(path, mesh):
  mesh_str = mesh_util.serialize(mesh)
  with base_util.FS.open(path, 'wb') as f:
    f.write(mesh_str)


def read_mesh(path):
  with base_util.FS.open(path, 'rb') as f:
    mesh_str = f.read()

  return mesh_util.deserialize(mesh_str)