Skip to content

Commit

Permalink
Update to use consDB
Browse files Browse the repository at this point in the history
  • Loading branch information
fred3m committed Jun 27, 2024
1 parent 974d621 commit 59da7b3
Show file tree
Hide file tree
Showing 16 changed files with 797 additions and 286 deletions.
12 changes: 0 additions & 12 deletions data/butler.yaml

This file was deleted.

175 changes: 0 additions & 175 deletions data/summit.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion python/lsst/rubintv/analysis/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from . import butler, command, commands, data, database, efd, query, utils, worker
from . import butler, command, commands, data, database, efd, query, utils, viewer, worker
3 changes: 2 additions & 1 deletion python/lsst/rubintv/analysis/service/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .db import *
from .butler import *
from .db import *
from .image import *
14 changes: 8 additions & 6 deletions python/lsst/rubintv/analysis/service/commands/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from ..data import DataCenter


logger = logging.getLogger("lsst.rubintv.analysis.service.command")
logger = logging.getLogger("lsst.rubintv.analysis.service.commands.db")


@dataclass(kw_only=True)
Expand Down Expand Up @@ -63,7 +63,7 @@ class LoadColumnsCommand(BaseCommand):

def build_contents(self, data_center: DataCenter) -> dict:
# Query the database to return the requested columns
database = data_center.databases[self.database]
database = data_center.schemas[self.database]
data = database.query(self.columns, self.query)

if not data:
Expand All @@ -76,7 +76,7 @@ def build_contents(self, data_center: DataCenter) -> dict:
else:
content = {
"schema": self.database,
"columns": self.columns,
"columns": list(data.keys()),
"data": data,
}

Expand All @@ -101,7 +101,7 @@ class CalculateBoundsCommand(BaseCommand):

def build_contents(self, data_center: DataCenter) -> dict:
# Query the database to return the requested columns
database = data_center.databases[self.database]
database = data_center.schemas[self.database]
data = database.calculate_bounds(
column=self.column,
)
Expand Down Expand Up @@ -156,12 +156,13 @@ def build_contents(self, data_center: DataCenter) -> dict:
}

# Load the data base to access the schema
schema_name = f"cdb_{instrument}"
try:
schema_name = f"cdb_{instrument}"
database = data_center.databases[schema_name]
database = data_center.schemas[schema_name]
result["schema"] = database.schema
except KeyError:
logger.warning(f"No database connection available for {schema_name}")
logger.warning(f"Available databases: {data_center.schemas.keys()}")

return result

Expand All @@ -170,6 +171,7 @@ def build_contents(self, data_center: DataCenter) -> dict:
class SelectDataPointsCommand(BaseCommand):
pass


# Register the commands
LoadColumnsCommand.register("load columns")
CalculateBoundsCommand.register("get bounds")
Expand Down
53 changes: 53 additions & 0 deletions python/lsst/rubintv/analysis/service/commands/image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This file is part of lsst_rubintv_analysis_service.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from __future__ import annotations

from dataclasses import dataclass
import logging
from typing import Any, TYPE_CHECKING

Check failure on line 26 in python/lsst/rubintv/analysis/service/commands/image.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

F401

'typing.Any' imported but unused

from lsst.rubintv.analysis.service.data import DataCenter

from ..command import BaseCommand

if TYPE_CHECKING:
from ..data import DataCenter

Check failure on line 33 in python/lsst/rubintv/analysis/service/commands/image.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

F811

redefinition of unused 'DataCenter' from line 28

logger = logging.getLogger("lsst.rubintv.analysis.service.commands.image")





@dataclass(kw_only=True)

Check failure on line 41 in python/lsst/rubintv/analysis/service/commands/image.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E303

too many blank lines (5)
class LoadDetectorImageCommand(BaseCommand):
"""Load an image from a data center.
"""
database: str
detector: int
visit_id: int

def build_contents(self, data_center: DataCenter) -> dict:
#butler = data_center.butler

Check failure on line 50 in python/lsst/rubintv/analysis/service/commands/image.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E265

block comment should start with '# '
#assert butler is not None

Check failure on line 51 in python/lsst/rubintv/analysis/service/commands/image.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E265

block comment should start with '# '
#image = butler.get(, **data_id)

Check failure on line 52 in python/lsst/rubintv/analysis/service/commands/image.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E265

block comment should start with '# '
pass
17 changes: 7 additions & 10 deletions python/lsst/rubintv/analysis/service/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
if TYPE_CHECKING:
from lsst.daf.butler import Butler

from .database import DatabaseConnection
from .database import ConsDbSchema
from .efd import EfdClient


Expand Down Expand Up @@ -143,19 +143,16 @@ class DataCenter:
An EFD client instance.
"""

matches: dict[tuple[DataId, DataId], Callable]
databases: dict[str, DatabaseConnection]
butler: Butler | None = None
schemas: dict[str, ConsDbSchema]
butlers: dict[str, Butler] | None = None
efd_client: EfdClient | None = None

def __init__(
self,
databases: dict[str, DatabaseConnection],
butler: Butler | None = None,
schemas: dict[str, ConsDbSchema],
butlers: dict[str, Butler] | None = None,
efd_client: EfdClient | None = None,
matches: dict[tuple[DataId, DataId], Callable] | None = None,
):
self.databases = databases
self.butler = butler
self.schemas = schemas
self.butlers = butlers
self.efdClient = efd_client
self.matches = matches or {}
Loading

0 comments on commit 59da7b3

Please sign in to comment.