Skip to content

Commit 44b3a44

Browse files
committedNov 3, 2018
Make the base module a ABC
1 parent 0e2ee5d commit 44b3a44

13 files changed

+57
-151
lines changed
 

‎.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ casa.log
77
.virtualenv*/
88
*.egg-info/
99
.eggs/
10-
data/small.tgz
11-
data/small/
10+
data/
1211
cwl/outdir/

‎apercal/modules/base.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
from glob import glob
22
from os import path
3+
from apercal.libs.lib import show
34
from typing import List, Tuple, Any
45

6+
from abc import abstractproperty, ABCMeta
7+
58

69
class BaseModule:
7-
subdirification = None
8-
basedir = None
9-
rawsubdir = None
10+
11+
__metaclass__ = ABCMeta
12+
13+
@abstractproperty
14+
def module_name(self):
15+
pass
16+
1017
fluxcal = None
1118
polcal = None
1219
target = None
20+
basedir = None
21+
beam = None
22+
rawsubdir = None
23+
crosscalsubdir = None
24+
selfcalsubdir = None
25+
linesubdir = None
26+
contsubdir = None
27+
polsubdir = None
28+
mossubdir = None
29+
transfersubdir = None
30+
subdirification = True
1331

1432
def get_fluxcal_path(self):
1533
if self.subdirification:
@@ -35,3 +53,6 @@ def get_datasets(self, beams=None):
3553
else:
3654
# TODO: (gijs) is it okay to just always set this to 0?
3755
return [(self.target, '00')]
56+
57+
def show(self, showall=False):
58+
show(self, self.module_name, showall)

‎apercal/modules/ccal.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class ccal(BaseModule):
2525
Crosscal class to handle applying the calibrator gains and prepare the dataset for self-calibration.
2626
"""
2727

28+
module_name = 'CROSSCALL'
29+
2830
fluxcal = None
2931
polcal = None
3032
target = None
@@ -87,9 +89,6 @@ def go(self):
8789
self.transfer_to_target()
8890
logger.info("CROSS CALIBRATION done ")
8991

90-
def show(self, showall=False):
91-
lib.show(self, 'CROSSCALL', showall)
92-
9392
def TEC(self):
9493
"""
9594
Creates the TEC correction images and TEC calibration tables for all datasets

‎apercal/modules/continuum.py

+3-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pandas as pd
55
import os
66

7+
from apercal.modules.base import BaseModule
78
from apercal.libs.calculations import calc_dr_maj, calc_theoretical_noise, calc_theoretical_noise_threshold, \
89
calc_dynamic_range_threshold, calc_clean_cutoff, calc_noise_threshold, calc_mask_threshold
910
from apercal.subs import setinit as subs_setinit
@@ -19,24 +20,12 @@
1920
logger = logging.getLogger(__name__)
2021

2122

22-
class continuum:
23+
class continuum(BaseModule):
2324
"""
2425
Continuum class to produce continuum data products (Deep continuum images of individual frequency chunks and
2526
stacked continuum image).
2627
"""
27-
fluxcal = None
28-
polcal = None
29-
target = None
30-
basedir = None
31-
beam = None
32-
rawsubdir = None
33-
crosscalsubdir = None
34-
selfcalsubdir = None
35-
linesubdir = None
36-
contsubdir = None
37-
polsubdir = None
38-
mossubdir = None
39-
transfersubdir = None
28+
module_name = 'CONTINUUM'
4029

4130
contdir = None
4231
selfcaldir = None
@@ -995,9 +984,6 @@ def detailed_summary(self):
995984

996985
return df
997986

