sdss-almanac 0.2.12__py3-none-any.whl → 0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
almanac/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.12"
1
+ __version__ = "0.3"
2
2
 
3
3
  from .config import config, get_config_path, ConfigManager
4
4
  from .logger import logger
almanac/cli.py CHANGED
@@ -225,23 +225,34 @@ def lookup(identifier, careful, **kwargs):
225
225
  from rich.console import Console
226
226
  from rich.live import Live
227
227
 
228
- identifiers = (
228
+ sq = (
229
229
  SDSS_ID_flat
230
- .select(
231
- SDSS_ID_flat.catalogid,
232
- SDSS_ID_flat.sdss_id,
233
- )
230
+ .select(SDSS_ID_flat.sdss_id)
234
231
  .where(
235
232
  (SDSS_ID_flat.sdss_id == identifier)
236
233
  | (SDSS_ID_flat.catalogid == identifier)
237
234
  )
235
+ .alias("sq")
236
+ )
237
+ q = (
238
+ SDSS_ID_flat
239
+ .select(SDSS_ID_flat.catalogid, SDSS_ID_flat.sdss_id)
240
+ .distinct()
241
+ .join(sq, on=(SDSS_ID_flat.sdss_id == sq.c.sdss_id))
238
242
  .tuples()
239
243
  )
240
244
 
241
- identifiers = { catalogid: sdss_id for catalogid, sdss_id in identifiers }
242
- if not identifiers:
245
+ sdss_ids, catalogids = (set(), [])
246
+ for catalogid, sdss_id in q:
247
+ sdss_ids.add(sdss_id)
248
+ catalogids.append(catalogid)
249
+
250
+ if not catalogids:
243
251
  raise click.ClickException(f"Identifier {identifier} not found in SDSS-V database")
244
252
 
253
+ if len(sdss_ids) != 1:
254
+ raise click.ClickException(f"Identifier {identifier} is ambiguous and matches multiple SDSS IDs: {', '.join(map(str, sdss_ids))}")
255
+
245
256
  q = (
246
257
  Target
247
258
  .select(
@@ -255,7 +266,7 @@ def lookup(identifier, careful, **kwargs):
255
266
  .join(Hole)
256
267
  .join(Observatory)
257
268
  .where(
258
- Target.catalogid.in_(tuple(identifiers.keys()))
269
+ Target.catalogid.in_(tuple(catalogids))
259
270
  & (AssignmentStatus.status == 1)
260
271
  )
261
272
  .tuples()
@@ -264,23 +275,25 @@ def lookup(identifier, careful, **kwargs):
264
275
 
265
276
  console = Console()
266
277
 
267
- title = "; ".join([f"SDSS ID {sdss_id} / Catalog ID {catalogid}" for catalogid, sdss_id in identifiers.items()])
278
+ title = f"SDSS ID {sdss_id}"
268
279
 
269
280
  # Create Rich table
270
281
  rich_table = RichTable(title=f"{title}", title_style="bold blue", show_header=True, header_style="bold cyan")
271
282
 
272
- for field_name in ("obs", "mjd", "exposure", "field", "fiber_id", "catalogid"):
283
+ for field_name in ("#", "obs", "mjd", "exposure", "field", "fiber_id", "catalogid"):
273
284
  rich_table.add_column(field_name, justify="center")
274
285
 
275
286
  fields = {}
276
- with Live(rich_table, console=console, refresh_per_second=4, screen=False) as live:
287
+ i = 1
288
+ with Live(rich_table, console=console, refresh_per_second=4) as live:
277
289
  for exposure in chain(*starmap(get_exposures, q)):
278
290
  key = (exposure.observatory, exposure.mjd)
279
291
  if (key not in fields or fields[key] == exposure.field_id) or careful:
280
292
  for target in exposure.targets:
281
- if target.catalogid in identifiers:
293
+ if target.catalogid in catalogids:
282
294
  fields[key] = exposure.field_id
283
295
  rich_table.add_row(*list(map(str, (
296
+ i,
284
297
  exposure.observatory,
285
298
  exposure.mjd,
286
299
  exposure.exposure,
@@ -288,8 +301,10 @@ def lookup(identifier, careful, **kwargs):
288
301
  target.fiber_id,
289
302
  target.catalogid
290
303
  ))))
304
+ i += 1
291
305
  break
292
306
 
307
+
293
308
  @main.group()
294
309
  def add(**kwargs):
295
310
  """Add new information to an existing Almanac file."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdss-almanac
3
- Version: 0.2.12
3
+ Version: 0.3
4
4
  Summary: Everything we've got
5
5
  Author-email: Andy Casey <andrew.casey@monash.edu>
6
6
  License: BSD 3-Clause License
@@ -1,7 +1,7 @@
1
- almanac/__init__.py,sha256=vR2wU2aXGUfju14ePXTgSjjq-pHXFyWCqs8ZlD17mO0,110
1
+ almanac/__init__.py,sha256=IVYEfNRXAC4OOVay7i4tcf3qG76xQA4qXlHoStx8pRA,107
2
2
  almanac/apogee.py,sha256=Q7juc7BJdnP56-4UZ4CSg6FCULr22KHinHly2d0KMt8,10390
3
3
  almanac/catalog.py,sha256=tVwlLtVaUbSt1hoTpIPP2bMhgd4rpcUUP_zdr6uks2c,11633
4
- almanac/cli.py,sha256=4nlH0zjdeW_kMXvkCoxaNmfpUhUAJbFFjzZNvIKy88k,29678
4
+ almanac/cli.py,sha256=WuAFwfMeID4HJoUdQt0w7wrmrkdUBhFP5MBdYU7UL7M,30009
5
5
  almanac/config.py,sha256=5oRO-mrtaCKIcqGxcrfeNHZIjHkULDRrI_Bv1CU5uxE,3259
6
6
  almanac/database.py,sha256=6YeuRSFU5zfIen7zU-nI4pN_Z_fnYkglPcYxzVF4Xqo,758
7
7
  almanac/display.py,sha256=IflM5Y3yOJEDkvyUYQe3bOFs1iEwoe3mUj8mbODsYDk,15388
@@ -20,9 +20,9 @@ almanac/etc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  almanac/etc/bad_exposures.csv,sha256=VQQoq6uXDhnnIyp6vw0cfeTaoyNqPi5dW0MwfKsDRCk,25394
21
21
  almanac/stash/data_models.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  almanac/stash/plugmap_models.py,sha256=8yxw6ZXuLP1ZdFuT7wCW_Z5JSJll4uymiIWRb6WvSOk,8973
23
- sdss_almanac-0.2.12.dist-info/licenses/LICENSE.md,sha256=_7dAUQQ5Ph_x1hcFXhi9aHBcqq9H11zco12eO4B3Cyg,1504
24
- sdss_almanac-0.2.12.dist-info/METADATA,sha256=QVqM9dBL87gm9bXuiqEOE8ED10-G45NUvkysBkRfdek,6995
25
- sdss_almanac-0.2.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
- sdss_almanac-0.2.12.dist-info/entry_points.txt,sha256=5Obfm-uaVxE3RnRm2W7dYaX_O_j5ggGvAW5UQG5AtuE,45
27
- sdss_almanac-0.2.12.dist-info/top_level.txt,sha256=sWBGH9a-2-nFB2-rGqioyigbkcz14t1u8rqAs_RYe_w,8
28
- sdss_almanac-0.2.12.dist-info/RECORD,,
23
+ sdss_almanac-0.3.dist-info/licenses/LICENSE.md,sha256=_7dAUQQ5Ph_x1hcFXhi9aHBcqq9H11zco12eO4B3Cyg,1504
24
+ sdss_almanac-0.3.dist-info/METADATA,sha256=ZGX1P4Vfs9n3Cbx0I9wdqrEKPRiyK1q8Tlb6XmLG11Y,6992
25
+ sdss_almanac-0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
+ sdss_almanac-0.3.dist-info/entry_points.txt,sha256=5Obfm-uaVxE3RnRm2W7dYaX_O_j5ggGvAW5UQG5AtuE,45
27
+ sdss_almanac-0.3.dist-info/top_level.txt,sha256=sWBGH9a-2-nFB2-rGqioyigbkcz14t1u8rqAs_RYe_w,8
28
+ sdss_almanac-0.3.dist-info/RECORD,,