Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Gain smoothing (do not merge) #311

Open
wants to merge 85 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
3d0535c
Use nearest-neighbour interpolation in regions where extrapolation is…
JSKenyon Jul 26, 2023
3d1d5a6
Merge branch 'v0.2.1-dev' of github.com:ratt-ru/QuartiCal into v0.2.1…
JSKenyon Jul 26, 2023
6b22750
Add interface for degrid models.
JSKenyon Jul 28, 2023
a6b6acc
Add optional label and single field selection to backup app
Jul 28, 2023
e1e3dcb
Commit initial, semi-working code for generating model visibilities f…
JSKenyon Jul 28, 2023
40f5029
remove item instead of pop@index
Jul 30, 2023
d7e69e9
Add ducc0 and sympy as extras under degrid banner in pyproject.toml.
JSKenyon Jul 31, 2023
d8b6f3a
do not .remove() from xds_list
Jul 31, 2023
0b26002
Add/change functionlity to enable new-style models.
JSKenyon Jul 31, 2023
aed942a
Change advanced model to a simple boolean flag.
JSKenyon Jul 31, 2023
0d43f3e
Renaming.
JSKenyon Jul 31, 2023
6aa67f2
Fix tag format.
JSKenyon Jul 31, 2023
bba12a2
Make dask usage less unholy.
JSKenyon Jul 31, 2023
808e17a
Add clone.
JSKenyon Jul 31, 2023
519106b
Don't init vis as empty - duh.
JSKenyon Jul 31, 2023
58eff19
Fix correlation handling in degrid code.
JSKenyon Aug 1, 2023
2371715
Expose degrid (predict) threading in model arguments.
JSKenyon Aug 1, 2023
7f1bc9a
Disable degrid inputs in non-advanced mode.
JSKenyon Aug 1, 2023
00af518
Use legacy models in tests until such time as I can reconfigure them.
JSKenyon Aug 1, 2023
e334026
inconsistent RNG error
landmanbester Aug 2, 2023
aaaf76a
Utilise environment variable when dask.address is unset. (#288)
JSKenyon Aug 3, 2023
5f0368c
Merge branch 'v0.2.1-dev' of github.com:ratt-ru/QuartiCal into v0.2.1…
JSKenyon Aug 4, 2023
a5b6650
Merge branch 'v0.2.1-dev' into v0.2.1-degridder
JSKenyon Aug 4, 2023
ad4f91b
Fix incorrect import in tests.
JSKenyon Aug 4, 2023
232ae41
Commit WIP code for experimental fragment branch.
JSKenyon Aug 4, 2023
ec2f496
Import from fragments.
JSKenyon Aug 4, 2023
f56b2cf
depend on stimela@FIASCO3 and dask-ms@multisource-experimental
Aug 10, 2023
037a40d
depend on stimela@FIASCO3-hlb
Aug 10, 2023
1bb7448
Add output.fragment_path, which, if set, causes QC to write columns t…
JSKenyon Aug 10, 2023
e734507
Add plotting functionality (#290)
JSKenyon Aug 25, 2023
b23b168
Merge branch 'v0.2.1-dev' of github.com:ratt-ru/QuartiCal into v0.2.1…
JSKenyon Aug 29, 2023
d6d8701
Merge in plotter.
JSKenyon Aug 29, 2023
fecf61b
Merge in plotter.
JSKenyon Aug 29, 2023
c107e48
Merge branch 'v0.2.1-degridder' of github.com:ratt-ru/QuartiCal into …
JSKenyon Aug 29, 2023
2e0b9e8
Fix #293 - OOB access caused by `output.subtract_directions` (#294)
JSKenyon Aug 30, 2023
5cfadc4
Merge branch 'v0.2.1-dev' of github.com:ratt-ru/QuartiCal into v0.2.1…
JSKenyon Sep 13, 2023
9a28794
Namedbackups (#296)
landmanbester Sep 13, 2023
b740a37
Merge branch 'v0.2.1-dev' of github.com:ratt-ru/QuartiCal into v0.2.1…
JSKenyon Sep 13, 2023
9f1d03a
Merge branch 'v0.2.1-dev' into v0.2.1-degridder
JSKenyon Sep 13, 2023
5a1d5c7
Merge branch 'v0.2.1-dev' into v0.2.1-experimental-dask-ms
JSKenyon Sep 15, 2023
d8a9719
Depend on dask-ms master.
JSKenyon Sep 21, 2023
34db3fb
Merge in changes from experimental dask-ms branch i.e. fragment support.
JSKenyon Sep 21, 2023
d733257
Add rechunking in fragments code and ROWID to columns in backup app.
JSKenyon Sep 21, 2023
b6b700e
Expose model component help.
JSKenyon Sep 22, 2023
bb37e9c
Fix broken identitiy model behaviour caused by addition of degridder.
JSKenyon Sep 26, 2023
9aa54da
Selectively disable MAD flagging criteria (#298)
JSKenyon Oct 3, 2023
72c5726
Merge branch 'v0.2.1-dev' of github.com:ratt-ru/QuartiCal into v0.2.1…
JSKenyon Oct 3, 2023
ce5997b
Merge branch 'v0.2.1-dev' into v0.2.1-degridder
JSKenyon Oct 3, 2023
80428a0
nifty thread safety woes
landmanbester Oct 5, 2023
d2808a2
Disable mad flagging on off-diagonals by default (#300)
JSKenyon Oct 19, 2023
cec8d21
Merge branch 'v0.2.1-dev' of github.com:ratt-ru/QuartiCal into v0.2.1…
JSKenyon Oct 19, 2023
6bebfa6
Merge branch 'v0.2.1-dev' into v0.2.1-degridder
JSKenyon Oct 19, 2023
1626f4a
Fix bug affecting non-standard columns in `input_ms.data_column` (#301)
JSKenyon Oct 20, 2023
f8de83e
Don't allow restore app to overwrite metadata (#307)
landmanbester Oct 25, 2023
1fa06c3
Merge branch 'v0.2.1-dev' into v0.2.1-degridder
Oct 30, 2023
3575b69
fix merge conflicts
Oct 30, 2023
5a9f7e5
add nifty dependency
Oct 30, 2023
3478252
Merge branch 'bandpass_smoothing' of https://github.com/ratt-ru/Quart…
landmanbester Oct 30, 2023
0808c00
nifty -> nifty8 in pyproject.toml
Oct 30, 2023
4a3b076
Merge branch 'bandpass_smoothing' of https://github.com/ratt-ru/Quart…
landmanbester Oct 30, 2023
8a16e94
make concat_by_time optional in 1dsmooth
landmanbester Nov 2, 2023
e05ceb3
redirect nifty logs to a file
landmanbester Nov 3, 2023
98c51ea
propagate dask_opts to interpolation code
Nov 3, 2023
72d8e19
Fix for summary reporting SOURCE_ID as FIELD_ID (#309)
JSKenyon Nov 9, 2023
7b3ee49
move interpolation into executor
landmanbester Nov 10, 2023
58f9efc
hack to render params to gains
landmanbester Nov 10, 2023
c564aa8
Fix receptor summary (#310)
JSKenyon Nov 13, 2023
34d2a89
force branch = 'master' for dask-ms in pyproject.toml
landmanbester Nov 13, 2023
ed922d3
drop python3.8 in ci.yaml
landmanbester Nov 13, 2023
f08cd2c
merge in v0.2.1-dev
landmanbester Nov 13, 2023
14e76d2
fix merge error
landmanbester Nov 13, 2023
dfc6563
python = "^3.9" in pyproject.toml + fix for smoothing gains when full…
landmanbester Nov 13, 2023
eb25780
python = '^3.9, < 3.13' in pyproject.toml
landmanbester Nov 13, 2023
749f271
add jax nifty dependency
landmanbester Nov 13, 2023
6ac6790
remove optional jax dependency for nifty as it is not installed corre…
landmanbester Nov 13, 2023
5ddd329
pass dask opts in interpolation tests
landmanbester Nov 14, 2023
5bb4a09
adjust nifty optimization parameters
Dec 11, 2023
ff7ae29
make detrending optional during 1dsmooth
Dec 19, 2023
13d26cc
allow smoothing complex type gains
Dec 19, 2023
a790f7a
merge in master
Jan 30, 2024
dfb390e
python >= 3.10 for nifty_8
Jan 30, 2024
7379267
remove 3.9 from testing matrix
Jan 30, 2024
23491ab
regenerate lock file
Jan 30, 2024
dc56fb5
xds_from_fragment_ms in ms_handler
Jan 30, 2024
829948f
fix unmerged conflicts
Jan 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
python-version: ["3.9", "3.10"]
python-version: ["3.10"]

steps:
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -77,10 +77,10 @@ jobs:
# Run on tagged push (generated by tbump).
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.10

- name: Install poetry
uses: abatilo/actions-poetry@v2
Expand Down Expand Up @@ -120,4 +120,4 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Release
uses: softprops/[email protected]
uses: softprops/[email protected]
298 changes: 177 additions & 121 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include = [
]

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.10"
astro-tigger-lsm = ">=1.7.2, <=1.7.3"
codex-africanus = {extras = ["dask", "scipy", "astropy", "python-casacore"], version = ">=0.3.4, <=0.3.4"}
colorama = ">=0.4.6, <=0.4.6"
Expand All @@ -40,6 +40,12 @@ requests = ">=2.31.0, <=2.31.0"
"ruamel.yaml" = ">=0.17.26, <=0.17.40"
stimela = "2.0rc8"
tbump = ">=6.10.0, <=6.11.0"
ducc0 = "^0.31.0"
sympy = "^1.12"
nifty8 = {git = "https://gitlab.mpcdf.mpg.de/ift/nifty.git", branch = "NIFTy_8"}

[tool.poetry.extras]
degrid = ["ducc0", "sympy"]

[tool.poetry.scripts]
goquartical = 'quartical.executor:execute'
Expand Down
4 changes: 2 additions & 2 deletions quartical/apps/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def backup():
# This call exists purely to get the relevant shape and dtype info.
data_xds_list = xds_from_storage_ms(
args.ms_path,
columns=column_name,
columns=(column_name, "ROWID"),
index_cols=("TIME",),
group_cols=("FIELD_ID", "DATA_DESC_ID", "SCAN_NUMBER"),
)
Expand All @@ -81,7 +81,7 @@ def backup():
# Repeat of above call but now with correct chunking information.
data_xds_list = xds_from_storage_ms(
args.ms_path,
columns=column_name,
columns=(column_name, "ROWID"),
index_cols=("TIME",),
group_cols=("FIELD_ID", "DATA_DESC_ID", "SCAN_NUMBER"),
chunks=chunks
Expand Down
31 changes: 17 additions & 14 deletions quartical/apps/summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import argparse
from pathlib import Path
from daskms import xds_from_storage_ms, xds_from_storage_table
from daskms.experimental.fragments import (
xds_from_ms_fragment,
xds_from_table_fragment
)
from daskms.fsspec_store import DaskMSStore
import numpy as np
import dask.array as da
Expand Down Expand Up @@ -44,7 +47,7 @@ def configure_loguru(output_dir):
def antenna_info(path):

# NOTE: Assume one dataset for now.
ant_xds = xds_from_storage_table(path + "::ANTENNA")[0]
ant_xds = xds_from_table_fragment(path + "::ANTENNA")[0]

antenna_names = ant_xds.NAME.values
antenna_mounts = ant_xds.MOUNT.values
Expand All @@ -64,7 +67,7 @@ def antenna_info(path):

def data_desc_info(path):

dd_xds_list = xds_from_storage_table( # noqa
dd_xds_list = xds_from_table_fragment( # noqa
path + "::DATA_DESCRIPTION",
group_cols=["__row__"],
chunks={"row": 1, "chan": -1}
Expand All @@ -76,7 +79,7 @@ def data_desc_info(path):

def feed_info(path):

feed_xds_list = xds_from_storage_table(
feed_xds_list = xds_from_table_fragment(
path + "::FEED",
group_cols=["SPECTRAL_WINDOW_ID"],
chunks={"row": -1}
Expand Down Expand Up @@ -106,15 +109,15 @@ def feed_info(path):

def flag_cmd_info(path):

flag_cmd_xds = xds_from_storage_table(path + "::FLAG_CMD") # noqa
flag_cmd_xds = xds_from_table_fragment(path + "::FLAG_CMD") # noqa

# Not printing any summary information for this subtable yet - not sure
# what is relevant.


def field_info(path):

field_xds = xds_from_storage_table(path + "::FIELD")[0]
field_xds = xds_from_table_fragment(path + "::FIELD")[0]

field_ids = list(range(field_xds.sizes['row']))
source_ids = [i for i in field_xds.SOURCE_ID.values]
Expand Down Expand Up @@ -148,23 +151,23 @@ def field_info(path):

def history_info(path):

history_xds = xds_from_storage_table(path + "::HISTORY")[0] # noqa
history_xds = xds_from_table_fragment(path + "::HISTORY")[0] # noqa

# Not printing any summary information for this subtable yet - not sure
# what is relevant.


def observation_info(path):

observation_xds = xds_from_storage_table(path + "::OBSERVATION")[0] # noqa
observation_xds = xds_from_table_fragment(path + "::OBSERVATION")[0] # noqa

# Not printing any summary information for this subtable yet - not sure
# what is relevant.


def polarization_info(path):

polarization_xds = xds_from_storage_table(path + "::POLARIZATION")[0]
polarization_xds = xds_from_table_fragment(path + "::POLARIZATION")[0]

corr_types = polarization_xds.CORR_TYPE.values

Expand All @@ -182,15 +185,15 @@ def polarization_info(path):

def processor_info(path):

processor_xds = xds_from_storage_table(path + "::PROCESSOR")[0] # noqa
processor_xds = xds_from_table_fragment(path + "::PROCESSOR")[0] # noqa

# Not printing any summary information for this subtable yet - not sure
# what is relevant.


def spw_info(path):

spw_xds_list = xds_from_storage_table(
spw_xds_list = xds_from_table_fragment(
path + "::SPECTRAL_WINDOW",
group_cols=["__row__"],
chunks={"row": 1, "chan": -1}
Expand All @@ -214,7 +217,7 @@ def spw_info(path):

def state_info(path):

state_xds = xds_from_storage_table(path + "::STATE")[0] # noqa
state_xds = xds_from_table_fragment(path + "::STATE")[0] # noqa

# Not printing any summary information for this subtable yet - not sure
# what is relevant.
Expand All @@ -233,7 +236,7 @@ def source_info(path):

def pointing_info(path):

pointing_xds = xds_from_storage_table(path + "::POINTING")[0] # noqa
pointing_xds = xds_from_table_fragment(path + "::POINTING")[0] # noqa

# Not printing any summary information for this subtable yet - not sure
# what is relevant.
Expand Down Expand Up @@ -362,7 +365,7 @@ def summary():
# Open the data, grouping by the usual columns. Use these datasets to
# produce some useful summaries.

data_xds_list = xds_from_storage_ms(
data_xds_list = xds_from_ms_fragment(
path,
index_cols=("TIME",),
columns=("TIME", "FLAG", "FLAG_ROW", "DATA"),
Expand Down
25 changes: 4 additions & 21 deletions quartical/calibration/calibrate.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-
import numpy as np
import dask.array as da
from quartical.calibration.mapping import make_mapping_datasets
from quartical.gains.general.generics import (compute_residual,
compute_corrected_residual,
compute_corrected_weights)
from quartical.calibration.constructor import construct_solver
from quartical.gains.datasets import (make_gain_xds_lod,
make_net_xds_lod,
populate_net_xds_list)
from quartical.interpolation.interpolate import load_and_interpolate_gains
from quartical.gains.baseline import (compute_baseline_corrections,
apply_baseline_corrections)
from loguru import logger # noqa
Expand Down Expand Up @@ -114,7 +112,10 @@ def add_calibration_graph(
stats_xds_list,
solver_opts,
chain,
output_opts
mapping_xds_list,
gain_xds_lod,
output_opts,
dask_opts
):
"""Given data graph and options, adds the steps necessary for calibration.

Expand Down Expand Up @@ -144,24 +145,6 @@ def add_calibration_graph(
"indicate user error."
)

# Create a list of dicts of xarray.Dataset objects which will describe the
# gains per data xarray.Dataset.
gain_xds_lod = make_gain_xds_lod(data_xds_list, chain)

# Create a list of datasets containing mappings. TODO: Is this the best
# place to do this?
mapping_xds_list = make_mapping_datasets(data_xds_list, chain)

# If there are gains to be loaded from disk, this will load an interpolate
# them to be consistent with this calibration run. TODO: This needs to
# be substantially improved to handle term specific behaviour/utilize
# mappings.
gain_xds_lod = load_and_interpolate_gains(
gain_xds_lod,
chain,
output_opts.gain_directory
)

# Poplulate the gain xarray.Datasets with solutions and convergence info.
gain_xds_lod, data_xds_list, stats_xds_list = construct_solver(
data_xds_list,
Expand Down
22 changes: 20 additions & 2 deletions quartical/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
class _GainSchema(object):
gain: Dict[str, Parameter]

# The gain section is loaded explicitly, since we need to form up multiple
# instances.
# The gain and model sections are loaded explicitly, since we need to form
# up multiple instances.
gain_schema = oc.merge(
oc.structured(_GainSchema),
oc.load(f"{dirname}/gain_schema.yaml")
Expand All @@ -42,3 +42,21 @@ class _GainSchema(object):
bases=(BaseConfigSection,),
post_init=POST_INIT_MAP['gain']
)

@dataclass
class _ModelComponentSchema(object):
model_component: Dict[str, Parameter]

model_component_schema = oc.merge(
oc.structured(_ModelComponentSchema),
oc.load(f"{dirname}/model_component_schema.yaml")
)
model_component_schema = model_component_schema.model_component

# Create model dataclass.
ModelComponent = schema_utils.schema_to_dataclass(
model_component_schema,
"ModelComponent",
bases=(BaseConfigSection,),
post_init=POST_INIT_MAP['model_component']
)
34 changes: 33 additions & 1 deletion quartical/config/argument_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ input_model:
given by the dE tagged clusters in LSM1. Leaving this value unset
(the default) will use an identity model.

advanced_recipe:
dtype: bool
default: false
info:
Enable advanced recipe specification for use with degridder/more
complicated modes of model construction.

threads:
dtype: int
default: 1
info:
Controls the number of threads used internally by the various predict
methods. This should typically be set to the same value as
solver.threads if solver.threads is in use. Currently only supported
for degridding.

beam:
dtype: Optional[str]
info:
Expand Down Expand Up @@ -177,6 +193,15 @@ output:
Name of directory in which QuartiCal logging outputs will be stored.
s3 is not currently supported for these outputs.

fragment_path:
dtype: Optional[str]
info:
If set, instead of mutating the input by e.g. writing flags, instead
writes a fragment to this location. A fragment is a zarr backed data
format that is read and dynamically combined with any parent datasets.
This allows QuartiCal to operate in an entirely read-only fashion.
This option is experimental.

log_to_terminal:
default: true
dtype: bool
Expand Down Expand Up @@ -392,6 +417,13 @@ solver:
Specify as the integer index of the antenna - antenna names are not
currently supported.

bypass:
dtype: bool
default: false
info:
Disable executing the solver graph (eg. if only gain interpolation is
required).

dask:
threads:
dtype: Optional[int]
Expand All @@ -413,7 +445,7 @@ dask:

scheduler:
default: threads
choices: ["threads", "single-threaded", "distributed"]
choices: ["processes", "threads", "single-threaded", "distributed"]
info:
Which dask scheduler to use. The default, threads, is the most
appropriate for non-cluster use.
6 changes: 6 additions & 0 deletions quartical/config/config_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def __input_model_post_init__(self):
self.__validate_element_choices__()


def __model_component_post_init__(self):
self.__validate_choices__()
self.__validate_element_choices__()


def __output_post_init__(self):

self.__validate_choices__()
Expand Down Expand Up @@ -182,6 +187,7 @@ def __gain_post_init__(self):
POST_INIT_MAP = {
"input_ms": __input_ms_post_init__,
"input_model": __input_model_post_init__,
"model_component": __model_component_post_init__,
"output": __output_post_init__,
"mad_flags": __mad_flags_post_init__,
"solver": __solver_post_init__,
Expand Down
Loading
Loading