Skip to content

Commit

Permalink
Debug ccdVisit dicts and name to id conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
morriscb committed May 9, 2018
1 parent 3e00cdf commit a14151b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
21 changes: 11 additions & 10 deletions python/lsst/ap/association/assoc_db_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from __future__ import absolute_import, division, print_function

from collections import OrderedDict as odict
from collections import OrderedDict as oDict
import numpy as np
import sqlite3

Expand Down Expand Up @@ -101,7 +101,7 @@ def ccdVisitSchema():
ccdVisitNames: `collections.OrderedDict`
Names of columns in the ccdVisit table.
"""
return odict([("ccdVisitId", "INTEGER PRIMARY KEY"),
return oDict([("ccdVisitId", "INTEGER PRIMARY KEY"),
("ccdNum", "INTEGER"),
("filterName", "TEXT"),
("ra", "REAL"),
Expand Down Expand Up @@ -339,10 +339,10 @@ def create_tables(self):
"CREATE INDEX diaObjectId_index ON dia_sources(diaObjectId)")
self._commit()

self._ccdVisitSchema = ccdVisitSchema()
ccd_visit_schema = ccdVisitSchema()
table_schema = ",".join(
"%s %s" % (key, self._ccdVisitSchema[key])
for key in self._ccdVisitSchema.keys())
"%s %s" % (key, ccd_visit_schema[key])
for key in ccd_visit_schema.keys())
self._db_cursor.execute(
"CREATE TABLE CcdVisit (%s)" % table_schema)
self._commit()
Expand Down Expand Up @@ -476,11 +476,12 @@ def store_ccd_visit_info(self, exposure):
exposure : `lsst.afw.image.Exposure`
Exposure to store information from.
"""

values = self._get_ccd_visit_info_from_exposure(exposure)
self._db_cursor.execute(
"INSERT OR REPLACE INTO CcdVisit VALUES (%s)" %
",".join("?" for idx in len(values)),
[values[key] for key in self._ccdVisitSchema.keys()])
",".join("?" for idx in range(len(values))),
[values[key] for key in ccdVisitSchema().keys()])

def _get_ccd_visit_info_from_exposure(self, exposure):
"""
Expand Down Expand Up @@ -510,7 +511,7 @@ def _get_ccd_visit_info_from_exposure(self, exposure):
# dateTimeMJD ``seconds``,
# flux zero point ``counts``,
# flux zero point error ``counts``]
values = {'CcdVisitId': visit_info.getExposureId(),
values = {'ccdVisitId': visit_info.getExposureId(),
'ccdNum': exposure.getDetector().getId(),
'filterName': exposure.getFilter().getName(),
'ra': sphPoint.getRa().asDegrees(),
Expand Down Expand Up @@ -722,7 +723,7 @@ def get_db_filter_id_from_name(self, filter_name):
Integer id stored in this db.
"""
self._db_cursor.execute(
"SELECT filterId FROM FilterMap WHERE filterName = ?", filter_name)
"SELECT filterId FROM FilterMap WHERE filterName = ?", (filter_name,))
row = self._db_cursor.fetchone()
if row is None:
raise InvalidParameterError(
Expand All @@ -746,7 +747,7 @@ def get_db_filter_name_from_id(self, filter_id):
String filter named stored in this db.
"""
self._db_cursor.execute(
"SELECT filterName FROM FilterMap WHERE filterId = ?", filter_id)
"SELECT filterName FROM FilterMap WHERE filterId = ?", (filter_id,))
row = self._db_cursor.fetchone()
if row is None:
raise InvalidParameterError(
Expand Down
3 changes: 1 addition & 2 deletions tests/test_association_db_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from lsst.ap.association import \
AssociationDBSqliteTask, \
AssociationDBSqliteConfig, \
make_minimal_dia_object_schema, \
make_minimal_dia_source_schema
from lsst.afw.cameraGeom.testUtils import DetectorWrapper
import lsst.afw.image as afwImage
Expand Down Expand Up @@ -333,7 +332,7 @@ def test_store_ccd_visit_info(self):
self.exposure)
rows = self.assoc_db._db_cursor.fetchall()
for row in rows:
for db_value, value in zip(row, stored_values):
for db_value, value in zip(row, stored_values.values()):
self.assertEqual(db_value, value)

def test_load_dia_sources(self):
Expand Down

0 comments on commit a14151b

Please sign in to comment.