Skip to content

Commit

Permalink
fixed flake8 unusued import error
Browse files Browse the repository at this point in the history
  • Loading branch information
AOS55 committed Mar 14, 2024
1 parent f6db917 commit 1ad9423
Show file tree
Hide file tree
Showing 22 changed files with 24 additions and 43 deletions.
3 changes: 1 addition & 2 deletions flyer_env/aircraft/controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import os
from typing import List, Tuple, Union, Optional
from typing import Union
from flyer_env.utils import Vector
from simple_pid import PID
from pyflyer import Aircraft
Expand Down
2 changes: 0 additions & 2 deletions flyer_env/aircraft/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def _unit_dir_vector(start_point, end_point):
def arc_path(self, pos):

if self.goal_state < len(self.goal_set) - 2:
final_state = False

# Get points defining trajecotries
point_a = self.goal_set[self.goal_state]
Expand Down Expand Up @@ -149,7 +148,6 @@ def arc_path(self, pos):
heading = tangent_track + (np.arctan(k_orbit * error))
# heading = tangent_track
else:
final_state = True
points = list(self.goal_set.values())

point_a = points[-2]
Expand Down
1 change: 0 additions & 1 deletion flyer_env/envs/common/abstract.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from typing import List, Tuple, Optional, TypeVar, Dict, Text
import gymnasium as gym
import numpy as np
Expand Down
3 changes: 1 addition & 2 deletions flyer_env/envs/common/action.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import functools
import itertools
from typing import TYPE_CHECKING, Optional, Union, Tuple, Callable, List, Dict
from typing import TYPE_CHECKING, Optional, Union, Tuple, Callable, Dict
from gymnasium import spaces
import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion flyer_env/envs/common/observation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pandas as pd
from gymnasium import spaces
from typing import List, Dict, TYPE_CHECKING, Tuple, OrderedDict
from typing import List, Dict, TYPE_CHECKING, OrderedDict

if TYPE_CHECKING:
from flyer_env.envs.common.abstract import AbstractEnv
Expand Down
1 change: 0 additions & 1 deletion flyer_env/envs/flyer_env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Dict, Text
import sys
import os
import numpy as np
from gymnasium import Env
Expand Down
2 changes: 0 additions & 2 deletions flyer_env/envs/forced_landing_env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing import Dict, Text
import os
import numpy as np
from flyer_env import utils
from flyer_env.aircraft import ControlledAircraft
from flyer_env.envs.common.abstract import AbstractEnv
Expand Down
1 change: 0 additions & 1 deletion flyer_env/envs/runway_env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Dict, Text
import sys
import os
import numpy as np
from flyer_env import utils
Expand Down
2 changes: 1 addition & 1 deletion flyer_env/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from typing import Tuple, Dict, Callable, List, Optional, Union, Sequence
from typing import Tuple, List, Union, Sequence

# Useful types
Vector = Union[np.ndarray, Sequence[float]]
Expand Down
8 changes: 4 additions & 4 deletions scripts/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pandas as pd
import matplotlib.pyplot as plt

from typing import List, Union, DefaultDict
from typing import Union, DefaultDict
from flyer_env.utils import Vector
from simple_pid import PID
from pyflyer import Aircraft
Expand Down Expand Up @@ -255,9 +255,9 @@ def clip_heading(heading: float) -> float:
def simulate():

# Trim values for given airspeed and conditions
pitch = -0.06081844622950141
elevator = 0.04055471935347572
tla = 0.6730648623679762
# pitch = -0.06081844622950141
# elevator = 0.04055471935347572
# tla = 0.6730648623679762

dt = 0.01
c_ac = ControlledAircraft(dt)
Expand Down
3 changes: 1 addition & 2 deletions scripts/pid_landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pandas as pd
import matplotlib.pyplot as plt

from typing import Dict
from flyer_env import utils
from flyer_env.aircraft import TrackPoints

Expand Down Expand Up @@ -104,7 +103,7 @@ def main():
obs, reward, terminated, truncated, info = env.step(action)

v_dict = env.unwrapped.vehicle.dict
controls = env.unwrapped.vehicle.aircraft.controls
# controls = env.unwrapped.vehicle.aircraft.controls
obs_dict = {"x": v_dict["x"], "y": v_dict["y"], "z": v_dict["z"]}
# print(f'z: {v_dict["z"]}')
observations.append(obs_dict)
Expand Down
5 changes: 2 additions & 3 deletions scripts/pid_traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pandas as pd
import matplotlib.pyplot as plt

from typing import Dict
from flyer_env import utils

plt.rcParams.update({"text.usetex": True})
Expand Down Expand Up @@ -55,10 +54,10 @@ def main():
"other_controls": np.array([alt, speed]),
}

v_dict = env.unwrapped.vehicle.dict
# v_dict = env.unwrapped.vehicle.dict
controls = env.unwrapped.vehicle.aircraft.controls

