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

Using a negative longitude in DemoEnv.py throws an error. #54

Open
kovar-ursa opened this issue Jul 18, 2023 · 5 comments
Open

Using a negative longitude in DemoEnv.py throws an error. #54

kovar-ursa opened this issue Jul 18, 2023 · 5 comments

Comments

@kovar-ursa
Copy link

If I modify DemoEnv.py as follows:

self.aircraft_head = Aircraft(self.traffic, call_sign="GHOST", aircraft_type="C25C", flight_phase=FlightPhase.CRUISE, configuration=Config.CLEAN, lat=43.223267, long=71.631273, alt=5000.0, heading=175.0, cas=250.0, fuel_weight=10000.0, payload_weight=12000.0)

Then the simulation runs as expected.

If I try to place the aircraft at Concord, NH, USA using the following code:

self.aircraft_head = Aircraft(self.traffic, call_sign="GHOST", aircraft_type="C25C", flight_phase=FlightPhase.CRUISE, configuration=Config.CLEAN, lat=43.223267, long=-71.631273, alt=5000.0, heading=175.0, cas=250.0, fuel_weight=10000.0, payload_weight=12000.0)

Then the simulation fails with the following:

emitting event "loadingMsg" to all [/] ERA5 data exists. Traffic.py - add_aircraft() GHOST Type: C25C Traffic.py - add_aircraft() FOLLOW Type: A20N emitting event "simulationEnvironment" to all [/] Exception in thread Thread-7 (_handle_event_internal): Traceback (most recent call last): File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/threading.py", line 1038, in _bootstrap_inner self.run() File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/threading.py", line 975, in run self._target(*self._args, **self._kwargs) File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/socketio/server.py", line 733, in _handle_event_internal r = server._trigger_event(data[0], namespace, sid, *data[1:]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/socketio/server.py", line 758, in _trigger_event return self.handlers[namespace][event](*args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/flask_socketio/__init__.py", line 282, in _handler return self._handle_event(handler, message, namespace, sid, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/flask_socketio/__init__.py", line 828, in _handle_event ret = handler(*args) ^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/airtrafficsim/server/server.py", line 153, in run_simulation env.run(socketio) File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/airtrafficsim/core/environment.py", line 134, in run self.step(socketio) File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/airtrafficsim/core/environment.py", line 81, in step self.traffic.update(self.global_time) File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/airtrafficsim/core/traffic.py", line 262, in update self.weather.update(self.lat, self.long, self.alt, File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/airtrafficsim/core/weather/weather.py", line 124, in update ds = self.weather_data.sel(longitude=xr.DataArray(long, dims="points"), latitude=xr.DataArray(lat, dims="points"), time=np.datetime64( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/xarray/core/dataset.py", line 2642, in sel query_results = map_index_queries( ^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/xarray/core/indexing.py", line 190, in map_index_queries results.append(index.sel(labels, **options)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/xarray/core/indexes.py", line 498, in sel raise KeyError(f"not all values found in index {coord_name!r}") KeyError: "not all values found in index 'longitude'"

The only difference between the two is the negative sign on the longitude.

@harrylui1995
Copy link
Collaborator

harrylui1995 commented Jul 21, 2023

Hi David, did you solve your problem? For me I can generate the aircraft at Concord using your setting.

from datetime import datetime
from pathlib import Path
from airtrafficsim.core.environment import Environment
from airtrafficsim.core.aircraft import Aircraft
from airtrafficsim.utils.enums import Config, FlightPhase


class demo_2(Environment):

    def __init__(self):
        # Initialize environment super class
        super().__init__(file_name=Path(__file__).name.removesuffix('.py'),  # File name (do not change)
                         start_time=datetime.fromisoformat(
                             '2022-03-22T00:00:00+00:00'),
                         end_time=1000,
                         weather_mode="",
                         performance_mode="BADA"
                         )

        # Add aircraft
        self.aircraft_head = Aircraft(self.traffic, call_sign="GHOST", aircraft_type="C25C", flight_phase=FlightPhase.CRUISE, configuration=Config.CLEAN, lat=43.223267, long=-71.631273, alt=5000.0, heading=175.0, cas=250.0, fuel_weight=10000.0, payload_weight=12000.0)

    def should_end(self):
        return False

concord

@kovar-ursa
Copy link
Author

kovar-ursa commented Jul 21, 2023

Good morning,

I copied your code verbatim and it produced the same error:

    query_results = map_index_queries(
                    ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/xarray/core/indexing.py", line 190, in map_index_queries
    results.append(index.sel(labels, **options))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/airtrafficsim/lib/python3.11/site-packages/xarray/core/indexes.py", line 498, in sel
    raise KeyError(f"not all values found in index {coord_name!r}")
KeyError: "not all values found in index 'longitude'"

I am using the 0.1.0 conda version. Is there a more recent version that doesn't have this behavior?

@harrylui1995
Copy link
Collaborator

harrylui1995 commented Jul 23, 2023

As I checked your error, I believe you install the conda "airtrafficsim" package in your "base" environment of conda, which creates conflicts between packages. You should follow the readme in our mainpage (https://github.com/HKUST-OCTAD-LAB/AirTrafficSim), which you could try to create an individual environment for "airtrafficsim".

Then you need to put the demo_2 script under the correct directory. The directory for new demos should be

"Your_root_address_for_anaconda"/anaconda3/envs/airtrafficsim/lib/python3.11/site-packages/airtrafficsim/data/environment/

@kovar-ursa
Copy link
Author

Good morning,

Your example works when I save it to a new file. It does not work when I add it to my existing file. So, the error is on my end and not in the code.

Thank you for helping me sort through this.

@kovar-ursa
Copy link
Author

Try setting:

weather_mode="ERA5",

in your code. When I do this, it throws the reported error.

Changing "ERA5" back to "" fixes the problem.

@kovar-ursa kovar-ursa reopened this Jul 24, 2023
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

No branches or pull requests

2 participants