Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Add concept notebook using glue unit conversion #1398

Closed
wants to merge 1 commit into from

Conversation

javerbukh
Copy link
Contributor

@javerbukh javerbukh commented Jun 14, 2022

Description

This PR is a proof of concept notebook of unit conversion in specviz. It is a companion to the following PRs in glue-core and glue-jupyter:

This PR should:

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a change log needed? If yes, is it added to CHANGES.rst?
  • Is a milestone set?
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@github-actions github-actions bot added the documentation Explanation of code and concepts label Jun 14, 2022
@codecov
Copy link

codecov bot commented Jun 14, 2022

Codecov Report

Merging #1398 (352d0aa) into main (8c3d3e7) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1398   +/-   ##
=======================================
  Coverage   84.91%   84.91%           
=======================================
  Files          91       91           
  Lines        8288     8288           
=======================================
  Hits         7038     7038           
  Misses       1250     1250           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c3d3e7...352d0aa. Read the comment docs.

"class UnitConverterWithTemperature:\n",
"\n",
" def equivalent_units(self, data, cid, units):\n",
" equivalencies = u.temperature() if 'temp' in cid.label.lower() else None\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will this work in practice (we don't want all equivalencies for all axes)? Is the lack of the spectral equivalency here the reason Hz is not converting as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both good questions. I will look into the second one, no good answer for the first one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a lookup dictionary of some sort to map conv type to equivalencies, or a bunch of if-else logic blocks?

FWIW, if-else is applied at https://github.com/spacetelescope/synphot_refactor/blob/2a382d7bdf29cc4a1e6b69e59d5c1d0f82dabffc/synphot/units.py#L242

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this doesn't work currently is because you should indeed be using the spectral equivalency for some components - here's a simple example that works for this particular example:

from astropy import units as u
from glue.core.units import unit_converter

@unit_converter('custom-astropy')
class UnitConverterWithSpectral:

    def equivalent_units(self, data, cid, units):
        equivalencies = u.spectral() if cid.label.lower() in ['freq', 'wave'] else None
        return map(str, u.Unit(units).find_equivalent_units(include_prefix_units=True, equivalencies=equivalencies))

    def to_unit(self, data, cid, values, original_units, target_units):
        equivalencies = u.spectral() if cid.label.lower() in ['freq', 'wave'] else None
        return (values * u.Unit(original_units)).to_value(target_units, equivalencies=equivalencies)

@pllim pllim mentioned this pull request Nov 14, 2022
9 tasks
@pllim pllim added this to the 3.3 milestone Jan 23, 2023
@pllim pllim added bug Something isn't working plugin Label for plugins common to multiple configurations cubeviz specviz mosviz specviz2d labels Jan 23, 2023
@astrofrog
Copy link
Collaborator

astrofrog commented Jan 24, 2023

@javerbukh I've tested this with the latest version of glue-core and glue-jupyter but ran into issues because the conversion isn't right for spectral axes - see https://github.com/spacetelescope/jdaviz/pull/1398/files#r1085558149 - I also couldn't get the data to show up in specviz but I think that's just because I wasn't sure what UI steps I should do in addition to the notebook code. Maybe you could give this a spin with the updated unit converter above and the latest glue-core and glue-jupyter branches?

@javerbukh
Copy link
Contributor Author

I was able to get the unit conversion working when following one of the tests you added to glue-jupyter:
https://github.com/glue-viz/glue-jupyter/pull/311/files#diff-e542cb99a33595d0713cfa320a27bae9b241a3b602275fe70fb94929a78338c3R37-R59
Screen Shot 2023-01-24 at 4 46 38 PM

As for adding data in the UI, you may need to go to the data dropdown (top left of viewer), click the arrows pointing down, and then add those data using the plus icon.

@javerbukh
Copy link
Contributor Author

javerbukh commented Jan 25, 2023

