Skip to content

Commit

Permalink
check for valid catalog file
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Oct 7, 2022
1 parent 0173e1a commit c3bf2d8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
nitpick_ignore.append((dtype, target))

# Extra intersphinx in addition to what is already in sphinx-astropy
intersphinx_mapping['astropy'] = ('https://docs.astropy.org/en/stable/', None)
intersphinx_mapping['glue'] = ('http://docs.glueviz.org/en/stable/', None)
intersphinx_mapping['glue_jupyter'] = ('https://glue-jupyter.readthedocs.io/en/stable/', None)
intersphinx_mapping['regions'] = ('https://astropy-regions.readthedocs.io/en/stable/', None)
Expand Down
4 changes: 4 additions & 0 deletions docs/imviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ catalog dropdown menu.
This plugin is still under active development. As a result, the search only uses the SDSS DR17 catalog
and works best when you only have a single image loaded in a viewer.

To load a catalog from an ecsv file, choose "From File..." and choose a valid file. The file must be able
to be parsed by `astropy.table.Table.read` and contain a column labeled 'sky_centroid'. Clicking
:guilabel:`SEARCH` will show markers for any entry within the filtered zoom window.

If you have multiple viewers open, you will see another dropdown menu to select the active
viewer.

Expand Down
29 changes: 24 additions & 5 deletions jdaviz/configs/imviz/plugins/catalogs/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Catalogs(PluginTemplateMixin, ViewerSelectMixin):
catalog_items = List([]).tag(sync=True)
catalog_selected = Unicode("").tag(sync=True)
from_file = Unicode().tag(sync=True)
valid_path = Bool(True).tag(sync=True)
from_file_message = Unicode().tag(sync=True)
results_available = Bool(False).tag(sync=True)
number_of_results = Int(0).tag(sync=True)

Expand All @@ -48,14 +48,31 @@ def __init__(self, *args, **kwargs):
self._file_upload = FileChooser(start_path)
self.components = {'g-file-import': self._file_upload}
self._file_upload.observe(self._on_file_path_changed, names='file_path')
self._cached_table_from_file = {}

def _on_file_path_changed(self, event):
self.from_file_message = 'Checking if file is valid'
if (self._file_upload.file_path is not None
and not os.path.exists(self._file_upload.file_path)
or not os.path.isfile(self._file_upload.file_path)):
self.valid_path = False
else:
self.valid_path = True
self.from_file_message = 'File path does not exist'
return

try:
table = QTable.read(self._file_upload.file_path)
except Exception:
self.from_file_message = 'Could not parse file with astropy.table.QTable.read'
return

if 'sky_centroid' not in table.keys():
self.from_file_message = 'Table does not contain required sky_centroid column'
return

# since we loaded the file already to check if its valid, we might as well cache the table
# so we don't have to re-load it when clicking search. We'll only keep the latest entry
# though, but store in a dict so we can catch if the file path was changed from the API
self._cached_table_from_file = {self._file_upload.file_path: table}
self.from_file_message = ''

@observe('from_file')
def _from_file_changed(self, event):
Expand Down Expand Up @@ -121,7 +138,9 @@ def search(self):
unit='deg')

elif self.catalog_selected == 'From File...':
table = QTable.read(self.from_file)
# all exceptions when going through the UI should have prevented setting this path
# but this exceptions might be raised here if setting from_file from the UI
table = self._cached_table_from_file.get(self.from_file, QTable.read(self.from_file))
skycoord_table = table['sky_centroid']

else:
Expand Down
8 changes: 7 additions & 1 deletion jdaviz/configs/imviz/plugins/catalogs/catalogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@
<g-file-import id="file-uploader"></g-file-import>
</v-col>
</v-row>
<v-row v-if="from_file_message.length > 0" :style='"color: red"'>
{{from_file_message}}
</v-row>
<v-row v-else>
Valid catalog file
</v-row>
</v-container>
</v-card-text>

<v-card-actions>
<div class="flex-grow-1"></div>
<v-btn color="primary" text @click="catalog_selected = catalog_items[0].label">Cancel</v-btn>
<v-btn color="primary" text @click="set_file_from_dialog" :disabled="!valid_path">Select</v-btn>
<v-btn color="primary" text @click="set_file_from_dialog" :disabled="from_file_message.length > 0">Select</v-btn>
</v-card-actions>

</v-card>
Expand Down

0 comments on commit c3bf2d8

Please sign in to comment.