diff --git a/skais/ais/ais_points.py b/skais/ais/ais_points.py index 27b18f2cb6fb2eba754d2ee4766f6ecbe68c6261..e76b2a446da10a63b47a93bccfaf46766d448195 100644 --- a/skais/ais/ais_points.py +++ b/skais/ais/ais_points.py @@ -50,18 +50,20 @@ class AISPoints: self.df = df - @staticmethod - def load_from_csv(file_name): - df = pd.read_csv(file_name) - ais_points = AISPoints(df) - return ais_points - + # cleaning functions def remove_outliers(self, features, rank=4): if rank <= 0: raise ValueError(f"Rank is equal to {rank}, must be positive and superior to 0") for feature in features: self.df = self.df.drop(self.df[(np.abs(stats.zscore(self.df[feature])) > rank)].index) + def clean_angles(self): + self.df = self.df[self.df["cog"] <= 360] + self.df = self.df[self.df["cog"] >= 0] + + self.df = self.df[self.df["heading"] <= 360] + self.df = self.df[self.df["heading"] >= 0] + def normalize(self, features, normalization_type="min-max"): normalization_dict = {} if normalization_type == "min-max": @@ -93,20 +95,12 @@ class AISPoints: f"standardization]") return normalization_type, normalization_dict + # New features # TODO: rename def compute_diff_heading_cog(self): self.df["diff"] = self.df.apply(lambda x: 180 - abs(abs(x['heading'] - x['cog']) - 180), axis=1) - def clean_angles(self): - self.df = self.df[self.df["cog"] <= 360] - self.df = self.df[self.df["cog"] >= 0] - - self.df = self.df[self.df["heading"] <= 360] - self.df = self.df[self.df["heading"] >= 0] - - - # TODO: redo def get_trajectories(self, time_gap=30, min_size=50, interpolation_time=None): @@ -139,6 +133,7 @@ class AISPoints: return stats + # Static methods @staticmethod def fuse(*args): if len(args) == 1: @@ -153,3 +148,9 @@ class AISPoints: dfs.append(aisPosition.df) return AISPoints(pd.concat(dfs).reindex()) + + @staticmethod + def load_from_csv(file_name): + df = pd.read_csv(file_name) + ais_points = AISPoints(df) + return ais_points \ No newline at end of file