LSSTApplications
10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
home
lsstsw
stack
Linux64
datarel
11.0+1
python
lsst
datarel
ingest.py
Go to the documentation of this file.
1
#
2
# LSST Data Management System
3
# Copyright 2008, 2009, 2010, 2012 LSST Corporation.
4
#
5
# This product includes software developed by the
6
# LSST Project (http://www.lsst.org/).
7
#
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the LSST License Statement and
19
# the GNU General Public License along with this program. If not,
20
# see <http://www.lsstcorp.org/LegalNotices/>.
21
#
22
import
argparse
23
from
itertools
import
izip
24
import
os, os.path
25
import
re
26
import
shlex
27
import
sys
28
29
import
lsst.daf.persistence
as
dafPersist
30
from
.mysqlExecutor
import
addDbOptions
31
from
.datasetScanner
import
parseDataIdRules
32
33
__all__ = [
"makeArgumentParser"
,
34
"makeRules"
,
35
]
36
37
def
_line_to_args
(self, line):
38
for
arg
in
shlex.split(line, comments=
True
, posix=
True
):
39
if
not
arg.strip():
40
continue
41
yield
arg
42
43
44
def
makeArgumentParser
(description, inRootsRequired=True, addRegistryOption=True):
45
parser = argparse.ArgumentParser(
46
description=description,
47
fromfile_prefix_chars=
"@"
,
48
formatter_class=argparse.RawDescriptionHelpFormatter,
49
epilog=
"Data IDs are expected to be of the form:\n"
50
" --id k1=v11[^v12[...]] [k2=v21[^v22[...]]\n"
51
"\n"
52
"Examples:\n"
53
" 1. --id visit=12345 raft=1,1\n"
54
" 2. --id skyTile=12345\n"
55
" 3. --id visit=12 raft=1,2^2,2 sensor=1,1^1,3\n"
56
"\n"
57
"The first example identifies all sensors in raft 1,1 of visit "
58
"12345. The second identifies all sources/objects in sky-tile "
59
"12345. The cross product is computed for keys with multiple "
60
"values, so the third example is equivalent to:\n"
61
" --id visit=12 raft=1,2 sensor=1,1\n"
62
" --id visit=12 raft=1,2 sensor=1,3\n"
63
" --id visit=12 raft=2,2 sensor=1,1\n"
64
" --id visit=12 raft=2,2 sensor=1,3\n"
65
"\n"
66
"Redundant specification of a data ID will *not* result in "
67
"loads of duplicate data - data IDs are de-duped before ingest "
68
"starts. Note also that the keys allowed in data IDs are "
69
"specific to the type of data the ingestion script deals with. "
70
"For example, one cannot load sensor metadata by sky tile ID, nor "
71
"sources by sensor (CCD) ID.\n"
72
"\n"
73
"Any omitted keys are assumed to take all legal values. So, "
74
"`--id raft=1,2` identifies all sensors of raft 1,2 for all "
75
"available visits.\n"
76
"\n"
77
"Finally, calling an ingestion script multiple times is safe. "
78
"Attempting to load the same data item twice will result "
79
"in an error or (if --strict is specified) or cause previously "
80
"loaded data item to be skipped. Database activity is strictly "
81
"append only."
)
82
parser.convert_arg_line_to_args = _line_to_args
83
addDbOptions
(parser)
84
parser.add_argument(
85
"-d"
,
"--database"
, dest=
"database"
,
86
help=
"MySQL database to load CSV files into."
)
87
parser.add_argument(
88
"-s"
,
"--strict"
, dest=
"strict"
, action=
"store_true"
,
89
help=
"Error out if previously ingested, incomplete, or otherwise "
90
"suspicious data items are encountered (by default, these are "
91
"skipped). Note that if --database is not supplied, detecting "
92
"previously ingested data is not possible."
)
93
parser.add_argument(
94
"-i"
,
"--id"
, dest=
"id"
, nargs=
"+"
, default=
None
, action=
"append"
,
95
help=
"Data ID specifying what to ingest. May appear multiple times."
)
96
if
addRegistryOption:
97
parser.add_argument(
98
"-R"
,
"--registry"
, dest=
"registry"
, help=
"Input registry path; "
99
"used for all input roots. If omitted, a file named registry.sqlite3 "
100
"must exist in each input root."
)
101
parser.add_argument(
102
"outroot"
, help=
"Output directory for CSV files"
)
103
parser.add_argument(
104
"inroot"
, nargs=
"+"
if
inRootsRequired
else
"*"
,
105
help=
"One or more input root directories"
)
106
return
parser
107
108
109
def
makeRules
(dataIdSpecs, camera, validKeys):
110
"""Return a list of data ID rules from command line --id specifications.
111
Ensures only the given keys are referenced by the data id specs."""
112
if
not
dataIdSpecs:
113
return
None
114
rules = []
115
for
id
in
dataIdSpecs:
116
r =
parseDataIdRules
(id, camera)
117
for
k
in
r:
118
if
k
not
in
validKeys:
119
raise
RuntimeError(k +
" is not a legal data ID key for this ingest script"
)
120
rules.append(r)
121
return
rules
122
lsst.datarel.ingest._line_to_args
def _line_to_args
Definition:
ingest.py:37
lsst::daf::persistence
Definition:
Utils.h:44
lsst.datarel.ingest.makeRules
def makeRules
Definition:
ingest.py:109
lsst.datarel.ingest.makeArgumentParser
def makeArgumentParser
Definition:
ingest.py:44
lsst.datarel.datasetScanner.parseDataIdRules
def parseDataIdRules
Definition:
datasetScanner.py:104
lsst.datarel.mysqlExecutor.addDbOptions
def addDbOptions
Definition:
mysqlExecutor.py:137
Generated on Thu Sep 24 2015 02:29:24 for LSSTApplications by
1.8.5