Skip to content

Commit

Permalink
address issue #215
Browse files Browse the repository at this point in the history
  • Loading branch information
kkappler committed Sep 3, 2022
1 parent d37763e commit cdbe3aa
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions aurora/transfer_function/kernel_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ def clone_dataframe(self):
return copy.deepcopy(self.df)

def from_run_summary(self, run_summary, local_station_id, remote_station_id=None):
"""
Parameters
----------
run_summary: aurora.pipelines.run_summary.RunSummary
Summary of available data for processing from one or more stations
local_station_id: string
Label of the station for which an estimate will be computed
remote_station_id: string
Label of the remote reference station
Returns
-------
"""
self.local_station_id = local_station_id
self.remote_station_id = remote_station_id

Expand All @@ -133,6 +148,9 @@ def from_run_summary(self, run_summary, local_station_id, remote_station_id=None
df.remote = cond

self.df = df
if remote_station_id:
self.restrict_run_intervals_to_simultaneous()
self._add_duration_column()

@property
def mini_summary(self):
Expand All @@ -142,19 +160,29 @@ def mini_summary(self):
def print_mini_summary(self):
print(self.mini_summary)

@property
def add_duration(self):
def _add_duration_column(self):
""" """
timedeltas = self.df.end - self.df.start
durations = [x.total_seconds() for x in timedeltas]
self.df["duration"] = durations
return

def drop_runs_shorter_than(self, duration, units="s"):
"""
This needs to have duration refreshed before hand
Parameters
----------
duration
units
Returns
-------
"""
if units != "s":
raise NotImplementedError
if "duration" not in self.df.columns:
self.add_duration
self._add_duration_column()
drop_cond = self.df.duration < duration
self.df.drop(self.df[drop_cond].index, inplace=True)
self.df.reset_index(drop=True, inplace=True)
Expand Down Expand Up @@ -201,27 +229,26 @@ def restrict_run_intervals_to_simultaneous(self):
if intervals_overlap(
local_row.start, local_row.end, remote_row.start, remote_row.end
):
print(f"OVERLAP {i_local}, {i_remote}")
# print(f"OVERLAP {i_local}, {i_remote}")
olap_start, olap_end = overlap(
local_row.start, local_row.end, remote_row.start, remote_row.end
)
print(
f"{olap_start} -- {olap_end}\n "
f"{(olap_end-olap_start).seconds}s\n\n"
)
# print(
# f"{olap_start} -- {olap_end}\n "
# f"{(olap_end-olap_start).seconds}s\n\n"
# )

local_sub_run = local_row.copy(deep=True)
# local_sub_run.drop("index", inplace=True)
remote_sub_run = remote_row.copy(deep=True)
# remote_sub_run.drop("index", inplace=True)
local_sub_run.start = olap_start
local_sub_run.end = olap_end
remote_sub_run.start = olap_start
remote_sub_run.end = olap_end
output_sub_runs.append(local_sub_run)
output_sub_runs.append(remote_sub_run)
else:
print(f"NOVERLAP {i_local}, {i_remote}")
pass
# print(f"NOVERLAP {i_local}, {i_remote}")
df = pd.DataFrame(output_sub_runs)
df = df.reset_index(drop=True)
self.df = df
Expand Down

0 comments on commit cdbe3aa

Please sign in to comment.