def loadParams(self, path): """ Load a file with parameters from a local file system or S3. Assumes file is JSON with basic types (strings, integers, doubles, lists), in either a single dict or list of dict-likes, and each dict has at least a "name" field and a "value" field. Useful for loading generic meta data, parameters, covariates, etc. Parameters ---------- path : str Path to file, can be on a local file system or an S3 bucket Returns ------- A dict or list with the parameters """ import json from thunder.rdds.fileio.readers import getFileReaderForPath, FileNotFoundError reader = getFileReaderForPath(path)( awsCredentialsOverride=self._credentials) try: buffer = reader.read(path) except FileNotFoundError: raise Exception("Cannot find file %s" % path) return Params(json.loads(buffer))
def test_paramsMethods(self): param1 = {'name': 'p1', 'value': array([1, 2, 3])} param2 = {'name': 'p2', 'value': array([4, 5, 6])} params = Params([param1, param2]) target1 = array([1, 2, 3]) target = array([[1, 2, 3], [4, 5, 6]]) assert_true(params.names() == ['p1', 'p2']) assert_true(array_equal(params.values(), target)) assert_true(array_equal(params.values('p1'), target1)) assert_true(array_equal(params.values(['p1', 'p2']), target)) assert_true(array_equal(params.values(('p1', 'p2')), target))
def loadParams(self, path): """ Load a file with parameters from a local file system or S3. Assumes file is JSON with basic types (strings, integers, doubles, lists), in either a single dict or list of dict-likes, and each dict has at least a "name" field and a "value" field. Useful for loading generic meta data, parameters, covariates, etc. Parameters ---------- path : str Path to file, can be on a local file system or an S3 bucket Returns ------- A dict or list with the parameters """ blob = self.loadJSON(path) return Params(blob)