From 46d8fd4a07cacaaa69f3612501de8f6595e462d9 Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Sat, 23 Jan 2021 17:43:59 +0000 Subject: [PATCH 01/14] modified gleam --- pyradiosky/test.ipynb | 101 +++++++++++++++++++++++++++++++++ pyradiosky/tests/test_utils.py | 16 ++++++ pyradiosky/utils.py | 101 ++++++++++++++++++++++++++++++++- 3 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 pyradiosky/test.ipynb diff --git a/pyradiosky/test.ipynb b/pyradiosky/test.ipynb new file mode 100644 index 00000000..a6f87a18 --- /dev/null +++ b/pyradiosky/test.ipynb @@ -0,0 +1,101 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#import pyradiosky.utils as utils\n", + "from utils import modified_gleam" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "true gleam catalogue file - gleamegc.dat\n" + ] + } + ], + "source": [ + "cat_gleam = modified_gleam(gleam_filename='gleamegc.dat', usecols=(10,12,77,-5), \n", + " nside=32, fill_blank=True, add_peeled_sources=True,\n", + " modified_gleam_filename='tmp.dat')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "414610" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "245453+169157" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(414619, 4)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cat_gleam.shape" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/pyradiosky/tests/test_utils.py b/pyradiosky/tests/test_utils.py index 89f23661..74f0e449 100644 --- a/pyradiosky/tests/test_utils.py +++ b/pyradiosky/tests/test_utils.py @@ -134,3 +134,19 @@ def jy2ksr_nonastropy(freq_arr): conv1 = jy2ksr_nonastropy(freqs) * units.K * units.sr / units.Jy assert np.allclose(conv0, conv1) + + +def test_modified_gleam(): + + #if file is not present in that directory + skyutils.modified_gleam('testgleam.dat') + + #if file is present in the directory + cat1 = skyutils.modified_gleam('gleamegc.dat') + cat2 = skyutils.modified_gleam('gleamegc.dat',fill_blank=True) + cat3 = skyutils.modified_gleam('gleamegc.dat',fill_blank=True, add_peeled_sources=True) + + assert len(cat2) > len(cat1) + + #9 is added peeled source + assert len(cat3) - len(cat2) == 9 \ No newline at end of file diff --git a/pyradiosky/utils.py b/pyradiosky/utils.py index 1d235b72..d8d8779c 100644 --- a/pyradiosky/utils.py +++ b/pyradiosky/utils.py @@ -2,8 +2,9 @@ # Copyright (c) 2019 Radio Astronomy Software Group # Licensed under the 3-clause BSD License """Utility methods.""" -import os +import os, sys import warnings +import copy import numpy as np @@ -18,7 +19,7 @@ from astropy.coordinates import Angle import astropy.units as units from astropy.units import Quantity - +import healpy as hp # The frame radio astronomers call the apparent or current epoch is the # "true equator & equinox" frame, notated E_upsilon in the USNO circular @@ -278,3 +279,99 @@ def download_gleam(path=".", filename="gleam.vot", overwrite=False, row_limit=No table.write(opath, format="votable", overwrite=overwrite) print("GLEAM catalog downloaded and saved to " + opath) + + + +def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10,12,77,-5), fill_blank=False, nside=32, + add_peeled_sources=False, modified_gleam_filename=''): + """ + Write modified gleam catalogue to fill the blank regions, and also to add the peeled sources. + + Parameters + ---------- + gleam_filename : str + name of the gleam catalogue file. + usecols : tuple + default = (10,12,77,-5) + 4 columns, 1st-RA (deg), 2nd-Dec (deg), 3rd - Flux at 100 MHz (Jy), 4th - sp. index + fill_blank : bool + If True, it will fill the blank regions + nside : int + Use for healpix pixalization + add_peeled_sources : bool + If True, it will add the peeled sources from Table 2 Hurley-Walker, N et al. 2017 + modified_gleam_filename : str + name of the modified gleam catalogue file. + + """ + #check if file exists in the given path + if os.path.exists(gleam_filename): + print('true gleam catalogue file - ',gleam_filename) + else: + raise ValueError('File not found') + + + #read array of RA (deg), Dec (deg), Flux at 100 MHz (Jy), sp. index + aa = np.genfromtxt(gleam_filename,usecols = usecols) + + # use sources with finite flux and sp. index values + cat_gleam = aa[(aa[:,2] >= 0.) & np.isfinite(aa[:,2]) & np.isfinite(aa[:,3])] + + #fill blank regions + if fill_blank: + npix=hp.nside2npix(nside) + numhpxmap = np.zeros(npix, dtype=np.float) + indices=hp.ang2pix(nside,cat_gleam[:,0],cat_gleam[:,1],lonlat=True) + + #fill hpmap with number of source + for i in range(npix): + wr = np.where(indices == i) + numhpxmap[i]=wr[0].size + + #non zero indices in the hpmap + non_zero_ind = np.nonzero(numhpxmap)[0] + + #find zero indices with neighbour >2 + nn = hp.get_all_neighbours(nside,np.arange(npix)) + zero_ind = [] + + for i in range(npix): + if np.where(numhpxmap[nn[:,i]] == 0)[0].size > 2: + zero_ind.append(i) + zero_ind = np.array(zero_ind) + + #fill zero indices with randomly chosen non zero indices + np.random.seed(10) + zero_fill_ind = np.random.choice(non_zero_ind, size=len(zero_ind)) + + numhpxmap_fill = copy.deepcopy(numhpxmap) + numhpxmap_fill[zero_ind] = numhpxmap[zero_fill_ind] + + ra_zero, dec_zero = hp.pix2ang(nside,zero_ind,lonlat=True) + + cat_random = [] + for i in range(len(ra_zero)): + wr = np.where(indices == zero_fill_ind[i]) + for j in wr[0]: + cat_random.append((ra_zero[i], dec_zero[i], cat_gleam[j,2],cat_gleam[j,3])) + cat_random = np.array(cat_random) + cat_gleam = np.vstack((cat_gleam, cat_random)) + + #add peeled sources + if add_peeled_sources: + gleam_peeled = np.array([[201.3667, -43.0192, 1937.472, -0.50],#Centaurus A + [139.5250, -12.0956, 544.686, -0.96],#Hydra A + [79.9583, -45.7789, 774.612, -0.99],#Pictor A + [252.7833, 4.9925, 791.486, -1.07],#Hercules A + [187.7042, 12.3911, 1562.747, -0.86],#Virgo A + [83.6333, 22.0144, 1560.743, -0.22],#Crab + [299.8667, 40.7339, 13599.676, -0.78],#Cygnus A + [350.8667, 58.8117, 15811.361, -0.41],#Cassiopeia A + [50.6708, -37.2083, 1256.016, -0.81]])#Fornax A + cat_gleam = np.vstack((gleam_peeled,cat_gleam)) + + #save in a file + if modified_gleam_filename != '': + np.savetxt(modified_gleam_filename,cat_gleam) + + return cat_gleam \ No newline at end of file From b932211e288c9c7684f59ffc373bbb78a2d80cb1 Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Sat, 23 Jan 2021 18:33:06 +0000 Subject: [PATCH 02/14] modified gleam --- pyradiosky/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyradiosky/utils.py b/pyradiosky/utils.py index d8d8779c..d339fba4 100644 --- a/pyradiosky/utils.py +++ b/pyradiosky/utils.py @@ -2,7 +2,7 @@ # Copyright (c) 2019 Radio Astronomy Software Group # Licensed under the 3-clause BSD License """Utility methods.""" -import os, sys +import os import warnings import copy @@ -374,4 +374,4 @@ def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10,12,77,-5), fill_bl if modified_gleam_filename != '': np.savetxt(modified_gleam_filename,cat_gleam) - return cat_gleam \ No newline at end of file + return cat_gleam From c27a16ac73cc0cac8a0eac7ca31bb00c0b55ad5f Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Mon, 25 Jan 2021 13:12:05 +0000 Subject: [PATCH 03/14] modified gleam --- pyradiosky/data/cat_mock.dat | 2 ++ pyradiosky/tests/test_utils.py | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 pyradiosky/data/cat_mock.dat diff --git a/pyradiosky/data/cat_mock.dat b/pyradiosky/data/cat_mock.dat new file mode 100644 index 00000000..4cef1e5c --- /dev/null +++ b/pyradiosky/data/cat_mock.dat @@ -0,0 +1,2 @@ +GLEAM J235139-894114 -0.001036 0.026022 23 51 39.45 -89 41 14.30 357.914368 0.002407 -89.687309 0.002410 0.262282 0.026270 0.248581 2.95339e-02 2.19263e+02 1.11849e+01 146.4811 5.638908 -4.158033 0.446378 -0.011716 0.015203 80 3 221.397 152.189 22.430508 0.116048 0.230260 0.531743 0.199787 0.528997 0.198755 5.18718e+02 443.560 -4.158033 0.150878 0.245333 519.623 445.444 14.269532 0.064158 0.170919 0.512256 0.152039 0.509285 0.151157 4.68570e+02 376.896 -4.158033 0.031757 0.134961 469.572 379.126 4.874937 -0.001032 0.226090 0.427771 0.209262 0.423489 0.207168 4.40963e+02 342.630 -4.158033 -0.011465 0.171556 442.027 345.088 13.513020 0.035764 0.245972 0.444216 0.222199 0.438262 0.219220 4.00925e+02 283.699 -4.158033 -0.031922 0.304453 402.096 286.674 2.319414 0.000086 0.097613 0.332228 0.087342 0.326553 0.085850 3.66049e+02 271.377 -4.158033 0.016291 0.086581 367.331 274.487 9.087766 0.007765 0.067661 0.296139 0.059777 0.291348 0.058810 3.32573e+02 256.153 -4.158033 0.034249 0.100245 333.983 259.448 9.828724 0.022250 0.069156 0.202653 0.061831 0.198947 0.060700 3.16835e+02 244.937 -4.158033 0.010231 0.068757 318.315 248.382 2.127662 0.012362 0.052444 0.298724 0.046800 0.292667 0.045851 3.02262e+02 230.963 -4.158033 -0.013592 0.076489 303.812 234.615 22.214157 0.008152 0.052375 0.341529 0.048493 0.331788 0.047110 2.67819e+02 183.996 -4.158033 0.006087 0.070793 269.568 188.566 20.953054 0.001960 0.050528 0.276829 0.045727 0.267163 0.044130 2.54018e+02 171.133 -4.158033 0.012933 0.094522 255.862 176.038 22.808126 0.024398 0.071617 0.248030 0.064988 0.239452 0.062741 2.46127e+02 170.159 -4.158033 0.029935 0.116816 248.029 175.092 12.885068 0.007915 0.056775 0.278406 0.052344 0.268323 0.050448 2.28098e+02 165.932 -4.158033 -0.003216 0.038754 230.149 170.987 19.574308 0.008273 0.050534 0.345853 0.045476 0.330670 0.043480 2.27678e+02 148.799 -4.158033 -0.000142 0.058509 229.733 154.417 21.433491 0.007071 0.072735 0.317384 0.065278 0.303373 0.062396 2.16998e+02 141.9525 -4.158033 -0.003245 0.054701 219.153 147.832 10.051599 0.001770 0.058237 0.320320 0.052301 0.304456 0.049711 2.13273e+02 138.8363 -4.158033 -0.005387 0.040263 215.466 144.842 6.488752 -0.004338 0.059530 0.179936 0.053834 0.168986 0.050558 2.07908e+02 130.4126 -4.158033 -0.015960 0.085525 210.156 136.790 12.743345 0.004307 0.070833 0.205871 0.064479 0.194392 0.060883 1.88324e+02 134.0238 -4.158033 -0.069456 0.078095 190.803 140.237 14.509152 -0.007659 0.112504 0.495948 0.101910 0.464646 0.095478 1.72234e+02 125.0827 -4.158033 -0.014896 0.124724 174.942 131.7186 7.999518 -0.009265 0.082080 0.167417 0.074100 0.156235 0.069151 1.71534e+02 127.1215 -4.158033 -0.038894 0.098901 174.253 133.6561 17.220127 -0.008993 0.063705 0.097147 0.058071 0.090779 0.054264 1.70630e+02 123.0671 -4.158033 0.010692 0.061223 173.363 129.8062 18.959024 -0.370882 0.206630 1.327554 0.271901 0.282624 +GLEAM J223320-891247 0.005786 0.027336 22 33 20.70 -89 12 47.90 338.336243 0.002644 -89.213310 0.005215 0.160685 0.027332 0.150291 3.06360e-02 2.17707e+02 1.63764e+01 145.0885 12.104796 8.403455 0.819455 -0.000382 0.002031 80 3 221.397 152.189 22.430508 0.145184 0.235298 -0.032964 0.172094 -0.032702 0.170727 5.18061e+02 443.072 8.403455 -0.043365 0.177417 519.623 445.444 14.269532 0.089438 0.176423 0.047469 0.163485 0.046991 0.161839 4.67844e+02 376.335 8.403455 0.010040 0.192257 469.572 379.126 4.874937 0.015943 0.235867 0.128079 0.227157 0.126356 0.224101 4.40191e+02 342.019 8.403455 0.008484 0.222494 442.027 345.088 13.513020 0.040699 0.377322 0.142839 0.382264 0.140268 0.375383 4.00076e+02 282.970 8.403455 -0.038435 0.257183 402.096 286.674 2.319414 0.017534 0.106599 0.253755 0.097220 0.248429 0.095180 3.65119e+02 270.616 8.403455 0.014032 0.074087 367.331 274.487 9.087766 0.026090 0.073951 0.165963 0.065950 0.162184 0.064448 3.31549e+02 255.349 8.403455 0.005107 0.077997 333.983 259.448 9.828724 0.049018 0.077362 0.210111 0.068139 0.204836 0.066429 3.15760e+02 244.097 8.403455 -0.029577 0.078783 318.315 248.382 2.127662 0.025180 0.059016 0.239816 0.053152 0.233148 0.051674 3.01134e+02 230.074 8.403455 0.025429 0.062932 303.812 234.615 22.214157 0.013240 0.054271 0.162333 0.049681 0.155820 0.047688 2.66546e+02 182.884 8.403455 -0.001366 0.043916 269.568 188.566 20.953054 0.008886 0.051497 0.115085 0.046964 0.109704 0.044768 2.52676e+02 169.938 8.403455 0.003019 0.040917 255.862 176.038 22.808126 0.038015 0.067749 0.129781 0.063438 0.123631 0.060432 2.44741e+02 168.957 8.403455 -0.065214 0.073274 248.029 175.092 12.885068 0.016190 0.055426 0.134795 0.051177 0.127968 0.048584 2.26602e+02 164.700 8.403455 0.000205 0.059096 230.149 170.987 19.574308 0.014585 0.051557 0.095750 0.047087 0.090058 0.044288 2.26179e+02 147.425 8.403455 -0.005963 0.037156 229.733 154.417 21.433491 0.010127 0.074096 0.243093 0.067382 0.227618 0.063093 2.15425e+02 140.5117 8.403455 0.000677 0.063932 219.153 147.832 10.051599 0.009068 0.060119 0.106840 0.054225 0.099611 0.050556 2.11673e+02 137.3630 8.403455 -0.019822 0.071932 215.466 144.842 6.488752 0.001938 0.062486 0.195201 0.055663 0.180154 0.051372 2.06266e+02 128.8436 8.403455 0.012022 0.040339 210.156 136.790 12.743345 0.007127 0.073501 0.143984 0.066566 0.133045 0.061509 1.86509e+02 132.4975 8.403455 -0.008034 0.054549 190.803 140.237 14.509152 0.002146 0.099728 0.266312 0.090945 0.243056 0.083003 1.70248e+02 123.4464 8.403455 -0.038080 0.076928 174.942 131.7186 7.999518 -0.001221 0.088576 0.198049 0.080596 0.180743 0.073553 1.69540e+02 125.5117 8.403455 0.013916 0.063156 174.253 133.6561 17.220127 0.005891 0.065832 0.084467 0.060414 0.076873 0.054982 1.68625e+02 121.4038 8.403455 0.013542 0.040994 173.363 129.8062 18.959024 --- --- --- --- --- \ No newline at end of file diff --git a/pyradiosky/tests/test_utils.py b/pyradiosky/tests/test_utils.py index 74f0e449..a61ba08e 100644 --- a/pyradiosky/tests/test_utils.py +++ b/pyradiosky/tests/test_utils.py @@ -139,14 +139,15 @@ def jy2ksr_nonastropy(freq_arr): def test_modified_gleam(): #if file is not present in that directory - skyutils.modified_gleam('testgleam.dat') - + with pytest.raises(ValueError, match="File not found"): + skyutils.modified_gleam('testgleam.dat') + #if file is present in the directory - cat1 = skyutils.modified_gleam('gleamegc.dat') - cat2 = skyutils.modified_gleam('gleamegc.dat',fill_blank=True) - cat3 = skyutils.modified_gleam('gleamegc.dat',fill_blank=True, add_peeled_sources=True) + cat1 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat') + cat2 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat',fill_blank=True, nside=8) + cat3 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat',fill_blank=True, nside=8, add_peeled_sources=True) assert len(cat2) > len(cat1) #9 is added peeled source - assert len(cat3) - len(cat2) == 9 \ No newline at end of file + assert len(cat3) - len(cat2) == 9 From 44302b9d5d54150be53b38e4f9fba9ea224e5d07 Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Mon, 25 Jan 2021 17:27:20 +0000 Subject: [PATCH 04/14] modified gleam --- pyradiosky/tests/test_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyradiosky/tests/test_utils.py b/pyradiosky/tests/test_utils.py index a61ba08e..fadcdb90 100644 --- a/pyradiosky/tests/test_utils.py +++ b/pyradiosky/tests/test_utils.py @@ -142,9 +142,13 @@ def test_modified_gleam(): with pytest.raises(ValueError, match="File not found"): skyutils.modified_gleam('testgleam.dat') - #if file is present in the directory + #read the dummy cat file present in the directory cat1 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat') + + #read the dummy cat file and fill the blank regions cat2 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat',fill_blank=True, nside=8) + + #read the dummy cat file and fill the blank regions,and also add the peeled sources cat3 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat',fill_blank=True, nside=8, add_peeled_sources=True) assert len(cat2) > len(cat1) From d24d3537e5c89cd1fd32a38d1958b47c3a1b56cd Mon Sep 17 00:00:00 2001 From: samirchoudhuri <46684209+samirchoudhuri@users.noreply.github.com> Date: Mon, 25 Jan 2021 18:11:52 +0000 Subject: [PATCH 05/14] Delete test.ipynb --- pyradiosky/test.ipynb | 101 ------------------------------------------ 1 file changed, 101 deletions(-) delete mode 100644 pyradiosky/test.ipynb diff --git a/pyradiosky/test.ipynb b/pyradiosky/test.ipynb deleted file mode 100644 index a6f87a18..00000000 --- a/pyradiosky/test.ipynb +++ /dev/null @@ -1,101 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "#import pyradiosky.utils as utils\n", - "from utils import modified_gleam" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "true gleam catalogue file - gleamegc.dat\n" - ] - } - ], - "source": [ - "cat_gleam = modified_gleam(gleam_filename='gleamegc.dat', usecols=(10,12,77,-5), \n", - " nside=32, fill_blank=True, add_peeled_sources=True,\n", - " modified_gleam_filename='tmp.dat')" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "414610" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "245453+169157" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(414619, 4)" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "cat_gleam.shape" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} From d559442033362ab90499c7654b38cd43d15cd77d Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Mon, 25 Jan 2021 18:41:50 +0000 Subject: [PATCH 06/14] modified gleam --- environment.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment.yaml b/environment.yaml index c602d449..6fe92243 100644 --- a/environment.yaml +++ b/environment.yaml @@ -18,5 +18,6 @@ dependencies: - scipy - setuptools_scm - sphinx + - healpy - pip: - lunarsky From 4af5be1539fde96e9dbe190af88fbc543a1506d8 Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Tue, 2 Feb 2021 22:15:14 +0000 Subject: [PATCH 07/14] modified gleam --- environment.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/environment.yaml b/environment.yaml index 6fe92243..c602d449 100644 --- a/environment.yaml +++ b/environment.yaml @@ -18,6 +18,5 @@ dependencies: - scipy - setuptools_scm - sphinx - - healpy - pip: - lunarsky From 32a555fcd8f1fd20e6ea424eda6f6331173e289a Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Wed, 3 Feb 2021 18:44:29 +0000 Subject: [PATCH 08/14] modified gleam --- pyradiosky/utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pyradiosky/utils.py b/pyradiosky/utils.py index d339fba4..65c0fc3c 100644 --- a/pyradiosky/utils.py +++ b/pyradiosky/utils.py @@ -19,7 +19,8 @@ from astropy.coordinates import Angle import astropy.units as units from astropy.units import Quantity -import healpy as hp +import astropy_healpix.healpy as hp +import astropy_healpix as astrohp # The frame radio astronomers call the apparent or current epoch is the # "true equator & equinox" frame, notated E_upsilon in the USNO circular @@ -319,20 +320,21 @@ def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10,12,77,-5), fill_bl #fill blank regions if fill_blank: - npix=hp.nside2npix(nside) + + npix = hp.nside2npix(nside) numhpxmap = np.zeros(npix, dtype=np.float) - indices=hp.ang2pix(nside,cat_gleam[:,0],cat_gleam[:,1],lonlat=True) + indices = hp.ang2pix(nside,cat_gleam[:,0],cat_gleam[:,1],lonlat=True) #fill hpmap with number of source for i in range(npix): wr = np.where(indices == i) - numhpxmap[i]=wr[0].size + numhpxmap[i] = wr[0].size #non zero indices in the hpmap non_zero_ind = np.nonzero(numhpxmap)[0] #find zero indices with neighbour >2 - nn = hp.get_all_neighbours(nside,np.arange(npix)) + nn = astrohp.neighbours(np.arange(npix),nside) zero_ind = [] for i in range(npix): From 78847f0367dce74e2278f077e4e22a319b87d098 Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Fri, 5 Feb 2021 16:30:22 +0000 Subject: [PATCH 09/14] modified gleam --- pyradiosky/tests/test_utils.py | 14 ++++---- pyradiosky/utils.py | 63 +++++++++++++++++----------------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/pyradiosky/tests/test_utils.py b/pyradiosky/tests/test_utils.py index fadcdb90..185d0853 100644 --- a/pyradiosky/tests/test_utils.py +++ b/pyradiosky/tests/test_utils.py @@ -138,20 +138,20 @@ def jy2ksr_nonastropy(freq_arr): def test_modified_gleam(): - #if file is not present in that directory + # if file is not present in that directory with pytest.raises(ValueError, match="File not found"): skyutils.modified_gleam('testgleam.dat') - #read the dummy cat file present in the directory + # read the dummy cat file present in the directory cat1 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat') - #read the dummy cat file and fill the blank regions - cat2 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat',fill_blank=True, nside=8) + # read the dummy cat file and fill the blank regions + cat2 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', fill_blank=True, nside=8) - #read the dummy cat file and fill the blank regions,and also add the peeled sources - cat3 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat',fill_blank=True, nside=8, add_peeled_sources=True) + # read the dummy cat file and fill the blank regions,and also add the peeled sources + cat3 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', fill_blank=True, nside=8, add_peeled_sources=True) assert len(cat2) > len(cat1) - #9 is added peeled source + # 9 is added peeled source assert len(cat3) - len(cat2) == 9 diff --git a/pyradiosky/utils.py b/pyradiosky/utils.py index 65c0fc3c..007f1e02 100644 --- a/pyradiosky/utils.py +++ b/pyradiosky/utils.py @@ -27,6 +27,8 @@ # astropy doesn't have this frame but it's pretty easy to adapt the CIRS frame # by modifying the ra to reflect the difference between # GAST (Grenwich Apparent Sidereal Time) and the earth rotation angle (theta) + + def _tee_to_cirs_ra(tee_ra, time): """ Convert from the true equator & equinox frame to the CIRS frame. @@ -282,9 +284,7 @@ def download_gleam(path=".", filename="gleam.vot", overwrite=False, row_limit=No print("GLEAM catalog downloaded and saved to " + opath) - -def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10,12,77,-5), fill_blank=False, nside=32, - add_peeled_sources=False, modified_gleam_filename=''): +def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10,12,77,-5), fill_blank=False, nside=32, add_peeled_sources=False, modified_gleam_filename=''): """ Write modified gleam catalogue to fill the blank regions, and also to add the peeled sources. @@ -305,75 +305,74 @@ def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10,12,77,-5), fill_bl name of the modified gleam catalogue file. """ - #check if file exists in the given path + # check if file exists in the given path if os.path.exists(gleam_filename): - print('true gleam catalogue file - ',gleam_filename) + print('true gleam catalogue file - ', gleam_filename) else: raise ValueError('File not found') - - #read array of RA (deg), Dec (deg), Flux at 100 MHz (Jy), sp. index - aa = np.genfromtxt(gleam_filename,usecols = usecols) + # read array of RA (deg), Dec (deg), Flux at 100 MHz (Jy), sp. index + aa = np.genfromtxt(gleam_filename, usecols=usecols) # use sources with finite flux and sp. index values - cat_gleam = aa[(aa[:,2] >= 0.) & np.isfinite(aa[:,2]) & np.isfinite(aa[:,3])] + cat_gleam = aa[(aa[:, 2] >= 0.) & np.isfinite(aa[:, 2]) & np.isfinite(aa[:, 3])] - #fill blank regions + # fill blank regions if fill_blank: npix = hp.nside2npix(nside) numhpxmap = np.zeros(npix, dtype=np.float) - indices = hp.ang2pix(nside,cat_gleam[:,0],cat_gleam[:,1],lonlat=True) + indices = hp.ang2pix(nside, cat_gleam[:,0], cat_gleam[:,1], lonlat=True) - #fill hpmap with number of source + # fill hpmap with number of source for i in range(npix): wr = np.where(indices == i) numhpxmap[i] = wr[0].size - #non zero indices in the hpmap + # non zero indices in the hpmap non_zero_ind = np.nonzero(numhpxmap)[0] - #find zero indices with neighbour >2 - nn = astrohp.neighbours(np.arange(npix),nside) + # find zero indices with neighbour >2 + nn = astrohp.neighbours(np.arange(npix), nside) zero_ind = [] for i in range(npix): - if np.where(numhpxmap[nn[:,i]] == 0)[0].size > 2: + if np.where(numhpxmap[nn[:, i]] == 0)[0].size > 2: zero_ind.append(i) zero_ind = np.array(zero_ind) - #fill zero indices with randomly chosen non zero indices + # fill zero indices with randomly chosen non zero indices np.random.seed(10) zero_fill_ind = np.random.choice(non_zero_ind, size=len(zero_ind)) numhpxmap_fill = copy.deepcopy(numhpxmap) numhpxmap_fill[zero_ind] = numhpxmap[zero_fill_ind] - ra_zero, dec_zero = hp.pix2ang(nside,zero_ind,lonlat=True) + ra_zero, dec_zero = hp.pix2ang(nside, zero_ind, lonlat=True) cat_random = [] for i in range(len(ra_zero)): wr = np.where(indices == zero_fill_ind[i]) for j in wr[0]: - cat_random.append((ra_zero[i], dec_zero[i], cat_gleam[j,2],cat_gleam[j,3])) + cat_random.append((ra_zero[i], dec_zero[i], cat_gleam[j, 2], cat_gleam[j, 3])) cat_random = np.array(cat_random) cat_gleam = np.vstack((cat_gleam, cat_random)) - #add peeled sources + # add peeled sources if add_peeled_sources: - gleam_peeled = np.array([[201.3667, -43.0192, 1937.472, -0.50],#Centaurus A - [139.5250, -12.0956, 544.686, -0.96],#Hydra A - [79.9583, -45.7789, 774.612, -0.99],#Pictor A - [252.7833, 4.9925, 791.486, -1.07],#Hercules A - [187.7042, 12.3911, 1562.747, -0.86],#Virgo A - [83.6333, 22.0144, 1560.743, -0.22],#Crab - [299.8667, 40.7339, 13599.676, -0.78],#Cygnus A - [350.8667, 58.8117, 15811.361, -0.41],#Cassiopeia A - [50.6708, -37.2083, 1256.016, -0.81]])#Fornax A - cat_gleam = np.vstack((gleam_peeled,cat_gleam)) + gleam_peeled = np.array([[201.3667, -43.0192, 1937.472, -0.50], # Centaurus A + [139.5250, -12.0956, 544.686, -0.96], # Hydra A + [79.9583, -45.7789, 774.612, -0.99], # Pictor A + [252.7833, 4.9925, 791.486, -1.07], # Hercules A + [187.7042, 12.3911, 1562.747, -0.86], # Virgo A + [83.6333, 22.0144, 1560.743, -0.22], # Crab + [299.8667, 40.7339, 13599.676, -0.78], # Cygnus A + [350.8667, 58.8117, 15811.361, -0.41], # Cassiopeia A + [50.6708, -37.2083, 1256.016, -0.81]]) # Fornax A + cat_gleam = np.vstack((gleam_peeled, cat_gleam)) - #save in a file + # save in a file if modified_gleam_filename != '': - np.savetxt(modified_gleam_filename,cat_gleam) + np.savetxt(modified_gleam_filename, cat_gleam) return cat_gleam From ce824fcc9ec504dd16a44410c75363c862667464 Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Fri, 5 Feb 2021 17:07:10 +0000 Subject: [PATCH 10/14] modified gleam --- pyradiosky/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyradiosky/utils.py b/pyradiosky/utils.py index 007f1e02..280fbd51 100644 --- a/pyradiosky/utils.py +++ b/pyradiosky/utils.py @@ -284,7 +284,7 @@ def download_gleam(path=".", filename="gleam.vot", overwrite=False, row_limit=No print("GLEAM catalog downloaded and saved to " + opath) -def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10,12,77,-5), fill_blank=False, nside=32, add_peeled_sources=False, modified_gleam_filename=''): +def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10, 12, 77, -5), fill_blank=False, nside=32, add_peeled_sources=False, modified_gleam_filename=''): """ Write modified gleam catalogue to fill the blank regions, and also to add the peeled sources. @@ -322,7 +322,7 @@ def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10,12,77,-5), fill_bl npix = hp.nside2npix(nside) numhpxmap = np.zeros(npix, dtype=np.float) - indices = hp.ang2pix(nside, cat_gleam[:,0], cat_gleam[:,1], lonlat=True) + indices = hp.ang2pix(nside, cat_gleam[:, 0], cat_gleam[:, 1], lonlat=True) # fill hpmap with number of source for i in range(npix): From cf5e523eca307d6f5ed370d35f628d4a5fcd5885 Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Wed, 10 Mar 2021 18:10:28 +0000 Subject: [PATCH 11/14] modified gleam --- pyradiosky/tests/test_utils.py | 3 +++ pyradiosky/utils.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pyradiosky/tests/test_utils.py b/pyradiosky/tests/test_utils.py index 185d0853..5b7e1717 100644 --- a/pyradiosky/tests/test_utils.py +++ b/pyradiosky/tests/test_utils.py @@ -137,6 +137,9 @@ def jy2ksr_nonastropy(freq_arr): def test_modified_gleam(): + + pytest.importorskip("astropy_healpix") + import astropy_healpix # if file is not present in that directory with pytest.raises(ValueError, match="File not found"): diff --git a/pyradiosky/utils.py b/pyradiosky/utils.py index 280fbd51..f9b39b0b 100644 --- a/pyradiosky/utils.py +++ b/pyradiosky/utils.py @@ -19,8 +19,6 @@ from astropy.coordinates import Angle import astropy.units as units from astropy.units import Quantity -import astropy_healpix.healpy as hp -import astropy_healpix as astrohp # The frame radio astronomers call the apparent or current epoch is the # "true equator & equinox" frame, notated E_upsilon in the USNO circular @@ -305,6 +303,9 @@ def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10, 12, 77, -5), fill name of the modified gleam catalogue file. """ + import astropy_healpix as astrohp + import astropy_healpix.healpy as hp + # check if file exists in the given path if os.path.exists(gleam_filename): print('true gleam catalogue file - ', gleam_filename) From 6a180bf9a6dcd0814ac2cb322771db1f43a8acbc Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Wed, 10 Mar 2021 19:47:30 +0000 Subject: [PATCH 12/14] modified gleam --- pyradiosky/tests/test_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyradiosky/tests/test_utils.py b/pyradiosky/tests/test_utils.py index 5b7e1717..2d5ce29f 100644 --- a/pyradiosky/tests/test_utils.py +++ b/pyradiosky/tests/test_utils.py @@ -139,14 +139,13 @@ def jy2ksr_nonastropy(freq_arr): def test_modified_gleam(): pytest.importorskip("astropy_healpix") - import astropy_healpix # if file is not present in that directory with pytest.raises(ValueError, match="File not found"): skyutils.modified_gleam('testgleam.dat') # read the dummy cat file present in the directory - cat1 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat') + cat1 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', modified_gleam_filename='pyradiosky/data/cat_moc_out.dat') # read the dummy cat file and fill the blank regions cat2 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', fill_blank=True, nside=8) From 385709fa6ebcd57bb8818c3e2990cff27bee27ee Mon Sep 17 00:00:00 2001 From: Samir Choudhuri Date: Thu, 11 Mar 2021 18:24:05 +0000 Subject: [PATCH 13/14] modified gleam --- pyradiosky/data/cat_mock.dat | 4 ++-- pyradiosky/tests/test_utils.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyradiosky/data/cat_mock.dat b/pyradiosky/data/cat_mock.dat index 4cef1e5c..67f60c26 100644 --- a/pyradiosky/data/cat_mock.dat +++ b/pyradiosky/data/cat_mock.dat @@ -1,2 +1,2 @@ -GLEAM J235139-894114 -0.001036 0.026022 23 51 39.45 -89 41 14.30 357.914368 0.002407 -89.687309 0.002410 0.262282 0.026270 0.248581 2.95339e-02 2.19263e+02 1.11849e+01 146.4811 5.638908 -4.158033 0.446378 -0.011716 0.015203 80 3 221.397 152.189 22.430508 0.116048 0.230260 0.531743 0.199787 0.528997 0.198755 5.18718e+02 443.560 -4.158033 0.150878 0.245333 519.623 445.444 14.269532 0.064158 0.170919 0.512256 0.152039 0.509285 0.151157 4.68570e+02 376.896 -4.158033 0.031757 0.134961 469.572 379.126 4.874937 -0.001032 0.226090 0.427771 0.209262 0.423489 0.207168 4.40963e+02 342.630 -4.158033 -0.011465 0.171556 442.027 345.088 13.513020 0.035764 0.245972 0.444216 0.222199 0.438262 0.219220 4.00925e+02 283.699 -4.158033 -0.031922 0.304453 402.096 286.674 2.319414 0.000086 0.097613 0.332228 0.087342 0.326553 0.085850 3.66049e+02 271.377 -4.158033 0.016291 0.086581 367.331 274.487 9.087766 0.007765 0.067661 0.296139 0.059777 0.291348 0.058810 3.32573e+02 256.153 -4.158033 0.034249 0.100245 333.983 259.448 9.828724 0.022250 0.069156 0.202653 0.061831 0.198947 0.060700 3.16835e+02 244.937 -4.158033 0.010231 0.068757 318.315 248.382 2.127662 0.012362 0.052444 0.298724 0.046800 0.292667 0.045851 3.02262e+02 230.963 -4.158033 -0.013592 0.076489 303.812 234.615 22.214157 0.008152 0.052375 0.341529 0.048493 0.331788 0.047110 2.67819e+02 183.996 -4.158033 0.006087 0.070793 269.568 188.566 20.953054 0.001960 0.050528 0.276829 0.045727 0.267163 0.044130 2.54018e+02 171.133 -4.158033 0.012933 0.094522 255.862 176.038 22.808126 0.024398 0.071617 0.248030 0.064988 0.239452 0.062741 2.46127e+02 170.159 -4.158033 0.029935 0.116816 248.029 175.092 12.885068 0.007915 0.056775 0.278406 0.052344 0.268323 0.050448 2.28098e+02 165.932 -4.158033 -0.003216 0.038754 230.149 170.987 19.574308 0.008273 0.050534 0.345853 0.045476 0.330670 0.043480 2.27678e+02 148.799 -4.158033 -0.000142 0.058509 229.733 154.417 21.433491 0.007071 0.072735 0.317384 0.065278 0.303373 0.062396 2.16998e+02 141.9525 -4.158033 -0.003245 0.054701 219.153 147.832 10.051599 0.001770 0.058237 0.320320 0.052301 0.304456 0.049711 2.13273e+02 138.8363 -4.158033 -0.005387 0.040263 215.466 144.842 6.488752 -0.004338 0.059530 0.179936 0.053834 0.168986 0.050558 2.07908e+02 130.4126 -4.158033 -0.015960 0.085525 210.156 136.790 12.743345 0.004307 0.070833 0.205871 0.064479 0.194392 0.060883 1.88324e+02 134.0238 -4.158033 -0.069456 0.078095 190.803 140.237 14.509152 -0.007659 0.112504 0.495948 0.101910 0.464646 0.095478 1.72234e+02 125.0827 -4.158033 -0.014896 0.124724 174.942 131.7186 7.999518 -0.009265 0.082080 0.167417 0.074100 0.156235 0.069151 1.71534e+02 127.1215 -4.158033 -0.038894 0.098901 174.253 133.6561 17.220127 -0.008993 0.063705 0.097147 0.058071 0.090779 0.054264 1.70630e+02 123.0671 -4.158033 0.010692 0.061223 173.363 129.8062 18.959024 -0.370882 0.206630 1.327554 0.271901 0.282624 -GLEAM J223320-891247 0.005786 0.027336 22 33 20.70 -89 12 47.90 338.336243 0.002644 -89.213310 0.005215 0.160685 0.027332 0.150291 3.06360e-02 2.17707e+02 1.63764e+01 145.0885 12.104796 8.403455 0.819455 -0.000382 0.002031 80 3 221.397 152.189 22.430508 0.145184 0.235298 -0.032964 0.172094 -0.032702 0.170727 5.18061e+02 443.072 8.403455 -0.043365 0.177417 519.623 445.444 14.269532 0.089438 0.176423 0.047469 0.163485 0.046991 0.161839 4.67844e+02 376.335 8.403455 0.010040 0.192257 469.572 379.126 4.874937 0.015943 0.235867 0.128079 0.227157 0.126356 0.224101 4.40191e+02 342.019 8.403455 0.008484 0.222494 442.027 345.088 13.513020 0.040699 0.377322 0.142839 0.382264 0.140268 0.375383 4.00076e+02 282.970 8.403455 -0.038435 0.257183 402.096 286.674 2.319414 0.017534 0.106599 0.253755 0.097220 0.248429 0.095180 3.65119e+02 270.616 8.403455 0.014032 0.074087 367.331 274.487 9.087766 0.026090 0.073951 0.165963 0.065950 0.162184 0.064448 3.31549e+02 255.349 8.403455 0.005107 0.077997 333.983 259.448 9.828724 0.049018 0.077362 0.210111 0.068139 0.204836 0.066429 3.15760e+02 244.097 8.403455 -0.029577 0.078783 318.315 248.382 2.127662 0.025180 0.059016 0.239816 0.053152 0.233148 0.051674 3.01134e+02 230.074 8.403455 0.025429 0.062932 303.812 234.615 22.214157 0.013240 0.054271 0.162333 0.049681 0.155820 0.047688 2.66546e+02 182.884 8.403455 -0.001366 0.043916 269.568 188.566 20.953054 0.008886 0.051497 0.115085 0.046964 0.109704 0.044768 2.52676e+02 169.938 8.403455 0.003019 0.040917 255.862 176.038 22.808126 0.038015 0.067749 0.129781 0.063438 0.123631 0.060432 2.44741e+02 168.957 8.403455 -0.065214 0.073274 248.029 175.092 12.885068 0.016190 0.055426 0.134795 0.051177 0.127968 0.048584 2.26602e+02 164.700 8.403455 0.000205 0.059096 230.149 170.987 19.574308 0.014585 0.051557 0.095750 0.047087 0.090058 0.044288 2.26179e+02 147.425 8.403455 -0.005963 0.037156 229.733 154.417 21.433491 0.010127 0.074096 0.243093 0.067382 0.227618 0.063093 2.15425e+02 140.5117 8.403455 0.000677 0.063932 219.153 147.832 10.051599 0.009068 0.060119 0.106840 0.054225 0.099611 0.050556 2.11673e+02 137.3630 8.403455 -0.019822 0.071932 215.466 144.842 6.488752 0.001938 0.062486 0.195201 0.055663 0.180154 0.051372 2.06266e+02 128.8436 8.403455 0.012022 0.040339 210.156 136.790 12.743345 0.007127 0.073501 0.143984 0.066566 0.133045 0.061509 1.86509e+02 132.4975 8.403455 -0.008034 0.054549 190.803 140.237 14.509152 0.002146 0.099728 0.266312 0.090945 0.243056 0.083003 1.70248e+02 123.4464 8.403455 -0.038080 0.076928 174.942 131.7186 7.999518 -0.001221 0.088576 0.198049 0.080596 0.180743 0.073553 1.69540e+02 125.5117 8.403455 0.013916 0.063156 174.253 133.6561 17.220127 0.005891 0.065832 0.084467 0.060414 0.076873 0.054982 1.68625e+02 121.4038 8.403455 0.013542 0.040994 173.363 129.8062 18.959024 --- --- --- --- --- \ No newline at end of file +2.013e+02 -4.301e+01 1.937e+03 -5.000e-01 +1.395e+02 -1.209e+01 5.446e+02 -9.599e-01 \ No newline at end of file diff --git a/pyradiosky/tests/test_utils.py b/pyradiosky/tests/test_utils.py index 2d5ce29f..8100484d 100644 --- a/pyradiosky/tests/test_utils.py +++ b/pyradiosky/tests/test_utils.py @@ -145,13 +145,13 @@ def test_modified_gleam(): skyutils.modified_gleam('testgleam.dat') # read the dummy cat file present in the directory - cat1 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', modified_gleam_filename='pyradiosky/data/cat_moc_out.dat') + cat1 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', usecols=(0, 1, 2, 3), modified_gleam_filename='pyradiosky/data/cat_moc_out.dat') # read the dummy cat file and fill the blank regions - cat2 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', fill_blank=True, nside=8) + cat2 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', usecols=(0, 1, 2, 3), fill_blank=True, nside=8) # read the dummy cat file and fill the blank regions,and also add the peeled sources - cat3 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', fill_blank=True, nside=8, add_peeled_sources=True) + cat3 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', usecols=(0, 1, 2, 3), fill_blank=True, nside=8, add_peeled_sources=True) assert len(cat2) > len(cat1) From 035fccde53a62df5f82d439cacd8239c4e95b3cf Mon Sep 17 00:00:00 2001 From: Bryna Hazelton Date: Thu, 11 Mar 2021 13:11:50 -0800 Subject: [PATCH 14/14] linting fixes --- pyradiosky/data/cat_mock.dat | 2 +- pyradiosky/tests/test_utils.py | 34 +++++++++++------ pyradiosky/utils.py | 67 ++++++++++++++++++++-------------- 3 files changed, 64 insertions(+), 39 deletions(-) diff --git a/pyradiosky/data/cat_mock.dat b/pyradiosky/data/cat_mock.dat index 67f60c26..6193a674 100644 --- a/pyradiosky/data/cat_mock.dat +++ b/pyradiosky/data/cat_mock.dat @@ -1,2 +1,2 @@ 2.013e+02 -4.301e+01 1.937e+03 -5.000e-01 -1.395e+02 -1.209e+01 5.446e+02 -9.599e-01 \ No newline at end of file +1.395e+02 -1.209e+01 5.446e+02 -9.599e-01 diff --git a/pyradiosky/tests/test_utils.py b/pyradiosky/tests/test_utils.py index 8100484d..55d02f2c 100644 --- a/pyradiosky/tests/test_utils.py +++ b/pyradiosky/tests/test_utils.py @@ -134,26 +134,38 @@ def jy2ksr_nonastropy(freq_arr): conv1 = jy2ksr_nonastropy(freqs) * units.K * units.sr / units.Jy assert np.allclose(conv0, conv1) - - + + def test_modified_gleam(): pytest.importorskip("astropy_healpix") - + # if file is not present in that directory with pytest.raises(ValueError, match="File not found"): - skyutils.modified_gleam('testgleam.dat') - + skyutils.modified_gleam("testgleam.dat") + # read the dummy cat file present in the directory - cat1 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', usecols=(0, 1, 2, 3), modified_gleam_filename='pyradiosky/data/cat_moc_out.dat') + cat1 = skyutils.modified_gleam( + "pyradiosky/data/cat_mock.dat", + usecols=(0, 1, 2, 3), + modified_gleam_filename="pyradiosky/data/cat_moc_out.dat", + ) # read the dummy cat file and fill the blank regions - cat2 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', usecols=(0, 1, 2, 3), fill_blank=True, nside=8) + cat2 = skyutils.modified_gleam( + "pyradiosky/data/cat_mock.dat", usecols=(0, 1, 2, 3), fill_blank=True, nside=8 + ) # read the dummy cat file and fill the blank regions,and also add the peeled sources - cat3 = skyutils.modified_gleam('pyradiosky/data/cat_mock.dat', usecols=(0, 1, 2, 3), fill_blank=True, nside=8, add_peeled_sources=True) - + cat3 = skyutils.modified_gleam( + "pyradiosky/data/cat_mock.dat", + usecols=(0, 1, 2, 3), + fill_blank=True, + nside=8, + add_peeled_sources=True, + ) + assert len(cat2) > len(cat1) - + # 9 is added peeled source - assert len(cat3) - len(cat2) == 9 + assert len(cat3) - len(cat2) == 9 diff --git a/pyradiosky/utils.py b/pyradiosky/utils.py index f9b39b0b..e04496c3 100644 --- a/pyradiosky/utils.py +++ b/pyradiosky/utils.py @@ -282,7 +282,14 @@ def download_gleam(path=".", filename="gleam.vot", overwrite=False, row_limit=No print("GLEAM catalog downloaded and saved to " + opath) -def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10, 12, 77, -5), fill_blank=False, nside=32, add_peeled_sources=False, modified_gleam_filename=''): +def modified_gleam( + gleam_filename="gleamegc.dat", + usecols=(10, 12, 77, -5), + fill_blank=False, + nside=32, + add_peeled_sources=False, + modified_gleam_filename="", +): """ Write modified gleam catalogue to fill the blank regions, and also to add the peeled sources. @@ -291,7 +298,7 @@ def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10, 12, 77, -5), fill gleam_filename : str name of the gleam catalogue file. usecols : tuple - default = (10,12,77,-5) + default = (10,12,77,-5) 4 columns, 1st-RA (deg), 2nd-Dec (deg), 3rd - Flux at 100 MHz (Jy), 4th - sp. index fill_blank : bool If True, it will fill the blank regions @@ -308,23 +315,23 @@ def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10, 12, 77, -5), fill # check if file exists in the given path if os.path.exists(gleam_filename): - print('true gleam catalogue file - ', gleam_filename) + print("true gleam catalogue file - ", gleam_filename) else: - raise ValueError('File not found') - + raise ValueError("File not found") + # read array of RA (deg), Dec (deg), Flux at 100 MHz (Jy), sp. index aa = np.genfromtxt(gleam_filename, usecols=usecols) # use sources with finite flux and sp. index values - cat_gleam = aa[(aa[:, 2] >= 0.) & np.isfinite(aa[:, 2]) & np.isfinite(aa[:, 3])] - + cat_gleam = aa[(aa[:, 2] >= 0.0) & np.isfinite(aa[:, 2]) & np.isfinite(aa[:, 3])] + # fill blank regions if fill_blank: - + npix = hp.nside2npix(nside) numhpxmap = np.zeros(npix, dtype=np.float) indices = hp.ang2pix(nside, cat_gleam[:, 0], cat_gleam[:, 1], lonlat=True) - + # fill hpmap with number of source for i in range(npix): wr = np.where(indices == i) @@ -347,33 +354,39 @@ def modified_gleam(gleam_filename="gleamegc.dat", usecols=(10, 12, 77, -5), fill zero_fill_ind = np.random.choice(non_zero_ind, size=len(zero_ind)) numhpxmap_fill = copy.deepcopy(numhpxmap) - numhpxmap_fill[zero_ind] = numhpxmap[zero_fill_ind] - + numhpxmap_fill[zero_ind] = numhpxmap[zero_fill_ind] + ra_zero, dec_zero = hp.pix2ang(nside, zero_ind, lonlat=True) - + cat_random = [] for i in range(len(ra_zero)): wr = np.where(indices == zero_fill_ind[i]) for j in wr[0]: - cat_random.append((ra_zero[i], dec_zero[i], cat_gleam[j, 2], cat_gleam[j, 3])) + cat_random.append( + (ra_zero[i], dec_zero[i], cat_gleam[j, 2], cat_gleam[j, 3]) + ) cat_random = np.array(cat_random) cat_gleam = np.vstack((cat_gleam, cat_random)) - - # add peeled sources + + # add peeled sources if add_peeled_sources: - gleam_peeled = np.array([[201.3667, -43.0192, 1937.472, -0.50], # Centaurus A - [139.5250, -12.0956, 544.686, -0.96], # Hydra A - [79.9583, -45.7789, 774.612, -0.99], # Pictor A - [252.7833, 4.9925, 791.486, -1.07], # Hercules A - [187.7042, 12.3911, 1562.747, -0.86], # Virgo A - [83.6333, 22.0144, 1560.743, -0.22], # Crab - [299.8667, 40.7339, 13599.676, -0.78], # Cygnus A - [350.8667, 58.8117, 15811.361, -0.41], # Cassiopeia A - [50.6708, -37.2083, 1256.016, -0.81]]) # Fornax A + gleam_peeled = np.array( + [ + [201.3667, -43.0192, 1937.472, -0.50], # Centaurus A + [139.5250, -12.0956, 544.686, -0.96], # Hydra A + [79.9583, -45.7789, 774.612, -0.99], # Pictor A + [252.7833, 4.9925, 791.486, -1.07], # Hercules A + [187.7042, 12.3911, 1562.747, -0.86], # Virgo A + [83.6333, 22.0144, 1560.743, -0.22], # Crab + [299.8667, 40.7339, 13599.676, -0.78], # Cygnus A + [350.8667, 58.8117, 15811.361, -0.41], # Cassiopeia A + [50.6708, -37.2083, 1256.016, -0.81], + ] + ) # Fornax A cat_gleam = np.vstack((gleam_peeled, cat_gleam)) - + # save in a file - if modified_gleam_filename != '': + if modified_gleam_filename != "": np.savetxt(modified_gleam_filename, cat_gleam) - + return cat_gleam