###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() nx.write_graphml(net_to_save, network_file)
# we now make sure that links between TL 0 and 3 are removed for any network, both those read from file and those created on the fly. network_file = output_dir+'/'+SRC_NET_FILE ## use this when generating niche modle networks and want to save in output directory #network_file = SRC_NET_FILE ## use this when running with networks saved locally in src #network_file = output_dir + '/new_network_%d.graphml' %(int(task)-1) if READ_FILE_NETWORK: graph = nx.read_graphml(network_file) net = Network(graph) else: net = obtain_interactions_network() 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() if not READ_FILE_NETWORK: net_to_save = net.copy() nx.write_graphml(net_to_save, network_file)
if not os.path.exists(output_dir): os.makedirs(output_dir) if os.path.isfile("./output/" + SRC_NET_FILE): shutil.copy("./output/" + SRC_NET_FILE, output_dir) ############################################## # network_file = output_dir+'/'+SRC_NET_FILE network_file = output_dir + "/new_network_%d.graphml" % (int(task) - 1) # if True: 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() nx.write_graphml(net_to_save, network_file)
###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() #nx.write_graphml(net_to_save, network_file) ## new networkx doesn't like numpy floats
###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() nx.write_graphml(net_to_save, network_file)
###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() #nx.write_graphml(net_to_save, network_file) ## new networkx doesn't like numpy floats
G = nx.Graph(G) #find modularity #net = Network(G) #tls = net.get_trophic_levels() #part = community.best_partition(G) #IG = igr.read_graphml(graphml_file) IG = igr.load(graphml_file) IG.to_undirected() # = IG0.to_undirected() membs = IG.community_multilevel() mod = IG.modularity(membs) #mod = modularity(part, G) print("Modularity:") print(mod) print(IG.transitivity_undirected()) print(Net.connectance()) Net.get_trophic_levels() Net.find_trophic_positions() #print(Net.omnivory()) print(Net.generality_vulnerability_sd()) print(Net.maximum_similarity()) gsd, vsd = Net.generality_vulnerability_sd() all_results[0,0] = G.number_of_nodes() #/ 120.0 Now normalising all elements all_results[0,1] = Net.connectance() all_results[0,2] = mod all_results[0,3] = IG.transitivity_undirected() all_results[0,4] = gsd all_results[0,5] = vsd all_results[0,6] = Net.maximum_similarity()