998-
def show(self, showall=False):
999-
lib.show(self, 'CONTINUUM', showall)
1000-
1001987
def reset(self):
1002988
"""
1003989
Function to reset the current step and remove all generated data including continuum parameters in the

‎apercal/modules/convert.py

+3-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import drivecasa
77
import os
88

9+
from apercal.modules.base import BaseModule
910
from apercal.subs import setinit as subs_setinit
1011
from apercal.subs import managefiles as subs_managefiles
1112
from apercal.subs.param import get_param_def
@@ -16,24 +17,12 @@
1617
logger = logging.getLogger(__name__)
1718

1819

19-
class convert:
20+
class convert(BaseModule):
2021
"""
2122
Class to convert data from MS-format into UVFITS, and from UVFITS into MIRIAD format. Resulting datasets will
2223
have the endings .MS, .UVFITS, and .mir.
2324
"""
24-
fluxcal = None
25-
polcal = None
26-
target = None
27-
basedir = None
28-
beam = None
29-
rawsubdir = None
30-
crosscalsubdir = None
31-
selfcalsubdir = None
32-
linesubdir = None
33-
contsubdir = None
34-
polsubdir = None
35-
mossubdir = None
36-
transfersubdir = None
25+
module_name = 'CONVERT'
3726

3827
convert_fluxcal = True # Convert the flux calibrator dataset
3928
convert_polcal = True # Convert the polarised calibrator dataset
@@ -489,9 +478,6 @@ def summary(self):
489478

490479
return df
491480

492-
def show(self, showall=False):
493-
lib.show(self, 'CONVERT', showall)
494-
495481
def reset(self):
496482
"""
497483
Function to reset the current step and remove all generated data. Be careful! Deletes all data generated in

‎apercal/modules/line.py

+4-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import os
88

9+
from apercal.modules.base import BaseModule
910
from apercal.libs.calculations import calc_dr_maj, calc_theoretical_noise, calc_theoretical_noise_threshold, \
1011
calc_dynamic_range_threshold, calc_clean_cutoff, calc_noise_threshold, calc_mask_threshold, get_freqstart, \
1112
calc_dr_min, calc_line_masklevel, calc_miniter
@@ -16,23 +17,12 @@
1617
logger = logging.getLogger(__name__)
1718

1819

19-
class line:
20+
class line(BaseModule):
2021
"""
2122
Line class to do continuum subtraction and prepare data for line imaging.
2223
"""
23-
fluxcal = None
24-
polcal = None
25-
target = None
26-
basedir = None
27-
beam = None
28-
rawsubdir = None
29-
crosscalsubdir = None
30-
selfcalsubdir = None
31-
linesubdir = None
32-
contsubdir = None
33-
polsubdir = None
34-
mossubdir = None
35-
transfersubdir = None
24+
module_name = 'LINE'
25+
3626

3727
line_splitdata = None
3828
line_splitdata_chunkbandwidth = None
@@ -765,9 +755,6 @@ def get_last_major_iteration(self, chunk):
765755
lastmajor = n
766756
return lastmajor
767757

768-
def show(self, showall=False):
769-
lib.show(self, 'LINE', showall)
770-
771758
def reset(self):
772759
"""
773760
Function to reset the current step and remove all generated data. Be careful! Deletes all data generated in

‎apercal/modules/line_parallel.py

+3-17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import time
1111
import timeit
1212

13+
from apercal.modules.base import BaseModule
1314
from apercal.libs.calculations import calc_dr_maj, calc_theoretical_noise, calc_theoretical_noise_threshold, \
1415
calc_dynamic_range_threshold, calc_clean_cutoff, calc_noise_threshold, calc_mask_threshold, get_freqstart, \
1516
calc_dr_min, calc_line_masklevel, calc_miniter
@@ -21,23 +22,11 @@
2122
logger = logging.getLogger(__name__)
2223

2324

24-
class line_parallel:
25+
class line_parallel(BaseModule):
2526
"""
2627
Line class to do continuum subtraction and prepare data for line imaging.
2728
"""
28-
fluxcal = None
29-
polcal = None
30-
target = None
31-
basedir = None
32-
beam = None
33-
rawsubdir = None
34-
crosscalsubdir = None
35-
selfcalsubdir = None
36-
linesubdir = None
37-
contsubdir = None
38-
polsubdir = None
39-
mossubdir = None
40-
transfersubdir = None
29+
module_name = 'LINE'
4130

4231
line_splitdata = None
4332
line_splitdata_chunkbandwidth = None
@@ -1905,9 +1894,6 @@ def get_last_major_iteration(self, chunk):
19051894
lastmajor = n
19061895
return lastmajor
19071896

1908-
def show(self, showall=False):
1909-
lib.show(self, 'LINE', showall)
1910-
19111897
def reset(self):
19121898
"""
19131899
Function to reset the current step and remove all generated data. Be careful! Deletes all data generated in

