LarsBentsen / FFTransformer

Multi-Step Spatio-Temporal Forecasting: https://authors.elsevier.com/sd/article/S0306-2619(22)01822-0
60 stars 16 forks source link

how to calculate the data of edge_feats.csv? #3

Closed Jeffrey-JDong closed 1 year ago

Jeffrey-JDong commented 1 year ago

Hello, your work is very interesting and meaningful, but I have a question, how to calculate the data of edge_feats.csv, looking forward to your reply.

LarsBentsen commented 1 year ago

Hi. I am glad you found the repo useful! There are various ways in which you could create the edge_feats.csv, depending on what features you would like to include. Let's say that you want the edge_feats.csv file to contain the distance in latitude and longitude between stations, the code below would compute all the distances, assuming that the stations_info data frame has stations 'name', 'lat' and 'lon' columns.

edge_feats = {}
    for i, row_i in stations_info.iterrows():
        dists = np.array(stations_info.apply(
            lambda row: [row['lat'] - row_i.lat, row['lon'] - row_i.lon], axis=1).to_list())
        name_i = row_i['name'].replace(' ', '')
        edge_feats[name_i] = dict()
        edge_feats[name_i]['dlat'] = dists[:, 0]
        edge_feats[name_i]['dlon'] = dists[:, 1]
    edge_feats = pd.DataFrame(
        {(outerKey, innerKey): values
         for outerKey, innerDict in edge_feats.items()
         for innerKey, values in innerDict.items()}
    )
    edge_feats.index = stations_info['name'].str.replace(' ', '').to_list()

Feel free to open the issue again if this didn't answer your question.