Skip to content

Commit 36e62c1

Browse files
committed
Merge pull request #626 from bsipocz/overall_code_cleanup
Overall code cleanup
2 parents 01e2d61 + 4786798 commit 36e62c1

File tree

26 files changed

+287
-569
lines changed

26 files changed

+287
-569
lines changed

astroquery/_astropy_init.py

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test(package=None, test_path=None, args=None, plugins=None,
116116
if not _ASTROPY_SETUP_:
117117
import os
118118
from warnings import warn
119-
from astropy import config
119+
import astropy.config.configuration as config
120120

121121
# add these here so we only need to cleanup the namespace at the end
122122
config_dir = None
@@ -126,52 +126,16 @@ def test(package=None, test_path=None, args=None, plugins=None,
126126
config_template = os.path.join(config_dir, __package__ + ".cfg")
127127
if os.path.isfile(config_template):
128128
try:
129-
config.configuration.update_default_config(
129+
config.update_default_config(
130130
__package__, config_dir, version=__version__)
131131
except TypeError as orig_error:
132132
try:
133-
config.configuration.update_default_config(
133+
config.update_default_config(
134134
__package__, config_dir)
135-
except config.configuration.ConfigurationDefaultMissingError as e:
135+
except config.ConfigurationDefaultMissingError as e:
136136
wmsg = (e.args[0] + " Cannot install default profile. If "
137137
"you are importing from source, this is expected.")
138-
warn(config.configuration.ConfigurationDefaultMissingWarning(wmsg))
138+
warn(config.ConfigurationDefaultMissingWarning(wmsg))
139139
del e
140140
except:
141141
raise orig_error
142-
143-
144-
# This is to monkey-patch around a config system bug in astropy 1.0.1.
145-
# REMOVEME: when astropy 1.0.1 support is no longer needed
146-
if not _ASTROPY_SETUP_:
147-
import astropy
148-
if astropy.__version__ == '1.0.1':
149-
from astropy.config import configuration
150-
151-
_existing_ConfigItem__init__ = configuration.ConfigItem.__init__
152-
153-
def _monkey_patch_1_0_1_ConfigItem__init__(
154-
self, defaultvalue='', description=None, cfgtype=None,
155-
module=None, aliases=None):
156-
if module is None:
157-
from astropy.utils import find_current_module
158-
module = find_current_module(2)
159-
if module is None:
160-
raise RuntimeError(
161-
"Cannot automatically determine get_config module, "
162-
"because it is not called from inside a valid module")
163-
else:
164-
module = module.__name__
165-
166-
return _existing_ConfigItem__init__(
167-
self,
168-
defaultvalue=defaultvalue,
169-
description=description,
170-
cfgtype=cfgtype,
171-
module=module,
172-
aliases=aliases)
173-
174-
# Don't apply the same monkey patch twice
175-
if (configuration.ConfigItem.__init__.__name__ !=
176-
'_monkey_patch_1_0_1_ConfigItem__init__'):
177-
configuration.ConfigItem.__init__ = _monkey_patch_1_0_1_ConfigItem__init__

astroquery/alma/core.py

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -306,26 +306,6 @@ def stage_data(self, uids):
306306
))
307307
tbl = self._json_summary_to_table(json_data, base_url=base_url)
308308

309-
# staging_root = BeautifulSoup(data_page.content)
310-
# downloadFileURL = staging_root.find('form').attrs['action']
311-
# data_list_url = os.path.split(downloadFileURL)[0]
312-
313-
# # Old version, unreliable: data_list_url = staging_submission.url
314-
# log.debug("Data list URL: {0}".format(data_list_url))
315-
# self._staging_log['data_list_url'] = data_list_url
316-
317-
# time.sleep(1)
318-
# data_list_page = self._request('GET', data_list_url, cache=True)
319-
# self._staging_log['data_list_page'] = data_list_page
320-
# data_list_page.raise_for_status()
321-
322-
# if 'Error' in data_list_page.text:
323-
# errormessage = staging_root.find(
324-
# 'div', id='errorContent').string.strip()
325-
# raise RemoteServiceError(errormessage)
326-
327-
# tbl = self._parse_staging_request_page(data_list_page)
328-
329309
return tbl
330310

331311
def _HEADER_data_size(self, files):
@@ -770,27 +750,6 @@ def _parse_staging_request_page(self, data_list_page):
770750

771751
root = BeautifulSoup(data_list_page.content, 'html5lib')
772752

773-
# for link in root.findAll('a'):
774-
# if 'script.sh' in link.text:
775-
# download_script_url = urljoin(self.dataarchive_url,
776-
# link['href'])
777-
# if 'download_script_url' not in locals():
778-
# raise RemoteServiceError("No download links were found.")
779-
780-
# download_script = self._request('GET', download_script_url,
781-
# cache=False)
782-
# download_script_target_urls = []
783-
# for line in download_script.text.split('\n'):
784-
# if line and line.split() and line.split()[0] == 'wget':
785-
# download_script_target_urls.append(line.split()[1].strip('"'))
786-
787-
# if len(download_script_target_urls) == 0:
788-
# raise RemoteServiceError("There was an error parsing the download"
789-
# " script; it is empty. "
790-
# "You can access the download script "
791-
# "directly from this URL: "
792-
# "{0}".format(download_script_url))
793-
794753
data_table = root.findAll('table', class_='list', id='report')[0]
795754
columns = {'uid': [], 'URL': [], 'size': []}
796755
for tr in data_table.findAll('tr'):
@@ -864,28 +823,6 @@ def _parse_staging_request_page(self, data_list_page):
864823
"Please include {0} in a bug report."
865824
.format(self._staging_log['data_list_url']))
866825

867-
# if len(download_script_target_urls) != len(columns['URL']):
868-
# log.warn("There was an error parsing the data staging page. "
869-
# "The results from the page and the download script "
870-
# "differ. You can access the download script directly "
871-
# "from this URL: {0}".format(download_script_url))
872-
# else:
873-
# bad_urls = []
874-
# for (rurl,url) in (zip(columns['URL'],
875-
# download_script_target_urls)):
876-
# if rurl == 'None_Found':
877-
# url_uid = os.path.split(url)[-1]
878-
# ind = np.where(np.array(columns['uid']) == url_uid)[0][0]
879-
# columns['URL'][ind] = url
880-
# elif rurl != url:
881-
# bad_urls.append((rurl, url))
882-
# if bad_urls:
883-
# log.warn("There were mismatches between the parsed URLs "
884-
# "from the staging page ({0}) and the download "
885-
# "script ({1})."
886-
# .format(self._staging_log['data_list_url'],
887-
# download_script_url))
888-
889826
tbl = Table([Column(name=k, data=v) for k, v in iteritems(columns)])
890827

891828
return tbl
@@ -966,50 +903,3 @@ def unique(seq):
966903
def filter_printable(s):
967904
""" extract printable characters from a string """
968905
return filter(lambda x: x in string.printable, s)
969-
970-
971-
def parse_frequency_support(frequency_support_str):
972-
"""
973-
ALMA "Frequency Support" strings have the form:
974-
975-
[100.63..101.57GHz,488.28kHz, XX YY] U
976-
[102.43..103.37GHz,488.28kHz, XX YY] U
977-
[112.74..113.68GHz,488.28kHz, XX YY] U
978-
[114.45..115.38GHz,488.28kHz, XX YY]
979-
980-
at least, as far as we have seen. The "U" is meant to be the Union symbol.
981-
This function will parse such a string into a list of pairs of astropy
982-
Quantities representing the frequency range. It will ignore the resolution
983-
and polarizations.
984-
"""
985-
supports = frequency_support_str.split("U")
986-
freq_ranges = [(float(sup[0]),
987-
float(sup[1].split(',')[0].strip(string.letters))) *
988-
u.Unit(sup[1].split(',')[0].strip(string.punctuation +
989-
string.digits))
990-
for i in supports for sup in [i.strip('[] ').split('..'), ]]
991-
992-
return freq_ranges
993-
994-
995-
def approximate_primary_beam_sizes(frequency_support_str,
996-
dish_diameter=12 * u.m, first_null=1.220):
997-
"""
998-
Using parse_frequency_support, determine the mean primary beam size in each
999-
observed band
1000-
1001-
Parameters
1002-
----------
1003-
frequency_support_str : str
1004-
The frequency support string, see `parse_frequency_support`
1005-
dish_diameter : `~astropy.units.Quantity`
1006-
Meter-equivalent unit. The diameter of the dish.
1007-
first_null : float
1008-
The position of the first null of an Airy. Used to compute resolution
1009-
as :math:`R = 1.22 \lambda/D`
1010-
"""
1011-
freq_ranges = parse_frequency_support(frequency_support_str)
1012-
beam_sizes = [(first_null * fr.mean().to(u.m, u.spectral()) /
1013-
(dish_diameter)).to(u.arcsec, u.dimensionless_angles())
1014-
for fr in freq_ranges]
1015-
return beam_sizes

astroquery/alma/utils.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ def pyregion_subset(region, data, mywcs):
3131

3232
shapelist = pyregion.ShapeList([region])
3333
if shapelist[0].coord_format not in ('physical', 'image'):
34-
# Requires astropy >0.4...
35-
# pixel_regions = shapelist.as_imagecoord(
36-
# self.wcs.celestial.to_header())
37-
# convert the regions to image (pixel) coordinates
3834
celhdr = mywcs.sub([wcs.WCSSUB_CELESTIAL]).to_header()
3935
pixel_regions = shapelist.as_imagecoord(celhdr)
4036
else:
@@ -81,12 +77,17 @@ def pyregion_subset(region, data, mywcs):
8177

8278
def parse_frequency_support(frequency_support_str):
8379
"""
84-
Given a "Frequency Support" string from ALMA queries, parse it into a set
85-
of frequency ranges
80+
ALMA "Frequency Support" strings have the form:
8681
87-
Example input:
82+
[100.63..101.57GHz,488.28kHz, XX YY] U
83+
[102.43..103.37GHz,488.28kHz, XX YY] U
84+
[112.74..113.68GHz,488.28kHz, XX YY] U
85+
[114.45..115.38GHz,488.28kHz, XX YY]
8886
89-
'[86.26..88.14GHz,976.56kHz, XX YY] U [88.15..90.03GHz,976.56kHz, XX YY] U [98.19..100.07GHz,976.56kHz, XX YY] U [100.15..102.03GHz,976.56kHz, XX YY]'
87+
at least, as far as we have seen. The "U" is meant to be the Union symbol.
88+
This function will parse such a string into a list of pairs of astropy
89+
Quantities representing the frequency range. It will ignore the resolution
90+
and polarizations.
9091
"""
9192
supports = str(frequency_support_str).split('U')
9293

@@ -98,14 +99,25 @@ def parse_frequency_support(frequency_support_str):
9899
return u.Quantity(freq_ranges)
99100

100101

101-
def approximate_primary_beam_sizes(frequency_support_str):
102+
def approximate_primary_beam_sizes(frequency_support_str,
103+
dish_diameter=12 * u.m, first_null=1.220):
102104
"""
103-
Given a frequency support string, return the approximate 12m array beam
104-
size using 1.22 lambda / D
105+
Using parse_frequency_support, determine the mean primary beam size in each
106+
observed band
107+
108+
Parameters
109+
----------
110+
frequency_support_str : str
111+
The frequency support string, see `parse_frequency_support`
112+
dish_diameter : `~astropy.units.Quantity`
113+
Meter-equivalent unit. The diameter of the dish.
114+
first_null : float
115+
The position of the first null of an Airy. Used to compute resolution
116+
as :math:`R = 1.22 \lambda/D`
105117
"""
106118
freq_ranges = parse_frequency_support(frequency_support_str)
107-
beam_sizes = [(1.22 * fr.mean().to(u.m, u.spectral()) /
108-
(12 * u.m)).to(u.arcsec, u.dimensionless_angles())
119+
beam_sizes = [(first_null * fr.mean().to(u.m, u.spectral()) /
120+
(dish_diameter)).to(u.arcsec, u.dimensionless_angles())
109121
for fr in freq_ranges]
110122
return u.Quantity(beam_sizes)
111123

@@ -118,8 +130,7 @@ def make_finder_chart(target, radius, save_prefix, service=SkyView.get_images,
118130
public_band_colors=('blue', 'cyan', 'green',
119131
'turquoise', 'teal'),
120132
integration_time_contour_levels=np.logspace(0, 5, base=2,
121-
num=6),
122-
):
133+
num=6)):
123134
"""
124135
Create a "finder chart" showing where ALMA has pointed in various bands,
125136
including different color coding for public/private data and each band.

astroquery/besancon/core.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ def get_besancon_model_file(self, filename, verbose=True, timeout=5.0):
118118
sys.stdout.write(u"\r")
119119
sys.stdout.flush()
120120
try:
121-
# U = requests.get(url,timeout=timeout,stream=True) TODO:
122-
# add timeout= keyword to get_readable_fileobj (when PR
123-
# https://github.com/astropy/astropy/pull/1258 is merged)
124-
with commons.get_readable_fileobj(url, cache=True) as f:
121+
with commons.get_readable_fileobj(url, remote_timeout=timeout,
122+
cache=True) as f:
125123
results = f.read()
126124
break
127125
except URLError:

astroquery/conftest.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import print_function
33
import os
44

5-
from .utils import turn_off_internet
65

76
# This is to figure out the astroquery version, rather than using Astropy's
87
from . import version
@@ -20,25 +19,6 @@
2019
except NameError:
2120
pass
2221

23-
24-
# pytest magic:
25-
# http://pytest.org/latest/plugins.html#_pytest.hookspec.pytest_configure
26-
# use pytest.set_trace() to interactively inspect config's features
27-
def pytest_configure(config):
28-
if config.getoption('remote_data'):
29-
pass
30-
else:
31-
turn_off_internet(verbose=config.option.verbose)
32-
33-
try:
34-
from astropy.tests.pytest_plugins import pytest_configure
35-
36-
pytest_configure(config)
37-
except ImportError:
38-
# assume astropy v<0.3
39-
pass
40-
41-
4222
# Add astropy to test header information and remove unused packages.
4323
# Pytest header customisation was introduced in astropy 1.0.
4424

0 commit comments

Comments
 (0)