<jupyter_start><jupyter_text>GMNS to AequilibraE example InputsNodes as a .csv flat file in GMNS formatomx skim files with numbers of tripsomx skim file with distnace Steps1.  Read the GMNS nodes, place centroids in dataframe2. Read the trips4. Generate new dataframe of O-D pairs<jupyter_code>#!/usr/bin/env python
# coding: utf-8
print('<NAME>: Python code to extract selected zone pairs from a person trip table \n')
import os
from os.path import join 
import numpy as np
import pandas as pd
import sqlite3
#import shutil  # needed?
import openmatrix as omx
import math
run_folder = 'C:/Users/Scott/Documents/Work/GMNS/ATL'  
highest_centroid_node_number = 6031
def sl_dist(lat1, lon1, lat2, lon2):
    from math import radians, cos, sqrt, pow
    mile_per_lat = 69.0
    mile_per_lon = mile_per_lat * math.cos(math.radians((lat1+lat2)/2.0))
    latdiff = mile_per_lat * (lat1-lat2)
    londiff = mile_per_lon * (lon1-lon2)
    return sqrt(pow(latdiff,2) + pow(londiff,2))

#print(sl_dist(40,-75,41,-76))<jupyter_output><empty_output><jupyter_text>Read the nodes, and set up the dictionary of centroidsThe dictionary of centroids is used later in setting up the omx trip table<jupyter_code>#Read the nodes
node_csvfile = os.path.join(run_folder, 'GMNS_node.csv')
df_taz = pd.read_csv(node_csvfile)   #data already has headers
print(df_taz.head())   #debugging
df_size = df_taz.shape[0]
print(df_size)
#print(df_node.loc[700,"node_type"])
# drop the non centroids
index = df_taz[df_taz['node_type'] != 'centroid'].index
df_taz.drop(index, inplace=True)
print(df_taz.head())   #debugging
df_size = df_taz.shape[0]
print(df_size)
# Set up the dictionary of centroids
# Assumption: the node_type = 'centroid' for centroid nodes
# The centroid nodes are the lowest numbered nodes, at the beginning of the list of nodes,
# but node numbers need not be consecutive
tazdictrow = {}
for index in df_taz.index:
    if df_taz['node_type'][index]=='centroid':
        #DEBUG print(index, df_node['node_id'][index], df_node['node_type'][index])
        tazdictrow[df_taz['node_id'][index]]=index
taz_list = list(tazdictrow.keys())
matrix_size = len(tazdictrow)   #Matches the number of nodes flagged as centroids
print(matrix_size)   #DEBUG
highest_centroid_node_number = max(tazdictrow, key=tazdictrow.get)  #for future use
print(highest_centroid_node_number)  #DEBUG
# Read the trip table and skim
dembf = omx.open_file(join(run_folder, '0_tntp_data' ,'demand.omx'),'r')
input_demand = np.array(dembf['matrix'])
print('sum of trips',np.sum(input_demand))

spbf = omx.open_file(join(run_folder, '2_skim_results','sp_skim.omx'),'r')
print('SP BASE SKIM FILE Shape:',spbf.shape(),'   Tables:',spbf.list_matrices(),'   Mappings:',spbf.list_mappings())
spbt = spbf['free_flow_time']
spbd = spbf['distance']
sp_dist = np.array(spbd)

outdebugfile = open(os.path.join(run_folder,'debug_demand2.txt'),"w")

for i in range(100):  #matrix_size)
    for j in range(matrix_size):
        if(input_demand[i][j]>0):
            lon1 = df_taz.loc[i,'x_coord']
            lat1 = df_taz.loc[i,'y_coord']
            lon2 = df_taz.loc[j,'x_coord']
            lat2 = df_taz.loc[j,'y_coord']
            sp_distance = sp_dist[i][j]
            sl_distance = sl_dist(lat1,lon1,lat2,lon2)
            print(i,j,lat1, lon1, lat2, lon2,sp_distance,sl_distance,file=outdebugfile)
outdebugfile.close()
dembf.close()
spbf.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12463514302393462, 'fraction_numerical': 0.016929363689433742, 'mean_word_length': 5.033450704225352, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '504593', 'license': 'Apache-2.0', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1269, 'n_words': 299, 'path': 'Small_Network_Examples/Lima/AequilibraE/Circuity.ipynb', 'repo_name': 'zephyr-data-specs/gmns', 'size': '3431'}