Skip to content

Commit

Permalink
In m1m3.InertiaCompensationSystemAnalysis, fix stats re-packing
Browse files Browse the repository at this point in the history
  • Loading branch information
b1quint committed Sep 15, 2023
1 parent 3136372 commit 910242c
Show file tree
Hide file tree
Showing 2 changed files with 254 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/python
import logging

import pandas as pd
from lsst.summit.utils.tmaUtils import TMAEvent, TMAEventMaker

# TODO @bquint: fix logger - not working now.

Check failure on line 7 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:7:46: W291 Trailing whitespace
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class InertiaCompensationSystemAnalysis:
"""
Evaluate the M1M3 Inertia Compensation System's performance by

Check failure on line 14 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:14:67: W291 Trailing whitespace
calculating the minima, maxima and peak-to-peak values during a
slew. In addition, calculates the mean, median and standard deviation
when the slew has contant velocity or zero acceleration.

Check failure on line 17 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:17:61: W291 Trailing whitespace

Check failure on line 18 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W293)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:18:1: W293 Blank line contains whitespace
Parameters
----------
event : `lsst.summit.utils.tmaUtils.TMAEvent`
Abtract representation of a slew event.

Check failure on line 22 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:22:48: W291 Trailing whitespace
"""

Check failure on line 23 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (D204)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:13:5: D204 1 blank line required after class docstring

Check failure on line 23 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (D411)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:13:5: D411 Missing blank line before section ("Parameters")
# ToDo @bquint
def __init__(event : TMAEvent):

Check failure on line 25 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (N805)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:25:18: N805 First argument of a method should be named `self`
raise NotImplementedError

Check failure on line 27 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W293)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:27:1: W293 Blank line contains whitespace
@staticmethod
def get_minmax_from_series(s):
"""
Calculate minimum, maximum, and peak-to-peak values for a data-series.
Parameters
----------
s : pandas.Series
The input pandas Series containing data.
Returns
-------
pandas.Series
A Series containing the following calculated values for the two

Check failure on line 41 in python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

python/lsst/summit/testing/analysis/m1m3/.ipynb_checkpoints/inertia_compensation_system-checkpoint.py:41:76: W291 Trailing whitespace
halves of the input Series:
- min: Minimum value of the Series.
- max: Maximum value of the Series.
- ptp: Peak-to-peak (ptp) value of the Series (abs(max - min)).
"""
result = pd.Series(
data=[s.min(), s.max(), np.ptp(s)],
index=["min", "max", "ptp"],
name=s.name,
)
return result

@staticmethod
def get_avgmedstd_from_series(s):
"""
Calculate average, median, and standard deviation for a data-series.
Parameters
----------
s : pandas.Series
The input pandas Series containing data.
Returns
-------
pandas.Series
A Series containing the following calculated values for the two
halves of the input Series:
- mean: The mean value of the Series.
- median: The median value of the Series.
- std: The standard deviation of the Series.
"""
result = pd.Series(
data=[s.mean(), s.median(), s.std()],
index=["mean", "median", "std"],
name=s.name,
)
return result


def get_tma_slew_event():
"""
Retrieve Telescope Mount Assembly (TMA) slew events within a specified time
range.
Parameters
----------
dayObs : int
Observation day in the YYYYMMDD format.
seqNum : int
Sequence number associated with the slew event.
Returns
-------
lsst.summit.utils.tmaUtils.TMAEvent
A TMA slew events that occurred within the specified time range.
Notes
-----
This function retrieves TMA slew events occurring between the specified
start and end times. It uses the TMAEventMaker class to obtain events for
the specified day of observation (dayObs). The events are filtered to
include only those that start after 1 second before the specified start time
and end before 1 second after the specified end time.
Example
-------
>>>
>>>
>>>
"""
events = event_maker.getEvents(day_obs_begin)

assert len(events) == 1
return events[0]


def evaluate_single_slew(day_obs, seq_number):
"""
Evaluates the M1M3 Inertia Compensation System in a single slew with a
`seqNumber` sequence number and observed during `dayObs`. `
Parameters
----------
day_obs : int
Observation day in the YYYYMMDD format.
seq_number : int
Sequence number associated with the slew event.
"""
event_maker = TMAEventMaker()

logger.info(f"Query events in {day_obs}")
events = event_maker.getEvents(day_obs)

logger.info(f"Found {len(events)} events.")
single_event = [e for e in events if e.seqNum == seq_number]

if len(single_event) > 1:
raise ValueError(
f"Expected a single event for {day_obs}. "
f"Found {len(single_event)} events."
)

if len(single_event) == 0:
raise ValueError(
f"Could not find any events for {day_obs}. "
)


if __name__ == "__main__":
evaluate_single_slew(20230802, 38)

Loading

0 comments on commit 910242c

Please sign in to comment.