@astrofrog I ran into an issue with not being able to apply a subset in this PR. Even before I change the display unit or add both data. The grayed out selector appears and moves when I click and drag but when I let go, nothing happens.

EDIT: I just tested other notebooks and subsets work as expected, so it is not a problem with the environment. Does the glue profile viewer work with the display units and subsets?

@astrofrog
Copy link
Collaborator

@javerbukh - I have now merged the two glue PRs. The glue-core changes are in glue-core 1.7.0 while for glue-jupyter the changes are unreleased for now but in the main branch. Could you check whether things in this PR work fine with the latest version of glue-core and latest developer version of glue-jupyter? Subsets work for me now in the glue-jupyter demo notebook but let me know if they still don't work here.

@javerbukh
Copy link
Contributor Author

Hi @astrofrog , I upgraded my environment but I'm still not seeing the subset work in the glue-jupyter test case (https://github.com/glue-viz/glue-jupyter/pull/311/files#diff-e542cb99a33595d0713cfa320a27bae9b241a3b602275fe70fb94929a78338c3R37-R59)

Screen.Recording.2023-02-03.at.9.32.37.AM.mov

And here is my pip freeze

anyio==3.6.2
appnope==0.1.3
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
asdf==2.14.3
asdf-astropy==0.3.0
asdf-coordinates-schemas==0.1.0
asdf-standard==1.0.3
asdf-transform-schemas==0.3.0
asdf-unit-schemas==0.1.0
asdf-wcs-schemas==0.1.1
asteval==0.9.28
astropy==5.2.1
astroquery==0.4.6
asttokens==2.2.1
attrs==22.2.0
Babel==2.11.0
backcall==0.2.0
beautifulsoup4==4.11.1
bleach==6.0.0
bqplot==0.12.36
bqplot-image-gl==1.4.11
casa-formats-io==0.2.1
certifi @ file:///private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_477u68wvzm/croot/certifi_1671487773341/work/certifi
cffi==1.15.1
charset-normalizer==3.0.1
click==8.1.3
cloudpickle==2.2.1
comm==0.1.2
contourpy==1.0.7
coverage==7.0.5
cycler==0.11.0
dask==2023.1.0
debugpy==1.6.6
decorator==5.1.1
defusedxml==0.7.1
dill==0.3.6
echo==0.8.0
entrypoints==0.4
et-xmlfile==1.1.0
exceptiongroup==1.1.0
executing==1.2.0
fast-histogram==0.11
fastjsonschema==2.16.2
fonttools==4.38.0
freetype-py==2.3.0
fsspec==2023.1.0
glue-astronomy==0.6.0
glue-core==1.7.0
glue-jupyter @ git+https://github.com/glue-viz/glue-jupyter.git@2b521c9701619419dcea7450e3a328351fc932a2
glue-vispy-viewers==1.0.6
gwcs==0.18.3
h5py==3.8.0
hsluv==5.0.3
html5lib==1.1
hypothesis==6.65.0
idna==3.4
imageio==2.25.0
importlib-metadata==6.0.0
iniconfig==2.0.0
ipydatawidgets==4.3.2
ipygoldenlayout==0.4.0
ipykernel==6.20.2
ipympl==0.9.2
ipypopout==1.0.0
ipysplitpanes==0.2.0
ipython==8.8.0
ipython-genutils==0.2.0
ipyvolume==0.6.0a10
ipyvue==1.8.0
ipyvuetify==1.8.4
ipywebrtc==0.6.0
ipywidgets==8.0.4
jaraco.classes==3.2.3
-e git+ssh://git@github.com/javerbukh/jdaviz.git@fe034020c96fee8bdee58bde7ae9f2782c4b2a1b#egg=jdaviz
jedi==0.18.2
Jinja2==3.1.2
jmespath==1.0.1
joblib==1.2.0
json5==0.9.11
jsonschema==4.17.3
jupyter-server==1.23.5
jupyter_client==7.4.1
jupyter_core==5.1.5
jupyterlab==3.5.3
jupyterlab-pygments==0.2.2
jupyterlab-widgets==3.0.5
jupyterlab_server==2.19.0
keyring==23.13.1
kiwisolver==1.4.4
locket==1.0.0
MarkupSafe==2.1.2
matplotlib==3.6.3
matplotlib-inline==0.1.6
mistune==2.0.4
more-itertools==9.0.0
mpl-scatter-density==0.7
nbclassic==0.4.8
nbclient==0.7.2
nbconvert==7.2.9
nbformat==5.7.3
ndcube==2.0.3
nest-asyncio==1.5.6
networkx==3.0
notebook==6.5.2
notebook_shim==0.2.2
numpy==1.24.1
openpyxl==3.0.10
packaging==23.0
pandas==1.5.3
pandocfilters==1.5.0
parso==0.8.3
partd==1.3.0
pexpect==4.8.0
photutils==1.6.0
pickleshare==0.7.5
Pillow==9.4.0
platformdirs==2.6.2
pluggy==1.0.0
prometheus-client==0.16.0
prompt-toolkit==3.0.36
psutil==5.9.4
ptyprocess==0.7.0
pure-eval==0.2.2
pvextractor==0.3
pycparser==2.21
pyerfa==2.0.0.1
Pygments==2.14.0
PyOpenGL==3.1.6
pyparsing==3.0.9
pyrsistent==0.19.3
pytest==7.2.1
pytest-arraydiff==0.5.0
pytest-astropy==0.10.0
pytest-astropy-header==0.2.2
pytest-cov==4.0.0
pytest-doctestplus==0.12.1
pytest-filter-subpackage==0.1.2
pytest-mock==3.10.0
pytest-openfiles==0.5.0
pytest-remotedata==0.4.0
pytest-tornasync==0.6.0.post2
python-dateutil==2.8.2
pythreejs==2.4.1
pytz==2022.7.1
pyvo==1.4
PyWavelets==1.4.1
PyYAML==6.0
pyzmq==24.0.0
qtconsole==5.4.0
QtPy==2.3.0
radio-beam==0.3.4
regions==0.7
requests==2.28.2
scikit-image==0.19.3
scipy==1.10.0
semantic-version==2.10.0
Send2Trash==1.8.0
sidecar==0.5.2
six==1.16.0
sniffio==1.3.0
sortedcontainers==2.4.0
soupsieve==2.3.2.post1
specreduce==1.3.0
spectral-cube==0.6.0
specutils==1.9.1
stack-data==0.6.2
synphot==1.1.1
terminado==0.17.1
tifffile==2023.1.23.1
tinycss2==1.2.1
tomli==2.0.1
toolz==0.12.0
tornado==6.2
traitlets==5.8.1
traittypes==0.2.1
urllib3==1.26.14
vispy==0.12.1
voila==0.4.0
wcwidth==0.2.6
webencodings==0.5.1
websocket-client==1.4.2
websockets==10.4
widgetsnbextension==4.0.5
xlrd==2.0.1
zipp==3.11.0

@astrofrog
Copy link
Collaborator

Could you check what happens if you add more datapoints? It might be that more than one point has to be selected for the subset to be visible (as it is drawn with lines)

@javerbukh
Copy link
Contributor Author

Good call! It does in fact work. Thank you!

Screen.Recording.2023-02-03.at.10.07.03.AM.mov

@astrofrog
Copy link
Collaborator

Great! I will go ahead and do a glue-jupyter release when I am at my computer next 😊

@rosteen rosteen modified the milestones: 3.3, 3.4 Feb 9, 2023
@javerbukh
Copy link
Contributor Author

Superseded by #2022 .

@javerbukh javerbukh closed this Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cubeviz documentation Explanation of code and concepts mosviz plugin Label for plugins common to multiple configurations specviz specviz2d
Projects
None yet
5 participants