Skip to content

Instantly share code, notes, and snippets.

from iteration_utilities import all_monotone
from itertools import tee
import operator
def is_sorted_by_alexandre(iterable, compare=operator.le):
a, b = tee(iterable)
next(b, None)
return all(map(compare, a, b))
import numpy as np
# =============================================================================
#
# Implementations
#
# Wrapped inside functions so the benchmark fails during setup not completly
# if library with this version or Python2 doesn't support this
#
# =============================================================================
import numpy as np
a = np.arange(1000000, dtype=float).reshape(1000, 1000)
a[100, 100] = np.nan
%timeit np.nanmedian(a, axis=None)
%timeit np.ma.median(np.ma.masked_invalid(a), axis=None)
%timeit np.nanmedian(a, axis=0)
%timeit np.ma.median(np.ma.masked_invalid(a), axis=0)
%timeit np.nanmedian(a, axis=1)
================================== FAILURES ===================================
______________________ TestSDSSRemote.test_sdss_specobj _______________________
self = <astroquery.sdss.tests.test_sdss_remote.TestSDSSRemote object at 0x000001F802A543C8>
def test_sdss_specobj(self):
colnames = ['ra', 'dec', 'objid', 'run', 'rerun', 'camcol', 'field',
'z', 'plate', 'mjd', 'fiberID', 'specobjid', 'run2d',
'instrument']
dtypes = [float, float, int, int, int, int, int, float, int, int, int,
C:\-\astroquery>python setup.py test --remote-data
astroquery\sdss\setup_package.py:2: RuntimeWarning: Parent module 'astroquery.sdss' not found while handling absolute import
import os
running test
running build
running build_py
running egg_info
writing requirements to astroquery.egg-info\requires.txt
writing astroquery.egg-info\PKG-INFO
writing top-level names to astroquery.egg-info\top_level.txt
============================= test session starts =============================
platform win32 -- Python 2.7.11, pytest-2.8.3, py-1.4.30, pluggy-0.3.1
benchmark: 3.0.0 (defaults: timer=time.clock disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Running tests with astroquery version 0.3.3.dev3307.
Running tests in lib.win-amd64-2.7\astroquery docs.
Date: 2016-06-21T11:29:25
Platform: Windows-10-10.0.10586
[work] C:\Users\-\GIT\asv>python setup.py test
running test
running egg_info
writing asv.egg-info\PKG-INFO
writing top-level names to asv.egg-info\top_level.txt
writing requirements to asv.egg-info\requires.txt
writing dependency_links to asv.egg-info\dependency_links.txt
writing entry points to asv.egg-info\entry_points.txt
reading manifest file 'asv.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
[work] C:\Users\-\GIT\asv>python setup.py test
running test
running egg_info
writing requirements to asv.egg-info\requires.txt
writing top-level names to asv.egg-info\top_level.txt
writing entry points to asv.egg-info\entry_points.txt
writing asv.egg-info\PKG-INFO
writing dependency_links to asv.egg-info\dependency_links.txt
reading manifest file 'asv.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
@MSeifert04
MSeifert04 / bool.py
Last active March 12, 2016 03:58
bool evaluation
class Test(object):
def __init__(self, var):
self.var = var
def __bool__(self):
print 'called it.'
return bool(self.var)
a = Test(10)
import numpy as numpy
from astropy.io import fits
from scipy.ndimage.filters import uniform_filter
#Directory: /Users/UCL_Astronomy/Documents/UCL/PHASG199/M33_UVOT_sum/UVOTIMSUM/M33_sum_epoch1_um2_norm.img
with fits.open('...') as ima_norm_um2:
#Open UVOTIMSUM file once and close it after extracting the relevant values:
ima_norm_um2_hdr = ima_norm_um2[0].header
ima_norm_um2_data = ima_norm_um2[0].data
#Individual dimensions for number of x pixels and number of y pixels: