def __init__(self): ''' Constructor ''' self.rnd = Random() self.rnd_uniform = uniform() self.net = Network()
out_eco = csv.DictWriter(file_eco, header_names) ###this is for python < 2.7 # headers_dict = dict() # for n in header_names: # headers_dict[n] = n # # out_eco.writerow(headers_dict) ### for python >= 2.7 comment the above block and uncomment the following line out_eco.writeheader() network_file = output_dir + '/' + SRC_NET_FILE if READ_FILE_NETWORK: graph = nx.read_graphml(network_file) net = Network(graph) print 'connectance = ', net.connectance() tls = net.get_trophic_levels() top, top_preds = net.top_predators() basal, basal_sps = net.basal() for u, v in net.edges(): if u in basal_sps and v in top_preds and tls[v] == 3: net.remove_edge(u, v) print 'new connectance = ', net.connectance() else: net = obtain_interactions_network() net_to_save = net.copy()