Skip to content

Commit

Permalink
refactor(ephemeris): Use ch_ephem
Browse files Browse the repository at this point in the history
This re-imports stuff moved to `ch_ephem`.  It both
re-imports everything that was moved back into `ch_util.ephemeris` for
backwards compatibility, but also removes references to
`ch_util.epheremis` from the code, using the newly-exported versions
of things directly.

This PR requires both:

* radiocosmology/caput#271
* chime-experiment/ch_ephem#1

Catalogs:

All the catalogs have been moved to `ch_ephem`, which provides a
standard interface to them via `ch_ephem.catalogs.load`.  To make this
change, `fluxcat.FluxCatalog.load` has been broken into two pieces.  The
new `fluxcat.FluxCatalog.load_dict` imports a catalog from an
already-parsed JSON dict (which is what `ch_ephem` provides).  The
original `fluxcat.FluxCatalog.load` works as it used to, but tail-calls
`load_dict` to do most of the importing.

Position data:

Position data (lat, lon, alt) is now obtained by fetching the parameter
out of the `caput.time.Observer` objects provided by `ch_ephem`.  The
constants in `ch_util.ephemeris` are populated by doing this.

Instrument geormetry:

`ch_ephem` has also taken on the geometry data (rotation, roll, offset)
that was in `tools` (where it's been re-imported from `ch_ephem`).

Private objects deleted:

I've also deleted a number of private objects which are no longer
being used (i.e. objects whose names start with a leading underscore).

Notable among these are the geometry constants from `ch_util.tools`
and the unused`ch_util.tools._LAT_LON` which had position data for
various instruments which differed from the position data provided
by `ch_util.ephemeris`.

Also removed are the long-deprectated `ch_util.ephemeris._get_chime` and
`ch_util.ephemeris.transit_RA`.
  • Loading branch information
ketiltrout committed Jul 27, 2024
1 parent 17cbd4d commit 1747772
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 39,662 deletions.
23 changes: 13 additions & 10 deletions ch_util/cal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
from scipy.linalg import lstsq, inv

from caput import memh5, time as ctime

from chimedb import dataset as ds
from chimedb.dataset.utils import state_id_of_type, unique_unmasked_entry
from ch_util import ephemeris, tools

from ch_ephem.observers import chime
import ch_ephem.sources

from ch_util import tools

# Set up logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -2474,13 +2479,13 @@ def thermal_amplitude(delta_T, freq):
def _el_to_dec(el):
"""Convert from el = sin(zenith angle) to declination in degrees."""

return np.degrees(np.arcsin(el)) + ephemeris.CHIMELATITUDE
return np.degrees(np.arcsin(el)) + chime.latitude


def _dec_to_el(dec):
"""Convert from declination in degrees to el = sin(zenith angle)."""

return np.sin(np.radians(dec - ephemeris.CHIMELATITUDE))
return np.sin(np.radians(dec - chime.latitude))


def get_reference_times_file(
Expand Down Expand Up @@ -2691,10 +2696,10 @@ def get_reference_times_dataset_id(

# The CHIME calibration sources
_source_dict = {
"cyga": ephemeris.CygA,
"casa": ephemeris.CasA,
"taua": ephemeris.TauA,
"vira": ephemeris.VirA,
"cyga": ch_ephem.sources.CygA,
"casa": ch_ephem.sources.CasA,
"taua": ch_ephem.sources.TauA,
"vira": ch_ephem.sources.VirA,
}

# Get the set of gain IDs for each time stamp
Expand Down Expand Up @@ -2728,9 +2733,7 @@ def get_reference_times_dataset_id(

# Calculate the source transit time, and sanity check it
source = _source_dict[d["source_name"]]
d["source_transit"] = ephemeris.transit_times(
source, d["gen_time"] - 24 * 3600.0
)
d["source_transit"] = chime.transit_times(source, d["gen_time"] - 24 * 3600.0)
cal_diff_hours = (d["gen_time"] - d["source_transit"]) / 3600
if cal_diff_hours > 3:
logger.warn(
Expand Down
Loading

0 comments on commit 1747772

Please sign in to comment.