From 92cfc291bfa187fa95253cbdc70852e4d13746e2 Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 14:49:39 +0200 Subject: [PATCH 01/42] deprecate log_func --- skyreader/result.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index e5e0b98d..84c431bd 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -587,14 +587,9 @@ def best_dir(self): def create_plot(self, dosave=False, dozoom=False, - log_func=None, upload_func=None, final_channels=None): - if log_func is None: - def log_func(x): - print(x) - if upload_func is None: def upload_func(file_buffer, name, title): pass @@ -834,7 +829,6 @@ def area(vs): def create_plot_zoomed(self, dosave=False, - log_func=None, upload_func=None, extra_ra=np.nan, extra_dec=np.nan, @@ -845,10 +839,6 @@ def create_plot_zoomed(self, final_channels=None): """Uses healpy to plot a map.""" - if log_func is None: - def log_func(x): - print(x) - if upload_func is None: def upload_func(file_buffer, name, title): pass @@ -1096,7 +1086,7 @@ def area(vs): ra, ra_plus, np.abs(ra_minus)) + " \n" + \ "\t Dec = {0:.2f} + {1:.2f} - {2:.2f}".format( dec, dec_plus, np.abs(dec_minus)) - log_func(contain_txt) + print(contain_txt) if plot_bounding_box: bounding_ras = []; bounding_decs = [] # lower bound @@ -1161,8 +1151,9 @@ def area(vs): print(upload_func(output, savename, savename)) output.truncate(0) del output - except OSError: - log_func("Memory Error prevented contours from being written") + except OSError as err: + print("OS Error prevented contours from being written, maybe a memory issue.") + print(err) uncertainty = [(ra_minus, ra_plus), (dec_minus, dec_plus)] fits_header = format_fits_header( From 01931ce901390ce5204c2a7ddfbfb2eb1091d552 Mon Sep 17 00:00:00 2001 From: wipacdevbot Date: Fri, 29 Sep 2023 12:50:29 +0000 Subject: [PATCH 02/42] update requirements-examples.txt --- requirements-examples.txt | 42 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/requirements-examples.txt b/requirements-examples.txt index 9c0c6128..37fe58f8 100644 --- a/requirements-examples.txt +++ b/requirements-examples.txt @@ -4,7 +4,7 @@ # # pip-compile --extra=examples --output-file=requirements-examples.txt # -astropy==5.3.1 +astropy==5.3.3 # via # healpy # icecube-skyreader (setup.py) @@ -12,31 +12,31 @@ cachetools==5.3.1 # via wipac-rest-tools certifi==2023.7.22 # via requests -cffi==1.15.1 +cffi==1.16.0 # via cryptography charset-normalizer==3.2.0 # via requests -contourpy==1.1.0 +contourpy==1.1.1 # via matplotlib -cryptography==41.0.3 +cryptography==41.0.4 # via pyjwt -cycler==0.11.0 +cycler==0.12.0 # via matplotlib -fonttools==4.42.0 +fonttools==4.43.0 # via matplotlib -healpy==1.16.3 +healpy==1.16.5 # via icecube-skyreader (setup.py) idna==3.4 # via requests -kiwisolver==1.4.4 +kiwisolver==1.4.5 # via matplotlib -matplotlib==3.7.2 +matplotlib==3.8.0 # via # healpy # icecube-skyreader (setup.py) meander==0.0.3 # via icecube-skyreader (setup.py) -numpy==1.25.2 +numpy==1.26.0 # via # astropy # contourpy @@ -50,9 +50,9 @@ packaging==23.1 # via # astropy # matplotlib -pandas==2.0.3 +pandas==2.1.1 # via icecube-skyreader (setup.py) -pillow==10.0.0 +pillow==10.0.1 # via matplotlib pycparser==2.21 # via cffi @@ -60,7 +60,7 @@ pyerfa==2.0.0.3 # via astropy pyjwt[crypto]==2.8.0 # via wipac-rest-tools -pyparsing==3.0.9 +pyparsing==3.1.1 # via matplotlib pypng==0.20220715.0 # via qrcode @@ -68,7 +68,7 @@ python-dateutil==2.8.2 # via # matplotlib # pandas -pytz==2023.3 +pytz==2023.3.post1 # via pandas pyyaml==6.0.1 # via astropy @@ -81,23 +81,25 @@ requests==2.31.0 # wipac-rest-tools requests-futures==1.0.1 # via wipac-rest-tools -scipy==1.11.1 +scipy==1.11.3 # via healpy six==1.16.0 # via python-dateutil -tornado==6.3.2 +tornado==6.3.3 # via wipac-rest-tools -typing-extensions==4.7.1 +typing-extensions==4.8.0 # via # qrcode # wipac-dev-tools tzdata==2023.3 # via pandas -urllib3==2.0.4 - # via requests +urllib3==2.0.5 + # via + # requests + # wipac-rest-tools wipac-dev-tools==1.6.16 # via # icecube-skyreader (setup.py) # wipac-rest-tools -wipac-rest-tools==1.5.1 +wipac-rest-tools==1.5.3 # via icecube-skyreader (setup.py) From bfdf70eabf31234f8a6bb75026fa489af771069e Mon Sep 17 00:00:00 2001 From: wipacdevbot Date: Fri, 29 Sep 2023 12:50:29 +0000 Subject: [PATCH 03/42] update requirements-tests.txt --- requirements-tests.txt | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 374604aa..642d51c5 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -4,7 +4,7 @@ # # pip-compile --extra=tests --output-file=requirements-tests.txt # -astropy==5.3.1 +astropy==5.3.3 # via # healpy # icecube-skyreader (setup.py) @@ -12,29 +12,29 @@ certifi==2023.7.22 # via requests charset-normalizer==3.2.0 # via requests -contourpy==1.1.0 +contourpy==1.1.1 # via matplotlib -cycler==0.11.0 +cycler==0.12.0 # via matplotlib -exceptiongroup==1.1.2 +exceptiongroup==1.1.3 # via pytest -fonttools==4.42.0 +fonttools==4.43.0 # via matplotlib -healpy==1.16.3 +healpy==1.16.5 # via icecube-skyreader (setup.py) idna==3.4 # via requests iniconfig==2.0.0 # via pytest -kiwisolver==1.4.4 +kiwisolver==1.4.5 # via matplotlib -matplotlib==3.7.2 +matplotlib==3.8.0 # via # healpy # icecube-skyreader (setup.py) meander==0.0.3 # via icecube-skyreader (setup.py) -numpy==1.25.2 +numpy==1.26.0 # via # astropy # contourpy @@ -49,17 +49,17 @@ packaging==23.1 # astropy # matplotlib # pytest -pandas==2.0.3 +pandas==2.1.1 # via icecube-skyreader (setup.py) -pillow==10.0.0 +pillow==10.0.1 # via matplotlib -pluggy==1.2.0 +pluggy==1.3.0 # via pytest pyerfa==2.0.0.3 # via astropy -pyparsing==3.0.9 +pyparsing==3.1.1 # via matplotlib -pytest==7.4.0 +pytest==7.4.2 # via # icecube-skyreader (setup.py) # pytest-mock @@ -69,23 +69,23 @@ python-dateutil==2.8.2 # via # matplotlib # pandas -pytz==2023.3 +pytz==2023.3.post1 # via pandas pyyaml==6.0.1 # via astropy requests==2.31.0 # via wipac-dev-tools -scipy==1.11.1 +scipy==1.11.3 # via healpy six==1.16.0 # via python-dateutil tomli==2.0.1 # via pytest -typing-extensions==4.7.1 +typing-extensions==4.8.0 # via wipac-dev-tools tzdata==2023.3 # via pandas -urllib3==2.0.4 +urllib3==2.0.5 # via requests wipac-dev-tools==1.6.16 # via icecube-skyreader (setup.py) From 036a62093258b1171489c250bc97cff69bf689cb Mon Sep 17 00:00:00 2001 From: wipacdevbot Date: Fri, 29 Sep 2023 12:50:29 +0000 Subject: [PATCH 04/42] update requirements.txt --- requirements.txt | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1df988c4..0d94f047 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ # # pip-compile --output-file=requirements.txt # -astropy==5.3.1 +astropy==5.3.3 # via # healpy # icecube-skyreader (setup.py) @@ -12,25 +12,25 @@ certifi==2023.7.22 # via requests charset-normalizer==3.2.0 # via requests -contourpy==1.1.0 +contourpy==1.1.1 # via matplotlib -cycler==0.11.0 +cycler==0.12.0 # via matplotlib -fonttools==4.42.0 +fonttools==4.43.0 # via matplotlib -healpy==1.16.3 +healpy==1.16.5 # via icecube-skyreader (setup.py) idna==3.4 # via requests -kiwisolver==1.4.4 +kiwisolver==1.4.5 # via matplotlib -matplotlib==3.7.2 +matplotlib==3.8.0 # via # healpy # icecube-skyreader (setup.py) meander==0.0.3 # via icecube-skyreader (setup.py) -numpy==1.25.2 +numpy==1.26.0 # via # astropy # contourpy @@ -44,33 +44,33 @@ packaging==23.1 # via # astropy # matplotlib -pandas==2.0.3 +pandas==2.1.1 # via icecube-skyreader (setup.py) -pillow==10.0.0 +pillow==10.0.1 # via matplotlib pyerfa==2.0.0.3 # via astropy -pyparsing==3.0.9 +pyparsing==3.1.1 # via matplotlib python-dateutil==2.8.2 # via # matplotlib # pandas -pytz==2023.3 +pytz==2023.3.post1 # via pandas pyyaml==6.0.1 # via astropy requests==2.31.0 # via wipac-dev-tools -scipy==1.11.1 +scipy==1.11.3 # via healpy six==1.16.0 # via python-dateutil -typing-extensions==4.7.1 +typing-extensions==4.8.0 # via wipac-dev-tools tzdata==2023.3 # via pandas -urllib3==2.0.4 +urllib3==2.0.5 # via requests wipac-dev-tools==1.6.16 # via icecube-skyreader (setup.py) From 478b2af81ef28eac0d6600a57c2a5b44c574efef Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 14:50:50 +0200 Subject: [PATCH 05/42] deprecate upload-func --- skyreader/result.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index 84c431bd..88236865 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -587,13 +587,8 @@ def best_dir(self): def create_plot(self, dosave=False, dozoom=False, - upload_func=None, final_channels=None): - if upload_func is None: - def upload_func(file_buffer, name, title): - pass - if final_channels is None: final_channels=["#test_messaging"] y_inches = 3.85 @@ -829,7 +824,6 @@ def area(vs): def create_plot_zoomed(self, dosave=False, - upload_func=None, extra_ra=np.nan, extra_dec=np.nan, extra_radius=np.nan, @@ -839,10 +833,6 @@ def create_plot_zoomed(self, final_channels=None): """Uses healpy to plot a map.""" - if upload_func is None: - def upload_func(file_buffer, name, title): - pass - if final_channels is None: final_channels=["#test_messaging"] @@ -1148,7 +1138,6 @@ def area(vs): if dosave: ascii.write(tab, output, overwrite=True) output.seek(0) - print(upload_func(output, savename, savename)) output.truncate(0) del output except OSError as err: @@ -1257,7 +1246,6 @@ def circular_contour(ra, dec, sigma, nside): savename = plot_filename[:-4] + ".png" print(savename) # config.slack_channel=ch - upload_func(imgdata, savename, title) plt.close() return imgdata From 36b94d3ba77fd6e650325ca3c18b8cfd4e67288e Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 14:58:33 +0200 Subject: [PATCH 06/42] deprecate further slack posting logic --- skyreader/result.py | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index 88236865..f208c1f4 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -586,11 +586,8 @@ def best_dir(self): def create_plot(self, dosave=False, - dozoom=False, - final_channels=None): + dozoom=False): - if final_channels is None: - final_channels=["#test_messaging"] y_inches = 3.85 x_inches = 6 dpi = 150 if not dozoom else 1200 @@ -829,13 +826,9 @@ def create_plot_zoomed(self, extra_radius=np.nan, systematics=False, plot_bounding_box=False, - plot_4fgl=False, - final_channels=None): + plot_4fgl=False): """Uses healpy to plot a map.""" - if final_channels is None: - final_channels=["#test_messaging"] - def bounding_box(ra, dec, theta, phi): shift = ra-180 @@ -1130,16 +1123,16 @@ def area(vs): tab = {"ra (rad)": ras, "dec (rad)": decs} savename = unique_id + ".contour_" + val + ".txt" try: - ascii.write(tab, savename, overwrite=True) print("Dumping to", savename) - for i, ch in enumerate(final_channels): - output = io.StringIO() - #output = str.encode(savename) - if dosave: - ascii.write(tab, output, overwrite=True) - output.seek(0) - output.truncate(0) - del output + ascii.write(tab, savename, overwrite=True) + # deprecated logic for slack posting + # for i, ch in enumerate(final_channels): + # output = io.StringIO() + # if dosave: + # ascii.write(tab, output, overwrite=True) + # output.seek(0) + # output.truncate(0) + # del output except OSError as err: print("OS Error prevented contours from being written, maybe a memory issue.") print(err) @@ -1238,14 +1231,14 @@ def circular_contour(ra, dec, sigma, nside): else: title = "Millipede contour, assuming Wilks' Theorem:" - for i, ch in enumerate(final_channels): - imgdata = io.BytesIO() - fig.savefig(imgdata, format='png', dpi=600, transparent=True) - imgdata.seek(0) + # deprecated logic for slack posting + #for i, ch in enumerate(final_channels): - savename = plot_filename[:-4] + ".png" - print(savename) - # config.slack_channel=ch + imgdata = io.BytesIO() + fig.savefig(imgdata, format='png', dpi=600, transparent=True) + imgdata.seek(0) + savename = plot_filename[:-4] + ".png" + print(savename) plt.close() return imgdata From ff212e4c84ee670154d850b1301f312cf7510a88 Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 15:04:06 +0200 Subject: [PATCH 07/42] further remove deprecated logic --- skyreader/result.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index f208c1f4..56e006e3 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -817,8 +817,6 @@ def area(vs): print("done.") - return imgdata - def create_plot_zoomed(self, dosave=False, extra_ra=np.nan, @@ -1125,14 +1123,6 @@ def area(vs): try: print("Dumping to", savename) ascii.write(tab, savename, overwrite=True) - # deprecated logic for slack posting - # for i, ch in enumerate(final_channels): - # output = io.StringIO() - # if dosave: - # ascii.write(tab, output, overwrite=True) - # output.seek(0) - # output.truncate(0) - # del output except OSError as err: print("OS Error prevented contours from being written, maybe a memory issue.") print(err) @@ -1226,19 +1216,7 @@ def circular_contour(ra, dec, sigma, nside): print("done.") - if systematics is True: - title = "Millipede contour, assuming IC160427A systematics:" - else: - title = "Millipede contour, assuming Wilks' Theorem:" - - # deprecated logic for slack posting - #for i, ch in enumerate(final_channels): - - imgdata = io.BytesIO() - fig.savefig(imgdata, format='png', dpi=600, transparent=True) - imgdata.seek(0) savename = plot_filename[:-4] + ".png" print(savename) plt.close() - return imgdata From 5d23c1b8092e6d60aaa33dcd10debca37873900b Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 15:30:26 +0200 Subject: [PATCH 08/42] assume we always save plots --- skyreader/result.py | 46 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index 56e006e3..af18de8e 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -585,7 +585,6 @@ def best_dir(self): """ def create_plot(self, - dosave=False, dozoom=False): y_inches = 3.85 @@ -605,8 +604,8 @@ def create_plot(self, unique_id = f'{str(event_metadata)}_{self.get_nside_string()}' plot_title = f"Run: {event_metadata.run_id} Event {event_metadata.event_id}: Type: {event_metadata.event_type} MJD: {event_metadata.mjd}" - plot_filename = f"{unique_id}.{'plot_zoomed.' if dozoom else ''}pdf" - print(f"saving plot to {plot_filename}") + plot_filename = f"{unique_id}.{'plot_zoomed_legacy.' if dozoom else ''}pdf" + print(f"TEST BRANCH: saving plot to {plot_filename}") nsides = self.nsides print(f"available nsides: {nsides}") @@ -805,20 +804,13 @@ def area(vs): # set the title fig.suptitle(plot_title) - if dosave: - print(f"saving: {plot_filename}...") + print(f"saving: {plot_filename}...") - fig.savefig(plot_filename, dpi=dpi, transparent=True) - - # use io.BytesIO to save this into a memory buffer - imgdata = io.BytesIO() - fig.savefig(imgdata, format='png', dpi=dpi, transparent=True) - imgdata.seek(0) + fig.savefig(plot_filename, dpi=dpi, transparent=True) print("done.") def create_plot_zoomed(self, - dosave=False, extra_ra=np.nan, extra_dec=np.nan, extra_radius=np.nan, @@ -1198,21 +1190,21 @@ def circular_contour(ra, dec, sigma, nside): print("Contour Area (90%):", contour_areas[1], "degrees (cartesian)", healpy_area, "degrees (scaled)") - if dosave: - # Dump the whole contour - path = unique_id + ".contour.pkl" - print("Saving contour to", path) - with open(path, "wb") as f: - pickle.dump(saving_contours, f) - - healpy.write_map(f"{unique_id}.skymap_nside_{mmap_nside}.fits.gz", - equatorial_map, coord = 'C', column_names = ['2LLH'], - extra_header = fits_header, overwrite=True) - - # Save the figure - print("saving: {0}...".format(plot_filename)) - #ax.invert_xaxis() - fig.savefig(plot_filename, dpi=dpi, transparent=True) + + # Dump the whole contour + path = unique_id + ".contour.pkl" + print("Saving contour to", path) + with open(path, "wb") as f: + pickle.dump(saving_contours, f) + + healpy.write_map(f"{unique_id}.skymap_nside_{mmap_nside}.fits.gz", + equatorial_map, coord = 'C', column_names = ['2LLH'], + extra_header = fits_header, overwrite=True) + + # Save the figure + print("saving: {0}...".format(plot_filename)) + #ax.invert_xaxis() + fig.savefig(plot_filename, dpi=dpi, transparent=True) print("done.") From e8cee41211511d13f34534a48521a30955f40c73 Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 15:53:54 +0200 Subject: [PATCH 09/42] single source of truth for inches/dpi --- skyreader/result.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index af18de8e..a86715f5 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -584,14 +584,16 @@ def best_dir(self): Plotting routines """ - def create_plot(self, - dozoom=False): + plot_y_size_in = 3.85 + plot_x_size_in = 6 + plot_dpi_standard = 150 + plot_dpi_zoomed = 1200 - y_inches = 3.85 - x_inches = 6 - dpi = 150 if not dozoom else 1200 - xsize = x_inches*dpi - ysize = xsize//2 + def create_plot(self, dozoom: bool = False) -> None: + + dpi = self.plot_dpi_standard if not dozoom else self.plot_dpi_zoomed + xsize = self.plot_x_size_in * dpi + ysize = xsize // 2 lonra=[-10.,10.] latra=[-10.,10.] @@ -605,7 +607,7 @@ def create_plot(self, plot_title = f"Run: {event_metadata.run_id} Event {event_metadata.event_id}: Type: {event_metadata.event_type} MJD: {event_metadata.mjd}" plot_filename = f"{unique_id}.{'plot_zoomed_legacy.' if dozoom else ''}pdf" - print(f"TEST BRANCH: saving plot to {plot_filename}") + print(f"saving plot to {plot_filename}") nsides = self.nsides print(f"available nsides: {nsides}") @@ -690,7 +692,7 @@ def create_plot(self, cmap.set_bad(alpha=1., color=(1.,0.,0.)) # make NaNs bright red # prepare the figure canvas - fig = matplotlib.pyplot.figure(figsize=[x_inches,y_inches]) + fig = matplotlib.pyplot.figure(figsize=[self.plot_x_size_in,self.plot_y_size_in]) if dozoom: ax = fig.add_subplot(111) #,projection='cartesian') else: @@ -828,11 +830,7 @@ def bounding_box(ra, dec, theta, phi): dec_minus = (np.pi/2-np.max(theta))*180./np.pi - dec return ra_plus, ra_minus, dec_plus, dec_minus - y_inches = 3.85 - x_inches = 6. - dpi = 1200. - xsize = x_inches*dpi - ysize = xsize/2. + dpi = self.plot_dpi_zoomed lonra=[-10.,10.] latra=[-10.,10.] From 6b6840db89bacb20d61f1c5d6b29c9aa1419a727 Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 15:54:26 +0200 Subject: [PATCH 10/42] remove unused vars --- skyreader/result.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index a86715f5..d0ee0de4 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -595,9 +595,6 @@ def create_plot(self, dozoom: bool = False) -> None: xsize = self.plot_x_size_in * dpi ysize = xsize // 2 - lonra=[-10.,10.] - latra=[-10.,10.] - for k in self.result: if "nside-" not in k: raise RuntimeError("\"nside\" not in result file..") From d3f44314b61f345d9eaf4e3103724cd894a6ce1a Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 16:00:15 +0200 Subject: [PATCH 11/42] remove import io --- skyreader/result.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index d0ee0de4..aacc9a6a 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -4,8 +4,6 @@ # pylint: skip-file # flake8: noqa - -import io import itertools as it import json import logging @@ -589,15 +587,20 @@ def best_dir(self): plot_dpi_standard = 150 plot_dpi_zoomed = 1200 + def check_result(self): + """Check in legacy plotting code. + """ + for k in self.result: + if "nside-" not in k: + raise RuntimeError("\"nside\" not in result file..") + def create_plot(self, dozoom: bool = False) -> None: dpi = self.plot_dpi_standard if not dozoom else self.plot_dpi_zoomed xsize = self.plot_x_size_in * dpi ysize = xsize // 2 - for k in self.result: - if "nside-" not in k: - raise RuntimeError("\"nside\" not in result file..") + self.check_result() event_metadata = self.get_event_metadata() unique_id = f'{str(event_metadata)}_{self.get_nside_string()}' @@ -832,9 +835,7 @@ def bounding_box(ra, dec, theta, phi): lonra=[-10.,10.] latra=[-10.,10.] - for k in self.result: - if "nside-" not in k: - raise RuntimeError("\"nside\" not in result file..") + self.check_result() event_metadata = self.get_event_metadata() unique_id = f'{str(event_metadata)}_{self.get_nside_string()}' From 1ee865ad73af4a9d821385c06c331dc74e7e2f36 Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 16:02:58 +0200 Subject: [PATCH 12/42] update example --- examples/plot_skydriver_scan_result.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/plot_skydriver_scan_result.py b/examples/plot_skydriver_scan_result.py index fd359d40..dc92a353 100644 --- a/examples/plot_skydriver_scan_result.py +++ b/examples/plot_skydriver_scan_result.py @@ -39,8 +39,8 @@ def main() -> None: serialzed = rc.request_seq("GET", f"/scan/{args.scan_id}/result")["skyscan_result"] result = SkyScanResult.deserialize(serialzed) - result.create_plot(dosave=True) - result.create_plot_zoomed(dosave=True, plot_bounding_box=True) + result.create_plot() + result.create_plot_zoomed(plot_bounding_box=True) if __name__ == "__main__": From cda98603d612136037b98cb7847118c71afbd28d Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 16:07:43 +0200 Subject: [PATCH 13/42] de-type plotting function --- skyreader/result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index aacc9a6a..3ff8a22f 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -594,7 +594,7 @@ def check_result(self): if "nside-" not in k: raise RuntimeError("\"nside\" not in result file..") - def create_plot(self, dozoom: bool = False) -> None: + def create_plot(self, dozoom: bool = False): dpi = self.plot_dpi_standard if not dozoom else self.plot_dpi_zoomed xsize = self.plot_x_size_in * dpi From 3d6747f06121520d5130fff96d3a3ca73427247c Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 16:16:41 +0200 Subject: [PATCH 14/42] some notes from mypy --- skyreader/result.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index 3ff8a22f..aa18a436 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -612,7 +612,6 @@ def create_plot(self, dozoom: bool = False): nsides = self.nsides print(f"available nsides: {nsides}") - maps = [] min_value = np.nan max_value = np.nan minRA=0. @@ -687,12 +686,12 @@ def create_plot(self, dozoom: bool = False): print(f"preparing plot: {plot_filename}...") # the color map to use - cmap = matplotlib.cm.plasma_r + cmap = matplotlib.cm.plasma_r # mypy warning cmap.set_under(alpha=0.) # make underflows transparent cmap.set_bad(alpha=1., color=(1.,0.,0.)) # make NaNs bright red # prepare the figure canvas - fig = matplotlib.pyplot.figure(figsize=[self.plot_x_size_in,self.plot_y_size_in]) + fig = matplotlib.pyplot.figure(figsize=(self.plot_x_size_in,self.plot_y_size_in)) if dozoom: ax = fig.add_subplot(111) #,projection='cartesian') else: @@ -730,8 +729,8 @@ def area(vs): if not dozoom: # graticule - ax.set_longitude_grid(30) - ax.set_latitude_grid(30) + ax.set_longitude_grid(30) # mypy warning + ax.set_latitude_grid(30) # mypy warning cb = fig.colorbar(image, orientation='horizontal', shrink=.6, pad=0.05, ticks=[min_value, max_value]) cb.ax.xaxis.set_label_text(r"$-2 \ln(L)$") else: @@ -756,6 +755,7 @@ def area(vs): x_width = 1.6 * np.sqrt(a) if np.isnan(x_width): + # mypy warning x_width = 1.6*(max(CS.allsegs[i][0][:,0]) - min(CS.allsegs[i][0][:,0])) print(x_width) y_width = 0.5 * x_width @@ -765,8 +765,9 @@ def area(vs): lower_y = max(minDec -y_width*np.pi/180., -np.pi/2.) upper_y = min(minDec + y_width*np.pi/180., np.pi/2.) - ax.set_xlim( [lower_x, upper_x][::-1]) - ax.set_ylim( [lower_y, upper_y]) + # should this just be set_xlim(upper_x, lower_x) ? + ax.set_xlim( [lower_x, upper_x][::-1]) # mypy warning + ax.set_ylim(lower_y, upper_y) ax.xaxis.set_major_formatter(DecFormatter()) ax.yaxis.set_major_formatter(DecFormatter()) @@ -781,7 +782,7 @@ def area(vs): # cb.ax.xaxis.labelpad = -8 # workaround for issue with viewers, see colorbar docstring - cb.solids.set_edgecolor("face") + cb.solids.set_edgecolor("face") # mypy warning if dozoom: ax.set_aspect('equal') @@ -793,8 +794,9 @@ def area(vs): # Otherwise, add the path effects. effects = [patheffects.withStroke(linewidth=1.1, foreground='w')] + # mypy warnings for artist in ax.findobj(text.Text): - artist.set_path_effects(effects) + artist.set_path_effects(effects) # mypy warning # remove white space around figure spacing = 0.01 @@ -916,7 +918,7 @@ def bounding_box(ra, dec, theta, phi): print("preparing plot: {0}...".format(plot_filename)) - cmap = matplotlib.cm.plasma_r + cmap = matplotlib.cm.plasma_r # mypy warning cmap.set_under('w') cmap.set_bad(alpha=1., color=(1.,0.,0.)) # make NaNs bright red From b0730dca3af35397187048f965ce24e4d09c4a3f Mon Sep 17 00:00:00 2001 From: Massimiliano Lincetto Date: Fri, 29 Sep 2023 16:27:13 +0200 Subject: [PATCH 15/42] mypy readiness step --- skyreader/result.py | 49 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index aa18a436..fe4f8c50 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -594,7 +594,7 @@ def check_result(self): if "nside-" not in k: raise RuntimeError("\"nside\" not in result file..") - def create_plot(self, dozoom: bool = False): + def create_plot(self, dozoom = False): dpi = self.plot_dpi_standard if not dozoom else self.plot_dpi_zoomed xsize = self.plot_x_size_in * dpi @@ -883,14 +883,14 @@ def bounding_box(ra, dec, theta, phi): grid_map[(tmp_dec, tmp_ra)] = value print("done with map for nside {0}...".format(nside)) - grid_dec = []; grid_ra = []; grid_value = [] + grid_dec_list, grid_ra_list, grid_value_list = [], [], [] for (dec, ra), value in grid_map.items(): - grid_dec.append(dec); grid_ra.append(ra) - grid_value.append(value) - grid_dec = np.asarray(grid_dec) - grid_ra = np.asarray(grid_ra) - grid_value = np.asarray(grid_value) + grid_dec_list.append(dec); grid_ra_list.append(ra) + grid_value_list.append(value) + grid_dec: np.ndarray = np.asarray(grid_dec) + grid_ra: np.ndarray = np.asarray(grid_ra) + grid_value: np.ndarray = np.asarray(grid_value) sorting_indices = np.argsort(grid_value) grid_value = grid_value[sorting_indices] @@ -1006,10 +1006,10 @@ def area(vs): _[:,1] %= 2*np.pi contour_area += area(_) contour_area = abs(contour_area) - contour_area *= (180.*180.)/(np.pi*np.pi) # convert to square-degrees - contour_areas.append(contour_area) + contour_area_sqdeg = contour_area * (180.*180.)/(np.pi*np.pi) # convert to square-degrees + contour_areas.append(contour_area_sqdeg) contour_label = contour_label + ' - area: {0:.2f} sqdeg'.format( - contour_area) + contour_area_sqdeg) first = True for contour in contours: theta, phi = contour.T @@ -1059,28 +1059,29 @@ def area(vs): dec, dec_plus, np.abs(dec_minus)) print(contain_txt) if plot_bounding_box: - bounding_ras = []; bounding_decs = [] + bounding_ras_list, bounding_decs_list = [], [] # lower bound - bounding_ras.extend(list(np.linspace(ra+ra_minus, + bounding_ras_list.extend(list(np.linspace(ra+ra_minus, ra+ra_plus, 10))) - bounding_decs.extend([dec+dec_minus]*10) + bounding_decs_list.extend([dec+dec_minus]*10) # right bound - bounding_ras.extend([ra+ra_plus]*10) - bounding_decs.extend(list(np.linspace(dec+dec_minus, + bounding_ras_list.extend([ra+ra_plus]*10) + bounding_decs_list.extend(list(np.linspace(dec+dec_minus, dec+dec_plus, 10))) # upper bound - bounding_ras.extend(list(np.linspace(ra+ra_plus, + bounding_ras_list.extend(list(np.linspace(ra+ra_plus, ra+ra_minus, 10))) - bounding_decs.extend([dec+dec_plus]*10) + bounding_decs_list.extend([dec+dec_plus]*10) # left bound - bounding_ras.extend([ra+ra_minus]*10) - bounding_decs.extend(list(np.linspace(dec+dec_plus, + bounding_ras_list.extend([ra+ra_minus]*10) + bounding_decs_list.extend(list(np.linspace(dec+dec_plus, dec+dec_minus,10))) # join end to beginning - bounding_ras.append(bounding_ras[0]) - bounding_decs.append(bounding_decs[0]) - bounding_ras = np.asarray(bounding_ras) - bounding_decs = np.asarray(bounding_decs) + bounding_ras_list.append(bounding_ras_list[0]) + bounding_decs_list.append(bounding_decs_list[0]) + + bounding_ras: np.ndarray = np.asarray(bounding_ras_list) + bounding_decs: np.ndarray = np.asarray(bounding_decs_list) bounding_phi = np.radians(bounding_ras) bounding_theta = np.pi/2 - np.radians(bounding_decs) bounding_contour = np.array([bounding_theta, bounding_phi]) @@ -1093,7 +1094,7 @@ def area(vs): c='r', linestyle='dashed', label=contour_label) # Output contours in RA, dec instead of theta, phi - saving_contours = [] + saving_contours: list = [] for contours in contours_by_level: saving_contours.append([]) for contour in contours: From 929b1854fd47207f88c10666fd27df2f919862ca Mon Sep 17 00:00:00 2001 From: wipacdevbot Date: Mon, 9 Oct 2023 09:04:25 +0000 Subject: [PATCH 16/42] update setup.cfg --- setup.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index ecaed838..83ca8da6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,6 +29,7 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 download_url = https://pypi.org/project/icecube-skyreader/ project_urls = Tracker = https://github.com/icecube/skyreader/issues @@ -53,7 +54,7 @@ install_requires = numpy pandas wipac-dev-tools -python_requires = >=3.8, <3.12 +python_requires = >=3.8, <3.13 packages = find: [options.extras_require] From dabfff5701ef19144e6ce1561276afc63f91127a Mon Sep 17 00:00:00 2001 From: wipacdevbot Date: Mon, 9 Oct 2023 09:04:53 +0000 Subject: [PATCH 17/42] update requirements-examples.txt --- requirements-examples.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/requirements-examples.txt b/requirements-examples.txt index 37fe58f8..77521e09 100644 --- a/requirements-examples.txt +++ b/requirements-examples.txt @@ -4,7 +4,7 @@ # # pip-compile --extra=examples --output-file=requirements-examples.txt # -astropy==5.3.3 +astropy==5.3.4 # via # healpy # icecube-skyreader (setup.py) @@ -14,17 +14,17 @@ certifi==2023.7.22 # via requests cffi==1.16.0 # via cryptography -charset-normalizer==3.2.0 +charset-normalizer==3.3.0 # via requests contourpy==1.1.1 # via matplotlib cryptography==41.0.4 # via pyjwt -cycler==0.12.0 +cycler==0.12.1 # via matplotlib -fonttools==4.43.0 +fonttools==4.43.1 # via matplotlib -healpy==1.16.5 +healpy==1.16.6 # via icecube-skyreader (setup.py) idna==3.4 # via requests @@ -46,7 +46,7 @@ numpy==1.26.0 # pandas # pyerfa # scipy -packaging==23.1 +packaging==23.2 # via # astropy # matplotlib @@ -93,11 +93,11 @@ typing-extensions==4.8.0 # wipac-dev-tools tzdata==2023.3 # via pandas -urllib3==2.0.5 +urllib3==2.0.6 # via # requests # wipac-rest-tools -wipac-dev-tools==1.6.16 +wipac-dev-tools==1.7.0 # via # icecube-skyreader (setup.py) # wipac-rest-tools From d80577d9c816072c525279bcb82034642068bfea Mon Sep 17 00:00:00 2001 From: wipacdevbot Date: Mon, 9 Oct 2023 09:04:53 +0000 Subject: [PATCH 18/42] update requirements-tests.txt --- requirements-tests.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 642d51c5..0c0e244f 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -4,23 +4,23 @@ # # pip-compile --extra=tests --output-file=requirements-tests.txt # -astropy==5.3.3 +astropy==5.3.4 # via # healpy # icecube-skyreader (setup.py) certifi==2023.7.22 # via requests -charset-normalizer==3.2.0 +charset-normalizer==3.3.0 # via requests contourpy==1.1.1 # via matplotlib -cycler==0.12.0 +cycler==0.12.1 # via matplotlib exceptiongroup==1.1.3 # via pytest -fonttools==4.43.0 +fonttools==4.43.1 # via matplotlib -healpy==1.16.5 +healpy==1.16.6 # via icecube-skyreader (setup.py) idna==3.4 # via requests @@ -44,7 +44,7 @@ numpy==1.26.0 # pandas # pyerfa # scipy -packaging==23.1 +packaging==23.2 # via # astropy # matplotlib @@ -85,7 +85,7 @@ typing-extensions==4.8.0 # via wipac-dev-tools tzdata==2023.3 # via pandas -urllib3==2.0.5 +urllib3==2.0.6 # via requests -wipac-dev-tools==1.6.16 +wipac-dev-tools==1.7.0 # via icecube-skyreader (setup.py) From 004881f69d43fe0cee3795e34902425a7c54fb82 Mon Sep 17 00:00:00 2001 From: wipacdevbot Date: Mon, 9 Oct 2023 09:04:53 +0000 Subject: [PATCH 19/42] update requirements.txt --- requirements.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0d94f047..90a0beb6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,21 +4,21 @@ # # pip-compile --output-file=requirements.txt # -astropy==5.3.3 +astropy==5.3.4 # via # healpy # icecube-skyreader (setup.py) certifi==2023.7.22 # via requests -charset-normalizer==3.2.0 +charset-normalizer==3.3.0 # via requests contourpy==1.1.1 # via matplotlib -cycler==0.12.0 +cycler==0.12.1 # via matplotlib -fonttools==4.43.0 +fonttools==4.43.1 # via matplotlib -healpy==1.16.5 +healpy==1.16.6 # via icecube-skyreader (setup.py) idna==3.4 # via requests @@ -40,7 +40,7 @@ numpy==1.26.0 # pandas # pyerfa # scipy -packaging==23.1 +packaging==23.2 # via # astropy # matplotlib @@ -70,7 +70,7 @@ typing-extensions==4.8.0 # via wipac-dev-tools tzdata==2023.3 # via pandas -urllib3==2.0.5 +urllib3==2.0.6 # via requests -wipac-dev-tools==1.6.16 +wipac-dev-tools==1.7.0 # via icecube-skyreader (setup.py) From a773efef8119682b21f736a1f3c4fd64e799e30e Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 11:47:56 +0200 Subject: [PATCH 20/42] Testing conection branch skymist --- skyreader/result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index fe4f8c50..e13d4e42 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -849,7 +849,7 @@ def bounding_box(ra, dec, theta, phi): if systematics is not True: plot_filename = unique_id + ".plot_zoomed_wilks.pdf" else: - plot_filename = unique_id + ".plot_zoomed.pdf" + plot_filename = unique_id + ".plot_zoomed_gentlerude.pdf" print("saving plot to {0}".format(plot_filename)) nsides = self.nsides From 612494d2222d1b6ee93196bae3e61e4a7cfd6843 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 13:36:50 +0200 Subject: [PATCH 21/42] Fixed minor bug in result.py, function make_plot_zoomed() --- skyreader/result.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index e13d4e42..ff5e63f1 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -888,9 +888,9 @@ def bounding_box(ra, dec, theta, phi): for (dec, ra), value in grid_map.items(): grid_dec_list.append(dec); grid_ra_list.append(ra) grid_value_list.append(value) - grid_dec: np.ndarray = np.asarray(grid_dec) - grid_ra: np.ndarray = np.asarray(grid_ra) - grid_value: np.ndarray = np.asarray(grid_value) + np.ndarray = np.asarray(grid_dec) + np.ndarray = np.asarray(grid_ra) + np.ndarray = np.asarray(grid_value) sorting_indices = np.argsort(grid_value) grid_value = grid_value[sorting_indices] From 4117ce88bc4e940e404a53f3cfdf489c8e75e7fc Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 13:42:54 +0200 Subject: [PATCH 22/42] Fixed minor bug in result.py, function make_plot_zoomed(), part 2 --- skyreader/result.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index ff5e63f1..a93719c1 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -888,9 +888,9 @@ def bounding_box(ra, dec, theta, phi): for (dec, ra), value in grid_map.items(): grid_dec_list.append(dec); grid_ra_list.append(ra) grid_value_list.append(value) - np.ndarray = np.asarray(grid_dec) - np.ndarray = np.asarray(grid_ra) - np.ndarray = np.asarray(grid_value) + grid_dec: np.ndarray = np.asarray(grid_dec_list) + grid_ra: np.ndarray = np.asarray(grid_ra_list) + grid_value: np.ndarray = np.asarray(grid_value_list) sorting_indices = np.argsort(grid_value) grid_value = grid_value[sorting_indices] From 438a1d7a2c290c1985d0dac3c783de6932ebb9d1 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 13:53:35 +0200 Subject: [PATCH 23/42] Testing conection branch skymist Part 2 --- skyreader/result.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index a93719c1..a701e188 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -847,9 +847,9 @@ def bounding_box(ra, dec, theta, phi): print(f"available nsides: {nsides}") if systematics is not True: - plot_filename = unique_id + ".plot_zoomed_wilks.pdf" + plot_filename = unique_id + ".plot_zoomed_wilks_gentlerude.pdf" else: - plot_filename = unique_id + ".plot_zoomed_gentlerude.pdf" + plot_filename = unique_id + ".plot_zoomed.pdf" print("saving plot to {0}".format(plot_filename)) nsides = self.nsides From 2761d60c72f6b4a7fe1ed639675d2fd60a8c5e6d Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 16:01:53 +0200 Subject: [PATCH 24/42] New boolean value to identify rude events --- skyreader/result.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index a701e188..b9ca7e23 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -820,7 +820,8 @@ def create_plot_zoomed(self, extra_radius=np.nan, systematics=False, plot_bounding_box=False, - plot_4fgl=False): + plot_4fgl=False, + is_rude=False): """Uses healpy to plot a map.""" def bounding_box(ra, dec, theta, phi): From d4604491756a4868972a534fe43aae295d282798 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 16:49:01 +0200 Subject: [PATCH 25/42] Exploring new contours for rude events Part 1 --- skyreader/result.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index b9ca7e23..7537e3c9 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -937,9 +937,13 @@ def bounding_box(ra, dec, theta, phi): sample_points = np.array([np.pi/2 - grid_dec, grid_ra]).T # Call meander module to find contours - contours_by_level = meander.spherical_contours(sample_points, - grid_value, contour_levels - ) + if not is_rude: + contours_by_level = meander.spherical_contours(sample_points, + grid_value, contour_levels + ) + print(contours_by_level) + if is_rude: + print('Work in progress') # Check for RA values that are out of bounds for level in contours_by_level: for contour in level: From 35ccbcff940032366adc6d495ed05a7a983e1fff Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 17:05:09 +0200 Subject: [PATCH 26/42] Exploring new contours for rude events Part 2 --- skyreader/result.py | 64 ++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index 7537e3c9..cecd28e0 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -936,14 +936,49 @@ def bounding_box(ra, dec, theta, phi): contour_colors=['k', 'r', 'g', 'b'][:3] sample_points = np.array([np.pi/2 - grid_dec, grid_ra]).T + + def circular_contour(ra, dec, sigma, nside): + """For plotting circular contours on skymaps ra, dec, sigma all + expected in radians.""" + dec = np.pi/2. - dec + sigma = np.rad2deg(sigma) + delta, step, bins = 0, 0, 0 + delta= sigma/180.0*np.pi + step = 1./np.sin(delta)/10. + bins = int(360./step) + Theta = np.zeros(bins+1, dtype=np.double) + Phi = np.zeros(bins+1, dtype=np.double) + # define the contour + for j in range(0,bins) : + phi = j*step/180.*np.pi + vx = np.cos(phi)*np.sin(ra)*np.sin(delta) + np.cos(ra)*(np.cos(delta)*np.sin(dec) + np.cos(dec)*np.sin(delta)*np.sin(phi)) + vy = np.cos(delta)*np.sin(dec)*np.sin(ra) + np.sin(delta)*(-np.cos(ra)*np.cos(phi) + np.cos(dec)*np.sin(ra)*np.sin(phi)) + vz = np.cos(dec)*np.cos(delta) - np.sin(dec)*np.sin(delta)*np.sin(phi) + idx = healpy.vec2pix(nside, vx, vy, vz) + DEC, RA = healpy.pix2ang(nside, idx) + Theta[j] = DEC + Phi[j] = RA + Theta[bins] = Theta[0] + Phi[bins] = Phi[0] + return Theta, Phi + # Call meander module to find contours if not is_rude: contours_by_level = meander.spherical_contours(sample_points, grid_value, contour_levels ) - print(contours_by_level) if is_rude: - print('Work in progress') + sigma50 = np.deg2rad(0.2) + sigma90 = np.deg2rad(0.7) + Theta50, Phi50 = circular_contour(minRA, minDec, sigma50, nside) + Theta90, Phi90 = circular_contour(minRA, minDec, sigma90, nside) + contour50 = np.array([]) + for i in range(len(Theta50)): + contour50 = np.append(contour50, [Theta50[i], Phi50[i]]) + contour90 = np.array([]) + for i in range(len(Theta90)): + contour90 = np.append(contour90, [Theta90[i], Phi90[i]]) + contours_by_level = [contour50, contour90] # Check for RA values that are out of bounds for level in contours_by_level: for contour in level: @@ -1136,31 +1171,6 @@ def area(vs): # Plot the original online reconstruction location if np.sum(np.isnan([extra_ra, extra_dec, extra_radius])) == 0: - def circular_contour(ra, dec, sigma, nside): - """For plotting circular contours on skymaps ra, dec, sigma all - expected in radians.""" - dec = np.pi/2. - dec - sigma = np.rad2deg(sigma) - delta, step, bins = 0, 0, 0 - delta= sigma/180.0*np.pi - step = 1./np.sin(delta)/10. - bins = int(360./step) - Theta = np.zeros(bins+1, dtype=np.double) - Phi = np.zeros(bins+1, dtype=np.double) - # define the contour - for j in range(0,bins) : - phi = j*step/180.*np.pi - vx = np.cos(phi)*np.sin(ra)*np.sin(delta) + np.cos(ra)*(np.cos(delta)*np.sin(dec) + np.cos(dec)*np.sin(delta)*np.sin(phi)) - vy = np.cos(delta)*np.sin(dec)*np.sin(ra) + np.sin(delta)*(-np.cos(ra)*np.cos(phi) + np.cos(dec)*np.sin(ra)*np.sin(phi)) - vz = np.cos(dec)*np.cos(delta) - np.sin(dec)*np.sin(delta)*np.sin(phi) - idx = healpy.vec2pix(nside, vx, vy, vz) - DEC, RA = healpy.pix2ang(nside, idx) - Theta[j] = DEC - Phi[j] = RA - Theta[bins] = Theta[0] - Phi[bins] = Phi[0] - return Theta, Phi - # dist = angular_distance(minRA, minDec, extra_ra * np.pi/180., extra_dec * np.pi/180.) # print("Millipede best fit is", dist /(np.pi * extra_radius/(1.177 * 180.)), "sigma from reported best fit") From 91425680406e99e4170513f995ee04ab77b8e88e Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 17:09:00 +0200 Subject: [PATCH 27/42] Exploring new contours for rude events Part 3 --- skyreader/result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index cecd28e0..e45eefac 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -978,7 +978,7 @@ def circular_contour(ra, dec, sigma, nside): contour90 = np.array([]) for i in range(len(Theta90)): contour90 = np.append(contour90, [Theta90[i], Phi90[i]]) - contours_by_level = [contour50, contour90] + contours_by_level = [[contour50], [contour90]] # Check for RA values that are out of bounds for level in contours_by_level: for contour in level: From f26a5f300a6892ba0f2727a1d2e75933855501c4 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 17:13:33 +0200 Subject: [PATCH 28/42] Exploring new contours for rude events Part 4 --- skyreader/result.py | 1 + 1 file changed, 1 insertion(+) diff --git a/skyreader/result.py b/skyreader/result.py index e45eefac..f9ece7be 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -979,6 +979,7 @@ def circular_contour(ra, dec, sigma, nside): for i in range(len(Theta90)): contour90 = np.append(contour90, [Theta90[i], Phi90[i]]) contours_by_level = [[contour50], [contour90]] + print(contours_by_level) # Check for RA values that are out of bounds for level in contours_by_level: for contour in level: From d93f2540a649564dd14722e3fee1b0d4ce3de9a8 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 17:18:44 +0200 Subject: [PATCH 29/42] Exploring new contours for rude events Part 5 --- skyreader/result.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index f9ece7be..f81f5a96 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -972,12 +972,14 @@ def circular_contour(ra, dec, sigma, nside): sigma90 = np.deg2rad(0.7) Theta50, Phi50 = circular_contour(minRA, minDec, sigma50, nside) Theta90, Phi90 = circular_contour(minRA, minDec, sigma90, nside) - contour50 = np.array([]) + contour50 = list() for i in range(len(Theta50)): - contour50 = np.append(contour50, [Theta50[i], Phi50[i]]) - contour90 = np.array([]) + contour50.append([Theta50[i], Phi50[i]]) + contour50 = np.asarray(contour50) + contour90 = list() for i in range(len(Theta90)): - contour90 = np.append(contour90, [Theta90[i], Phi90[i]]) + contour90.append([Theta90[i], Phi90[i]]) + contour90 = np.asarray(contour90) contours_by_level = [[contour50], [contour90]] print(contours_by_level) # Check for RA values that are out of bounds From 586d724f87ee85c2e75428d8a5f6f12ca27814b2 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 17:25:41 +0200 Subject: [PATCH 30/42] Exploring new contours for rude events Part 5 --- skyreader/result.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index f81f5a96..5e012f63 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -944,7 +944,7 @@ def circular_contour(ra, dec, sigma, nside): sigma = np.rad2deg(sigma) delta, step, bins = 0, 0, 0 delta= sigma/180.0*np.pi - step = 1./np.sin(delta)/10. + step = 1./np.sin(delta)/100. bins = int(360./step) Theta = np.zeros(bins+1, dtype=np.double) Phi = np.zeros(bins+1, dtype=np.double) @@ -981,7 +981,7 @@ def circular_contour(ra, dec, sigma, nside): contour90.append([Theta90[i], Phi90[i]]) contour90 = np.asarray(contour90) contours_by_level = [[contour50], [contour90]] - print(contours_by_level) + # Check for RA values that are out of bounds for level in contours_by_level: for contour in level: From 7c4424729bf76883d61622c12fdbf87f8cba4818 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 17:29:42 +0200 Subject: [PATCH 31/42] Exploring new contours for rude events Part 6 --- skyreader/result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index 5e012f63..79642f77 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -944,7 +944,7 @@ def circular_contour(ra, dec, sigma, nside): sigma = np.rad2deg(sigma) delta, step, bins = 0, 0, 0 delta= sigma/180.0*np.pi - step = 1./np.sin(delta)/100. + step = 1./np.sin(delta) bins = int(360./step) Theta = np.zeros(bins+1, dtype=np.double) Phi = np.zeros(bins+1, dtype=np.double) From 2368ce37ce8013026413ea255afd561326d25636 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 17:33:44 +0200 Subject: [PATCH 32/42] Exploring new contours for rude events Part 7 --- skyreader/result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index 79642f77..0d28d13f 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -944,7 +944,7 @@ def circular_contour(ra, dec, sigma, nside): sigma = np.rad2deg(sigma) delta, step, bins = 0, 0, 0 delta= sigma/180.0*np.pi - step = 1./np.sin(delta) + step = 1./np.sin(delta)/1000. bins = int(360./step) Theta = np.zeros(bins+1, dtype=np.double) Phi = np.zeros(bins+1, dtype=np.double) From 1017e00b09032e57cdff3ca28370671068174eae Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Mon, 9 Oct 2023 17:40:09 +0200 Subject: [PATCH 33/42] Implemented contours for rude events --- skyreader/result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index 0d28d13f..4c5136ed 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -944,7 +944,7 @@ def circular_contour(ra, dec, sigma, nside): sigma = np.rad2deg(sigma) delta, step, bins = 0, 0, 0 delta= sigma/180.0*np.pi - step = 1./np.sin(delta)/1000. + step = 1./np.sin(delta)/10. bins = int(360./step) Theta = np.zeros(bins+1, dtype=np.double) Phi = np.zeros(bins+1, dtype=np.double) From b897ee9dd27c51eecc2e4f61457aeeb42059c156 Mon Sep 17 00:00:00 2001 From: wipacdevbot Date: Thu, 12 Oct 2023 15:16:32 +0000 Subject: [PATCH 34/42] update requirements-examples.txt --- requirements-examples.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/requirements-examples.txt b/requirements-examples.txt index 11ae4ae6..6f87dc61 100644 --- a/requirements-examples.txt +++ b/requirements-examples.txt @@ -101,9 +101,5 @@ wipac-dev-tools==1.7.0 # via # icecube-skyreader (setup.py) # wipac-rest-tools -<<<<<<< HEAD -wipac-rest-tools==1.5.3 -======= wipac-rest-tools==1.6.0 ->>>>>>> main # via icecube-skyreader (setup.py) From d4725f765f1421efd5317145cd6a200e68254d8c Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Fri, 13 Oct 2023 10:34:08 +0200 Subject: [PATCH 35/42] Solve issues for merge --- skyreader/result.py | 53 +-------------------------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index 1e65ab12..fa70a983 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -586,10 +586,7 @@ def best_dir(self): plot_x_size_in = 6 plot_dpi_standard = 150 plot_dpi_zoomed = 1200 -<<<<<<< HEAD -======= plot_colormap = matplotlib.colormaps['plasma_r'] ->>>>>>> main def check_result(self): """Check in legacy plotting code. @@ -613,14 +610,6 @@ def calculate_area(vs) -> float: y0 = y1 return a - def create_plot(self, dozoom = False): - - dpi = self.plot_dpi_standard if not dozoom else self.plot_dpi_zoomed - xsize = self.plot_x_size_in * dpi - ysize = xsize // 2 - - self.check_result() - def create_plot(self, dozoom = False): dpi = self.plot_dpi_standard if not dozoom else self.plot_dpi_zoomed @@ -713,11 +702,7 @@ def create_plot(self, dozoom = False): print(f"preparing plot: {plot_filename}...") # the color map to use -<<<<<<< HEAD - cmap = matplotlib.cm.plasma_r # mypy warning -======= cmap = self.plot_colormap ->>>>>>> main cmap.set_under(alpha=0.) # make underflows transparent cmap.set_bad(alpha=1., color=(1.,0.,0.)) # make NaNs bright red @@ -749,15 +734,10 @@ def create_plot(self, dozoom = False): if not dozoom: # graticule -<<<<<<< HEAD - ax.set_longitude_grid(30) # mypy warning - ax.set_latitude_grid(30) # mypy warning -======= # mypy error: "Axes" has no attribute "set_longitude_grid" [attr-defined] ax.set_longitude_grid(30) # mypy error: "Axes" has no attribute "set_latitude_grid" [attr-defined] ax.set_latitude_grid(30) ->>>>>>> main cb = fig.colorbar(image, orientation='horizontal', shrink=.6, pad=0.05, ticks=[min_value, max_value]) cb.ax.xaxis.set_label_text(r"$-2 \ln(L)$") else: @@ -783,11 +763,7 @@ def create_plot(self, dozoom = False): x_width = 1.6 * np.sqrt(a) if np.isnan(x_width): -<<<<<<< HEAD - # mypy warning -======= # error: "QuadContourSet" has no attribute "allsegs" [attr-defined] ->>>>>>> main x_width = 1.6*(max(CS.allsegs[i][0][:,0]) - min(CS.allsegs[i][0][:,0])) print(x_width) y_width = 0.5 * x_width @@ -797,12 +773,7 @@ def create_plot(self, dozoom = False): lower_y = max(minDec -y_width*np.pi/180., -np.pi/2.) upper_y = min(minDec + y_width*np.pi/180., np.pi/2.) -<<<<<<< HEAD - # should this just be set_xlim(upper_x, lower_x) ? - ax.set_xlim( [lower_x, upper_x][::-1]) # mypy warning -======= ax.set_xlim(upper_x, lower_x) ->>>>>>> main ax.set_ylim(lower_y, upper_y) ax.xaxis.set_major_formatter(DecFormatter()) @@ -818,14 +789,10 @@ def create_plot(self, dozoom = False): # cb.ax.xaxis.labelpad = -8 # workaround for issue with viewers, see colorbar docstring -<<<<<<< HEAD - cb.solids.set_edgecolor("face") # mypy warning -======= # mypy compliance: since cb.solids could be None, we check that it is actually # a valid object before accessing it if isinstance(cb.solids, matplotlib.collections.QuadMesh): cb.solids.set_edgecolor("face") ->>>>>>> main if dozoom: ax.set_aspect('equal') @@ -839,12 +806,8 @@ def create_plot(self, dozoom = False): effects = [patheffects.withStroke(linewidth=1.1, foreground='w')] # mypy warnings for artist in ax.findobj(text.Text): -<<<<<<< HEAD - artist.set_path_effects(effects) # mypy warning -======= # mypy error: Argument 1 to "set_path_effects" of "Artist" has incompatible type "list[withStroke]"; expected "list[AbstractPathEffect]" [arg-type] artist.set_path_effects(effects) ->>>>>>> main # remove white space around figure spacing = 0.01 @@ -868,12 +831,8 @@ def create_plot_zoomed(self, extra_radius=np.nan, systematics=False, plot_bounding_box=False, -<<<<<<< HEAD plot_4fgl=False, is_rude=False): -======= - plot_4fgl=False): ->>>>>>> main """Uses healpy to plot a map.""" def bounding_box(ra, dec, theta, phi): @@ -900,7 +859,7 @@ def bounding_box(ra, dec, theta, phi): print(f"available nsides: {nsides}") if systematics is not True: - plot_filename = unique_id + ".plot_zoomed_wilks_gentlerude.pdf" + plot_filename = unique_id + ".plot_zoomed_wilks.pdf" else: plot_filename = unique_id + ".plot_zoomed.pdf" print("saving plot to {0}".format(plot_filename)) @@ -971,11 +930,7 @@ def bounding_box(ra, dec, theta, phi): print("preparing plot: {0}...".format(plot_filename)) -<<<<<<< HEAD - cmap = matplotlib.cm.plasma_r # mypy warning -======= cmap = self.plot_colormap ->>>>>>> main cmap.set_under('w') cmap.set_bad(alpha=1., color=(1.,0.,0.)) # make NaNs bright red @@ -1090,14 +1045,8 @@ def circular_contour(ra, dec, sigma, nside): _ = contour.copy() _[:,1] += np.pi-np.radians(ra) _[:,1] %= 2*np.pi -<<<<<<< HEAD - contour_area += area(_) - contour_area = abs(contour_area) - contour_area_sqdeg = contour_area * (180.*180.)/(np.pi*np.pi) # convert to square-degrees -======= contour_area += self.calculate_area(_) contour_area_sqdeg = abs(contour_area) * (180.*180.)/(np.pi*np.pi) # convert to square-degrees ->>>>>>> main contour_areas.append(contour_area_sqdeg) contour_label = contour_label + ' - area: {0:.2f} sqdeg'.format( contour_area_sqdeg) From ce5d6a996a2398096e2bd8133bd2128ff128ff3b Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Fri, 13 Oct 2023 10:55:43 +0200 Subject: [PATCH 36/42] Moved circular_contour() to class level --- skyreader/result.py | 54 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index fa70a983..bb78e95c 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -825,6 +825,31 @@ def create_plot(self, dozoom = False): print("done.") + def circular_contour(ra, dec, sigma, nside): + """For plotting circular contours on skymaps ra, dec, sigma all + expected in radians.""" + dec = np.pi/2. - dec + sigma = np.rad2deg(sigma) + delta, step, bins = 0, 0, 0 + delta= sigma/180.0*np.pi + step = 1./np.sin(delta)/10. + bins = int(360./step) + Theta = np.zeros(bins+1, dtype=np.double) + Phi = np.zeros(bins+1, dtype=np.double) + # define the contour + for j in range(0,bins) : + phi = j*step/180.*np.pi + vx = np.cos(phi)*np.sin(ra)*np.sin(delta) + np.cos(ra)*(np.cos(delta)*np.sin(dec) + np.cos(dec)*np.sin(delta)*np.sin(phi)) + vy = np.cos(delta)*np.sin(dec)*np.sin(ra) + np.sin(delta)*(-np.cos(ra)*np.cos(phi) + np.cos(dec)*np.sin(ra)*np.sin(phi)) + vz = np.cos(dec)*np.cos(delta) - np.sin(dec)*np.sin(delta)*np.sin(phi) + idx = healpy.vec2pix(nside, vx, vy, vz) + DEC, RA = healpy.pix2ang(nside, idx) + Theta[j] = DEC + Phi[j] = RA + Theta[bins] = Theta[0] + Phi[bins] = Phi[0] + return Theta, Phi + def create_plot_zoomed(self, extra_ra=np.nan, extra_dec=np.nan, @@ -948,31 +973,6 @@ def bounding_box(ra, dec, theta, phi): sample_points = np.array([np.pi/2 - grid_dec, grid_ra]).T - def circular_contour(ra, dec, sigma, nside): - """For plotting circular contours on skymaps ra, dec, sigma all - expected in radians.""" - dec = np.pi/2. - dec - sigma = np.rad2deg(sigma) - delta, step, bins = 0, 0, 0 - delta= sigma/180.0*np.pi - step = 1./np.sin(delta)/10. - bins = int(360./step) - Theta = np.zeros(bins+1, dtype=np.double) - Phi = np.zeros(bins+1, dtype=np.double) - # define the contour - for j in range(0,bins) : - phi = j*step/180.*np.pi - vx = np.cos(phi)*np.sin(ra)*np.sin(delta) + np.cos(ra)*(np.cos(delta)*np.sin(dec) + np.cos(dec)*np.sin(delta)*np.sin(phi)) - vy = np.cos(delta)*np.sin(dec)*np.sin(ra) + np.sin(delta)*(-np.cos(ra)*np.cos(phi) + np.cos(dec)*np.sin(ra)*np.sin(phi)) - vz = np.cos(dec)*np.cos(delta) - np.sin(dec)*np.sin(delta)*np.sin(phi) - idx = healpy.vec2pix(nside, vx, vy, vz) - DEC, RA = healpy.pix2ang(nside, idx) - Theta[j] = DEC - Phi[j] = RA - Theta[bins] = Theta[0] - Phi[bins] = Phi[0] - return Theta, Phi - # Call meander module to find contours if not is_rude: contours_by_level = meander.spherical_contours(sample_points, @@ -981,8 +981,8 @@ def circular_contour(ra, dec, sigma, nside): if is_rude: sigma50 = np.deg2rad(0.2) sigma90 = np.deg2rad(0.7) - Theta50, Phi50 = circular_contour(minRA, minDec, sigma50, nside) - Theta90, Phi90 = circular_contour(minRA, minDec, sigma90, nside) + Theta50, Phi50 = self.circular_contour(minRA, minDec, sigma50, nside) + Theta90, Phi90 = self.circular_contour(minRA, minDec, sigma90, nside) contour50 = list() for i in range(len(Theta50)): contour50.append([Theta50[i], Phi50[i]]) From 2c23451c18c539726b15a2b47c87c575603ab060 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Fri, 13 Oct 2023 10:59:53 +0200 Subject: [PATCH 37/42] Missing self in circular_contour() on class level --- skyreader/result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index bb78e95c..781433e8 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -825,7 +825,7 @@ def create_plot(self, dozoom = False): print("done.") - def circular_contour(ra, dec, sigma, nside): + def circular_contour(self, ra, dec, sigma, nside): """For plotting circular contours on skymaps ra, dec, sigma all expected in radians.""" dec = np.pi/2. - dec From 3c82025c303d15aa831e6b8d22dd8bf70726c85b Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Fri, 13 Oct 2023 11:06:53 +0200 Subject: [PATCH 38/42] boolean parameter 'is_rude' changed in 'circular'. Added 50% and 90% radii as parameters. --- skyreader/result.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index 781433e8..ddb8ce45 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -857,7 +857,9 @@ def create_plot_zoomed(self, systematics=False, plot_bounding_box=False, plot_4fgl=False, - is_rude=False): + circular=False, + circular_err50=0.2, + circular_err90=0.7): """Uses healpy to plot a map.""" def bounding_box(ra, dec, theta, phi): @@ -974,13 +976,13 @@ def bounding_box(ra, dec, theta, phi): sample_points = np.array([np.pi/2 - grid_dec, grid_ra]).T # Call meander module to find contours - if not is_rude: + if not circular: contours_by_level = meander.spherical_contours(sample_points, grid_value, contour_levels ) - if is_rude: - sigma50 = np.deg2rad(0.2) - sigma90 = np.deg2rad(0.7) + if circular: + sigma50 = np.deg2rad(circular_err50) + sigma90 = np.deg2rad(circular_err90) Theta50, Phi50 = self.circular_contour(minRA, minDec, sigma50, nside) Theta90, Phi90 = self.circular_contour(minRA, minDec, sigma90, nside) contour50 = list() @@ -1185,7 +1187,7 @@ def bounding_box(ra, dec, theta, phi): lonlat=True, c='m', marker='x', s=20, label=r'Reported online (50%, 90%)') for cont_lev, cont_scale, cont_col, cont_sty in zip(['50', '90.'], [1., 2.1459/1.177], ['m', 'm'], ['-', '--']): - spline_contour = circular_contour(extra_ra_rad, extra_dec_rad, + spline_contour = self.circular_contour(extra_ra_rad, extra_dec_rad, extra_radius_rad*cont_scale, healpy.get_nside(equatorial_map)) spline_lon = spline_contour[1] spline_lat = np.pi/2. - spline_contour[0] From b78a76817383035aef97b88d4af3355dcacf6e07 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Fri, 13 Oct 2023 13:20:10 +0200 Subject: [PATCH 39/42] Improved handling of circular contours with numpy --- skyreader/result.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index ddb8ce45..0188177b 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -985,14 +985,8 @@ def bounding_box(ra, dec, theta, phi): sigma90 = np.deg2rad(circular_err90) Theta50, Phi50 = self.circular_contour(minRA, minDec, sigma50, nside) Theta90, Phi90 = self.circular_contour(minRA, minDec, sigma90, nside) - contour50 = list() - for i in range(len(Theta50)): - contour50.append([Theta50[i], Phi50[i]]) - contour50 = np.asarray(contour50) - contour90 = list() - for i in range(len(Theta90)): - contour90.append([Theta90[i], Phi90[i]]) - contour90 = np.asarray(contour90) + contour50 = np.dstack(Theta50,Phi50) + contour90 = np.dstack(Theta90,Phi90) contours_by_level = [[contour50], [contour90]] # Check for RA values that are out of bounds From 08b5165df3b7326b892179f2bc5935412938dda1 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Fri, 13 Oct 2023 13:22:54 +0200 Subject: [PATCH 40/42] Fixed error in calling np.dstack() --- skyreader/result.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skyreader/result.py b/skyreader/result.py index 0188177b..a996e367 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -985,8 +985,8 @@ def bounding_box(ra, dec, theta, phi): sigma90 = np.deg2rad(circular_err90) Theta50, Phi50 = self.circular_contour(minRA, minDec, sigma50, nside) Theta90, Phi90 = self.circular_contour(minRA, minDec, sigma90, nside) - contour50 = np.dstack(Theta50,Phi50) - contour90 = np.dstack(Theta90,Phi90) + contour50 = np.dstack((Theta50,Phi50)) + contour90 = np.dstack((Theta90,Phi90)) contours_by_level = [[contour50], [contour90]] # Check for RA values that are out of bounds From 7488e495c1763b71dc840f294077ce758df01938 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Fri, 13 Oct 2023 13:28:14 +0200 Subject: [PATCH 41/42] Fixing bugs after implementation of np.dstack() --- skyreader/result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index a996e367..8f2a1bad 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -987,7 +987,7 @@ def bounding_box(ra, dec, theta, phi): Theta90, Phi90 = self.circular_contour(minRA, minDec, sigma90, nside) contour50 = np.dstack((Theta50,Phi50)) contour90 = np.dstack((Theta90,Phi90)) - contours_by_level = [[contour50], [contour90]] + contours_by_level = [contour50, contour90] # Check for RA values that are out of bounds for level in contours_by_level: From d3819d04fcaf2aa4478f1a2982ae144285c2a8b0 Mon Sep 17 00:00:00 2001 From: G-Sommani Date: Fri, 13 Oct 2023 16:04:40 +0200 Subject: [PATCH 42/42] circular_contour() as static method --- skyreader/result.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/skyreader/result.py b/skyreader/result.py index 8f2a1bad..d8b3584a 100644 --- a/skyreader/result.py +++ b/skyreader/result.py @@ -825,7 +825,8 @@ def create_plot(self, dozoom = False): print("done.") - def circular_contour(self, ra, dec, sigma, nside): + @staticmethod + def circular_contour(ra, dec, sigma, nside): """For plotting circular contours on skymaps ra, dec, sigma all expected in radians.""" dec = np.pi/2. - dec