sdss-almanac 0.2.12__tar.gz → 0.3.1__tar.gz

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.
Files changed (34) hide show
  1. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/PKG-INFO +1 -1
  2. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/pyproject.toml +1 -1
  3. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/__init__.py +1 -1
  4. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/cli.py +48 -21
  5. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/sdss_almanac.egg-info/PKG-INFO +1 -1
  6. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/LICENSE.md +0 -0
  7. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/README.md +0 -0
  8. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/setup.cfg +0 -0
  9. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/apogee.py +0 -0
  10. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/catalog.py +0 -0
  11. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/config.py +0 -0
  12. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/data_models/__init__.py +0 -0
  13. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/data_models/exposure.py +0 -0
  14. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/data_models/fps.py +0 -0
  15. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/data_models/metadata.py +0 -0
  16. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/data_models/plate.py +0 -0
  17. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/data_models/types.py +0 -0
  18. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/data_models/utils.py +0 -0
  19. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/database.py +0 -0
  20. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/display.py +0 -0
  21. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/etc/__init__.py +0 -0
  22. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/etc/bad_exposures.csv +0 -0
  23. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/io.py +0 -0
  24. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/logger.py +0 -0
  25. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/qa.py +0 -0
  26. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/stash/data_models.py +0 -0
  27. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/stash/plugmap_models.py +0 -0
  28. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/almanac/utils.py +0 -0
  29. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/sdss_almanac.egg-info/SOURCES.txt +0 -0
  30. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/sdss_almanac.egg-info/dependency_links.txt +0 -0
  31. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/sdss_almanac.egg-info/entry_points.txt +0 -0
  32. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/sdss_almanac.egg-info/not-zip-safe +0 -0
  33. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/sdss_almanac.egg-info/requires.txt +0 -0
  34. {sdss_almanac-0.2.12 → sdss_almanac-0.3.1}/src/sdss_almanac.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdss-almanac
3
- Version: 0.2.12
3
+ Version: 0.3.1
4
4
  Summary: Everything we've got
5
5
  Author-email: Andy Casey <andrew.casey@monash.edu>
6
6
  License: BSD 3-Clause License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sdss-almanac"
7
- version = "0.2.12"
7
+ version = "0.3.1"
8
8
  authors = [
9
9
  { name = "Andy Casey", email = "andrew.casey@monash.edu" }
10
10
  ]
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.12"
1
+ __version__ = "0.3.1"
2
2
 
3
3
  from .config import config, get_config_path, ConfigManager
4
4
  from .logger import logger
@@ -217,7 +217,7 @@ def lookup(identifier, careful, **kwargs):
217
217
  from almanac.apogee import get_exposures
218
218
  from sdssdb.peewee.sdss5db.targetdb import (
219
219
  Assignment, AssignmentStatus,CartonToTarget, Target, Hole, Observatory,
220
- Design, DesignToField
220
+ Design, DesignToField, Field
221
221
  )
222
222
  from sdssdb.peewee.sdss5db.catalogdb import SDSS_ID_flat
223
223
 
@@ -225,62 +225,87 @@ 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(
248
259
  fn.Lower(Observatory.label),
249
260
  AssignmentStatus.mjd,
261
+ Field.field_id,
250
262
  )
263
+ .distinct()
251
264
  .join(CartonToTarget)
252
265
  .join(Assignment)
253
266
  .join(AssignmentStatus)
254
267
  .switch(Assignment)
255
268
  .join(Hole)
256
269
  .join(Observatory)
270
+ .switch(Assignment)
271
+ .join(Design)
272
+ .join(DesignToField)
273
+ .join(Field)
257
274
  .where(
258
- Target.catalogid.in_(tuple(identifiers.keys()))
275
+ Target.catalogid.in_(tuple(catalogids))
259
276
  & (AssignmentStatus.status == 1)
260
277
  )
261
278
  .tuples()
262
279
  )
263
- q = tuple(set([(obs, int(mjd)) for obs, mjd in q]))
280
+ fields = {}
281
+ for obs, mjd, field_id in q:
282
+ mjd = int(mjd)
283
+ fields.setdefault((obs, mjd), set())
284
+ fields[(obs, mjd)].add(field_id)
264
285
 
265
286
  console = Console()
266
287
 
267
- title = "; ".join([f"SDSS ID {sdss_id} / Catalog ID {catalogid}" for catalogid, sdss_id in identifiers.items()])
288
+ title = f"SDSS ID {sdss_id}"
268
289
 
269
- # Create Rich table
270
- rich_table = RichTable(title=f"{title}", title_style="bold blue", show_header=True, header_style="bold cyan")
290
+ rich_table = RichTable(
291
+ title=f"{title}",
292
+ title_style="bold blue",
293
+ show_header=True,
294
+ header_style="bold cyan"
295
+ )
271
296
 
272
- for field_name in ("obs", "mjd", "exposure", "field", "fiber_id", "catalogid"):
297
+ for field_name in ("#", "obs", "mjd", "exposure", "field", "fiber_id", "catalogid"):
273
298
  rich_table.add_column(field_name, justify="center")
274
299
 
275
- fields = {}
276
- with Live(rich_table, console=console, refresh_per_second=4, screen=False) as live:
277
- for exposure in chain(*starmap(get_exposures, q)):
278
- key = (exposure.observatory, exposure.mjd)
279
- if (key not in fields or fields[key] == exposure.field_id) or careful:
300
+ i = 1
301
+ with Live(rich_table, console=console, refresh_per_second=4) as live:
302
+ for exposure in chain(*starmap(get_exposures, fields.keys())):
303
+ field_ids = fields[(exposure.observatory, exposure.mjd)]
304
+ if exposure.field_id in field_ids:
280
305
  for target in exposure.targets:
281
- if target.catalogid in identifiers:
282
- fields[key] = exposure.field_id
306
+ if target.catalogid in catalogids:
283
307
  rich_table.add_row(*list(map(str, (
308
+ i,
284
309
  exposure.observatory,
285
310
  exposure.mjd,
286
311
  exposure.exposure,
@@ -288,8 +313,10 @@ def lookup(identifier, careful, **kwargs):
288
313
  target.fiber_id,
289
314
  target.catalogid
290
315
  ))))
316
+ i += 1
291
317
  break
292
318
 
319
+
293
320
  @main.group()
294
321
  def add(**kwargs):
295
322
  """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.1
4
4
  Summary: Everything we've got
5
5
  Author-email: Andy Casey <andrew.casey@monash.edu>
6
6
  License: BSD 3-Clause License
File without changes
File without changes
File without changes