Coverage for python/lsst/summit/extras/annotations.py: 37%
35 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-15 03:30 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-15 03:30 -0800
1# This file is part of summit_extras.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22from lsst.summit.extras.imageSorter import ImageSorter, TAGS
25def _idTrans(dataIdDictOrTuple):
26 """Take a dataId and turn it into the internal tuple format.
27 """
28 if type(dataIdDictOrTuple) == tuple: 28 ↛ 29line 28 didn't jump to line 29, because the condition on line 28 was never true
29 return dataIdDictOrTuple
30 elif type(dataIdDictOrTuple) == dict: 30 ↛ 33line 30 didn't jump to line 33, because the condition on line 30 was never false
31 return (dataIdDictOrTuple['dayObs'], dataIdDictOrTuple['seqNum'])
32 else:
33 raise RuntimeError(f'Failed to parse dataId {dataIdDictOrTuple}')
36class Annotations():
37 """Class for interfacing with annotations, as written by the imageSorter.
38 """
40 def __init__(self, filename):
41 self.filename = filename
42 self.tags, self.notes = self._load(filename)
44 def _load(self, filename):
45 """Load tags and notes from specified file.
46 """
47 tags, notes = ImageSorter.loadAnnotations(filename)
48 return tags, notes
50 def getTags(self, dataId):
51 """Get the tags for a specified dataId.
53 Empty string means no tags, None means not examined"""
54 return self.tags.get(_idTrans(dataId), None)
56 def getNotes(self, dataId):
57 """Get the notes for the specified dataId.
58 """
59 return self.notes.get(_idTrans(dataId), None)
61 def hasTags(self, dataId, flags):
62 """Check if a dataId has all the specificed tags"""
63 tag = self.getTags(dataId)
64 if tag is None: # not just 'if tag' becuase '' is not the same as None but both as False-y
65 return None
66 return all(i in tag for i in flags.upper())
68 def getListOfCheckedData(self):
69 """Return a list of all dataIds which have been examined.
70 """
71 return sorted(list(self.tags.keys()))
73 def getListOfDataWithNotes(self):
74 """Return a list of all dataIds which have notes associated.
75 """
76 return sorted(list(self.notes.keys()))
78 def isExamined(self, dataId):
79 """Check if the dataId has been examined or not.
80 """
81 return _idTrans(dataId) in self.tags
83 def printTags(self):
84 """Display the list of tag definitions.
85 """
86 print(TAGS)
88 def getIdsWithGivenTags(self, tags, exactMatches=False):
89 if exactMatches:
90 return [dId for (dId, tag) in self.tags.items() if (all(t in tag for t in tags.upper()) and
91 (len(tags) == len(tag)))]
92 else:
93 return [dId for (dId, tag) in self.tags.items() if all(t in tag for t in tags.upper())]