RACS-tools 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- racs_tools-0.0.0/LICENSE +29 -0
- racs_tools-0.0.0/PKG-INFO +220 -0
- racs_tools-0.0.0/README.md +193 -0
- racs_tools-0.0.0/pyproject.toml +39 -0
- racs_tools-0.0.0/racs_tools/__init__.py +0 -0
- racs_tools-0.0.0/racs_tools/au2.py +167 -0
- racs_tools-0.0.0/racs_tools/beamcon_2D.py +839 -0
- racs_tools-0.0.0/racs_tools/beamcon_3D.py +1389 -0
- racs_tools-0.0.0/racs_tools/convolve_uv.py +174 -0
- racs_tools-0.0.0/racs_tools/gaussft.py +84 -0
- racs_tools-0.0.0/racs_tools/getnoise_list.py +277 -0
- racs_tools-0.0.0/racs_tools/logging.py +48 -0
racs_tools-0.0.0/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020, Alec Thomson
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: racs-tools
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Useful scripts for RACS.
|
|
5
|
+
License: BSD
|
|
6
|
+
Author: Alec Thomson
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Classifier: License :: Other/Proprietary License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Provides-Extra: mpi
|
|
16
|
+
Requires-Dist: astropy (>=5)
|
|
17
|
+
Requires-Dist: mpi4py ; extra == "mpi"
|
|
18
|
+
Requires-Dist: numba
|
|
19
|
+
Requires-Dist: numpy (<2)
|
|
20
|
+
Requires-Dist: radio_beam
|
|
21
|
+
Requires-Dist: schwimmbad
|
|
22
|
+
Requires-Dist: scipy
|
|
23
|
+
Requires-Dist: spectral_cube (>=0.6.3)
|
|
24
|
+
Requires-Dist: tqdm
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
[](https://github.com/AlecThomson/RACS-tools/actions/workflows/docker.yml)  [](https://github.com/AlecThomson/RACS-tools/actions/workflows/python-package.yml) [](https://github.com/AlecThomson/RACS-tools/actions/workflows/pypi.yml) [](https://github.com/psf/black)[](https://results.pre-commit.ci/latest/github/AlecThomson/RACS-tools/master)
|
|
28
|
+
|
|
29
|
+
# RACS-tools
|
|
30
|
+
Useful scripts for RACS
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
### Conda
|
|
35
|
+
The recommended way to install. First obtain `conda` from Anaconda or Miniconda. Clone this repo, build the environment, and activate:
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/AlecThomson/RACS-tools
|
|
38
|
+
cd RACS-tools
|
|
39
|
+
conda env create
|
|
40
|
+
conda activate racs-tools
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Docker / Singularity
|
|
44
|
+
A Dockerfile is provided if you wish to build your own container. Otherwise, images are provided on [DockerHub](https://hub.docker.com/r/alecthomson/racstools). You can pull these by running e.g.
|
|
45
|
+
```bash
|
|
46
|
+
docker pull alecthomson/racstools
|
|
47
|
+
```
|
|
48
|
+
or
|
|
49
|
+
```bash
|
|
50
|
+
singularity pull docker://alecthomson/racstools
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
NOTE: These builds are still experimental, and have not been widely tested. In particular, parallelisation may not work as expected.
|
|
54
|
+
|
|
55
|
+
### Pip
|
|
56
|
+
You can also use the package manager [pip](https://pip.pypa.io/en/stable/) to install RACS-tools.
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Stable
|
|
61
|
+
pip install RACS-tools
|
|
62
|
+
# Latest
|
|
63
|
+
pip install git+https://github.com/AlecThomson/RACS-tools
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
$ beamcon_2D -h
|
|
72
|
+
usage: beamcon_2D [-h] [-p PREFIX] [-s SUFFIX] [-o OUTDIR] [--conv_mode {robust,scipy,astropy,astropy_fft}] [-v] [-d] [--bmaj BMAJ] [--bmin BMIN] [--bpa BPA] [--log LOG] [--logfile LOGFILE] [-c CUTOFF] [--circularise] [-t TOLERANCE] [-e EPSILON] [-n NSAMPS] [--ncores N_CORES | --mpi] infile [infile ...]
|
|
73
|
+
|
|
74
|
+
Smooth a field of 2D images to a common resolution.
|
|
75
|
+
|
|
76
|
+
- Parallelisation can run using multiprocessing or MPI.
|
|
77
|
+
|
|
78
|
+
- Default names of output files are /path/to/beamlog{infile//.fits/.{SUFFIX}.fits}
|
|
79
|
+
|
|
80
|
+
- By default, the smallest common beam will be automatically computed.
|
|
81
|
+
- Optionally, you can specify a target beam to use.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
positional arguments:
|
|
86
|
+
infile Input FITS image(s) to smooth (can be a wildcard) - beam info must be in header.
|
|
87
|
+
|
|
88
|
+
optional arguments:
|
|
89
|
+
-h, --help show this help message and exit
|
|
90
|
+
-p PREFIX, --prefix PREFIX
|
|
91
|
+
Add prefix to output filenames.
|
|
92
|
+
-s SUFFIX, --suffix SUFFIX
|
|
93
|
+
Add suffix to output filenames [sm].
|
|
94
|
+
-o OUTDIR, --outdir OUTDIR
|
|
95
|
+
Output directory of smoothed FITS image(s) [same as input file].
|
|
96
|
+
--conv_mode {robust,scipy,astropy,astropy_fft}
|
|
97
|
+
Which method to use for convolution [robust].
|
|
98
|
+
'robust' computes the analytic FT of the convolving Gaussian.
|
|
99
|
+
Note this mode can now handle NaNs in the data.
|
|
100
|
+
Can also be 'scipy', 'astropy', or 'astropy_fft'.
|
|
101
|
+
Note these other methods cannot cope well with small convolving beams.
|
|
102
|
+
|
|
103
|
+
-v, --verbosity Increase output verbosity
|
|
104
|
+
-d, --dryrun Compute common beam and stop [False].
|
|
105
|
+
--bmaj BMAJ Target BMAJ (arcsec) to convolve to [None].
|
|
106
|
+
--bmin BMIN Target BMIN (arcsec) to convolve to [None].
|
|
107
|
+
--bpa BPA Target BPA (deg) to convolve to [None].
|
|
108
|
+
--log LOG Name of beamlog file. If provided, save beamlog data to a file [None - not saved].
|
|
109
|
+
--logfile LOGFILE Save logging output to file
|
|
110
|
+
-c CUTOFF, --cutoff CUTOFF
|
|
111
|
+
Cutoff BMAJ value (arcsec) -- Blank channels with BMAJ larger than this [None -- no limit]
|
|
112
|
+
--circularise Circularise the final PSF -- Sets the BMIN = BMAJ, and BPA=0.
|
|
113
|
+
-t TOLERANCE, --tolerance TOLERANCE
|
|
114
|
+
tolerance for radio_beam.commonbeam.
|
|
115
|
+
-e EPSILON, --epsilon EPSILON
|
|
116
|
+
epsilon for radio_beam.commonbeam.
|
|
117
|
+
-n NSAMPS, --nsamps NSAMPS
|
|
118
|
+
nsamps for radio_beam.commonbeam.
|
|
119
|
+
--ncores N_CORES Number of processes (uses multiprocessing).
|
|
120
|
+
--mpi Run with MPI.
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
$ beamcon_3D -h
|
|
125
|
+
usage: beamcon_3D [-h] [--uselogs] [--mode MODE] [--conv_mode {robust,scipy,astropy,astropy_fft}] [-v] [--logfile LOGFILE] [-d] [-p PREFIX] [-s SUFFIX] [-o OUTDIR] [--bmaj BMAJ] [--bmin BMIN] [--bpa BPA] [-c CUTOFF] [--circularise] [--ref_chan {first,last,mid}] [-t TOLERANCE] [-e EPSILON] [-n NSAMPS] infile [infile ...]
|
|
126
|
+
|
|
127
|
+
Smooth a field of 3D cubes to a common resolution.
|
|
128
|
+
|
|
129
|
+
- Parallelisation is done using MPI.
|
|
130
|
+
|
|
131
|
+
- Default names of output files are /path/to/beamlog{infile//.fits/.{SUFFIX}.fits}
|
|
132
|
+
|
|
133
|
+
- By default, the smallest common beam will be automatically computed.
|
|
134
|
+
- Optionally, you can specify a target beam to use.
|
|
135
|
+
|
|
136
|
+
- It is currently assumed that cubes will be 4D with a dummy Stokes axis.
|
|
137
|
+
- Iterating over Stokes axis is not yet supported.
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
positional arguments:
|
|
142
|
+
infile Input FITS image(s) to smooth (can be a wildcard)
|
|
143
|
+
- CASA beamtable will be used if present i.e. if CASAMBM = T
|
|
144
|
+
- Otherwise beam info must be in co-located beamlog files.
|
|
145
|
+
- beamlog must have the name /path/to/beamlog{infile//.fits/.txt}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
optional arguments:
|
|
149
|
+
-h, --help show this help message and exit
|
|
150
|
+
--uselogs Get convolving information from previous run [False].
|
|
151
|
+
--mode MODE Common resolution mode [natural].
|
|
152
|
+
natural -- allow frequency variation.
|
|
153
|
+
total -- smooth all plans to a common resolution.
|
|
154
|
+
|
|
155
|
+
--conv_mode {robust,scipy,astropy,astropy_fft}
|
|
156
|
+
Which method to use for convolution [robust].
|
|
157
|
+
'robust' computes the analytic FT of the convolving Gaussian.
|
|
158
|
+
Note this mode can now handle NaNs in the data.
|
|
159
|
+
Can also be 'scipy', 'astropy', or 'astropy_fft'.
|
|
160
|
+
Note these other methods cannot cope well with small convolving beams.
|
|
161
|
+
|
|
162
|
+
-v, --verbosity Increase output verbosity
|
|
163
|
+
--logfile LOGFILE Save logging output to file
|
|
164
|
+
-d, --dryrun Compute common beam and stop [False].
|
|
165
|
+
-p PREFIX, --prefix PREFIX
|
|
166
|
+
Add prefix to output filenames.
|
|
167
|
+
-s SUFFIX, --suffix SUFFIX
|
|
168
|
+
Add suffix to output filenames [{MODE}].
|
|
169
|
+
-o OUTDIR, --outdir OUTDIR
|
|
170
|
+
Output directory of smoothed FITS image(s) [None - same as input].
|
|
171
|
+
--bmaj BMAJ BMAJ to convolve to [max BMAJ from given image(s)].
|
|
172
|
+
--bmin BMIN BMIN to convolve to [max BMAJ from given image(s)].
|
|
173
|
+
--bpa BPA BPA to convolve to [0].
|
|
174
|
+
-c CUTOFF, --cutoff CUTOFF
|
|
175
|
+
Cutoff BMAJ value (arcsec) -- Blank channels with BMAJ larger than this [None -- no limit]
|
|
176
|
+
--circularise Circularise the final PSF -- Sets the BMIN = BMAJ, and BPA=0.
|
|
177
|
+
--ref_chan {first,last,mid}
|
|
178
|
+
Reference psf for header [None].
|
|
179
|
+
first -- use psf for first frequency channel.
|
|
180
|
+
last -- use psf for the last frequency channel.
|
|
181
|
+
mid -- use psf for the centre frequency channel.
|
|
182
|
+
Will use the CRPIX channel if not set.
|
|
183
|
+
|
|
184
|
+
-t TOLERANCE, --tolerance TOLERANCE
|
|
185
|
+
tolerance for radio_beam.commonbeam.
|
|
186
|
+
-e EPSILON, --epsilon EPSILON
|
|
187
|
+
epsilon for radio_beam.commonbeam.
|
|
188
|
+
-n NSAMPS, --nsamps NSAMPS
|
|
189
|
+
nsamps for radio_beam.commonbeam.
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
$ getnoise_list -h
|
|
194
|
+
usage: getnoise_list [-h] [-s] [-b] [-c CLIPLEV] [-i ITERATE] [-f FILE] qfile ufile
|
|
195
|
+
|
|
196
|
+
Find bad channels by checking statistics of each channel image.
|
|
197
|
+
|
|
198
|
+
positional arguments:
|
|
199
|
+
qfile Stokes Q fits file
|
|
200
|
+
ufile Stokes U fits file
|
|
201
|
+
|
|
202
|
+
options:
|
|
203
|
+
-h, --help show this help message and exit
|
|
204
|
+
-s, --save_noise Save noise values to disk [default False]
|
|
205
|
+
-b, --blank Blank bad channels? [default False - just print out bad channels]
|
|
206
|
+
-c CLIPLEV, --cliplev CLIPLEV
|
|
207
|
+
Clip level in sigma, make this number lower to be more aggressive [default 5]
|
|
208
|
+
-i ITERATE, --iterate ITERATE
|
|
209
|
+
Iterate flagging check N times [dafult 1 -- one pass only]
|
|
210
|
+
-f FILE, --file FILE Filename to write bad channel indices to file [None -- do not write]
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
If finding a common beam fails, try tweaking the `tolerance`, `epsilon`, and `nsamps` parameters. See [radio-beam](https://radio-beam.readthedocs.io/en/latest/) for more details.
|
|
214
|
+
|
|
215
|
+
## Contributing
|
|
216
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
[BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)
|
|
220
|
+
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
[](https://github.com/AlecThomson/RACS-tools/actions/workflows/docker.yml)  [](https://github.com/AlecThomson/RACS-tools/actions/workflows/python-package.yml) [](https://github.com/AlecThomson/RACS-tools/actions/workflows/pypi.yml) [](https://github.com/psf/black)[](https://results.pre-commit.ci/latest/github/AlecThomson/RACS-tools/master)
|
|
2
|
+
|
|
3
|
+
# RACS-tools
|
|
4
|
+
Useful scripts for RACS
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
### Conda
|
|
9
|
+
The recommended way to install. First obtain `conda` from Anaconda or Miniconda. Clone this repo, build the environment, and activate:
|
|
10
|
+
```bash
|
|
11
|
+
git clone https://github.com/AlecThomson/RACS-tools
|
|
12
|
+
cd RACS-tools
|
|
13
|
+
conda env create
|
|
14
|
+
conda activate racs-tools
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Docker / Singularity
|
|
18
|
+
A Dockerfile is provided if you wish to build your own container. Otherwise, images are provided on [DockerHub](https://hub.docker.com/r/alecthomson/racstools). You can pull these by running e.g.
|
|
19
|
+
```bash
|
|
20
|
+
docker pull alecthomson/racstools
|
|
21
|
+
```
|
|
22
|
+
or
|
|
23
|
+
```bash
|
|
24
|
+
singularity pull docker://alecthomson/racstools
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
NOTE: These builds are still experimental, and have not been widely tested. In particular, parallelisation may not work as expected.
|
|
28
|
+
|
|
29
|
+
### Pip
|
|
30
|
+
You can also use the package manager [pip](https://pip.pypa.io/en/stable/) to install RACS-tools.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Stable
|
|
35
|
+
pip install RACS-tools
|
|
36
|
+
# Latest
|
|
37
|
+
pip install git+https://github.com/AlecThomson/RACS-tools
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
$ beamcon_2D -h
|
|
46
|
+
usage: beamcon_2D [-h] [-p PREFIX] [-s SUFFIX] [-o OUTDIR] [--conv_mode {robust,scipy,astropy,astropy_fft}] [-v] [-d] [--bmaj BMAJ] [--bmin BMIN] [--bpa BPA] [--log LOG] [--logfile LOGFILE] [-c CUTOFF] [--circularise] [-t TOLERANCE] [-e EPSILON] [-n NSAMPS] [--ncores N_CORES | --mpi] infile [infile ...]
|
|
47
|
+
|
|
48
|
+
Smooth a field of 2D images to a common resolution.
|
|
49
|
+
|
|
50
|
+
- Parallelisation can run using multiprocessing or MPI.
|
|
51
|
+
|
|
52
|
+
- Default names of output files are /path/to/beamlog{infile//.fits/.{SUFFIX}.fits}
|
|
53
|
+
|
|
54
|
+
- By default, the smallest common beam will be automatically computed.
|
|
55
|
+
- Optionally, you can specify a target beam to use.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
positional arguments:
|
|
60
|
+
infile Input FITS image(s) to smooth (can be a wildcard) - beam info must be in header.
|
|
61
|
+
|
|
62
|
+
optional arguments:
|
|
63
|
+
-h, --help show this help message and exit
|
|
64
|
+
-p PREFIX, --prefix PREFIX
|
|
65
|
+
Add prefix to output filenames.
|
|
66
|
+
-s SUFFIX, --suffix SUFFIX
|
|
67
|
+
Add suffix to output filenames [sm].
|
|
68
|
+
-o OUTDIR, --outdir OUTDIR
|
|
69
|
+
Output directory of smoothed FITS image(s) [same as input file].
|
|
70
|
+
--conv_mode {robust,scipy,astropy,astropy_fft}
|
|
71
|
+
Which method to use for convolution [robust].
|
|
72
|
+
'robust' computes the analytic FT of the convolving Gaussian.
|
|
73
|
+
Note this mode can now handle NaNs in the data.
|
|
74
|
+
Can also be 'scipy', 'astropy', or 'astropy_fft'.
|
|
75
|
+
Note these other methods cannot cope well with small convolving beams.
|
|
76
|
+
|
|
77
|
+
-v, --verbosity Increase output verbosity
|
|
78
|
+
-d, --dryrun Compute common beam and stop [False].
|
|
79
|
+
--bmaj BMAJ Target BMAJ (arcsec) to convolve to [None].
|
|
80
|
+
--bmin BMIN Target BMIN (arcsec) to convolve to [None].
|
|
81
|
+
--bpa BPA Target BPA (deg) to convolve to [None].
|
|
82
|
+
--log LOG Name of beamlog file. If provided, save beamlog data to a file [None - not saved].
|
|
83
|
+
--logfile LOGFILE Save logging output to file
|
|
84
|
+
-c CUTOFF, --cutoff CUTOFF
|
|
85
|
+
Cutoff BMAJ value (arcsec) -- Blank channels with BMAJ larger than this [None -- no limit]
|
|
86
|
+
--circularise Circularise the final PSF -- Sets the BMIN = BMAJ, and BPA=0.
|
|
87
|
+
-t TOLERANCE, --tolerance TOLERANCE
|
|
88
|
+
tolerance for radio_beam.commonbeam.
|
|
89
|
+
-e EPSILON, --epsilon EPSILON
|
|
90
|
+
epsilon for radio_beam.commonbeam.
|
|
91
|
+
-n NSAMPS, --nsamps NSAMPS
|
|
92
|
+
nsamps for radio_beam.commonbeam.
|
|
93
|
+
--ncores N_CORES Number of processes (uses multiprocessing).
|
|
94
|
+
--mpi Run with MPI.
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
$ beamcon_3D -h
|
|
99
|
+
usage: beamcon_3D [-h] [--uselogs] [--mode MODE] [--conv_mode {robust,scipy,astropy,astropy_fft}] [-v] [--logfile LOGFILE] [-d] [-p PREFIX] [-s SUFFIX] [-o OUTDIR] [--bmaj BMAJ] [--bmin BMIN] [--bpa BPA] [-c CUTOFF] [--circularise] [--ref_chan {first,last,mid}] [-t TOLERANCE] [-e EPSILON] [-n NSAMPS] infile [infile ...]
|
|
100
|
+
|
|
101
|
+
Smooth a field of 3D cubes to a common resolution.
|
|
102
|
+
|
|
103
|
+
- Parallelisation is done using MPI.
|
|
104
|
+
|
|
105
|
+
- Default names of output files are /path/to/beamlog{infile//.fits/.{SUFFIX}.fits}
|
|
106
|
+
|
|
107
|
+
- By default, the smallest common beam will be automatically computed.
|
|
108
|
+
- Optionally, you can specify a target beam to use.
|
|
109
|
+
|
|
110
|
+
- It is currently assumed that cubes will be 4D with a dummy Stokes axis.
|
|
111
|
+
- Iterating over Stokes axis is not yet supported.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
positional arguments:
|
|
116
|
+
infile Input FITS image(s) to smooth (can be a wildcard)
|
|
117
|
+
- CASA beamtable will be used if present i.e. if CASAMBM = T
|
|
118
|
+
- Otherwise beam info must be in co-located beamlog files.
|
|
119
|
+
- beamlog must have the name /path/to/beamlog{infile//.fits/.txt}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
optional arguments:
|
|
123
|
+
-h, --help show this help message and exit
|
|
124
|
+
--uselogs Get convolving information from previous run [False].
|
|
125
|
+
--mode MODE Common resolution mode [natural].
|
|
126
|
+
natural -- allow frequency variation.
|
|
127
|
+
total -- smooth all plans to a common resolution.
|
|
128
|
+
|
|
129
|
+
--conv_mode {robust,scipy,astropy,astropy_fft}
|
|
130
|
+
Which method to use for convolution [robust].
|
|
131
|
+
'robust' computes the analytic FT of the convolving Gaussian.
|
|
132
|
+
Note this mode can now handle NaNs in the data.
|
|
133
|
+
Can also be 'scipy', 'astropy', or 'astropy_fft'.
|
|
134
|
+
Note these other methods cannot cope well with small convolving beams.
|
|
135
|
+
|
|
136
|
+
-v, --verbosity Increase output verbosity
|
|
137
|
+
--logfile LOGFILE Save logging output to file
|
|
138
|
+
-d, --dryrun Compute common beam and stop [False].
|
|
139
|
+
-p PREFIX, --prefix PREFIX
|
|
140
|
+
Add prefix to output filenames.
|
|
141
|
+
-s SUFFIX, --suffix SUFFIX
|
|
142
|
+
Add suffix to output filenames [{MODE}].
|
|
143
|
+
-o OUTDIR, --outdir OUTDIR
|
|
144
|
+
Output directory of smoothed FITS image(s) [None - same as input].
|
|
145
|
+
--bmaj BMAJ BMAJ to convolve to [max BMAJ from given image(s)].
|
|
146
|
+
--bmin BMIN BMIN to convolve to [max BMAJ from given image(s)].
|
|
147
|
+
--bpa BPA BPA to convolve to [0].
|
|
148
|
+
-c CUTOFF, --cutoff CUTOFF
|
|
149
|
+
Cutoff BMAJ value (arcsec) -- Blank channels with BMAJ larger than this [None -- no limit]
|
|
150
|
+
--circularise Circularise the final PSF -- Sets the BMIN = BMAJ, and BPA=0.
|
|
151
|
+
--ref_chan {first,last,mid}
|
|
152
|
+
Reference psf for header [None].
|
|
153
|
+
first -- use psf for first frequency channel.
|
|
154
|
+
last -- use psf for the last frequency channel.
|
|
155
|
+
mid -- use psf for the centre frequency channel.
|
|
156
|
+
Will use the CRPIX channel if not set.
|
|
157
|
+
|
|
158
|
+
-t TOLERANCE, --tolerance TOLERANCE
|
|
159
|
+
tolerance for radio_beam.commonbeam.
|
|
160
|
+
-e EPSILON, --epsilon EPSILON
|
|
161
|
+
epsilon for radio_beam.commonbeam.
|
|
162
|
+
-n NSAMPS, --nsamps NSAMPS
|
|
163
|
+
nsamps for radio_beam.commonbeam.
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
$ getnoise_list -h
|
|
168
|
+
usage: getnoise_list [-h] [-s] [-b] [-c CLIPLEV] [-i ITERATE] [-f FILE] qfile ufile
|
|
169
|
+
|
|
170
|
+
Find bad channels by checking statistics of each channel image.
|
|
171
|
+
|
|
172
|
+
positional arguments:
|
|
173
|
+
qfile Stokes Q fits file
|
|
174
|
+
ufile Stokes U fits file
|
|
175
|
+
|
|
176
|
+
options:
|
|
177
|
+
-h, --help show this help message and exit
|
|
178
|
+
-s, --save_noise Save noise values to disk [default False]
|
|
179
|
+
-b, --blank Blank bad channels? [default False - just print out bad channels]
|
|
180
|
+
-c CLIPLEV, --cliplev CLIPLEV
|
|
181
|
+
Clip level in sigma, make this number lower to be more aggressive [default 5]
|
|
182
|
+
-i ITERATE, --iterate ITERATE
|
|
183
|
+
Iterate flagging check N times [dafult 1 -- one pass only]
|
|
184
|
+
-f FILE, --file FILE Filename to write bad channel indices to file [None -- do not write]
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
If finding a common beam fails, try tweaking the `tolerance`, `epsilon`, and `nsamps` parameters. See [radio-beam](https://radio-beam.readthedocs.io/en/latest/) for more details.
|
|
188
|
+
|
|
189
|
+
## Contributing
|
|
190
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
[BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "racs-tools"
|
|
3
|
+
version = "0.0.0" # A placeholder
|
|
4
|
+
description = "Useful scripts for RACS."
|
|
5
|
+
authors = ["Alec Thomson"]
|
|
6
|
+
license = "BSD"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
packages = [{include = "racs_tools"}]
|
|
9
|
+
|
|
10
|
+
[tool.poetry.dependencies]
|
|
11
|
+
python = ">=3.8"
|
|
12
|
+
numpy = "<2"
|
|
13
|
+
astropy = ">=5"
|
|
14
|
+
radio_beam = "*"
|
|
15
|
+
schwimmbad = "*"
|
|
16
|
+
scipy = "*"
|
|
17
|
+
spectral_cube = ">=0.6.3"
|
|
18
|
+
tqdm = "*"
|
|
19
|
+
numba = "*"
|
|
20
|
+
mpi4py = {version = "*", optional = true}
|
|
21
|
+
|
|
22
|
+
[tool.poetry.dev-dependencies]
|
|
23
|
+
black = "*"
|
|
24
|
+
isort = "*"
|
|
25
|
+
|
|
26
|
+
[tool.poetry.extras]
|
|
27
|
+
mpi = ["mpi4py"]
|
|
28
|
+
|
|
29
|
+
[tool.poetry.scripts]
|
|
30
|
+
beamcon_2D = "racs_tools.beamcon_2D:cli"
|
|
31
|
+
beamcon_3D = "racs_tools.beamcon_3D:cli"
|
|
32
|
+
getnoise_list = "racs_tools.getnoise_list:cli"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
[tool.poetry-dynamic-versioning]
|
|
36
|
+
enable = true
|
|
37
|
+
[build-system]
|
|
38
|
+
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
|
|
39
|
+
build-backend = "poetry_dynamic_versioning.backend"
|
|
File without changes
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
""" For getting fluxes right in Jy/beam """
|
|
3
|
+
__author__ = "Tessa Vernstrom"
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from typing import List, Tuple
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def gaussianDeconvolve(smaj, smin, spa, bmaj, bmin, bpa):
|
|
12
|
+
"""'s' as in 'source', 'b' as in 'beam'. All arguments in
|
|
13
|
+
radians. (Well, major and minor axes can be in any units, so long
|
|
14
|
+
as they're consistent.)
|
|
15
|
+
|
|
16
|
+
Returns dmaj, dmin, dpa, status
|
|
17
|
+
Return units are consistent with the inputs.
|
|
18
|
+
status is one of 'ok', 'pointlike', 'fail'
|
|
19
|
+
|
|
20
|
+
Derived from miriad gaupar.for:GauDfac()
|
|
21
|
+
|
|
22
|
+
We currently don't do a great job of dealing with pointlike
|
|
23
|
+
sources. I've added extra code ensure smaj >= bmaj, smin >= bmin,
|
|
24
|
+
and increased coefficient in front of "limit" from 0.1 to
|
|
25
|
+
0.5. Feel a little wary about that first change.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
spa = np.radians(spa)
|
|
29
|
+
bpa = np.radians(bpa)
|
|
30
|
+
if smaj < bmaj:
|
|
31
|
+
smaj = bmaj
|
|
32
|
+
if smin < bmin:
|
|
33
|
+
smin = bmin
|
|
34
|
+
|
|
35
|
+
alpha = (
|
|
36
|
+
(smaj * np.cos(spa)) ** 2
|
|
37
|
+
+ (smin * np.sin(spa)) ** 2
|
|
38
|
+
- (bmaj * np.cos(bpa)) ** 2
|
|
39
|
+
- (bmin * np.sin(bpa)) ** 2
|
|
40
|
+
)
|
|
41
|
+
beta = (
|
|
42
|
+
(smaj * np.sin(spa)) ** 2
|
|
43
|
+
+ (smin * np.cos(spa)) ** 2
|
|
44
|
+
- (bmaj * np.sin(bpa)) ** 2
|
|
45
|
+
- (bmin * np.cos(bpa)) ** 2
|
|
46
|
+
)
|
|
47
|
+
gamma = 2 * (
|
|
48
|
+
(smin**2 - smaj**2) * np.sin(spa) * np.cos(spa)
|
|
49
|
+
- (bmin**2 - bmaj**2) * np.sin(bpa) * np.cos(bpa)
|
|
50
|
+
)
|
|
51
|
+
# print smaj,smin
|
|
52
|
+
# print alpha,beta,gamma
|
|
53
|
+
s = alpha + beta
|
|
54
|
+
t = np.sqrt((alpha - beta) ** 2 + gamma**2)
|
|
55
|
+
# print s,t
|
|
56
|
+
dmaj = np.sqrt(0.5 * (s + t))
|
|
57
|
+
if s > t:
|
|
58
|
+
dmin = np.sqrt(0.5 * (s - t))
|
|
59
|
+
else:
|
|
60
|
+
dmin = 0
|
|
61
|
+
# print dmaj,dmin
|
|
62
|
+
if alpha < 0 or beta < 0:
|
|
63
|
+
dmaj = dmin = dpa = 0
|
|
64
|
+
|
|
65
|
+
# if(smaj>bmaj):
|
|
66
|
+
# dmaj= sqrt (0.5 * (s + t))
|
|
67
|
+
if abs(gamma) + abs(alpha - beta) == 0:
|
|
68
|
+
dpa = 0
|
|
69
|
+
else:
|
|
70
|
+
dpa = 0.5 * np.arctan2(-gamma, alpha - beta)
|
|
71
|
+
# if((s>=t)&(bmin!=smin)):
|
|
72
|
+
# dmin=sqrt (0.5 * (s - t))
|
|
73
|
+
|
|
74
|
+
return dmaj, dmin, np.degrees(dpa)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def gauss_factor(
|
|
78
|
+
beamConv: List[float], beamOrig: List[float], dx1: float = 1, dy1: float = 1
|
|
79
|
+
) -> Tuple[float, float, float, float, float]:
|
|
80
|
+
"""
|
|
81
|
+
Calculates the scaling factor to be applied after convolving
|
|
82
|
+
a map in Jy/beam with a gaussian to get fluxes in Jy/beam again.
|
|
83
|
+
|
|
84
|
+
This function is a copy of the FORTRAN gaufac function from the Miriad
|
|
85
|
+
package, which determine the Gaussian parameters resulting from
|
|
86
|
+
convolving two gaussians. This function yields the same result as
|
|
87
|
+
the MIRIAD gaufac function.
|
|
88
|
+
|
|
89
|
+
Parameters
|
|
90
|
+
----------
|
|
91
|
+
beamConv : list
|
|
92
|
+
A list of the [major axis, minor axis, position_angle]
|
|
93
|
+
of the gaussion used for convolution.
|
|
94
|
+
beamOrig :
|
|
95
|
+
Same format as beamConv but giving the parameters of the original
|
|
96
|
+
beam of the map. As Default the self.resolution list is used.
|
|
97
|
+
dx1, dy1 : floats
|
|
98
|
+
Being the pixel size in both dimensions of the map.
|
|
99
|
+
By default the ``CDELT1`` and ``CDELT2`` keywords from the
|
|
100
|
+
fits header are used.
|
|
101
|
+
|
|
102
|
+
Returns
|
|
103
|
+
-------
|
|
104
|
+
fac :
|
|
105
|
+
Factor for the output Units.
|
|
106
|
+
amp :
|
|
107
|
+
Amplitude of resultant gaussian.
|
|
108
|
+
bmaj, bmin :
|
|
109
|
+
Major and minor axes of resultant gaussian.
|
|
110
|
+
bpa :
|
|
111
|
+
Position angle of the resulting gaussian.
|
|
112
|
+
"""
|
|
113
|
+
# include 'mirconst.h'
|
|
114
|
+
# Define cosine and Sinus of the position Angles of the
|
|
115
|
+
# Gaussians
|
|
116
|
+
arcsecInGrad = 1 # (1./3600)*(np.pi/180.)
|
|
117
|
+
deg2Grad = np.pi / 180
|
|
118
|
+
bmaj2, bmin2, bpa2 = beamConv
|
|
119
|
+
bmaj2, bmin2, bpa2 = (bmaj2 * arcsecInGrad, bmin2 * arcsecInGrad, bpa2 * deg2Grad)
|
|
120
|
+
# if beamOrig is None:
|
|
121
|
+
bmaj1, bmin1, bpa1 = beamOrig
|
|
122
|
+
bmaj1, bmin1, bpa1 = (bmaj1 * arcsecInGrad, bmin1 * arcsecInGrad, bpa1 * deg2Grad)
|
|
123
|
+
# if dx1 is None:
|
|
124
|
+
dx1 = dx1 * arcsecInGrad
|
|
125
|
+
# if dy1 is None:
|
|
126
|
+
dy1 = dy1 * arcsecInGrad
|
|
127
|
+
cospa1 = math.cos(bpa1)
|
|
128
|
+
cospa2 = math.cos(bpa2)
|
|
129
|
+
sinpa1 = math.sin(bpa1)
|
|
130
|
+
sinpa2 = math.sin(bpa2)
|
|
131
|
+
alpha = (
|
|
132
|
+
(bmaj1 * cospa1) ** 2
|
|
133
|
+
+ (bmin1 * sinpa1) ** 2
|
|
134
|
+
+ (bmaj2 * cospa2) ** 2
|
|
135
|
+
+ (bmin2 * sinpa2) ** 2
|
|
136
|
+
)
|
|
137
|
+
beta = (
|
|
138
|
+
(bmaj1 * sinpa1) ** 2
|
|
139
|
+
+ (bmin1 * cospa1) ** 2
|
|
140
|
+
+ (bmaj2 * sinpa2) ** 2
|
|
141
|
+
+ (bmin2 * cospa2) ** 2
|
|
142
|
+
)
|
|
143
|
+
gamma = 2 * (
|
|
144
|
+
(bmin1**2 - bmaj1**2) * sinpa1 * cospa1
|
|
145
|
+
+ (bmin2**2 - bmaj2**2) * sinpa2 * cospa2
|
|
146
|
+
)
|
|
147
|
+
s = alpha + beta
|
|
148
|
+
t = math.sqrt((alpha - beta) ** 2 + gamma**2)
|
|
149
|
+
bmaj = math.sqrt(0.5 * (s + t))
|
|
150
|
+
bmin = math.sqrt(0.5 * (s - t))
|
|
151
|
+
if (abs(gamma) + abs(alpha - beta)) == 0:
|
|
152
|
+
bpa = 0.0
|
|
153
|
+
else:
|
|
154
|
+
bpa = 0.5 * np.arctan2(-1 * gamma, alpha - beta)
|
|
155
|
+
# print alpha,beta,gamma
|
|
156
|
+
amp = (
|
|
157
|
+
math.pi
|
|
158
|
+
/ (4.0 * math.log(2.0))
|
|
159
|
+
* bmaj1
|
|
160
|
+
* bmin1
|
|
161
|
+
* bmaj2
|
|
162
|
+
* bmin2
|
|
163
|
+
/ math.sqrt(alpha * beta - 0.25 * gamma * gamma)
|
|
164
|
+
)
|
|
165
|
+
fac = ((math.sqrt(dx1**2) * math.sqrt(dy1**2))) / amp
|
|
166
|
+
|
|
167
|
+
return fac, amp, bmaj, bmin, np.degrees(bpa)
|