def from_adjacency(cls, input_adjacency, basepath=None): """ Instantiate the class using an adjacency dict or file. The input must contain relative or absolute paths to image files. Parameters ---------- input_adjacency : dict or str An adjacency dictionary or the name of a file containing an adjacency dictionary. Returns ------- : object A Network graph object Examples -------- >>> from autocnet.examples import get_path >>> inputfile = get_path('adjacency.json') >>> candidate_graph = network.CandidateGraph.from_adjacency(inputfile) """ if not isinstance(input_adjacency, dict): input_adjacency = io_json.read_json(input_adjacency) if basepath is not None: for k, v in input_adjacency.items(): input_adjacency[k] = [os.path.join(basepath, i) for i in v] input_adjacency[os.path.join(basepath, k)] = input_adjacency.pop(k) return cls(input_adjacency)
def from_adjacency(cls, inputfile): """ Instantiate the class using an adjacency list Parameters ========== inputfile : str The input file containing the graph representation """ #TODO: This is better as a generic reader that tries drivers until # a valid dict is returned. adjacency_dict = io_json.read_json(inputfile) return cls(adjacency_dict)
def from_adjacency(cls, input_adjacency): """ Instantiate the class using an adjacency dict or file. The input must contain relative or absolute paths to image files. Parameters ---------- input_adjacency : dict or str An adjacency dictionary or the name of a file containing an adjacency dictionary. Returns ------- : object A Network graph object Examples -------- >>> from autocnet.examples import get_path >>> inputfile = get_path('adjacency.json') >>> candidate_graph = network.CandidateGraph.from_adjacency(inputfile) """ if not isinstance(input_adjacency, dict): input_adjacency = io_json.read_json(input_adjacency) return cls(input_adjacency)