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: Attempt to package jdaviz in cx_Freeze #1936

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ New Features

- Model fitting plugin can optionally expose the residuals as an additional data collection entry.
[#1864]
- CLI launchers no longer require data to be specified [#1890]

- Added direct launchers for each config (e.g. ``specviz``) [#1890]

Cubeviz
^^^^^^^
Expand Down
51 changes: 42 additions & 9 deletions jdaviz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
CONFIGS_DIR = os.path.join(os.path.dirname(__file__), 'configs')


def main(filename, layout='default', instrument=None, browser='default',
def main(filename='', layout='default', instrument='', browser='default',
theme='light', verbosity='warning', history_verbosity='info',
hotreload=False):
"""
Start a Jdaviz application instance with data loaded from FILENAME.

Parameters
----------
filename : str
filename : str, optional
The path to the file to be loaded into the Jdaviz application.
layout : str, optional
Optional specification for which configuration to use on startup.
Expand All @@ -49,8 +49,11 @@ def main(filename, layout='default', instrument=None, browser='default',
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

# Support comma-separate file list
filepath = ','.join([str(pathlib.Path(f).absolute()).replace('\\', '/')
for f in filename.split(',')])
if filename:
filepath = ','.join([str(pathlib.Path(f).absolute()).replace('\\', '/')
for f in filename.split(',')])
else:
filepath = ''

with open(os.path.join(CONFIGS_DIR, layout, layout + '.ipynb')) as f:
notebook_template = f.read()
Expand Down Expand Up @@ -85,15 +88,20 @@ def main(filename, layout='default', instrument=None, browser='default',
os.chdir(start_dir)


def _main():
def _main(config=None):
import argparse
import sys

parser = argparse.ArgumentParser(description='Start a Jdaviz application instance with data '
'loaded from FILENAME.')
parser.add_argument('layout', choices=['cubeviz', 'specviz', 'specviz2d', 'mosviz', 'imviz'],
help='Configuration to use.')
parser.add_argument('filename', type=str,
filename_nargs = '?'
if config is None:
parser.add_argument('layout', choices=['cubeviz', 'specviz', 'specviz2d',
'mosviz', 'imviz'],
help='Configuration to use.')
if (config == "mosviz") or ("mosviz" in sys.argv):
filename_nargs = 1
parser.add_argument('filename', type=str, nargs=filename_nargs, default=None,
help='The path to the file to be loaded into the Jdaviz application.')
parser.add_argument('--instrument', type=str, default='nirspec',
help='Manually specifies which instrument parser to use, for Mosviz')
Expand All @@ -115,6 +123,31 @@ def _main():
parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}')
args = parser.parse_args()

main(args.filename, layout=args.layout, instrument=args.instrument, browser=args.browser,
if config is None:
layout = args.layout
else:
layout = config

main(filename=args.filename, layout=layout, instrument=args.instrument, browser=args.browser,
theme=args.theme, verbosity=args.verbosity, history_verbosity=args.history_verbosity,
hotreload=args.hotreload)


def _specviz():
_main(config='specviz')


def _specviz2d():
_main(config='specviz2d')


def _imviz():
_main(config='imviz')


def _cubeviz():
_main(config='cubeviz')


def _mosviz():
_main(config='mosviz')
4 changes: 3 additions & 1 deletion jdaviz/configs/cubeviz/cubeviz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"from jdaviz import Cubeviz\n",
"\n",
"cubeviz = Cubeviz(verbosity='JDAVIZ_VERBOSITY', history_verbosity='JDAVIZ_HISTORY_VERBOSITY')\n",
"cubeviz.load_data('DATA_FILENAME')\n",
"data_path = 'DATA_FILENAME'\n",
"if data_path:\n",
" cubeviz.load_data('DATA_FILENAME')\n",
"cubeviz.app"
]
}
Expand Down
40 changes: 5 additions & 35 deletions jdaviz/configs/default/default.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,19 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: FITSFixedWarning: PLATEID = 7495 / Current plate \n",
"a string value was expected. [astropy.wcs.wcs]\n",
"WARNING:astropy:FITSFixedWarning: PLATEID = 7495 / Current plate \n",
"a string value was expected.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'label': 'Image 2D', 'cls': <class 'glue_jupyter.bqplot.image.viewer.BqplotImageView'>}\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "49d5f6d8c5a24df690f53c8c2bd57cff",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Application(components={'g-viewer-area': ViewerArea(), 'g-default-toolbar': DefaultToolbar(components={'g-subs…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"from jdaviz.app import Application\n",
"app = Application(configuration='default')\n",
"app.verbosity = 'JDAVIZ_VERBOSITY'\n",
"app.history_verbosity = 'JDAVIZ_HISTORY_VERBOSITY'\n",
"app.load_data('DATA_FILENAME')\n",
"data_path = 'DATA_FILENAME'\n",
"if data_path:\n",
" app.load_data('DATA_FILENAME')\n",
"app"
]
},
Expand Down
4 changes: 3 additions & 1 deletion jdaviz/configs/imviz/imviz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"from jdaviz import Imviz\n",
"\n",
"imviz = Imviz(verbosity='JDAVIZ_VERBOSITY', history_verbosity='JDAVIZ_HISTORY_VERBOSITY')\n",
"imviz.load_data('DATA_FILENAME')\n",
"data_path = 'DATA_FILENAME'\n",
"if data_path:\n",
" imviz.load_data('DATA_FILENAME')\n",
"imviz.app"
]
}
Expand Down
6 changes: 4 additions & 2 deletions jdaviz/configs/mosviz/mosviz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
"data_path = pathlib.Path('DATA_FILENAME')\n",
"\n",
"mosviz = Mosviz(verbosity='JDAVIZ_VERBOSITY', history_verbosity='JDAVIZ_HISTORY_VERBOSITY')\n",
"mosviz.load_data(directory=data_path, instrument='INSTRUMENT')\n",
"data_path = 'DATA_FILENAME'\n",
"if data_path:\n",
" mosviz.load_data(directory=data_path, instrument='INSTRUMENT')\n",
"mosviz.app"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
4 changes: 3 additions & 1 deletion jdaviz/configs/specviz/specviz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"from jdaviz import Specviz\n",
"\n",
"specviz = Specviz(verbosity='JDAVIZ_VERBOSITY', history_verbosity='JDAVIZ_HISTORY_VERBOSITY')\n",
"specviz.load_data('DATA_FILENAME')\n",
"data_path = 'DATA_FILENAME'\n",
"if data_path:\n",
" specviz.load_data(data_path)\n",
"specviz.app"
]
}
Expand Down
4 changes: 3 additions & 1 deletion jdaviz/configs/specviz2d/specviz2d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"from jdaviz import Specviz2d\n",
"\n",
"specviz = Specviz2d(verbosity='JDAVIZ_VERBOSITY', history_verbosity='JDAVIZ_HISTORY_VERBOSITY')\n",
"specviz.load_data('DATA_FILENAME')\n",
"data_path = 'DATA_FILENAME'\n",
"if data_path:\n",
" specviz.load_data('DATA_FILENAME')\n",
"specviz.app"
]
}
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ jdaviz.configs.imviz.tests = data/*
[options.entry_points]
console_scripts =
jdaviz = jdaviz.cli:_main
specviz = jdaviz.cli:_specviz
specviz2d = jdaviz.cli:_specviz2d
imviz = jdaviz.cli:_imviz
cubeviz = jdaviz.cli:_cubeviz
mosviz = jdaviz.cli:_mosviz
gui_scripts =
jdaviz_plugins =
default = jdaviz.configs.default
Expand Down
24 changes: 24 additions & 0 deletions setup_cxfreeze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
build_options = {'include_files': [("E:\\STScI\\gitRepos\\jdaviz\\envhacking\\Lib\\site-packages\\astropy", "lib\\astropy"),
("E:\\STScI\\gitRepos\\jdaviz\\envhacking\\Lib\\site-packages\\scipy", "lib\\scipy"),
("E:\\STScI\\gitRepos\\jdaviz\\envhacking\\Lib\\site-packages\\gwcs", "lib\\gwcs"),
("E:\\STScI\\gitRepos\\jdaviz\\jdaviz", "lib\\jdaviz")
],
'excludes': []}

base = 'console'

executables = [
Executable('start_jdaviz.py', base=base)
]

setup(name='jdaviz',
version = '1.0',
description = '',
options = {'build_exe': build_options},
executables = executables)

#Manual copies: astropy, scipy, gwcs, jdaviz
3 changes: 3 additions & 0 deletions start_jdaviz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from jdaviz.cli import main

main()