obs, reward, terminated, truncated, info = env.step(action)
_, reward, terminated, truncated, info = env.step(action)
obs_dict = {
"elevator": controls["elevator"],
"aileron": controls["aileron"],
Expand Down
6 changes: 3 additions & 3 deletions scripts/sac_control_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ def main():
}

c_env = gym.make("control-v1", config=control_env_config)
c_obs, c_info = c_env.reset()
c_done = False
_, _ = c_env.reset()
# c_done = False
c_action = [
0.0,
1.0,
lmap(-1000.0, [0.0, -10000], [-1.0, 1.0]),
lmap(100.0, [60.0, 110.0], [-1.0, 1.0]),
]

obs, info = env.reset()
obs, _ = env.reset()
done = False

observations = []
Expand Down
2 changes: 1 addition & 1 deletion scripts/sac_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
render=False,
)

model = SAC("MlpPolicy", env, verbose=1, tensorboard_log=f".runs/sac")
model = SAC("MlpPolicy", env, verbose=1, tensorboard_log=".runs/sac")
model.learn(
total_timesteps=config["total_timesteps"],
log_interval=4,
Expand Down
1 change: 0 additions & 1 deletion scripts/test_plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import gymnasium as gym
Expand Down
8 changes: 4 additions & 4 deletions scripts/train.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import gymnasium as gym
import hydra
from pathlib import Path
from omegaconf import DictConfig, OmegaConf
from omegaconf import OmegaConf

from stable_baselines3 import HerReplayBuffer, SAC, PPO, DDPG
from stable_baselines3 import HerReplayBuffer, SAC
from stable_baselines3.common.env_util import make_vec_env
from stable_baselines3.common.callbacks import EvalCallback
from stable_baselines3.common.monitor import Monitor
Expand Down Expand Up @@ -65,11 +65,11 @@ def __init__(self, cfg):
n_sampled_goal=4, goal_selection_strategy="future"
),
learning_starts=self.cfg.learning_starts,
tensorboard_log=f".runs/sac",
tensorboard_log=".runs/sac",
)
else:
self.model = SAC(
"MlpPolicy", self.train_env, verbose=1, tensorboard_log=f".runs/sac"
"MlpPolicy", self.train_env, verbose=1, tensorboard_log=".runs/sac"
)
return

Expand Down
2 changes: 1 addition & 1 deletion scripts/trim_disturbance.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def simulate():

# Trim values for given airspeed and conditions
pitch = -0.06081844622950141
# pitch = -0.06081844622950141
elevator = 0.04055471935347572
tla = 0.6730648623679762

Expand Down
5 changes: 2 additions & 3 deletions scripts/wb_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import gymnasium as gym
import wandb
import numpy as np
from stable_baselines3 import PPO
from stable_baselines3.common.vec_env import DummyVecEnv


def make_env():
env = gym.make("CartPole-v1", render_mode="rgb_array")
env = gym.wrappers.RecordVideo(env, f"videos") # record videos
env = gym.wrappers.RecordVideo(env, "videos") # record videos
env = gym.wrappers.RecordEpisodeStatistics(env) # record stats such as returns
return env

Expand All @@ -23,6 +22,6 @@ def make_env():
)

env = DummyVecEnv([make_env])
model = PPO(config["policy"], env, verbose=1, tensorboard_log=f"runs/ppo")
model = PPO(config["policy"], env, verbose=1, tensorboard_log="runs/ppo")
model.learn(total_timesteps=config["total_timesteps"])
wandb.finish()
1 change: 0 additions & 1 deletion tests/aircraft/test_controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from pyflyer import Aircraft


Expand Down
3 changes: 1 addition & 2 deletions tests/aircraft/test_trajectory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -40,7 +39,7 @@ def step(self, hdg: float, alt: float, speed: float):
def test_trajectory():

dt = 0.01
start_pos = np.array([0.0, 0.0])
# start_pos = np.array([0.0, 0.0])
# target_points = [
# [0.0, 0.0],
# [24060.25390625, -15000.0],
Expand Down
1 change: 0 additions & 1 deletion tests/aircraft/test_trim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from pyflyer import Aircraft


Expand Down
5 changes: 1 addition & 4 deletions tests/envs/test_gym.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import gymnasium as gym
import pytest
import flyer_env
import numpy as np
from flyer_env.envs.flyer_env import FlyerEnv
from PIL import Image

flyer_env.register_flyer_envs()

Expand All @@ -15,7 +12,7 @@ def test_env_step(env_spec):

env_configuration = {"screen_size": 256, "duration": 10.0}
env = gym.make(env_spec, config=env_configuration, render_mode="rgb_array")
obs, info = env.reset()
obs, _ = env.reset()
assert env.observation_space.contains(obs)
observations = []
terminated = truncated = False
Expand Down

0 comments on commit 1ad9423

Please sign in to comment.