LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+b203dec576,g18429d2f64+358861cd2c,g199a45376c+0ba108daf9,g1fd858c14a+dd066899e3,g262e1987ae+ebfced1d55,g29ae962dfc+72fd90588e,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+b668f15bc5,g4595892280+3897dae354,g47891489e3+abcf9c3559,g4d44eb3520+fb4ddce128,g53246c7159+8c5ae1fdc5,g67b6fd64d1+abcf9c3559,g67fd3c3899+1f72b5a9f7,g74acd417e5+cb6b47f07b,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+abcf9c3559,g8d7436a09f+bcf525d20c,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+6054cc57f1,g97be763408+06f794da49,g9dd6db0277+1f72b5a9f7,ga681d05dcb+7e36ad54cd,gabf8522325+735880ea63,gac2eed3f23+abcf9c3559,gb89ab40317+abcf9c3559,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+1f72b5a9f7,gdab6d2f7ff+cb6b47f07b,gdc713202bf+1f72b5a9f7,gdfd2d52018+8225f2b331,ge365c994fd+375fc21c71,ge410e46f29+abcf9c3559,geaed405ab2+562b3308c0,gf9a733ac38+8c5ae1fdc5,w.2025.35
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.dax.apdb.scripts.partition Namespace Reference

Functions

int partition_show_temporal (str apdb_config)
 
int partition_extend_temporal (str apdb_config, str time, bool past, int max_days)
 
int partition_delete_temporal (str apdb_config, str time, bool after, bool force)
 
bool _confirm_delete (*, list[int] partitions, list[str] tables, Partitioner partitioner)
 

Function Documentation

◆ _confirm_delete()

bool lsst.dax.apdb.scripts.partition._confirm_delete ( * ,
list[int] partitions,
list[str] tables,
Partitioner partitioner )
protected

Definition at line 175 of file partition.py.

175def _confirm_delete(*, partitions: list[int], tables: list[str], partitioner: Partitioner) -> bool:
176 print("Partitions to be deleted:")
177 for part in partitions:
178 start_time, end_time = partitioner.partition_period(part)
179 print(f" {part}: [{start_time.tai.isot}, {end_time.tai.isot})")
180 answer = input("Confirm deletion y/n: ")
181 return answer.strip().lower() == "y"

◆ partition_delete_temporal()

int lsst.dax.apdb.scripts.partition.partition_delete_temporal ( str apdb_config,
str time,
bool after,
bool force )
Delete some temporal partitions.

Parameters
----------
apdb_config : `str`
    URL for APDB configuration file.
time : `str`
    Timestamps in ISOT format and TAI scale. Partition that includes this
    time is not deleted.
after : `bool`
    If `True` then delete partitions after the specified time. Default is
    to delete partitions before this time.
force : `bool`
    If `True` then do not ask confirmation.

Definition at line 119 of file partition.py.

119def partition_delete_temporal(apdb_config: str, time: str, after: bool, force: bool) -> int:
120 """Delete some temporal partitions.
121
122 Parameters
123 ----------
124 apdb_config : `str`
125 URL for APDB configuration file.
126 time : `str`
127 Timestamps in ISOT format and TAI scale. Partition that includes this
128 time is not deleted.
129 after : `bool`
130 If `True` then delete partitions after the specified time. Default is
131 to delete partitions before this time.
132 force : `bool`
133 If `True` then do not ask confirmation.
134 """
135 try:
136 astro_time = astropy.time.Time(time, format="isot", scale="tai")
137 except ValueError as exc:
138 print(f"ERROR: {exc}", file=sys.stderr)
139 return 1
140
141 apdb = Apdb.from_uri(apdb_config)
142 if not isinstance(apdb, ApdbCassandra):
143 print("ERROR: Non-Cassandra APDB does not use time-partitioned tables.", file=sys.stderr)
144 return 1
145
146 admin = apdb.admin
147 try:
148 result = admin.delete_time_partitions(
149 astro_time, after=after, confirm=None if force else _confirm_delete
150 )
151 except (TypeError, ValueError) as exc:
152 print(f"ERROR: {exc}", file=sys.stderr)
153 return 1
154
155 part_range = admin.time_partitions()
156 start_time, _ = admin.partitioner.partition_period(part_range.start)
157 _, end_time = admin.partitioner.partition_period(part_range.end)
158
159 if result:
160 print(
161 "Time partitions succesfully deleted.\n"
162 f"New time partition range: {part_range.start} - {part_range.end} "
163 f"[{start_time.tai.isot}, {end_time.tai.isot})"
164 )
165 else:
166 print(
167 "Time partitions were not deleted.\n"
168 f"Current time partition range: {part_range.start} - {part_range.end} "
169 f"[{start_time.tai.isot}, {end_time.tai.isot})"
170 )
171
172 return 0
173
174