‎apercal/modules/mosaic.py

+3-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pandas as pd
55
import os
66

7+
from apercal.modules.base import BaseModule
78
from apercal.subs import setinit as subs_setinit
89
from apercal.subs import managefiles as subs_managefiles
910
from apercal.subs import readmirhead as subs_readmirhead
@@ -16,23 +17,11 @@
1617
logger = logging.getLogger(__name__)
1718

1819

19-
class mosaic:
20+
class mosaic(BaseModule):
2021
"""
2122
Mosaic class to produce mosaics of continuum, line and polarisation images.
2223
"""
23-
fluxcal = None
24-
polcal = None
25-
target = None
26-
basedir = None
27-
beam = None
28-
rawsubdir = None
29-
crosscalsubdir = None
30-
selfcalsubdir = None
31-
linesubdir = None
32-
contsubdir = None
33-
polsubdir = None
34-
mossubdir = None
35-
transfersubdir = None
24+
module_name = 'MOSAIC'
3625

3726
mosdir = None
3827
mosaic_continuum_stack = None
@@ -774,9 +763,6 @@ def detailed_summary_continuumchunks(self, chunk=None):
774763

775764
return df
776765

777-
def show(self, showall=False):
778-
lib.show(self, 'MOSAIC', showall)
779-
780766
def reset(self):
781767
"""
782768
Function to reset the current step and remove all generated data. Be careful! Deletes all data generated in

‎apercal/modules/polarisation.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import logging
22
from apercal.subs import setinit as subs_setinit
33
from apercal.libs import lib
4-
4+
from apercal.modules.base import BaseModule
55

66
logger = logging.getLogger(__name__)
77

88

9-
class polarisation:
9+
class polarisation(BaseModule):
1010
"""
1111
Final class to produce final data products (Deep continuum images, line cubes, and polairsation images and
1212
Faraday-cubes).
1313
"""
14+
module_name = 'POLARISATION'
1415

1516
def __init__(self, file_=None, **kwargs):
1617
self.default = lib.load_config(self, file_)

‎apercal/modules/preflag.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class preflag(BaseModule):
2626
"""
2727
Preflagging class. Used to automatically flag data and apply preknown flags.
2828
"""
29+
module_name = 'PREFLAG'
30+
2931
fluxcal = None
3032
polcal = None
3133
target = None
@@ -1214,9 +1216,6 @@ def summary(self):
12141216

12151217
return df
12161218

1217-
def show(self, showall=False):
1218-
lib.show(self, 'PREFLAG', showall)
1219-
12201219
def reset(self):
12211220
"""
12221221
Function to reset the current step and remove all generated data. Be careful! Deletes all data generated in

‎apercal/modules/prepare.py

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import ConfigParser
21
import glob
32
import logging
43
import pandas as pd
54
import os
65
import numpy as np
76

7+
from apercal.modules.base import BaseModule
88
from apercal.subs import irods as subs_irods
99
from apercal.subs import setinit as subs_setinit
1010
from apercal.subs import managefiles as subs_managefiles
@@ -16,23 +16,11 @@
1616
logger = logging.getLogger(__name__)
1717

1818

19-
class prepare:
19+
class prepare(BaseModule):
2020
"""
2121
Prepare class. Automatically copies the datasets into the directories and selects valid data (in case of multi-element observations)
2222
"""
23-
fluxcal = None
24-
polcal = None
25-
target = None
26-
basedir = None
27-
beam = None
28-
rawsubdir = None
29-
crosscalsubdir = None
30-
selfcalsubdir = None
31-
linesubdir = None
32-
contsubdir = None
33-
polsubdir = None
34-
mossubdir = None
35-
transfersubdir = None
23+
module_name = 'PREPARE'
3624

3725
prepare_date = None
3826
prepare_obsnum_fluxcal = None
@@ -374,9 +362,6 @@ def summary(self):
374362

375363
return df
376364

377-
def show(self, showall=False):
378-
lib.show(self, 'PREPARE', showall)
379-
380365
def reset(self):
381366
"""
382367
Function to reset the current step and remove all generated data. Be careful! Deletes all data generated in this step!

0 commit comments

Comments
 (0)
Failed to load comments.