Commit da3988f9 authored by ssomnath's avatar ssomnath
Browse files

is_valid_file now more robust and returns file path instead of boolean

parent 9fd8a4cb
......@@ -8,6 +8,7 @@ Created on Tue Nov 3 15:24:12 2015
from __future__ import division, print_function, absolute_import, unicode_literals
from os import path, listdir, remove
import sys
from warnings import warn
import h5py
import numpy as np
......@@ -23,6 +24,9 @@ from pyUSID.io.hdf_utils import write_ind_val_dsets, write_main_dataset, write_r
from pyUSID.io.usi_data import USIDataset
from pyUSID.processing.comp_utils import get_available_memory
if sys.version_info.major == 3:
unicode = str
class BEodfTranslator(Translator):
"""
......@@ -39,37 +43,56 @@ class BEodfTranslator(Translator):
self.expt_type = None
@staticmethod
def is_valid_file(file_path):
def is_valid_file(data_path):
"""
Checks whether the provided file can be read by this translator
Parameters
----------
file_path : str
data_path : str
Path to raw data file
Returns
-------
bool : Whether or not this translator can read this file
obj : str
Path to file that will be accepted by the translate() function if
this translator is indeed capable of translating the provided file.
Otherwise, None will be returned
"""
file_path = path.abspath(file_path)
if not isinstance(data_path, (str, unicode)):
raise TypeError('data_path must be a string')
ndf = 'newdataformat'
data_path = path.abspath(data_path)
if path.isfile(data_path):
# we only care about the folder names at this point...
data_path, _ = path.split(data_path)
# Check if the data is in the new or old format:
data_dir, _ = path.split(file_path)
_, base_name = path.split(data_dir)
if base_name == 'newdataformat':
# Check one level up:
_, dir_name = path.split(data_path)
if dir_name == ndf:
# Though this translator could also read the files but the NDF Translator is more robust...
return None
# Check one level down:
if ndf in listdir(data_path):
# Though this translator could also read the files but the NDF Translator is more robust...
return False
return None
file_path = path.join(data_path, listdir(path=data_path)[0])
_, path_dict = BEodfTranslator._parse_file_path(file_path)
if any([x.find('bigtime_0') > 0 and x.endswith('.dat') for x in path_dict.values()]):
# This is a G-mode Line experiment:
return False
return None
if any([x in path_dict.keys() for x in ['parm_txt', 'old_mat_parms',
'read_real', 'write_real']]):
return True
return file_path
else:
return False
return None
def translate(self, file_path, show_plots=True, save_plots=True, do_histogram=False, verbose=False):
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment