Skip to content

Commit

Permalink
remove defaults dict from worker definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
landmanbester committed Aug 30, 2024
1 parent ce9890e commit f882eb0
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 80 deletions.
11 changes: 6 additions & 5 deletions pfb/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class _CabInputsOutputs(object):
outputs: Dict[str, Parameter] = EmptyDictDefault()
policies: Optional[Dict[str, Any]] = None


# load schema files
if schema is None:

Expand All @@ -38,9 +39,9 @@ class _CabInputsOutputs(object):
# and a set containing locations of .yaml configs for pfb workers
schema = OmegaConf.create(tmp[0])

# # is this still necessary?
# for worker in schema.keys():
# for param in schema[worker]['inputs']:
# if schema[worker]['inputs'][param]['default'] == _UNSET_DEFAULT:
# schema[worker]['inputs'][param]['default'] = None
# is this still necessary?
for worker in schema.keys():
for param in schema[worker]['inputs']:
if schema[worker]['inputs'][param]['default'] == _UNSET_DEFAULT:
schema[worker]['inputs'][param]['default'] = None

7 changes: 1 addition & 6 deletions pfb/workers/degrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.degrid["inputs"].keys():
defaults[key.replace("-", "_")] = schema.degrid["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.degrid)
def degrid(**kw):
'''
Predict model visibilities to measurement sets.
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)

from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)
Expand Down
7 changes: 1 addition & 6 deletions pfb/workers/fluxmop.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.fluxmop["inputs"].keys():
defaults[key.replace("-", "_")] = schema.fluxmop["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.fluxmop)
Expand All @@ -22,8 +18,7 @@ def fluxmop(**kw):
Forward step aka flux mop.
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)

from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)
Expand Down
9 changes: 1 addition & 8 deletions pfb/workers/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.grid["inputs"].keys():
defaults[key.replace("-", "_")] = schema.grid["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.grid)
def grid(**kw):
Expand All @@ -25,9 +20,7 @@ def grid(**kw):
Set the --fits-cubes flag to also produce fits cubes.
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)

opts = OmegaConf.create(kw)
from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)

Expand Down
7 changes: 1 addition & 6 deletions pfb/workers/hci.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.hci["inputs"].keys():
defaults[key.replace("-", "_")] = schema.hci["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.hci)
def hci(**kw):
'''
Produce high cadence residual images.
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)

from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)
Expand Down
21 changes: 13 additions & 8 deletions pfb/workers/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,28 @@
pyscilog.init('pfb')
log = pyscilog.get_logger('INIT')
import time

from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema
import psutil

# create default parameters from schema
defaults = {}
for key in schema.init["inputs"].keys():
defaults[key.replace("-", "_")] = schema.init["inputs"][key]["default"]

# from pfb import parser
# from scabha.configuratt import load_nested
# from scabha.schema_utils import Schema
# config_file = os.path.dirname(parser.__file__) + '/init.yaml'
# schema, _ = load_nested([config_file],
# structured=OmegaConf.structured(Schema),
# config_class="PfbCleanCabs",
# use_cache=False)
# schema = OmegaConf.create(schema).init

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.init)
def init(**kw):
'''
Initialise Stokes data products for imaging
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)

from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)
Expand Down Expand Up @@ -187,7 +192,7 @@ def _init(**kw):
'ANTENNA2', 'TIME', 'INTERVAL', 'FLAG_ROW')
schema = {}
if opts.flag_column != 'None':
columns += (opts.flag_column)
columns += (opts.flag_column,)
schema[opts.flag_column] = {'dims': ('chan', 'corr')}
schema[dc1] = {'dims': ('chan', 'corr')}
if dc2 is not None:
Expand Down
7 changes: 1 addition & 6 deletions pfb/workers/klean.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.klean["inputs"].keys():
defaults[key.replace("-", "_")] = schema.klean["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.klean)
def klean(**kw):
'''
Modified single-scale clean.
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)

from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)
Expand Down
12 changes: 1 addition & 11 deletions pfb/workers/model2comps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.model2comps["inputs"].keys():
defaults[key.replace("-", "_")] = schema.model2comps["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.model2comps)
def model2comps(**kw):
'''
Convert model in dds to components.
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)

from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)
Expand Down Expand Up @@ -53,11 +48,6 @@ def model2comps(**kw):
for key in opts.keys():
print(' %25s = %s' % (key, opts[key]), file=log)

# basename = f'{basedir}/{oname}'
# fits_oname = f'{opts.fits_output_folder}/{oname}'
# dds_name = f'{basename}_{opts.suffix}.dds'
# dds_store = DaskMSStore(dds_name)

with ExitStack() as stack:
ti = time.time()
_model2comps(**opts)
Expand Down
7 changes: 1 addition & 6 deletions pfb/workers/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.restore["inputs"].keys():
defaults[key.replace("-", "_")] = schema.restore["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.restore)
def restore(**kw):
'''
Create fits image cubes from data products (eg. restored images).
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)

from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)
Expand Down
7 changes: 1 addition & 6 deletions pfb/workers/sara.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.sara["inputs"].keys():
defaults[key.replace("-", "_")] = schema.sara["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.sara)
def sara(**kw):
'''
Deconvolution using SARA regularisation
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)

from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)
Expand Down
7 changes: 1 addition & 6 deletions pfb/workers/smoovie.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.smoovie["inputs"].keys():
defaults[key.replace("-", "_")] = schema.smoovie["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.smoovie)
def smoovie(**kw):
'''
Smooth high cadence imaging results
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)
timestamp = time.strftime("%Y%m%d-%H%M%S")
ldir = Path(opts.log_directory).resolve()
ldir.mkdir(parents=True, exist_ok=True)
Expand Down
7 changes: 1 addition & 6 deletions pfb/workers/spotless.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@
from scabha.schema_utils import clickify_parameters
from pfb.parser.schemas import schema

# create default parameters from schema
defaults = {}
for key in schema.spotless["inputs"].keys():
defaults[key.replace("-", "_")] = schema.spotless["inputs"][key]["default"]

@cli.command(context_settings={'show_default': True})
@clickify_parameters(schema.spotless)
def spotless(**kw):
'''
Distributed spotless algorithm.
'''
defaults.update(kw)
opts = OmegaConf.create(defaults)
opts = OmegaConf.create(kw)

from pfb.utils.naming import set_output_names
opts, basedir, oname = set_output_names(opts)
Expand Down

0 comments on commit f882eb0

Please sign in to comment.