def from_json_file(filename, check_format=True): ''' Decode a datablock from a JSON file. ''' from os.path import dirname, abspath from dxtbx.serialize.filename import temp_chdir filename = abspath(filename) with temp_chdir(dirname(filename)): with open(filename, 'r') as infile: return DataBlockFactory.from_json(infile.read(), check_format)
def from_json_file(filename, check_format=True): ''' Load an experiment list from a json file. ''' from dxtbx.serialize.filename import temp_chdir from os.path import dirname, abspath filename = abspath(filename) with temp_chdir(dirname(filename)): with open(filename, 'r') as infile: return ExperimentListFactory.from_json(infile.read(), check_format)
def tst_temp_chdir(self): from os import getcwd from os.path import join, realpath import libtbx cwd = realpath(getcwd()) new_path = realpath(join(libtbx.env.dist_path('dxtbx'), 'serialize')) with temp_chdir(new_path): assert (realpath(getcwd()) == new_path) assert (realpath(getcwd()) == cwd) print 'OK'
def tst_temp_chdir(self): from os import getcwd from os.path import join, realpath import libtbx cwd = realpath(getcwd()) new_path = realpath(join(libtbx.env.dist_path('dxtbx'), 'serialize')) with temp_chdir(new_path): assert(realpath(getcwd()) == new_path) assert(realpath(getcwd()) == cwd) print 'OK'
def _from_file(filename): ''' Load a model dictionary from a file. ''' from dxtbx.serialize.load import _decode_dict from dxtbx.serialize.filename import load_path, temp_chdir import json from os.path import dirname filename = load_path(filename) try: with temp_chdir(dirname(filename)): with open(filename, 'r') as infile: return json.loads(infile.read(), object_hook=_decode_dict) except IOError, e: raise IOError('unable to read file, %s' % filename)
def _from_file(filename): ''' Load a model dictionary from a file. ''' from dxtbx.serialize.load import _decode_dict from dxtbx.serialize.filename import load_path, temp_chdir import json from os.path import dirname filename = load_path(filename) try: with temp_chdir(dirname(filename)): with open(filename, 'r') as infile: return json.load(infile, object_hook=_decode_dict) except IOError: raise IOError('unable to read file, %s' % filename)
def imageset(filename): ''' Load the given JSON file. Params: infile The input filename Returns: The models ''' from dxtbx.serialize.filename import temp_chdir from os.path import abspath, dirname # If the input is a string then open and read from that file filename = abspath(filename) with temp_chdir(dirname(filename)): with open(filename, 'r') as infile: return imageset_from_string(infile.read())