From a4264667ab37bdc49293d55c3388eea8f9927db1 Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Tue, 20 Aug 2024 11:54:48 +0200 Subject: [PATCH 01/17] Remove dispatcher plot dependencies --- oda_api/plot_tools.py | 144 +++++++++++++++++++++++++++++++++++----- requirements.txt | 2 +- requirements_docker.txt | 2 +- setup.cfg | 2 +- setup.py | 3 +- 5 files changed, 134 insertions(+), 19 deletions(-) diff --git a/oda_api/plot_tools.py b/oda_api/plot_tools.py index 2c09db5b..4601637a 100644 --- a/oda_api/plot_tools.py +++ b/oda_api/plot_tools.py @@ -30,6 +30,22 @@ import time as _time import astropy.wcs as wcs +from bokeh.layouts import row, gridplot +#column, +from bokeh.models import HoverTool +# (CustomJS, +# Toggle, +# RangeSlider, +# HoverTool, +# ColorBar, +# LinearColorMapper, +# LabelSet, +# ColumnDataSource, +# LogColorMapper) +from bokeh.embed import components +from bokeh.plotting import figure +#from bokeh.palettes import Plasma256 + # NOTE GW, optional try: import ligo.skymap.plot @@ -691,7 +707,7 @@ def check_product_for_gallery(**kwargs): return True def get_html_image(self, source_name, systematic_fraction, color='blue'): - import cdci_data_analysis.analysis.plot_tools + x, dx, y, dy, e_min, e_max = self.get_lc(source_name, systematic_fraction) mask = numpy.logical_not(numpy.isnan(y)) @@ -704,10 +720,10 @@ def get_html_image(self, source_name, systematic_fraction, color='blue'): else: xlabel = 'Time [IJD]' - sp = cdci_data_analysis.analysis.plot_tools.ScatterPlot(w=800, h=600, - x_label=xlabel, - y_label='Rate (%.0f - %.0f keV)' % (e_min, e_max), - title=source_name) + sp = ScatterPlot(w=800, h=600, + x_label=xlabel, + y_label='Rate (%.0f - %.0f keV)' % (e_min, e_max), + title=source_name) sp.add_errorbar(x, y, yerr=dy, xerr=dx, color=color) html_dict = sp.get_html_draw() @@ -774,8 +790,7 @@ def show(self, in_source_name='', systematic_fraction=0, xlim=[]): plt.show() def get_html_image(self, in_source_name, systematic_fraction, x_range=None, y_range=None, color='blue'): - import cdci_data_analysis.analysis.plot_tools - + x, dx, y, dy = self.get_values(in_source_name, systematic_fraction) if len(x) == 0: @@ -787,14 +802,14 @@ def get_html_image(self, in_source_name, systematic_fraction, x_range=None, y_ra if y_range is None: y_range = [numpy.max([1e-4, (y-dy)[x < x_range[1]].min()]), (y+dy).max()] - sp = cdci_data_analysis.analysis.plot_tools.ScatterPlot(w=800, h=600, - x_label="Energy [keV]", - y_label='Counts/s/keV', - x_axis_type='log', - y_axis_type='log', - x_range=x_range, - y_range=y_range, - title=in_source_name) + sp = ScatterPlot(w=800, h=600, + x_label="Energy [keV]", + y_label='Counts/s/keV', + x_axis_type='log', + y_axis_type='log', + x_range=x_range, + y_range=y_range, + title=in_source_name) if len(x) == 0: return '' sp.add_errorbar(x, y, yerr=dy, xerr=dx, color=color) @@ -1051,3 +1066,102 @@ def build_fig(self, event_name=None): # TODO can an implementation of this method provided? def write_fits(self): raise NotImplementedError + + +class ScatterPlot(object): + + def __init__(self,w,h,x_label=None,y_label=None,x_range=None,y_range=None,title=None,y_axis_type='linear',x_axis_type='linear'): + hover = HoverTool(tooltips=[("x", "$x"), ("y", "$y")]) + + self.fig = figure(title=title, width=w, height=h,x_range=x_range,y_range=y_range, + y_axis_type=y_axis_type, + x_axis_type=x_axis_type, + tools=[hover, 'pan,box_zoom,box_select,wheel_zoom,reset,save,crosshair'] + ) + + if x_label is not None: + self.fig.xaxis.axis_label = x_label + + if y_label is not None: + self.fig.yaxis.axis_label = y_label + + def add_errorbar(self, x, y, xerr=None, yerr=None, color='red', + point_kwargs={}, error_kwargs={}): + + self.fig.circle(x, y, color=color, **point_kwargs) + + if xerr is not None: + x_err_x = [] + x_err_y = [] + for px, py, err in zip(x, y, xerr): + x_err_x.append((px - err, px + err)) + x_err_y.append((py, py)) + self.fig.multi_line(x_err_x, x_err_y, color=color, **error_kwargs) + + if yerr is not None: + y_err_x = [] + y_err_y = [] + for px, py, err in zip(x, y, yerr): + y_err_x.append((px, px)) + y_err_y.append((py - err, py + err)) + self.fig.multi_line(y_err_x, y_err_y, color=color, **error_kwargs) + + + + def add_step_line(self, x, y, legend=None): + if legend: + self.fig.step(x, y, legend_label=legend, mode="center") + else: + self.fig.step(x, y, mode="center") + + def add_line(self, x, y, legend=None, color='red'): + if legend: + self.fig.line(x, y, legend_label=legend, line_color=color) + else: + self.fig.line(x, y, line_color=color) + + def get_html_draw(self): + + + + layout = row( + self.fig + ) + #curdoc().add_root(layout) + + + #show(layout) + + script, div = components(layout) + + #print ('script',script) + #print ('div',div) + + html_dict = {} + html_dict['script'] = script + html_dict['div'] = div + return html_dict + + +class GridPlot(object): + + def __init__(self,f1,f2,w=None,h=None): + + self.f1=f1 + self.f2=f2 + + def get_html_draw(self,w=None,h=None): + #l = layout([self.f1.fig],[self.f2.fig]) + + + grid = gridplot([self.f1.fig,self.f2.fig],ncols=1,plot_width=w, plot_height=h) + #curdoc().add_root(grid) + #show(grid) + #output_file("test.html") + script, div = components(grid) + + html_dict={} + html_dict['script']=script + html_dict['div'] = div + return html_dict + diff --git a/requirements.txt b/requirements.txt index d0339578..82f0bbfd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ matplotlib numpy jsonschema astroquery --e git+https://github.com/oda-hub/dispatcher-app.git#egg=cdci_data_analysis[test] simplejson sentry_sdk rdflib +bokeh diff --git a/requirements_docker.txt b/requirements_docker.txt index aab1017e..e7f4ca26 100644 --- a/requirements_docker.txt +++ b/requirements_docker.txt @@ -1,2 +1,2 @@ --e git://github.com/andreatramacere/oda_api.git#egg=oda_api +-e git://github.com/oda-hub/oda_api.git#egg=oda_api matplotlib \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index efa2536f..37fd8edd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.2.25 +current_version = 1.2.26 commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? diff --git a/setup.py b/setup.py index 39bd4235..9f5de901 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,8 @@ "astroquery", "scipy", "rdflib", - "black" + "black", + "bokeh" ], extras_require={ 'test': [ From 9bd0ebea2413722062b4409e10bb9d6370f8b821 Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Tue, 20 Aug 2024 12:41:05 +0200 Subject: [PATCH 02/17] Requirements.txt n line with setup.py --- requirements.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 82f0bbfd..43d2a469 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,13 @@ requests future -astropy +astropy>=3.2 json_tricks matplotlib numpy jsonschema +pyjwt astroquery -simplejson -sentry_sdk +scipy rdflib +black bokeh From ef9864bd0e40712ad1ccef81a32edd80203293c0 Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Tue, 20 Aug 2024 12:49:31 +0200 Subject: [PATCH 03/17] Remove dispatcher from conftest.py --- tests/conftest.py | 76 +++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6e73ac5b..ede2e24e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,18 +5,18 @@ import shutil import os -from cdci_data_analysis.pytest_fixtures import ( - dispatcher_live_fixture, - dispatcher_live_fixture_with_gallery, - dispatcher_test_conf_fn, - dispatcher_test_conf_with_gallery_fn, - dispatcher_test_conf, - dispatcher_debug, - dispatcher_nodebug, - dispatcher_long_living_fixture, - dispatcher_test_conf_with_gallery, - default_token_payload, - ) +# from cdci_data_analysis.pytest_fixtures import ( +# dispatcher_live_fixture, +# dispatcher_live_fixture_with_gallery, +# dispatcher_test_conf_fn, +# dispatcher_test_conf_with_gallery_fn, +# dispatcher_test_conf, +# dispatcher_debug, +# dispatcher_nodebug, +# dispatcher_long_living_fixture, +# dispatcher_test_conf_with_gallery, +# default_token_payload, +# ) pytest_options = ["slow", "dda", "live"] @@ -45,29 +45,29 @@ def pytest_collection_modifyitems(config, items): -@pytest.fixture -def dispatcher_api(dispatcher_live_fixture): - import oda_api - disp = oda_api.api.DispatcherAPI( - url=dispatcher_live_fixture - ) - disp.allow_token_discovery = False - return disp +# @pytest.fixture +# def dispatcher_api(dispatcher_live_fixture): +# import oda_api +# disp = oda_api.api.DispatcherAPI( +# url=dispatcher_live_fixture +# ) +# disp.allow_token_discovery = False +# return disp -@pytest.fixture -def dispatcher_api_with_gallery(dispatcher_live_fixture_with_gallery): - import oda_api - disp = oda_api.gallery_api.GalleryDispatcherAPI( - url=dispatcher_live_fixture_with_gallery - ) - disp.allow_token_discovery = False - return disp +# @pytest.fixture +# def dispatcher_api_with_gallery(dispatcher_live_fixture_with_gallery): +# import oda_api +# disp = oda_api.gallery_api.GalleryDispatcherAPI( +# url=dispatcher_live_fixture_with_gallery +# ) +# disp.allow_token_discovery = False +# return disp -@pytest.fixture -def secret_key(dispatcher_test_conf): - return dispatcher_test_conf['secret_key'] +# @pytest.fixture +# def secret_key(dispatcher_test_conf): +# return dispatcher_test_conf['secret_key'] @pytest.fixture @@ -94,13 +94,13 @@ def remove_any_token_from_environment(): os.remove(os.path.join(os.environ["HOME"], ".oda-token")) -@pytest.fixture -def default_token(default_token_payload, secret_key) -> str: - token = jwt.encode(default_token_payload, secret_key, algorithm='HS256') - # this changes depending on jwt implementation - if isinstance(token, bytes): - token = token.decode() - return token +# @pytest.fixture +# def default_token(default_token_payload, secret_key) -> str: +# token = jwt.encode(default_token_payload, secret_key, algorithm='HS256') +# # this changes depending on jwt implementation +# if isinstance(token, bytes): +# token = token.decode() +# return token def remove_scratch_folders(job_id=None): From d6113e22185e57292e25b1212a0ed89971f2f2ca Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Tue, 20 Aug 2024 14:41:56 +0200 Subject: [PATCH 04/17] yodate address in tutorial --- doc/source/user_guide/tutorial_main.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/user_guide/tutorial_main.rst b/doc/source/user_guide/tutorial_main.rst index 841de97f..3ff4734c 100644 --- a/doc/source/user_guide/tutorial_main.rst +++ b/doc/source/user_guide/tutorial_main.rst @@ -27,12 +27,12 @@ The following tutorial covers a large fraction of the code features. The example Progress reporting for long running tasks - Examples of workflows + Examples of workflows .. image:: https://img.shields.io/badge/run%20quick%20start%20-binder-579ACA.svg?logo=data:image/png;base64,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 - :target: https://mybinder.org/v2/gh/cdcihub/oda_api/master + :target: https://mybinder.org/v2/gh/oda-hub/oda_api/master @@ -40,4 +40,4 @@ The following tutorial covers a large fraction of the code features. The example .. image:: https://img.shields.io/badge/run%20examples-binder-579ACA.svg?logo=data:image/png;base64,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 - :target: https://mybinder.org/v2/gh/cdcihub/oda_api_benchmark/master + :target: https://mybinder.org/v2/gh/oda-hub/oda_api_benchmark/master From 02d204da78aa49e63cf02cb6f98bdcac6670c824 Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Tue, 20 Aug 2024 14:42:30 +0200 Subject: [PATCH 05/17] update index.rst --- doc/source/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index 22a427ab..5a2f74d1 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -5,9 +5,9 @@ ODA API documentation =================================== -API for cdci_data_analysis +API for Multi Messenger Online Data Analysis (MMODA) -:Authors: `Andrea Tramacere , Carlo Ferrigno `_ +:Authors: `Andrea Tramacere , Carlo Ferrigno , Gabriele Barni `_ Documentation ------------- From 74ed463ff8160c8ba441f1f22bca3f3b209171f9 Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Tue, 20 Aug 2024 14:42:55 +0200 Subject: [PATCH 06/17] update test requirements --- requirements.txt | 2 ++ setup.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 43d2a469..c49494f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,5 @@ scipy rdflib black bokeh +git+https://github.com/oda-hub/dispatcher-app.git#egg=cdci_data_analysis[test] + diff --git a/setup.py b/setup.py index 9f5de901..f029a780 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ setup(name='oda_api', version=__version__, - description='API plugin for CDCI online data analysis', + description='API plugin for Multi-Messenger online data analysis', author='Andrea Tramacere, Volodymyr Savchenko', author_email='contact@odahub.io', packages=packs, @@ -49,7 +49,8 @@ 'test': [ "pytest-xdist[psutil]", "astroquery>=0.4.4", - "sentry_sdk" + "sentry_sdk", + "cdci_data_analysis" ], 'extra-test': [ "pytest-xdist[psutil]", From 47fe79e5ba1a615af09bd92ba58c2155a069b8ef Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Tue, 20 Aug 2024 14:43:28 +0200 Subject: [PATCH 07/17] remove references to CDCI in License, Readme and Vocab --- .github/styles/vocab.txt | 1 - LICENSE.rst | 2 +- README.md | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/styles/vocab.txt b/.github/styles/vocab.txt index 252e7d57..2fc4b479 100644 --- a/.github/styles/vocab.txt +++ b/.github/styles/vocab.txt @@ -1,4 +1,3 @@ -cdci oda api Tramacere diff --git a/LICENSE.rst b/LICENSE.rst index 5b6f929e..c9f93be3 100644 --- a/LICENSE.rst +++ b/LICENSE.rst @@ -1,4 +1,4 @@ -cdci_data_analysis is distributed under the terms of The MIT License (MIT), reproduced below. +oda_api is distributed under the terms of The MIT License (MIT), reproduced below. MIT License diff --git a/README.md b/README.md index 95d20c86..e6fc624a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ oda_api [![Documentation Status](https://readthedocs.org/projects/oda-api/badge/?version=latest)](https://oda-api.readthedocs.io/en/latest/?badge=latest) -![Upload Python Package](https://github.com/cdcihub/oda_api/workflows/Upload%20Python%20Package/badge.svg) +![Upload Python Package](https://github.com/oda-hub/oda_api/workflows/Upload%20Python%20Package/badge.svg) ![Prose Linting](https://github.com/volodymyrss/integral-isgri-rate-meaning/workflows/Prose%20Linting/badge.svg) ![Executing Notebook](https://github.com/volodymyrss/integral-isgri-rate-meaning/workflows/Executing%20Notebook/badge.svg) [![Python package](https://github.com/oda-hub/oda_api/actions/workflows/python-package.yml/badge.svg)](https://github.com/oda-hub/oda_api/actions/workflows/python-package.yml) From 15bfa5fa87dafdbcf70758165ac21fea8d61f425 Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Tue, 20 Aug 2024 14:43:49 +0200 Subject: [PATCH 08/17] revert conftest.py modifications --- tests/conftest.py | 77 +++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ede2e24e..a6eab463 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,18 +5,18 @@ import shutil import os -# from cdci_data_analysis.pytest_fixtures import ( -# dispatcher_live_fixture, -# dispatcher_live_fixture_with_gallery, -# dispatcher_test_conf_fn, -# dispatcher_test_conf_with_gallery_fn, -# dispatcher_test_conf, -# dispatcher_debug, -# dispatcher_nodebug, -# dispatcher_long_living_fixture, -# dispatcher_test_conf_with_gallery, -# default_token_payload, -# ) +from cdci_data_analysis.pytest_fixtures import ( + dispatcher_live_fixture, + dispatcher_live_fixture_with_gallery, + dispatcher_test_conf_fn, + dispatcher_test_conf_with_gallery_fn, + dispatcher_test_conf, + dispatcher_debug, + dispatcher_nodebug, + dispatcher_long_living_fixture, + dispatcher_test_conf_with_gallery, + default_token_payload, + ) pytest_options = ["slow", "dda", "live"] @@ -44,30 +44,29 @@ def pytest_collection_modifyitems(config, items): item.add_marker(pytest.mark.skip(reason=f"--run-only-{option} prevents this test from running")) - -# @pytest.fixture -# def dispatcher_api(dispatcher_live_fixture): -# import oda_api -# disp = oda_api.api.DispatcherAPI( -# url=dispatcher_live_fixture -# ) -# disp.allow_token_discovery = False -# return disp +@pytest.fixture +def dispatcher_api(dispatcher_live_fixture): + import oda_api + disp = oda_api.api.DispatcherAPI( + url=dispatcher_live_fixture + ) + disp.allow_token_discovery = False + return disp -# @pytest.fixture -# def dispatcher_api_with_gallery(dispatcher_live_fixture_with_gallery): -# import oda_api -# disp = oda_api.gallery_api.GalleryDispatcherAPI( -# url=dispatcher_live_fixture_with_gallery -# ) -# disp.allow_token_discovery = False -# return disp +@pytest.fixture +def dispatcher_api_with_gallery(dispatcher_live_fixture_with_gallery): + import oda_api + disp = oda_api.gallery_api.GalleryDispatcherAPI( + url=dispatcher_live_fixture_with_gallery + ) + disp.allow_token_discovery = False + return disp -# @pytest.fixture -# def secret_key(dispatcher_test_conf): -# return dispatcher_test_conf['secret_key'] +@pytest.fixture +def secret_key(dispatcher_test_conf): + return dispatcher_test_conf['secret_key'] @pytest.fixture @@ -94,13 +93,13 @@ def remove_any_token_from_environment(): os.remove(os.path.join(os.environ["HOME"], ".oda-token")) -# @pytest.fixture -# def default_token(default_token_payload, secret_key) -> str: -# token = jwt.encode(default_token_payload, secret_key, algorithm='HS256') -# # this changes depending on jwt implementation -# if isinstance(token, bytes): -# token = token.decode() -# return token +@pytest.fixture +def default_token(default_token_payload, secret_key) -> str: + token = jwt.encode(default_token_payload, secret_key, algorithm='HS256') + # this changes depending on jwt implementation + if isinstance(token, bytes): + token = token.decode() + return token def remove_scratch_folders(job_id=None): From b45b2079b14f8f51d6255370d08155790057c2ab Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Wed, 21 Aug 2024 10:47:16 +0200 Subject: [PATCH 09/17] accept requests by @burnout87 --- requirements.txt | 2 +- setup.cfg | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index c49494f1..659c1db9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ requests future -astropy>=3.2 +astropy>=5.0.1 json_tricks matplotlib numpy diff --git a/setup.cfg b/setup.cfg index 37fd8edd..efa2536f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.2.26 +current_version = 1.2.25 commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? diff --git a/setup.py b/setup.py index f029a780..8738cabc 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ install_requires=[ "requests", "future", - "astropy>=3.2", + "astropy>=5.0.1", "json_tricks", "matplotlib", "numpy", From a103607b82845ff672d0d9ce325fe853bbb601cc Mon Sep 17 00:00:00 2001 From: burnout87 Date: Wed, 21 Aug 2024 13:03:23 +0200 Subject: [PATCH 10/17] set requirement editable --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 659c1db9..c8756f40 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,5 +11,5 @@ scipy rdflib black bokeh -git+https://github.com/oda-hub/dispatcher-app.git#egg=cdci_data_analysis[test] +-e git+https://github.com/oda-hub/dispatcher-app.git#egg=cdci_data_analysis[test] From d81f799cb2443917ca26e3ff69ff6d2d55847ccf Mon Sep 17 00:00:00 2001 From: burnout87 Date: Wed, 21 Aug 2024 14:37:49 +0200 Subject: [PATCH 11/17] set requirement docs --- doc/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index 8542e837..fb4699f5 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -18,4 +18,4 @@ pyjwt==2.4.0 astroquery==0.4.4 rdflib - +bokeh From 693e88deb99149dbe4f32dfd9baf204f9e244fb6 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Wed, 21 Aug 2024 15:20:12 +0200 Subject: [PATCH 12/17] use bokeh 3.5.1 --- oda_api/plot_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oda_api/plot_tools.py b/oda_api/plot_tools.py index 4601637a..2ee758e8 100644 --- a/oda_api/plot_tools.py +++ b/oda_api/plot_tools.py @@ -729,8 +729,8 @@ def get_html_image(self, source_name, systematic_fraction, color='blue'): html_dict = sp.get_html_draw() html_str = html_dict['div'] + '\n' - html_str += '\n' + \ - '\n' + html_str += '\n' + \ + '\n' html_str += html_dict['script'] return html_str From ba4ec4f587c728966c3e8bc0e68ed21b04671bff Mon Sep 17 00:00:00 2001 From: Carlo Ferrigno Date: Wed, 21 Aug 2024 17:10:01 +0200 Subject: [PATCH 13/17] Add comment to requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index c8756f40..16f5bec1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,4 +12,5 @@ rdflib black bokeh -e git+https://github.com/oda-hub/dispatcher-app.git#egg=cdci_data_analysis[test] +# This needs to be editable to allow setting the necessary variables. From 0161ffc2bfcb0b11e50f99f252308605643880a2 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 24 Jan 2025 12:39:54 +0100 Subject: [PATCH 14/17] dedicated utils module for plot tools --- oda_api/plot_tools.py | 115 +----------------------------------- oda_api/plot_tools_utils.py | 109 ++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 114 deletions(-) create mode 100644 oda_api/plot_tools_utils.py diff --git a/oda_api/plot_tools.py b/oda_api/plot_tools.py index 2ee758e8..bc5619b4 100644 --- a/oda_api/plot_tools.py +++ b/oda_api/plot_tools.py @@ -26,25 +26,11 @@ from astroquery.simbad import Simbad import oda_api.api as api +from .plot_tools_utils import ScatterPlot, GridPlot import time as _time import astropy.wcs as wcs -from bokeh.layouts import row, gridplot -#column, -from bokeh.models import HoverTool -# (CustomJS, -# Toggle, -# RangeSlider, -# HoverTool, -# ColorBar, -# LinearColorMapper, -# LabelSet, -# ColumnDataSource, -# LogColorMapper) -from bokeh.embed import components -from bokeh.plotting import figure -#from bokeh.palettes import Plasma256 # NOTE GW, optional try: @@ -1066,102 +1052,3 @@ def build_fig(self, event_name=None): # TODO can an implementation of this method provided? def write_fits(self): raise NotImplementedError - - -class ScatterPlot(object): - - def __init__(self,w,h,x_label=None,y_label=None,x_range=None,y_range=None,title=None,y_axis_type='linear',x_axis_type='linear'): - hover = HoverTool(tooltips=[("x", "$x"), ("y", "$y")]) - - self.fig = figure(title=title, width=w, height=h,x_range=x_range,y_range=y_range, - y_axis_type=y_axis_type, - x_axis_type=x_axis_type, - tools=[hover, 'pan,box_zoom,box_select,wheel_zoom,reset,save,crosshair'] - ) - - if x_label is not None: - self.fig.xaxis.axis_label = x_label - - if y_label is not None: - self.fig.yaxis.axis_label = y_label - - def add_errorbar(self, x, y, xerr=None, yerr=None, color='red', - point_kwargs={}, error_kwargs={}): - - self.fig.circle(x, y, color=color, **point_kwargs) - - if xerr is not None: - x_err_x = [] - x_err_y = [] - for px, py, err in zip(x, y, xerr): - x_err_x.append((px - err, px + err)) - x_err_y.append((py, py)) - self.fig.multi_line(x_err_x, x_err_y, color=color, **error_kwargs) - - if yerr is not None: - y_err_x = [] - y_err_y = [] - for px, py, err in zip(x, y, yerr): - y_err_x.append((px, px)) - y_err_y.append((py - err, py + err)) - self.fig.multi_line(y_err_x, y_err_y, color=color, **error_kwargs) - - - - def add_step_line(self, x, y, legend=None): - if legend: - self.fig.step(x, y, legend_label=legend, mode="center") - else: - self.fig.step(x, y, mode="center") - - def add_line(self, x, y, legend=None, color='red'): - if legend: - self.fig.line(x, y, legend_label=legend, line_color=color) - else: - self.fig.line(x, y, line_color=color) - - def get_html_draw(self): - - - - layout = row( - self.fig - ) - #curdoc().add_root(layout) - - - #show(layout) - - script, div = components(layout) - - #print ('script',script) - #print ('div',div) - - html_dict = {} - html_dict['script'] = script - html_dict['div'] = div - return html_dict - - -class GridPlot(object): - - def __init__(self,f1,f2,w=None,h=None): - - self.f1=f1 - self.f2=f2 - - def get_html_draw(self,w=None,h=None): - #l = layout([self.f1.fig],[self.f2.fig]) - - - grid = gridplot([self.f1.fig,self.f2.fig],ncols=1,plot_width=w, plot_height=h) - #curdoc().add_root(grid) - #show(grid) - #output_file("test.html") - script, div = components(grid) - - html_dict={} - html_dict['script']=script - html_dict['div'] = div - return html_dict - diff --git a/oda_api/plot_tools_utils.py b/oda_api/plot_tools_utils.py new file mode 100644 index 00000000..5468502c --- /dev/null +++ b/oda_api/plot_tools_utils.py @@ -0,0 +1,109 @@ +# mypy: ignore-errors +# pylint: skip-file +# pylint: disable-all + +from __future__ import absolute_import, division, print_function + +import os.path +from builtins import (str, open, range, + zip, round, input, int, pow, object, zip) + + +__author__ = "Carlo Ferrigno" + + +from bokeh.layouts import row, gridplot +from bokeh.models import HoverTool +from bokeh.embed import components +from bokeh.plotting import figure + +# NOTE GW, optional +try: + import ligo.skymap.plot +except ModuleNotFoundError: + pass + +import logging + +logger = logging.getLogger("oda_api.plot_tools") + +__all__ = ['ScatterPlot', 'GridPlot'] + + +class ScatterPlot(object): + + def __init__(self,w,h,x_label=None,y_label=None,x_range=None,y_range=None,title=None,y_axis_type='linear',x_axis_type='linear'): + hover = HoverTool(tooltips=[("x", "$x"), ("y", "$y")]) + + self.fig = figure(title=title, width=w, height=h,x_range=x_range,y_range=y_range, + y_axis_type=y_axis_type, + x_axis_type=x_axis_type, + tools=[hover, 'pan,box_zoom,box_select,wheel_zoom,reset,save,crosshair'] + ) + + if x_label is not None: + self.fig.xaxis.axis_label = x_label + + if y_label is not None: + self.fig.yaxis.axis_label = y_label + + def add_errorbar(self, x, y, xerr=None, yerr=None, color='red', + point_kwargs={}, error_kwargs={}): + + self.fig.circle(x, y, color=color, **point_kwargs) + + if xerr is not None: + x_err_x = [] + x_err_y = [] + for px, py, err in zip(x, y, xerr): + x_err_x.append((px - err, px + err)) + x_err_y.append((py, py)) + self.fig.multi_line(x_err_x, x_err_y, color=color, **error_kwargs) + + if yerr is not None: + y_err_x = [] + y_err_y = [] + for px, py, err in zip(x, y, yerr): + y_err_x.append((px, px)) + y_err_y.append((py - err, py + err)) + self.fig.multi_line(y_err_x, y_err_y, color=color, **error_kwargs) + + + + def add_step_line(self, x, y, legend=None): + if legend: + self.fig.step(x, y, legend_label=legend, mode="center") + else: + self.fig.step(x, y, mode="center") + + def add_line(self, x, y, legend=None, color='red'): + if legend: + self.fig.line(x, y, legend_label=legend, line_color=color) + else: + self.fig.line(x, y, line_color=color) + + def get_html_draw(self): + + layout = row( + self.fig + ) + script, div = components(layout) + + html_dict = {'script': script, 'div': div} + return html_dict + + +class GridPlot(object): + + def __init__(self,f1,f2,w=None,h=None): + + self.f1=f1 + self.f2=f2 + + def get_html_draw(self,w=None,h=None): + grid = gridplot([self.f1.fig,self.f2.fig],ncols=1,plot_width=w, plot_height=h) + script, div = components(grid) + + html_dict= {'script': script, 'div': div} + return html_dict + From 3d90f3e684327345042aa85deb165c5599a2e2ec Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 24 Jan 2025 15:11:37 +0100 Subject: [PATCH 15/17] bokeh version 3.5.1 also for OdaSpectrum --- oda_api/plot_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oda_api/plot_tools.py b/oda_api/plot_tools.py index bef6aeef..875411be 100644 --- a/oda_api/plot_tools.py +++ b/oda_api/plot_tools.py @@ -822,8 +822,8 @@ def get_html_image(self, in_source_name, systematic_fraction, x_range=None, y_ra html_dict = sp.get_html_draw() html_str = html_dict['div'] + '\n' - html_str += '\n' + \ - '\n' + html_str += '\n' + \ + '\n' html_str += html_dict['script'] return html_str From dd60c2125128b38437107bf890f245cb136749f4 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 24 Jan 2025 17:14:33 +0100 Subject: [PATCH 16/17] moving Image class in the plot_tools_utils module --- oda_api/plot_tools_utils.py | 224 +++++++++++++++++++++++++++++++++++- 1 file changed, 220 insertions(+), 4 deletions(-) diff --git a/oda_api/plot_tools_utils.py b/oda_api/plot_tools_utils.py index 5468502c..f107081b 100644 --- a/oda_api/plot_tools_utils.py +++ b/oda_api/plot_tools_utils.py @@ -11,11 +11,22 @@ __author__ = "Carlo Ferrigno" - -from bokeh.layouts import row, gridplot -from bokeh.models import HoverTool +import numpy as np + +from astropy import wcs +from bokeh.layouts import row, gridplot, column +from bokeh.models import (CustomJS, + Toggle, + RangeSlider, + HoverTool, + ColorBar, + LinearColorMapper, + LabelSet, + ColumnDataSource, + LogColorMapper) from bokeh.embed import components from bokeh.plotting import figure +from bokeh.palettes import Plasma256 # NOTE GW, optional try: @@ -27,7 +38,212 @@ logger = logging.getLogger("oda_api.plot_tools") -__all__ = ['ScatterPlot', 'GridPlot'] +__all__ = ['ScatterPlot', 'GridPlot', 'Image'] + + +class Image(object): + + def __init__(self, data, header): + self.data = data + self.header = header + + def get_html_draw(self, + w=None, + h=None, + catalog=None, + sources_circle_size=15, + x_scale="linear", + y_scale="linear", + x_range=None, + y_range=None, + x0=0, + y0=0, + dw=None, + dh=None, + x_label=None, + y_label=None, + enable_log_cmap=True, + ): + + msk = ~np.isnan(self.data) + + min_v = self.data[msk].min() + max_v = self.data[msk].max() + + if x_range is None: + c = self.data.shape[1] + x_range = (0, c) + if y_range is None: + r = self.data.shape[0] + y_range = (0, r) + if dw is None: + dw = x_range[1] + if dh is None: + dh = y_range[1] + + fig = figure(plot_width=w, + plot_height=h, + x_axis_type=x_scale, + y_axis_type=y_scale, + x_range=x_range, + y_range=y_range, + x_axis_label=x_label, + y_axis_label=y_label, + tools=['pan,box_zoom,box_select,wheel_zoom,reset,save,crosshair']) + + lin_color_mapper = LinearColorMapper(low=min_v, high=max_v, palette='Plasma256') + + fig_im = fig.image(image=[self.data], x=x0, y=y0, dw=dw, dh=dh, + color_mapper=lin_color_mapper) + + hover = HoverTool(tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")], + renderers=[fig_im]) + + fig.add_tools(hover) + + if catalog is not None: + + lon = catalog.ra + lat = catalog.dec + + cur_wcs = wcs.WCS(self.header) + + if len(lat) > 0.: + pixcrd = cur_wcs.wcs_world2pix(np.column_stack((lon, lat)), 0) + + msk = ~np.isnan(pixcrd[:, 0]) + source = ColumnDataSource(data=dict(lon=pixcrd[:, 0][msk] + 0.5, + lat=pixcrd[:, 1][msk] + 0.5, + names=catalog.name[msk])) + + fig.scatter(x='lon', y='lat', marker='circle', size=sources_circle_size, + line_color="white", fill_color=None, alpha=1.0, source=source) + + labels = LabelSet(x='lon', y='lat', text='names', level='glyph', + x_offset=5, y_offset=5, render_mode='canvas', source=source, text_color='white') + + fig.add_layout(labels) + + lin_color_bar = ColorBar(color_mapper=lin_color_mapper, label_standoff=12, border_line_color=None, + location=(0, 0), width=15) + + fig.add_layout(lin_color_bar, 'right') + + graph_slider = RangeSlider(title='Sig. Range', start=min_v, end=max_v, step=(max_v - min_v) / 1000, + value=(min_v, max_v * 0.8)) + + graph_slider.js_link('value', lin_color_mapper, 'low', attr_selector=0) + graph_slider.js_link('value', lin_color_mapper, 'high', attr_selector=1) + + widgets = [graph_slider] + + if enable_log_cmap: + log_color_mapper = LogColorMapper(low=max(0, min_v), high=max_v, palette=Plasma256) + graph_slider.js_link('value', log_color_mapper, 'low', attr_selector=0) + graph_slider.js_link('value', log_color_mapper, 'high', attr_selector=1) + + log_color_bar = ColorBar(color_mapper=log_color_mapper, label_standoff=2, border_line_color=None, + location=(0, 0), width=15) + fig.add_layout(log_color_bar, 'right') + log_color_bar.visible = False + + log_toggle = Toggle(label='Toggle Log. Norm', active=False) + log_toggle.js_on_click(CustomJS(args=dict(lin_color_mapper=lin_color_mapper, + log_color_mapper=log_color_mapper, + fig_im=fig_im, + graph_slider=graph_slider, + min_v=min_v, + lin_color_bar=lin_color_bar, + log_color_bar=log_color_bar), + code=""" + if (this.active) { + graph_slider.value = [Math.max(0 + graph_slider.step, graph_slider.value[0]), graph_slider.value[1]]; + graph_slider.start = Math.max(0 + graph_slider.step, min_v); + fig_im.glyph.color_mapper = log_color_mapper; + log_color_bar.visible = true; + lin_color_bar.visible = false; + } else { + graph_slider.start = min_v; + fig_im.glyph.color_mapper = lin_color_mapper; + log_color_bar.visible = false; + lin_color_bar.visible = true; + } + """ + ) + ) + widgets.append(log_toggle) + + layout = column(row(widgets), + fig) + + script, div = components(layout) + + html_dict = {} + html_dict['script'] = script + html_dict['div'] = div + return html_dict + + def get_js9_html(self, file_path, region_file=None, js9_id='myJS9'): + + file = '''JS9.Preload("product/%s", {scale: 'log', colormap: 'plasma' ''' % file_path + # Region file needs to be loaded using an onload function + if region_file is not None: + file += ''', onload: function(im){ JS9.LoadRegions("product/%s");}}, {display: "%s"});\n''' % \ + (region_file, js9_id) + else: + file += '''}, {display: "%s"});''' % js9_id + t = ''' + + + + + + + + + + + + + + + + +
+
+ + + + + + + +
+ +
+
+
+
+
+ +

+

+ + + + + + ''' % (js9_id, js9_id, js9_id, file) + + return t class ScatterPlot(object): From 006945b6f5d44af5a1a01dcbeb45c0c4dd2e9124 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 24 Jan 2025 17:15:02 +0100 Subject: [PATCH 17/17] removed commented code --- oda_api/plot_tools_utils.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/oda_api/plot_tools_utils.py b/oda_api/plot_tools_utils.py index f107081b..3020c93f 100644 --- a/oda_api/plot_tools_utils.py +++ b/oda_api/plot_tools_utils.py @@ -1,14 +1,9 @@ -# mypy: ignore-errors -# pylint: skip-file -# pylint: disable-all - from __future__ import absolute_import, division, print_function import os.path from builtins import (str, open, range, zip, round, input, int, pow, object, zip) - __author__ = "Carlo Ferrigno" import numpy as np