Skip to content

Commit

Permalink
Merge pull request #825 from desihub/ADM-read-mtl-basic
Browse files Browse the repository at this point in the history
Add different Table reader options to mtl.update_ledger()
  • Loading branch information
geordie666 authored Jun 7, 2024
2 parents c77b037 + 6922a0f commit 957645b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ desitarget Change Log
2.7.1 (unreleased)
------------------

* Add different Table reader options to mtl.update_ledger() [`PR #825`_].
* Augments `PR #822`_.
* Add function to check format of secondary target files [`PR #824`_].
* When resolving, only set bits for northern cuts/imaging [`PR #823`_].
* And, similarly, for southern cuts in southern imaging.
Expand All @@ -27,6 +29,7 @@ desitarget Change Log
.. _`PR #822`: https://github.com/desihub/desitarget/pull/822
.. _`PR #823`: https://github.com/desihub/desitarget/pull/823
.. _`PR #824`: https://github.com/desihub/desitarget/pull/824
.. _`PR #825`: https://github.com/desihub/desitarget/pull/825

2.7.0 (2023-12-05)
------------------
Expand Down
19 changes: 14 additions & 5 deletions py/desitarget/mtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1643,14 +1643,18 @@ def standard_override_columns(mtl):
return mtl


def process_overrides(ledgerfn):
def process_overrides(ledgerfn, tabform='ascii.basic'):
"""
Recover MTL entries from override ledgers and update those ledgers.
Parameters
----------
ledgerfn : :class:`str`
Name of the override ledger to process.
tabform : :class:`str`, optional, defaults to 'ascii.basic'
Format to pass to the astropy Table.read() function. The default
('ascii.basic') is standard for reading and writing MTL files.
But 'ascii.ecsv' is useful for some of the mock/alt-MTL work.
Returns
-------
Expand All @@ -1670,7 +1674,7 @@ def process_overrides(ledgerfn):
log.info("Processing override ledgers")

# ADM read in the relevant entries in the override ledger.
mtl = Table(io.read_mtl_ledger(ledgerfn))
mtl = Table(io.read_mtl_ledger(ledgerfn, tabform=tabform))

# ADM limit to entries with NUMOVERRIDE > 0.
ii = mtl["NUMOVERRIDE"] > 0
Expand Down Expand Up @@ -2228,7 +2232,7 @@ def reprocess_ledger(hpdirname, zcat, obscon="DARK"):


def update_ledger(hpdirname, zcat, targets=None, obscon="DARK",
numobs_from_ledger=False):
numobs_from_ledger=False, tabform='ascii.basic'):
"""
Update relevant HEALPixel-split ledger files for some targets.
Expand All @@ -2255,6 +2259,10 @@ def update_ledger(hpdirname, zcat, targets=None, obscon="DARK",
If ``True`` then inherit the number of observations so far from
the ledger rather than expecting it to have a reasonable value
in the `zcat.`
tabform : :class:`str`, optional, defaults to 'ascii.basic'
Format to pass to the astropy Table.read() function. The default
('ascii.basic') is standard for reading and writing MTL files.
But 'ascii.ecsv' is useful for some of the mock/alt-MTL work.
Returns
-------
Expand Down Expand Up @@ -2282,7 +2290,8 @@ def update_ledger(hpdirname, zcat, targets=None, obscon="DARK",
pixnum = list(set(pixnum))
# ADM we'll read in too many targets, here, but that's OK as
# ADM make_mtl(trimtozcat=True) only returns the updated targets.
targets = io.read_mtl_in_hp(hpdirname, nside, pixnum, unique=True)
targets = io.read_mtl_in_hp(hpdirname, nside, pixnum, unique=True,
tabform=tabform)

# ADM if requested, use the previous values in the ledger to set
# ADM NUMOBS in the zcat.
Expand Down Expand Up @@ -2319,7 +2328,7 @@ def update_ledger(hpdirname, zcat, targets=None, obscon="DARK",
# ADM if an override ledger exists, update it and recover its
# ADM relevant MTL entries.
if os.path.exists(overfn):
overmtl = process_overrides(overfn)
overmtl = process_overrides(overfn, tabform=tabform)
# ADM add any override entries TO THE END OF THE LEDGER.
mtlpix = vstack([mtlpix, overmtl])

Expand Down

0 comments on commit 957645b

Please sign in to comment.