Skip to content

Commit

Permalink
All necessary methods to apply a transformation function have been im…
Browse files Browse the repository at this point in the history
…plemented.
  • Loading branch information
glaubervila committed May 13, 2024
1 parent c2c832d commit d6efe2d
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 108 deletions.
90 changes: 66 additions & 24 deletions .tmp/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,76 @@ columns:
-
name: lsst.sal.ATAOS.logevent_focusOffsetSummary
fields: ["total"]
window: 0.0

# - name: ATAOS_focusOffsetSummary_userApplied
# function: mean
# topics:
# -
# topic: lsst.sal.ATAOS.logevent_focusOffsetSummary
# fields: ["userApplied"]
# window: 0.0
- name: ATPtg_warning
function: mean
topics:
-
name: lsst.sal.ATPtg.logevent_airmassWarning
fields: ["level"]
-
name: lsst.sal.ATPtg.logevent_moonProximityWarning
fields: ["level"]
-
name: lsst.sal.ATPtg.logevent_mountDataWarning
fields: ["level"]
# -
# name: lsst.sal.ATPtg.logevent_azWrapWarning
# fields: ["level"]
# -
# name: lsst.sal.ATPtg.logevent_blindSpotWarning
# fields: ["level"]
# -
# name: lsst.sal.ATPtg.logevent_elLimitWarning
# fields: ["level"]
# -
# name: lsst.sal.ATPtg.logevent_focusNameInconsistentWarning
# fields: ["level"]
# -
# name: lsst.sal.ATPtg.logevent_objectSetWarning
# fields: ["level"]
# -
# name: lsst.sal.ATPtg.logevent_rotWrapWarning
# fields: ["level"]
# -
# name: lsst.sal.ATPtg.logevent_sunProximityWarning
# fields: ["level"]
# -
# name: lsst.sal.ATPtg.logevent_objectSetWarning
# fields: ["level"]

# - name: ATAOS_focusOffsetSummary_filter
# function: mean
# topics:
# -
# topic: lsst.sal.ATAOS.logevent_focusOffsetSummary
# fields: ["filter"]
# window: 0.0
- name: ATAOS_focusOffsetSummary_userApplied
function: min
topics:
-
name: lsst.sal.ATAOS.logevent_focusOffsetSummary
fields: ["userApplied"]

- name: ATAOS_focusOffsetSummary_filter
function: max
topics:
-
name: lsst.sal.ATAOS.logevent_focusOffsetSummary
fields: ["filter"]

# Exemplo retorna 0 Rows
# - name: ESS_pressure
# type: double
# function: mean
# window: 0.0
# topics:
# -
# topic: lsst.sal.ESS.pressure
# fields: ["pressureItem"]
- name: ATAOS_focusOffsetSummary_userApplied_min
function: min
topics:
-
name: lsst.sal.ATAOS.logevent_focusOffsetSummary
fields: ["userApplied"]
- name: ATAOS_focusOffsetSummary_userApplied_mean
function: mean
topics:
-
name: lsst.sal.ATAOS.logevent_focusOffsetSummary
fields: ["userApplied"]
- name: ATAOS_focusOffsetSummary_userApplied_max
function: max
topics:
-
name: lsst.sal.ATAOS.logevent_focusOffsetSummary
fields: ["userApplied"]

# topics:
# # other optional information
Expand Down
28 changes: 19 additions & 9 deletions python/lsst/consdb/efd_transform/butler_dao.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import astropy.time
import pandas
from lsst.daf.butler import Butler

import astropy.time

class ButlerDao:

Expand All @@ -10,23 +11,32 @@ def __init__(self, butler: Butler):
def query_dimension_to_list(self, resultset):
return [r.toDict() for r in resultset]

def exposures_by_period(self,
def query_dimension_to_dataframe(self, resultset):
return pandas.DataFrame([q.toDict() for q in resultset])

def exposures_by_period(
self,
instrument: str,
start_time: astropy.time.Time,
end_time: astropy.time.Time,
) -> list:
where_clause = f"instrument=instr and exposure.timespan OVERLAPS (T'{start_time}', T'{end_time}')"

return self.butler.registry.queryDimensionRecords(
"exposure", where=where_clause, bind=dict(instr=instrument))

def visits_by_period(self,
resultset = self.butler.registry.queryDimensionRecords(
"exposure", where=where_clause, bind=dict(instr=instrument)
)
return self.query_dimension_to_list(resultset)

def visits_by_period(
self,
instrument: str,
start_time: astropy.time.Time,
end_time: astropy.time.Time,
) -> list:
where_clause = f"instrument=instr and visit.timespan OVERLAPS (T'{start_time}', T'{end_time}')"

return self.butler.registry.queryDimensionRecords(
"visit", where=where_clause, bind=dict(instr=instrument))

resultset = self.butler.registry.queryDimensionRecords(
"visit", where=where_clause, bind=dict(instr=instrument)
)

return self.query_dimension_to_list(resultset)
26 changes: 26 additions & 0 deletions python/lsst/consdb/efd_transform/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy


class Transform:
"""
A class that performs various transformations on a list or numpy
Expand All @@ -20,13 +21,32 @@ def __init__(self, values: Union[List[Union[float, int, bool]], numpy.ndarray]):
"""
self.values = numpy.array(values)

def apply(self, method_name: str) -> Union[float, None]:
"""
Apply a transformation method specified by method_name.
Args:
method_name: Name of the method to apply.
Returns:
The result of the transformation method or None if the method is not found.
"""
method = getattr(self, method_name, None)
if method:
return method()
else:
return None

def mean(self) -> float:
"""
Calculate the mean of the values.
Returns:
The mean value as a float.
"""
if numpy.size(self.values) == 0:
return numpy.nan

return numpy.nanmean(self.values)

def std(self, ddof: Optional[int] = 1) -> float:
Expand All @@ -48,6 +68,9 @@ def max(self) -> Union[float, int, bool]:
Returns:
The maximum value as a float, int, or bool.
"""
if numpy.size(self.values) == 0:
return numpy.nan

return numpy.nanmax(self.values)

def min(self) -> Union[float, int, bool]:
Expand All @@ -57,6 +80,9 @@ def min(self) -> Union[float, int, bool]:
Returns:
The minimum value as a float, int, or bool.
"""
if numpy.size(self.values) == 0:
return numpy.nan

return numpy.nanmin(self.values)

def logical_and(self) -> Union[bool, numpy.ndarray]:
Expand Down
Loading

0 comments on commit d6efe2d

Please sign in to comment.