edges_cal

Build Status codecov Code style: black Documentation Status

Calculate calibration coefficients for EDGES Calibration Observations

Installation

Download/clone the repo and do

pip install .

in the top-level directory (optionally add an -e for develop-mode). Preferably, do this in an isolated python/conda environment.

Usage

CLI

There is a very basic CLI set up for running a full calibration pipeline over a set of data. To use it, do

$ edges-cal run --help

Multiple options exist, but the only ones required are CONFIG and PATH. The first should point to a YAML configuration for the run, and the second should point to a directory in which exists S11, Resistance and Spectra folders. Thus:

$ edges-cal run ~/config.yaml .

will work if you are in such a directory.

The config.yaml consists of a set of parameters passed to edges_cal.CalibrationObservation. See its docstring for more details.

In addition, you can run a “term sweep” over a given calibration, iterating over number of Cterms and Wterms until some threshold is met. This uses the same configuration as edges-cal run, but you can pass a maximum number of C and W-terms, along with a threshold at which to stop the sweep (this is a threshold in absolute RMS over degrees of freedom). This will write out a Calibration file for the “best” set of parameters.

You can also create full Jupyter notebook reports (and convert them to PDF!) using the CLI. To get this to work, you must install edges-cal with pip install edges-cal[report]. Then you must do the following:

  1. Activate the environment you wish to use to generate the reports (usually conda activate edges)

  2. Run python -m ipykernel install --user --name edges --display-name "edges"

Note that in the second command, calling it “edges” is necessary (regardless of the name of your environment!).

Now you can run

$ edges-cal report PATH --config ~/config.yaml

(obviously there are other parameters – use edges-cal report --help for help). The PATH should again be a calibration observation directory. The config can be the same file as in edges-cal run, and is optional. By default, both a notebook and a PDF will be produced, in the outputs/ directory of the observation. You can turn off the PDF production with a -R flag.

Similarly, you can compare two observations as a report notebook with

$ edges-cal compare PATH COMPARE --config ~/config.yaml --config-cmp ~/config.yaml

This is intended to more easily show up what might be wrong in an observation, when compared to a “golden” observation, for example.

Using the Library

To import:

import edges_cal as ec

Most of the functionality is highly object-oriented, and objects exist for each kind of data/measurement. However, there is a container object for all of these, which manages them. Thus you will typically use

>>> calobs = ec.CalibrationObservation(path="path/to/top/level")

Several other options exist, and they have documentation that you can access interactively by using

>>> help(ec.CalibrationObservation)

The most relevant attributes are the (lazily-evaluated) calibration coefficient models:

>>> plt.plot(calobs.freq.freq, calobs.C1())

the various plotting routines, eg.

>>> calobs.plot_coefficients()

and the calibrate/decalibrate methods:

>>> calibrated_temp = calobs.calibrate("ambient")

Note that this final method can be applied to any LoadSpectrum – i.e. you can pass in field observations, or an antenna simulator.

Contents

License

The MIT License (MIT)

Copyright (c) 2019 Steven Murray

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributors

  • Nivedita Mahesh @nmahesh1412

  • David Lewis @dmlewis9

  • Steven Murray @steven-murray

Changelog

v3.2.0

Added

  • New CompositeModel class that combines modular linear models and behaves like a simple Model.

Changed

  • Fully reworked NoiseWaves class to use the CompositeModel class.

v3.1.1

Changed

  • New model_filter function that xrfi_model calls and can be called by other more general functions.

Added

  • New tests of ModelFilterInfo and ModelFilterInfoContainer

v3.1.0

Added

  • New semi-rigid S-parameters file from 2017.

v3.0.0

Fixed

  • Tests were slow because they were using the wrong default for getting the standard deviation in xrfi_model. Now uses the fast kind.

Changed

  • modelling module got an overhaul. It now consists of smaller, self-consistent classes that are based on attrs and are read-only (but clonable). There is an explicit split between a Model and a FixedLinearModel which is defined at some coordinates x, allowing the latter to provide speedups for fitting lots of data at the same coordinates. They are also YAML-read/writable.

v2.1.0

Added

  • FourierDay linear model

Fixed

  • models were being mutated in ModelFit. No more.

v2.0.0

Added

  • Ability to pass through LNA S11 options

  • Ability to specify t_load and t_load_ns in spectra

  • Easier conversion to Calibration object from CalibrationObservation

  • New NoiseWaves linear model

  • Modular InternalSwitch class

Fixed

  • Ensure fitted models are always copied

v1.0.0

Added

  • Visualization of xrfi_model output.

  • Allow init_flags as input to xrfi_model

Changed

  • Performance boost for xrfi_model_sweep

  • Faster modelling in detail

  • Compatibility with edges-io v1.

  • More consistency in API between different XRFI models.

  • Allow not passing spectrum to xrfi_explicit ### Fixed

  • Improvements to typing.

  • Improvements to xrfi tests.

v0.7.0

Added

  • Automatic notebook reports for calibration

  • xrfi_model_sweep that actually works and is tested.

  • Faster model evaluations

Fixed

  • xRFI doesn’t assume that input spectrum is all positive (could be residuals, and therefore have negatives).

Version 0.4.0

Changed

  • Much faster modeling via re-use of basis function evaluations

Version 0.3.0

Changed

  • load_name now always an alias (hot_load, ambient, short, open)

  • Load.temp_ave now always the correct one (even for hot load)

Version 0.2.1

Added

  • Basic tests

  • Travis/tox/codecov setup

Version 0.2.0

Added

  • Many many many new features, and complete modularisation of code

  • Now based on edges-io package to do the hard work.

  • Refined most modules to remove redundant code

  • Added better package structure

Version 0.1.0

  • First working version on github.

Tutorials

A good place to get a feel for how edges-cal works is by following some tutorials:

If you’ve covered the tutorials and still have questions about “how to do stuff” in edges-cal, consult the FAQs:

Miscellaneous FAQs

Can I eat soup for breakfast?

You should not.

API Reference

High Level Interface

edges_cal.cal_coefficients

The main user-facing module of edges-cal.

Lower Level Methods

edges_cal.reflection_coefficient

Functions for working with reflection coefficients.

edges_cal.receiver_calibration_func

Functions for calibrating the receiver.

edges_cal.modelling

Functions for generating least-squares model fits for linear models.

edges_cal.xrfi

Functions for excising RFI.

edges_cal.tools

Tools to use in other modules.

Package Config

edges_cal.types

Simple type definitions for use internally.

edges_cal.cached_property

A wrapper of cached_property that also saves which things are cached.

Indices and tables