Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pandas dataframes traffic arrays #400

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

amorfinv
Copy link
Contributor

Here is a draft pull requests that makes pandas DataFrame traffic arrays. It should also work with a GeoDataFrame. This should help with performing vectorised calculations like when using state based detection along track.

-Andres

@amorfinv
Copy link
Contributor Author

Here is a simple example of when a dataframe could be helpful.

class DF_arrays(core.Entity):

    def __init__(self):
        super().__init__()

        with self.settrafarrays():
            self.flight_data = pd.DataFrame({
                                            'npassengers': pd.Series(dtype=int),
                                            'mean_fare': pd.Series(dtype=float),
                                            'departure_time': pd.Series(dtype=datetime),
                                            'arrival_time': pd.Series(dtype=datetime),
                                            'predicted_arrival_time': pd.Series(dtype=datetime),
                                            'flight_distance': pd.Series(dtype=float),
                                            'predicted_flight_distance': pd.Series(dtype=float),
                                            })

    def create(self, n=1):
        super().create(n)

        # Get some data at start of simulation
        self.flight_data.loc[-n:, 'npassengers'] = 10
        self.flight_data.loc[-n:, 'mean_fare'] = 100
        self.flight_data.loc[-n:, 'departure_time'] = datetime(2022, 1, 1) + timedelta(seconds = sim.simt)
        self.flight_data.loc[-n:, 'predicted_arrival_time'] = datetime(2022, 1, 1) + timedelta(seconds = sim.simt) + timedelta(seconds=randint(0, 100))
        self.flight_data.loc[-n:, 'predicted_flight_distance'] = randint(0, 100)

    
    def delete(self, idx):

        # Get arrival time and flight distance
        self.flight_data.loc[idx, 'arrival_time'] = self.flight_data.loc[idx, 'departure_time'] + timedelta(seconds = sim.simt)
        self.flight_data.loc[idx, 'flight_distance'] = traf.distflown
        
        # do some logging

        # Call the actual delete function
        super().delete(idx)

However, the main improvements I think would come from using geopandas. I will make an example soon.

-Andres

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant