Skip to content

Commit

Permalink
Suppress NoResultsWarning from astroquery.mast
Browse files Browse the repository at this point in the history
  • Loading branch information
troyraen committed Dec 5, 2024
1 parent 00ac891 commit 4b70220
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions spectroscopy/code_src/mast_functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import io
import os
import shutil
import warnings
from contextlib import redirect_stdout

import astropy.constants as const
import astropy.units as u
import astroquery.exceptions
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -96,8 +98,11 @@ def JWST_get_spec_helper(sample_table, search_radius_arcsec, datadir, verbose,

# Query results
search_coords = stab["coord"]
# [FIXME] Next code line raises a warning when stab['label'] == 'NGC3049'.
# 'WARNING: NoResultsWarning: Query returned no results. [astroquery.mast.discovery_portal]'
# If no results are found, this will raise a warning. We explicitly handle the no-results
# case below, so let's suppress the warning to avoid confusing notebook users.
warnings.filterwarnings("ignore", message='Query returned no results.',
category=astroquery.exceptions.NoResultsWarning,
module="astroquery.mast.discovery_portal")
query_results = Observations.query_criteria(
coordinates=search_coords, radius=search_radius_arcsec * u.arcsec,
dataproduct_type=["spectrum"], obs_collection=["JWST"], intentType="science",
Expand Down Expand Up @@ -313,8 +318,11 @@ def HST_get_spec(sample_table, search_radius_arcsec, datadir, verbose,

# Query results
search_coords = stab["coord"]
# [FIXME] Next code line raises a warning when stab['label'] == 'Arp220'.
# 'WARNING: NoResultsWarning: Query returned no results. [astroquery.mast.discovery_portal]'
# If no results are found, this will raise a warning. We explicitly handle the no-results
# case below, so let's suppress the warning to avoid confusing notebook users.
warnings.filterwarnings("ignore", message='Query returned no results.',
category=astroquery.exceptions.NoResultsWarning,
module="astroquery.mast.discovery_portal")
query_results = Observations.query_criteria(
coordinates=search_coords, radius=search_radius_arcsec * u.arcsec,
dataproduct_type=["spectrum"], obs_collection=["HST"], intentType="science",
Expand Down

0 comments on commit 4b70220

Please sign in to comment.