Skip to content

Commit

Permalink
add coord.get_availabilities()
Browse files Browse the repository at this point in the history
  • Loading branch information
atrabattoni committed May 21, 2024
1 parent 4619977 commit 51604bc
Showing 1 changed file with 74 additions and 8 deletions.
82 changes: 74 additions & 8 deletions xdas/core/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,18 +753,84 @@ def simplify(self, tolerance=None):
)

def get_discontinuities(self):
"""
Returns a DataFrame containing information about the discontinuities.
Returns
-------
pandas.DataFrame
A DataFrame with the following columns:
- start_index : int
The index where the discontinuity starts.
- end_index : int
The index where the discontinuity ends.
- start_value : float
The value at the start of the discontinuity.
- end_value : float
The value at the end of the discontinuity.
- delta : float
The difference between the end_value and start_value.
- type : str
The type of the discontinuity, either "gap" or "overlap".
"""
(indices,) = np.nonzero(np.diff(self.tie_indices) == 1)
records = []
for index in indices:
start = self.tie_values[index]
end = self.tie_values[index + 1]
start_index = self.tie_indices[index]
end_index = self.tie_indices[index + 1]
start_value = self.tie_values[index]
end_value = self.tie_values[index + 1]
record = {
"start_index": start_index,
"end_index": end_index,
"start_value": start_value,
"end_value": end_value,
"delta": end_value - start_value,
"type": ("gap" if end_value > start_value else "overlap"),
}
records.append(record)
return pd.DataFrame.from_records(records)

def get_availabilities(self):
"""
Returns a DataFrame containing information about the data availability.
Returns
-------
pandas.DataFrame
A DataFrame with the following columns:
- start_index : int
The index where the discontinuity starts.
- end_index : int
The index where the discontinuity ends.
- start_value : float
The value at the start of the discontinuity.
- end_value : float
The value at the end of the discontinuity.
- delta : float
The difference between the end_value and start_value.
- type : str
The type of the discontinuity, always "data".
"""
(indices,) = np.nonzero(np.diff(self.tie_indices) == 1)
indices = np.insert(indices, [0, len(indices)], [0, len(self.tie_indices) - 1])
records = []
for start, end in zip(indices[:-1], indices[1:]):
start_index = self.tie_indices[start]
end_index = self.tie_indices[end]
start_value = self.tie_values[start]
end_value = self.tie_values[end]
record = {
"start_index": self.tie_indices[index],
"end_index": self.tie_indices[index + 1],
"start_value": start,
"end_value": end,
"delta": end - start,
"type": ("gap" if end > start else "overlap"),
"start_index": start_index,
"end_index": end_index,
"start_value": start_value,
"end_value": end_value,
"delta": end_value - start_value,
"type": "data",
}
records.append(record)
return pd.DataFrame.from_records(records)
Expand Down

0 comments on commit 51604bc

Please sign in to comment.