-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-27344: Add butler query-dimension-records subcommand #442
Changes from all commits
2f6d57e
e0df06c
32daf5c
dfbd6e4
71dcdc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This file is part of daf_butler. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (http://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 <http://www.gnu.org/licenses/>. | ||
|
||
from astropy.table import Table | ||
|
||
from .. import Butler | ||
from ..core.utils import globToRegex | ||
|
||
|
||
def queryDimensionRecords(repo, element, datasets, collections, where, no_check): | ||
# Docstring for supported parameters is the same as | ||
# Registry.queryDimensionRecords except for ``no_check``, which is the | ||
# inverse of ``check``. | ||
|
||
if collections: | ||
collections = globToRegex(collections) | ||
else: | ||
collections = ... | ||
|
||
butler = Butler(repo) | ||
|
||
records = list(butler.registry.queryDimensionRecords(element, | ||
datasets=datasets, | ||
collections=collections, | ||
where=where, | ||
check=not no_check)) | ||
if not records: | ||
return None | ||
|
||
records.sort(key=lambda r: r.dataId) # use the dataId to sort the rows | ||
keys = records[0].fields.names # order the columns the same as the record's `field.names` | ||
|
||
return Table([[getattr(record, key, None) for record in records] for key in keys], names=keys) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ def readTable(textTable): | |
""" | ||
return AstropyTable.read(textTable, | ||
format="ascii", | ||
data_start=2, # skip the header row and the header row underlines. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit surprised that Astropy doesn't have a parser for the default pretty print table output. Part of me is wondering whether we should add an output format option to all the tabular output subcommands so that users can easily parse the output if they want. That would also let you specify csv format in tests for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatter options are not a bad idea. Another format might be an option to choose between Table and yaml, if there's ever going to be a case where a user may pipe the output of one command to the input of another? How to do naming/data structure with yaml would probably take a little thought though, or maybe you've got good ideas already. In this case,
and it was reading the |
||
fill_values=[("", 0, "")]) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TallJimbo what do we gain by having this option? When is disabling the check a good idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check can generate false positives for some valid-but-rare queries. Those all involve wanting multiple instruments and a WHERE constraint on a table derived from instrument (e.g.
exposure
) on a column in that table whose values are nevertheless instrument-agnostic (e.g.exposure.exposure_time > 30
). They then fall into two categories:IN
instead of=
andOR
:instrument IN ('HSC', 'DECam') AND exposure.exposure_time > 30
. The checker just isn't smart enough to rewrite theIN
.exposure.exposure_time > 30
. Note that I think we still want to check this case by default, because usually the user is thinking of a specific instrument but we don't know that.Similar cases may exist for skymaps, but it's harder to think of practically useful cases given the attributes actually on the tract and patch tables.
I'm open to opinions on whether that's sufficiently niche as to make this option not worth its maintenance weight.