Skip to content

Instantly share code, notes, and snippets.

@cdeil
Created August 31, 2018 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdeil/83b3807db856f6e1a438355365190370 to your computer and use it in GitHub Desktop.
Save cdeil/83b3807db856f6e1a438355365190370 to your computer and use it in GitHub Desktop.
_____________________________________________________________________________________ test_compute_lima_on_off_image ______________________________________________________________________________________
cls = <class 'astropy.units.format.generic.Generic'>, s = 'Count', debug = False
@classmethod
def _do_parse(cls, s, debug=False):
try:
# This is a short circuit for the case where the string
# is just a single unit name
> return cls._parse_unit(s, detailed_exception=False)
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py:482:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'astropy.units.format.generic.Generic'>, s = 'Count', detailed_exception = False
@classmethod
def _parse_unit(cls, s, detailed_exception=True):
registry = core.get_current_unit_registry().registry
if s == '%':
return registry['percent']
elif s in registry:
return registry[s]
if detailed_exception:
raise ValueError(
'{0} is not a valid unit. {1}'.format(
s, did_you_mean(s, registry)))
else:
> raise ValueError()
E ValueError
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py:462: ValueError
During handling of the above exception, another exception occurred:
cls = <class 'astropy.units.format.generic.Generic'>, t = LexToken(UNIT,'Count',1,0)
@classmethod
def _get_unit(cls, t):
try:
> return cls._parse_unit(t.value)
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py:443:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'astropy.units.format.generic.Generic'>, s = 'Count', detailed_exception = True
@classmethod
def _parse_unit(cls, s, detailed_exception=True):
registry = core.get_current_unit_registry().registry
if s == '%':
return registry['percent']
elif s in registry:
return registry[s]
if detailed_exception:
raise ValueError(
'{0} is not a valid unit. {1}'.format(
> s, did_you_mean(s, registry)))
E ValueError: Count is not a valid unit. Did you mean Ycount, Zcount, count, ycount or zcount?
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py:460: ValueError
During handling of the above exception, another exception occurred:
self = <class 'astropy.units.core.Unit'>, s = 'Count', represents = None, format = <class 'astropy.units.format.generic.Generic'>, namespace = None, doc = None, parse_strict = 'raise'
def __call__(self, s, represents=None, format=None, namespace=None,
doc=None, parse_strict='raise'):
# Short-circuit if we're already a unit
if hasattr(s, '_get_physical_type_id'):
return s
# turn possible Quantity input for s or represents into a Unit
from .quantity import Quantity
if isinstance(represents, Quantity):
if is_effectively_unity(represents.value):
represents = represents.unit
else:
# cannot use _error_check=False: scale may be effectively unity
represents = CompositeUnit(represents.value *
represents.unit.scale,
bases=represents.unit.bases,
powers=represents.unit.powers)
if isinstance(s, Quantity):
if is_effectively_unity(s.value):
s = s.unit
else:
s = CompositeUnit(s.value * s.unit.scale,
bases=s.unit.bases,
powers=s.unit.powers)
# now decide what we really need to do; define derived Unit?
if isinstance(represents, UnitBase):
# This has the effect of calling the real __new__ and
# __init__ on the Unit class.
return super().__call__(
s, represents, format=format, namespace=namespace, doc=doc)
# or interpret a Quantity (now became unit), string or number?
if isinstance(s, UnitBase):
return s
elif isinstance(s, (bytes, str)):
if len(s.strip()) == 0:
# Return the NULL unit
return dimensionless_unscaled
if format is None:
format = unit_format.Generic
f = unit_format.get_format(format)
if isinstance(s, bytes):
s = s.decode('ascii')
try:
> return f.parse(s)
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/core.py:1784:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'astropy.units.format.generic.Generic'>, s = 'Count', debug = False
@classmethod
def parse(cls, s, debug=False):
if not isinstance(s, str):
s = s.decode('ascii')
> result = cls._do_parse(s, debug=debug)
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py:469:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'astropy.units.format.generic.Generic'>, s = 'Count', debug = False
@classmethod
def _do_parse(cls, s, debug=False):
try:
# This is a short circuit for the case where the string
# is just a single unit name
return cls._parse_unit(s, detailed_exception=False)
except ValueError as e:
try:
> return cls._parser.parse(s, lexer=cls._lexer, debug=debug)
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py:485:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.extern.ply.yacc.LRParser object at 0x10b20e748>, input = 'Count', lexer = <astropy.extern.ply.lex.Lexer object at 0x10b20e550>, debug = False, tracking = False, tokenfunc = None
def parse(self, input=None, lexer=None, debug=False, tracking=False, tokenfunc=None):
if debug or yaccdevel:
if isinstance(debug, int):
debug = PlyLogger(sys.stderr)
return self.parsedebug(input, lexer, debug, tracking, tokenfunc)
elif tracking:
return self.parseopt(input, lexer, debug, tracking, tokenfunc)
else:
> return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/extern/ply/yacc.py:331:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.extern.ply.yacc.LRParser object at 0x10b20e748>, input = 'Count', lexer = <astropy.extern.ply.lex.Lexer object at 0x10b20e550>, debug = False, tracking = False, tokenfunc = None
def parseopt_notrack(self, input=None, lexer=None, debug=False, tracking=False, tokenfunc=None):
#--! parseopt-notrack-start
lookahead = None # Current lookahead symbol
lookaheadstack = [] # Stack of lookahead symbols
actions = self.action # Local reference to action table (to avoid lookup on self.)
goto = self.goto # Local reference to goto table (to avoid lookup on self.)
prod = self.productions # Local reference to production list (to avoid lookup on self.)
defaulted_states = self.defaulted_states # Local reference to defaulted states
pslice = YaccProduction(None) # Production object passed to grammar rules
errorcount = 0 # Used during error recovery
# If no lexer was given, we will try to use the lex module
if not lexer:
from . import lex
lexer = lex.lexer
# Set up the lexer and parser objects on pslice
pslice.lexer = lexer
pslice.parser = self
# If input was supplied, pass to lexer
if input is not None:
lexer.input(input)
if tokenfunc is None:
# Tokenize function
get_token = lexer.token
else:
get_token = tokenfunc
# Set the parser() token method (sometimes used in error recovery)
self.token = get_token
# Set up the state and symbol stacks
statestack = [] # Stack of parsing states
self.statestack = statestack
symstack = [] # Stack of grammar symbols
self.symstack = symstack
pslice.stack = symstack # Put in the production
errtoken = None # Err token
# The start state is assumed to be (0,$end)
statestack.append(0)
sym = YaccSymbol()
sym.type = '$end'
symstack.append(sym)
state = 0
while True:
# Get the next symbol on the input. If a lookahead symbol
# is already set, we just use that. Otherwise, we'll pull
# the next token off of the lookaheadstack or from the lexer
if state not in defaulted_states:
if not lookahead:
if not lookaheadstack:
> lookahead = get_token() # Get the next token
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/extern/ply/yacc.py:1061:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <astropy.extern.ply.lex.Lexer object at 0x10b20e550>
def token(self):
# Make local copies of frequently referenced attributes
lexpos = self.lexpos
lexlen = self.lexlen
lexignore = self.lexignore
lexdata = self.lexdata
while lexpos < lexlen:
# This code provides some short-circuit code for whitespace, tabs, and other ignored characters
if lexdata[lexpos] in lexignore:
lexpos += 1
continue
# Look for a regular expression match
for lexre, lexindexfunc in self.lexre:
m = lexre.match(lexdata, lexpos)
if not m:
continue
# Create a token for return
tok = LexToken()
tok.value = m.group()
tok.lineno = self.lineno
tok.lexpos = lexpos
i = m.lastindex
func, tok.type = lexindexfunc[i]
if not func:
# If no token type was set, it's an ignored token
if tok.type:
self.lexpos = m.end()
return tok
else:
lexpos = m.end()
break
lexpos = m.end()
# If token is processed by a function, call it
tok.lexer = self # Set additional attributes useful in token rules
self.lexmatch = m
self.lexpos = lexpos
> newtok = func(tok)
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/extern/ply/lex.py:350:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
t = LexToken(UNIT,'Count',1,0)
def t_UNIT(t):
r"%|([YZEPTGMkhdcmunpfazy]?'((?!\d)\w)+')|((?!\d)\w)+"
> t.value = cls._get_unit(t)
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py:151:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'astropy.units.format.generic.Generic'>, t = LexToken(UNIT,'Count',1,0)
@classmethod
def _get_unit(cls, t):
try:
return cls._parse_unit(t.value)
except ValueError as e:
raise ValueError(
"At col {0}, {1}".format(
> t.lexpos, str(e)))
E ValueError: At col 0, Count is not a valid unit. Did you mean Ycount, Zcount, count, ycount or zcount?
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py:447: ValueError
During handling of the above exception, another exception occurred:
@requires_dependency('scipy')
@requires_data('gammapy-extra')
def test_compute_lima_on_off_image():
"""
Test Li & Ma image with snippet from the H.E.S.S. survey data.
"""
filename = '$GAMMAPY_EXTRA/test_datasets/unbundled/hess/survey/hess_survey_snippet.fits.gz'
> n_on = Map.read(filename, hdu='ON')
gammapy/detect/tests/test_lima.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
gammapy/maps/base.py:196: in read
return Map.from_hdulist(hdulist, hdu, hdu_bands, map_type)
gammapy/maps/base.py:245: in from_hdulist
return cls_out.from_hdulist(hdulist, hdu=hdu, hdu_bands=hdu_bands)
gammapy/maps/wcsmap.py:143: in from_hdulist
return cls.from_hdu(hdu, hdu_bands)
gammapy/maps/wcsnd.py:108: in from_hdu
map_out = cls(geom, meta=meta, unit=unit)
gammapy/maps/wcsnd.py:52: in __init__
super(WcsNDMap, self).__init__(geom, data, meta, unit)
gammapy/maps/base.py:46: in __init__
self.unit = unit
gammapy/maps/base.py:100: in unit
self._unit = u.Unit(val)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <class 'astropy.units.core.Unit'>, s = 'Count', represents = None, format = <class 'astropy.units.format.generic.Generic'>, namespace = None, doc = None, parse_strict = 'raise'
def __call__(self, s, represents=None, format=None, namespace=None,
doc=None, parse_strict='raise'):
# Short-circuit if we're already a unit
if hasattr(s, '_get_physical_type_id'):
return s
# turn possible Quantity input for s or represents into a Unit
from .quantity import Quantity
if isinstance(represents, Quantity):
if is_effectively_unity(represents.value):
represents = represents.unit
else:
# cannot use _error_check=False: scale may be effectively unity
represents = CompositeUnit(represents.value *
represents.unit.scale,
bases=represents.unit.bases,
powers=represents.unit.powers)
if isinstance(s, Quantity):
if is_effectively_unity(s.value):
s = s.unit
else:
s = CompositeUnit(s.value * s.unit.scale,
bases=s.unit.bases,
powers=s.unit.powers)
# now decide what we really need to do; define derived Unit?
if isinstance(represents, UnitBase):
# This has the effect of calling the real __new__ and
# __init__ on the Unit class.
return super().__call__(
s, represents, format=format, namespace=namespace, doc=doc)
# or interpret a Quantity (now became unit), string or number?
if isinstance(s, UnitBase):
return s
elif isinstance(s, (bytes, str)):
if len(s.strip()) == 0:
# Return the NULL unit
return dimensionless_unscaled
if format is None:
format = unit_format.Generic
f = unit_format.get_format(format)
if isinstance(s, bytes):
s = s.decode('ascii')
try:
return f.parse(s)
except Exception as e:
if parse_strict == 'silent':
pass
else:
# Deliberately not issubclass here. Subclasses
# should use their name.
if f is not unit_format.Generic:
format_clause = f.name + ' '
else:
format_clause = ''
msg = ("'{0}' did not parse as {1}unit: {2}"
.format(s, format_clause, str(e)))
if parse_strict == 'raise':
> raise ValueError(msg)
E ValueError: 'Count' did not parse as unit: At col 0, Count is not a valid unit. Did you mean Ycount, Zcount, count, ycount or zcount?
../../../software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/core.py:1798: ValueError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment