Skip to content

Commit

Permalink
Merge pull request #98 from duncanmmacleod/python3
Browse files Browse the repository at this point in the history
Updated syntax for python3
  • Loading branch information
Alex L. Urban committed Aug 1, 2018
2 parents ba68807 + cbeaeb8 commit 4d8b6a6
Show file tree
Hide file tree
Showing 24 changed files with 35 additions and 79 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ env:
- PIP_FLAGS="--quiet --pre"
- PIP_FLAGS="--quiet"

matrix:
allow_failures:
- python: '3.5'
- python: '3.6'
fast_finish: true

before_install:
- pip install -q --upgrade pip
- pip install ${PIP_FLAGS} -r requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion bin/gwdetchar-lasso-correlation
Original file line number Diff line number Diff line change
Expand Up @@ -1141,4 +1141,4 @@ page.div.close() # container
with open('index.html', 'w') as f:
print(str(page), file=f)

print ("-- Process Completed")
print("-- Process Completed")
8 changes: 2 additions & 6 deletions bin/gwdetchar-omega
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ import re
import sys
import ast
import warnings
try:
# Python 3.x
from io import StringIO
except ImportError:
# Python 2.x
from StringIO import StringIO

from six.moves import StringIO

import numpy
from numpy import fft as npfft
Expand Down
2 changes: 1 addition & 1 deletion bin/gwdetchar-slow-correlation
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,4 @@ page.div.close() # container
with open('index.html', 'w') as f:
print(str(page), file=f)

print ("-- Process Completed")
print("-- Process Completed")
3 changes: 2 additions & 1 deletion bin/gwdetchar-software-saturations
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import re
import subprocess
import sys
from multiprocessing import (Pool, cpu_count)
from StringIO import StringIO

from six.moves import StringIO

from matplotlib import use
use('agg')
Expand Down
6 changes: 1 addition & 5 deletions gwdetchar/cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
"""Utilities for accessing information from CDS
"""

import re
try:
from urllib import request
except ImportError:
import urllib2 as request
from six.moves.urllib import request

RTDCUID_URL = (
'https://daqsvn.ligo-la.caltech.edu/websvn/filedetails.php?'
Expand Down
1 change: 0 additions & 1 deletion gwdetchar/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""

import argparse
import os

from gwpy.time import to_gps

Expand Down
5 changes: 2 additions & 3 deletions gwdetchar/daq.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def ligo_model_overflow_channels(dcuid, ifo=None, frametype=None, gpstime=None,
"""
"""
# FIXME: write a docstring
from lalframe.utils import get_channels

ifo = ifo or const.IFO
if ifo is None:
Expand All @@ -137,10 +136,10 @@ def ligo_model_overflow_channels(dcuid, ifo=None, frametype=None, gpstime=None,
_CHANNELS[framefile] = get_channel_names(framefile)
allchannels = _CHANNELS[framefile]
if accum:
regex = re.compile('%s:FEC-%d_(ADC|DAC)_OVERFLOW_ACC_\d+_\d+\Z'
regex = re.compile(r'%s:FEC-%d_(ADC|DAC)_OVERFLOW_ACC_\d+_\d+\Z'
% (ifo, dcuid))
else:
regex = re.compile('%s:FEC-%d_(ADC|DAC)_OVERFLOW_\d+_\d+\Z'
regex = re.compile(r'%s:FEC-%d_(ADC|DAC)_OVERFLOW_\d+_\d+\Z'
% (ifo, dcuid))
return natural_sort(filter(regex.match, allchannels))

Expand Down
1 change: 0 additions & 1 deletion gwdetchar/io/datafind.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def write_omega_cache(cache, fobj):
wcache = {}
for e in cache:
dir_ = os.path.split(e.path)[0]
lfn = os.path.basename(e.path)
if dir_ in wcache:
l = wcache[dir_]
if l[2] > int(e.segment[0]):
Expand Down
3 changes: 2 additions & 1 deletion gwdetchar/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"""

import os
from StringIO import StringIO

from six.moves import StringIO

from glue import markup

Expand Down
6 changes: 3 additions & 3 deletions gwdetchar/io/ligolw.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def new_table(tab, *args, **kwargs):
def sngl_burst_from_times(times, **params):
"""Create a `SnglBurstTable` from an array of times
"""
columns = set(params.keys() + ['peak_time', 'peak_time_ns', 'event_id'])
columns = set(params.keys()) | {'peak_time', 'peak_time_ns', 'event_id'}
table = new_table('sngl_burst', columns=list(columns))
get_next_id = table.get_next_id
RowType = table.RowType
Expand All @@ -62,7 +62,7 @@ def sngl_burst_from_times(times, **params):
row = RowType()
row.event_id = get_next_id()
row.set_peak(LIGOTimeGPS(t))
for key, val in params.iteritems():
for key, val in params.items():
setattr(row, key, val)
append(row)
return table
Expand All @@ -80,7 +80,7 @@ def sngl_burst_from_segments(segs, **params):
row.event_id = next_id()
row.set_period(seg)
row.set_peak(LIGOTimeGPS(seg[0] + abs(seg)/2.))
for key, val in params.iteritems():
for key, val in params.items():
setattr(row, key, val)
append(row)
return table
Expand Down
2 changes: 0 additions & 2 deletions gwdetchar/omega/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
import os
import sys
import datetime
import warnings
import subprocess
from functools import wraps
from getpass import getuser
from pytz import timezone

from glue import markup
from gwpy.time import tconvert
Expand Down
8 changes: 1 addition & 7 deletions gwdetchar/omega/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@

from __future__ import division

import os.path
import warnings

from matplotlib import cm
from matplotlib import rcParams
from matplotlib.colors import LogNorm

from gwpy.plotter import (SpectrogramPlot,
TimeSeriesPlot, Plot)
from gwpy.plotter.colors import GW_OBSERVATORY_COLORS

__author__ = 'Alex Urban <alexander.urban@ligo.org>'
Expand Down Expand Up @@ -77,7 +71,7 @@ def omega_plot(series, gps, span, channel, colormap='viridis', clim=None,
else:
ax.set_xlabel('Time [seconds]')
# set y-axis properties
chan = channel.replace('_', '\_')
chan = channel.replace('_', r'\_')
if (qscan or eventgram):
ax.set_yscale('log')
ax.set_title('%s at %.3f with $Q=%.1f$' % (chan, gps, series.q),
Expand Down
1 change: 0 additions & 1 deletion gwdetchar/omega/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from __future__ import print_function

import re
import os
import subprocess
import sys
Expand Down
6 changes: 3 additions & 3 deletions gwdetchar/saturation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

__author__ = 'Duncan Macleod <duncan.macleod@ligo.org>'

re_limit = re.compile('_LIMIT\Z')
re_limen = re.compile('_LIMEN\Z')
re_swstat = re.compile('_SWSTAT\Z')
re_limit = re.compile(r'_LIMIT\Z')
re_limen = re.compile(r'_LIMEN\Z')
re_swstat = re.compile(r'_SWSTAT\Z')
re_software = re.compile(
'(%s)' % '|'.join([re_limit.pattern, re_limen.pattern, re_swstat.pattern]))

Expand Down
2 changes: 0 additions & 2 deletions gwdetchar/scattering.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import numpy

from . import const

__author__ = 'Duncan Macleod <duncan.macleod@ligo.org>'

OPTIC_MOTION_CHANNELS = {
Expand Down
27 changes: 0 additions & 27 deletions gwdetchar/tests/common.py

This file was deleted.

2 changes: 2 additions & 0 deletions gwdetchar/tests/test_cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@


def mock_request(output):
if isinstance(output, str):
output = output.encode('utf-8')
return mock.patch('gwdetchar.cds.request.urlopen',
return_value=BytesIO(output))

Expand Down
6 changes: 5 additions & 1 deletion gwdetchar/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"""

import argparse
try:
from importlib import reload
except ImportError: # python < 3
reload = reload

import pytest

Expand Down Expand Up @@ -58,7 +62,7 @@ def test_add_version_option(parser, inv, outv):
@pytest.mark.parametrize('ifo', (_const.IFO, None))
def add_ifo_option(parser, const, ifo):
const.IFO == ifo
act = parser.add_ifo_option()
parser.add_ifo_option()
args = parser.parse_args([])
assert args.ifo == ifo
if ifo is None:
Expand Down
8 changes: 6 additions & 2 deletions gwdetchar/tests/test_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
"""Test suite for `gwdetchar.const`
"""

import argparse
import os

try:
from importlib import reload
except ImportError: # python < 3
reload = reload

import pytest

from .. import (cli, const as _const)
from .. import const as _const

_DEFAULT_ENV = os.environ.copy()

Expand Down
2 changes: 0 additions & 2 deletions gwdetchar/tests/test_io_ligolw.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"""Tests for `gwdetchar.io.ligolw`
"""

import pytest

import numpy
from numpy.testing import (assert_array_equal, assert_allclose)

Expand Down
5 changes: 2 additions & 3 deletions gwdetchar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import re

from gwpy.io.kerberos import which

__author__ = 'Duncan Macleod <duncan.macleod@ligo.org>'


Expand All @@ -45,7 +43,8 @@ def natural_sort(l, key=str):
sorted : `list`
a sorted version of the input list
"""
k = key and map(key, l) or l
l = list(l)
k = list(map(key, l)) if key else l
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [convert(c) for c in
re.split('([0-9]+)', k[l.index(key)])]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
six
numpy >= 1.10
scipy >= 0.16
matplotlib >= 1.4.1
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'pytest-runner',
]
install_requires = [
'six',
'numpy>=1.10',
'scipy>=0.16',
'matplotlib>=1.4.1',
Expand Down

0 comments on commit 4d8b6a6

Please sign in to comment.