◆ partition_extend_temporal()

int lsst.dax.apdb.scripts.partition.partition_extend_temporal ( str apdb_config,
str time,
bool past,
int max_days )
Extend the range of temporal partitions.

Parameters
----------
apdb_config : `str`
    URL for APDB configuration file.
time : `str`
    Timestamps in ISOT format and TAI scale.
past : `bool`
    If `True` extend the range in the past.
max_days : `int`
    Max. number of days for extension.

Definition at line 66 of file partition.py.

66def partition_extend_temporal(apdb_config: str, time: str, past: bool, max_days: int) -> int:
67 """Extend the range of temporal partitions.
68
69 Parameters
70 ----------
71 apdb_config : `str`
72 URL for APDB configuration file.
73 time : `str`
74 Timestamps in ISOT format and TAI scale.
75 past : `bool`
76 If `True` extend the range in the past.
77 max_days : `int`
78 Max. number of days for extension.
79 """
80 try:
81 astro_time = astropy.time.Time(time, format="isot", scale="tai")
82 max_delta = astropy.time.TimeDelta(float(max_days), format="jd", scale="tai")
83 except ValueError as exc:
84 print(f"ERROR: {exc}", file=sys.stderr)
85 return 1
86
87 apdb = Apdb.from_uri(apdb_config)
88 if not isinstance(apdb, ApdbCassandra):
89 print("ERROR: Non-Cassandra APDB does not use time-partitioned tables.", file=sys.stderr)
90 return 1
91
92 admin = apdb.admin
93 try:
94 result = admin.extend_time_partitions(astro_time, forward=not past, max_delta=max_delta)
95 except (TypeError, ValueError) as exc:
96 print(f"ERROR: {exc}", file=sys.stderr)
97 return 1
98
99 part_range = admin.time_partitions()
100 start_time, _ = admin.partitioner.partition_period(part_range.start)
101 _, end_time = admin.partitioner.partition_period(part_range.end)
102
103 if result:
104 print(
105 "Time partition range succesfully extended.\n"
106 f"New time partition range: {part_range.start} - {part_range.end} "
107 f"[{start_time.tai.isot}, {end_time.tai.isot})"
108 )
109 else:
110 print(
111 "Time partition range was not extended.\n"
112 f"Current time partition range: {part_range.start} - {part_range.end} "
113 f"[{start_time.tai.isot}, {end_time.tai.isot})"
114 )
115
116 return 0
117
118

◆ partition_show_temporal()

int lsst.dax.apdb.scripts.partition.partition_show_temporal ( str apdb_config)
Print range of temporal partitions.

Parameters
----------
apdb_config : `str`
    URL for APDB configuration file.

Definition at line 35 of file partition.py.

35def partition_show_temporal(apdb_config: str) -> int:
36 """Print range of temporal partitions.
37
38 Parameters
39 ----------
40 apdb_config : `str`
41 URL for APDB configuration file.
42 """
43 apdb = Apdb.from_uri(apdb_config)
44 if not isinstance(apdb, ApdbCassandra):
45 print("ERROR: Non-Cassandra APDB does not use time-partitioned tables.", file=sys.stderr)
46 return 1
47
48 admin = apdb.admin
49 try:
50 part_range = admin.time_partitions()
51 except TypeError as exc:
52 print(f"ERROR: {exc}", file=sys.stderr)
53 return 1
54
55 start_time, _ = admin.partitioner.partition_period(part_range.start)
56 _, end_time = admin.partitioner.partition_period(part_range.end)
57
58 print(
59 f"Current time partition range: {part_range.start} - {part_range.end} "
60 f"[{start_time.tai.isot}, {end_time.tai.isot})"
61 )
62
63 return 0
64
65