Skip to content
Snippets Groups Projects
Commit 55b3c05a authored by Mattia Mancini's avatar Mattia Mancini
Browse files

Add inspect subworkflow

parent 232d170a
No related branches found
No related tags found
No related merge requests found
class: Workflow class: Workflow
cwlVersion: v1.0 cwlVersion: v1.1
id: compress_pipeline_cwl id: compress_pipeline_cwl
label: compress_pipeline.cwl label: compress_pipeline.cwl
inputs: inputs:
...@@ -24,6 +24,14 @@ outputs: ...@@ -24,6 +24,14 @@ outputs:
outputSource: outputSource:
- format_ingest/ingest - format_ingest/ingest
type: Any type: Any
- id: uv_plot
type: File
outputSource:
- plot_uvw_coverage/uv_plot
- id: uv_coverage
type: File
outputSource:
- inspect_flagging_dataloss/flags_output
steps: steps:
- id: extract_sip_meta - id: extract_sip_meta
in: in:
...@@ -76,8 +84,16 @@ steps: ...@@ -76,8 +84,16 @@ steps:
source: msin source: msin
out: out:
- id: output - id: output
- id: flags_output
run: steps/inspect_flagging_dataloss.cwl run: steps/inspect_flagging_dataloss.cwl
label: inspect_flagging_dataloss label: inspect_flagging_dataloss
- id: plot_uvw_coverage
in:
- id: input_file
source: inspect_flagging_dataloss/flags_output
out:
- id: uv_plot
run: steps/plot_uvw_coverage.cwl
- id: compress - id: compress
in: in:
- id: directory - id: directory
......
class: Workflow class: Workflow
cwlVersion: v1.0 cwlVersion: v1.1
id: compress_pipeline_cwl id: compress_pipeline_cwl
label: compress_pipeline.cwl label: compress_pipeline.cwl
inputs: inputs:
...@@ -28,6 +28,14 @@ outputs: ...@@ -28,6 +28,14 @@ outputs:
outputSource: outputSource:
- compress/inspect - compress/inspect
type: Any[] type: Any[]
- id: uv_coverage
type: File[]
outputSource:
- compress/uv_coverage
- id: uv_plot
type: File[]
outputSource:
- compress/uv_plot
steps: steps:
- id: fetch_data - id: fetch_data
in: in:
...@@ -52,6 +60,8 @@ steps: ...@@ -52,6 +60,8 @@ steps:
- id: inspect - id: inspect
- id: logfile - id: logfile
- id: ingest - id: ingest
- id: uv_coverage
- id: uv_plot
run: ./compress_pipeline.cwl run: ./compress_pipeline.cwl
requirements: requirements:
- class: ScatterFeatureRequirement - class: ScatterFeatureRequirement
......
class: CommandLineTool class: CommandLineTool
cwlVersion: v1.0 cwlVersion: v1.1
id: dppp id: dppp
baseCommand: baseCommand:
- DPPP - DPPP
......
id: compress id: compress
label: compress label: compress
class: CommandLineTool class: CommandLineTool
cwlVersion: v1.0 cwlVersion: v1.1
inputs: inputs:
- id: directory - id: directory
type: Directory type: Directory
......
class: CommandLineTool class: CommandLineTool
cwlVersion: v1.0 cwlVersion: v1.1
$namespaces:
sbg: 'https://www.sevenbridges.com/'
id: define_parset id: define_parset
baseCommand: baseCommand:
- cp - cp
...@@ -30,7 +28,7 @@ requirements: ...@@ -30,7 +28,7 @@ requirements:
listing: listing:
- entryname: input.parset - entryname: input.parset
entry: |+ entry: |+
steps=[flagedge,flagelev,aoflag,flagamp] steps=[flagedge,flagelev,aoflag,flagamp $(inputs.demix? ',demix': '')]
# #
flagedge.chan=[0..nchan/32-1,31*nchan/32..nchan-1] flagedge.chan=[0..nchan/32-1,31*nchan/32..nchan-1]
flagedge.type=preflagger flagedge.type=preflagger
...@@ -41,6 +39,7 @@ requirements: ...@@ -41,6 +39,7 @@ requirements:
aoflag.autocorr=$(inputs.flag_autocorrelation?'True':'False') aoflag.autocorr=$(inputs.flag_autocorrelation?'True':'False')
aoflag.strategy=/usr/local/share/aoflagger/strategies/lofar-default.lua aoflag.strategy=/usr/local/share/aoflagger/strategies/lofar-default.lua
# #
flagbaseline.type=preflagger flagbaseline.type=preflagger
flagbaseline.baseline=[] flagbaseline.baseline=[]
# #
......
class: CommandLineTool class: CommandLineTool
cwlVersion: v1.0 cwlVersion: v1.1
id: inspect_flagging_dataloss id: inspect_flagging_dataloss
baseCommand: baseCommand:
- bash - bash
......
id: fetchdata id: fetchdata
label: fetch_data label: fetch_data
class: CommandLineTool class: CommandLineTool
cwlVersion: v1.0 cwlVersion: v1.1
inputs: inputs:
- id: surl_link - id: surl_link
type: string type: string
......
class: CommandLineTool class: CommandLineTool
cwlVersion: v1.0 cwlVersion: v1.1
$namespaces: $namespaces:
sbg: 'https://www.sevenbridges.com/' sbg: 'https://www.sevenbridges.com/'
id: inspect_compression_quality id: inspect_compression_quality
......
class: CommandLineTool class: CommandLineTool
cwlVersion: v1.0 cwlVersion: v1.1
$namespaces:
sbg: 'https://www.sevenbridges.com/'
id: inspect_flagging_dataloss id: inspect_flagging_dataloss
baseCommand: baseCommand:
- python3 - python3
...@@ -12,11 +10,20 @@ inputs: ...@@ -12,11 +10,20 @@ inputs:
inputBinding: inputBinding:
position: 0 position: 0
shellQuote: false shellQuote: false
- id: uvw_sampling
type: int?
default: 100
inputBinding:
position: 1
outputs: outputs:
- id: output - id: output
type: 'File' type: 'File'
outputBinding: outputBinding:
glob: metrics.json glob: metrics.json
- id: flags_output
type: 'File'
outputBinding:
glob: flags.h5
label: inspect_flagging_dataloss label: inspect_flagging_dataloss
requirements: requirements:
- class: ShellCommandRequirement - class: ShellCommandRequirement
...@@ -26,11 +33,92 @@ requirements: ...@@ -26,11 +33,92 @@ requirements:
entry: | entry: |
import sys import sys
from casacore.tables import table from casacore.tables import table
import itertools
import json
import h5py
import numpy as np
import re
from scipy.constants import c as LIGHT_SPEED
input_ms_path = sys.argv[1] input_ms_path = sys.argv[1]
sampling = int(sys.argv[2])
main_table = table(input_ms_path, 'r')
antennas = table(input_ms_path + '/ANTENNA', 'r')
spec_window = table(input_ms_path + '/SPECTRAL_WINDOW', 'r')
observation = table(input_ms_path + '/OBSERVATION', 'r')
sas_id, sap, sb = re.search('L(\d*).*SAP(\d{3}).*SB(\d{3}).*',
observation.getcell('LOFAR_FILENAME', 0)).groups()
antenna_names = antennas.getcol('NAME')
antenna_positions = antennas.getcol('POSITION')
ref_frequency = spec_window.getcell('REF_FREQUENCY', 0)
TO_UVW = ref_frequency / LIGHT_SPEED # 1 / (c/nu)
flags = np.array(main_table.getcol('FLAG'))
vis = np.array(main_table.getcol('DATA'))
uvw = np.array(main_table.getcol('UVW') * TO_UVW)
antenna1 = np.array(main_table.getcol('ANTENNA1'))
antenna2 = np.array(main_table.getcol('ANTENNA2'))
time = np.array(main_table.getcol('TIME'))
n_antennas = antennas.nrows()
n_baselines = int((n_antennas + 1) * n_antennas * .5)
n_times = flags.shape[0] // n_baselines
dataloss = np.array(vis == 0, dtype=np.int)
dataloss_matrix, (urange, vrange, wrange) = np.histogramdd(uvw, bins=[sampling, sampling, 1], weights=np.nanmean(dataloss, axis=(1,2)))
flag_matrix, (urange, vrange, wrange) = np.histogramdd(uvw, bins=[sampling, sampling, 1], weights=np.nanmean(flags, axis=(1,2)))
coverage, (urange, vrange, wrange) = np.histogramdd(uvw, bins=[sampling, sampling, 1])
flags = flags.reshape(n_times, n_baselines, *flags.shape[1:], order='C')
dataloss = dataloss.reshape(n_times, n_baselines, *flags.shape[2:], order='C')
uvw = uvw.reshape(n_times, n_baselines, *uvw.shape[1:], order='C')
timestamp = time.reshape(n_times, n_baselines, order='C')[:, 0]
baselines = [
"%s,%s" % (antenna_names[i], antenna_names[j])
for i, j in itertools.product(range(n_antennas), range(n_antennas)) if i >= j]
dataloss_as_function_of_time = np.nanmean(dataloss, axis=(1, 2, 3))
dataloss_as_function_of_baseline = np.nanmean(dataloss, axis=(0, 2, 3))
flags_as_function_of_time = np.nanmean(flags, axis=(1,2,3))
flags_as_function_of_baseline = np.nanmean(flags, axis=(0,2,3))
metrics = dict(baselines=baselines,
dataloss_vs_time=dataloss_as_function_of_time.tolist(),
dataloss_vs_baseline=dataloss_as_function_of_baseline.tolist(),
flags_vs_time=flags_as_function_of_time.tolist(),
flags_vs_baseline=flags_as_function_of_baseline.tolist(),
timestamp=timestamp.tolist(),
sap=sap,
subband=sb
)
with open('metrics.json', 'w') as f_stream: with open('metrics.json', 'w') as f_stream:
pass json.dump(metrics, f_stream)
with h5py.File('flags.h5', 'w') as flags_file:
flags_file['/FLAGS'] = flag_matrix
flags_file['/COVERAGE'] = coverage
flags_file['/DATALOSS'] = dataloss_matrix
flags_file['/'].attrs['REF_FREQUENCY'] = ref_frequency
flags_file['/'].attrs['BASELINES'] = baselines
flags_file['/'].attrs['PROJECT'] = observation.getcell('PROJECT', 0)
flags_file['/'].attrs['TELESCOPE'] = observation.getcell('TELESCOPE_NAME', 0)
flags_file['/'].attrs['SAS_ID'] = sas_id
flags_file['/'].attrs['SAP'] = sap
flags_file['/'].attrs['SUBBAND'] = sb
flags_file['/URANGE'] = urange
flags_file['/VRANGE'] = vrange
flags_file['/WRANGE'] = wrange
- class: DockerRequirement - class: DockerRequirement
dockerPull: 'lofareosc/lofar-pipeline:latest' dockerPull: 'astronsdc/lofar-ms-software:latest'
cwlVersion: v1.1
class: CommandLineTool
baseCommand:
- python3
- script.py
inputs:
- id: input_file
type: File
inputBinding:
position: 0
- id: output_name
type: string?
default: 'uv_coverage.png'
inputBinding:
position: 1
outputs:
- id: uv_plot
type: File
outputBinding:
glob: $(inputs.output_name)
requirements:
- class: InlineJavascriptRequirement
- class: InitialWorkDirRequirement
listing:
- entryname: script.py
entry: |
import h5py
import matplotlib.pylab as plt
import sys
import numpy as np
from matplotlib import cm
h5_file = h5py.File(sys.argv[1], 'r')
output_name = sys.argv[2]
u = h5_file['URANGE']
v = h5_file['VRANGE']
plt.imshow(np.log10(h5_file['COVERAGE'][:, :, 0]), extent= [u[0], u[-1], v[0], v[-1]], cmap=cm.Blues)
plt.imshow(np.log10(h5_file['FLAGS'][:, :, 0]), extent= [u[0], u[-1], v[0], v[-1]] , cmap=cm.Reds)
plt.imshow(np.log10(h5_file['DATALOSS'][:, :, 0]), extent= [u[0], u[-1], v[0], v[-1]] , cmap=cm.Greens)
plt.savefig(output_name)
class: ExpressionTool class: ExpressionTool
cwlVersion: v1.0 cwlVersion: v1.1
id: read_surl_file id: read_surl_file
inputs: inputs:
- id: surl_list - id: surl_list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment