sdss-almanac 0.2.11__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.11"
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
@@ -41,7 +41,12 @@ def main(
41
41
 
42
42
  # This keeps the default behaviour as 'query mode' but allows for commands like 'config'.
43
43
  if ctx.invoked_subcommand is not None:
44
- command = dict(config=config, dump=dump, add=add)[ctx.invoked_subcommand]
44
+ command = dict(
45
+ config=config,
46
+ dump=dump,
47
+ add=add,
48
+ lookup=lookup
49
+ )[ctx.invoked_subcommand]
45
50
  return ctx.invoke(command, **ctx.params)
46
51
 
47
52
  import h5py as h5
@@ -196,6 +201,110 @@ def main(
196
201
  for item in buffered_critical_logs:
197
202
  logger.critical(item)
198
203
 
204
+
205
+ @main.command()
206
+ @click.argument("identifier", type=int)
207
+ @click.option("--careful", is_flag=True, help="Don't assume unique field for a given (obs, mjd, catalogid)")
208
+ def lookup(identifier, careful, **kwargs):
209
+ """Lookup a target by catalog identifier or SDSS identifier."""
210
+
211
+ if not identifier:
212
+ return
213
+
214
+ from peewee import fn
215
+ from itertools import chain, starmap
216
+ from almanac.database import database
217
+ from almanac.apogee import get_exposures
218
+ from sdssdb.peewee.sdss5db.targetdb import (
219
+ Assignment, AssignmentStatus,CartonToTarget, Target, Hole, Observatory,
220
+ Design, DesignToField
221
+ )
222
+ from sdssdb.peewee.sdss5db.catalogdb import SDSS_ID_flat
223
+
224
+ from rich.table import Table as RichTable
225
+ from rich.console import Console
226
+ from rich.live import Live
227
+
228
+ sq = (
229
+ SDSS_ID_flat
230
+ .select(SDSS_ID_flat.sdss_id)
231
+ .where(
232
+ (SDSS_ID_flat.sdss_id == identifier)
233
+ | (SDSS_ID_flat.catalogid == identifier)
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))
242
+ .tuples()
243
+ )
244
+
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:
251
+ raise click.ClickException(f"Identifier {identifier} not found in SDSS-V database")
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
+
256
+ q = (
257
+ Target
258
+ .select(
259
+ fn.Lower(Observatory.label),
260
+ AssignmentStatus.mjd,
261
+ )
262
+ .join(CartonToTarget)
263
+ .join(Assignment)
264
+ .join(AssignmentStatus)
265
+ .switch(Assignment)
266
+ .join(Hole)
267
+ .join(Observatory)
268
+ .where(
269
+ Target.catalogid.in_(tuple(catalogids))
270
+ & (AssignmentStatus.status == 1)
271
+ )
272
+ .tuples()
273
+ )
274
+ q = tuple(set([(obs, int(mjd)) for obs, mjd in q]))
275
+
276
+ console = Console()
277
+
278
+ title = f"SDSS ID {sdss_id}"
279
+
280
+ # Create Rich table
281
+ rich_table = RichTable(title=f"{title}", title_style="bold blue", show_header=True, header_style="bold cyan")
282
+
283
+ for field_name in ("#", "obs", "mjd", "exposure", "field", "fiber_id", "catalogid"):
284
+ rich_table.add_column(field_name, justify="center")
285
+
286
+ fields = {}
287
+ i = 1
288
+ with Live(rich_table, console=console, refresh_per_second=4) as live:
289
+ for exposure in chain(*starmap(get_exposures, q)):
290
+ key = (exposure.observatory, exposure.mjd)
291
+ if (key not in fields or fields[key] == exposure.field_id) or careful:
292
+ for target in exposure.targets:
293
+ if target.catalogid in catalogids:
294
+ fields[key] = exposure.field_id
295
+ rich_table.add_row(*list(map(str, (
296
+ i,
297
+ exposure.observatory,
298
+ exposure.mjd,
299
+ exposure.exposure,
300
+ exposure.field_id,
301
+ target.fiber_id,
302
+ target.catalogid
303
+ ))))
304
+ i += 1
305
+ break
306
+
307
+
199
308
  @main.group()
200
309
  def add(**kwargs):
201
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.11
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=QcoH8UccOj3uxeiDxyRPNh9TKep9l3jXrrZOuFVxFVc,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=MUqE9kBfRfJPl6FLw-pJ1EUpIfZcami5IakGqxCvXsQ,26523
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.11.dist-info/licenses/LICENSE.md,sha256=_7dAUQQ5Ph_x1hcFXhi9aHBcqq9H11zco12eO4B3Cyg,1504
24
- sdss_almanac-0.2.11.dist-info/METADATA,sha256=AwjbNYmVC86tJsJj09tcXOXt1-SiOgjYsVQmOU0vcnE,6995
25
- sdss_almanac-0.2.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
- sdss_almanac-0.2.11.dist-info/entry_points.txt,sha256=5Obfm-uaVxE3RnRm2W7dYaX_O_j5ggGvAW5UQG5AtuE,45
27
- sdss_almanac-0.2.11.dist-info/top_level.txt,sha256=sWBGH9a-2-nFB2-rGqioyigbkcz14t1u8rqAs_RYe_w,8
28
- sdss_almanac-0.2.11.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,,