sot / chandra_aca

Chandra Aspect Camera Tools
https://sot.github.io/chandra_aca
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

required type for numba flickering? #97

Closed jeanconn closed 4 years ago

jeanconn commented 4 years ago

It looks like the numba default doesn't work with the floats coming out of get_dark_cal_image. Seems like flicker_update should warn on this or just do the (re)cast? I don't know if this is about endianness or what but...

In [122]: ccd_bgd = aca_dark.dark_cal.get_dark_cal_image('2019:001', t_ccd_ref=-
     ...: 8, aca_image=True)
     ...: 
     ...: 

In [123]: ccd_bgd.flicker_init(seed=1)

In [124]: ccd_bgd.flicker_update(4.0)
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-124-5e387588e49c> in <module>()
----> 1 ccd_bgd.flicker_update(4.0)

/proj/sot/ska3/flight/lib/python3.6/site-packages/chandra_aca/aca_image.py in flicker_update(self, dt, use_numba)
    436                                   self.flicker_cdfs,
    437                                   self.flicker_scale,
--> 438                                   self.flicker_mean_time)
    439             if self.test_idx > 0:
    440                 self.test_idx += 1

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/dispatcher.py in _compile_for_args(self, *args, **kws)
    328                                 for i, err in failed_args))
    329                 e.patch_message(msg)
--> 330             raise e
    331 
    332     def inspect_llvm(self, signature=None):

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/dispatcher.py in _compile_for_args(self, *args, **kws)
    305                 argtypes.append(self.typeof_pyval(a))
    306         try:
--> 307             return self.compile(tuple(argtypes))
    308         except errors.TypingError as e:
    309             # Intercept typing error that may be due to an argument

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/dispatcher.py in compile(self, sig)
    577 
    578                 self._cache_misses[sig] += 1
--> 579                 cres = self._compiler.compile(args, return_type)
    580                 self.add_overload(cres)
    581                 self._cache.save_overload(sig, cres)

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/dispatcher.py in compile(self, args, return_type)
     78                                       impl,
     79                                       args=args, return_type=return_type,
---> 80                                       flags=flags, locals=self.locals)
     81         # Check typing error if object mode is used
     82         if cres.typing_error is not None and not flags.enable_pyobject:

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/compiler.py in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library)
    702     pipeline = Pipeline(typingctx, targetctx, library,
    703                         args, return_type, flags, locals)
--> 704     return pipeline.compile_extra(func)
    705 
    706 

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/compiler.py in compile_extra(self, func)
    355         self.lifted = ()
    356         self.lifted_from = None
--> 357         return self._compile_bytecode()
    358 
    359     def compile_ir(self, func_ir, lifted=(), lifted_from=None):

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/compiler.py in _compile_bytecode(self)
    663         """
    664         assert self.func_ir is None
--> 665         return self._compile_core()
    666 
    667     def _compile_ir(self):

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/compiler.py in _compile_core(self)
    650 
    651         pm.finalize()
--> 652         res = pm.run(self.status)
    653         if res is not None:
    654             # Early pipeline completion

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/compiler.py in run(self, status)
    241                     # No more fallback pipelines?
    242                     if is_final_pipeline:
--> 243                         raise patched_exception
    244                     # Go to next fallback pipeline
    245                     else:

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/compiler.py in run(self, status)
    233                 try:
    234                     event(stage_name)
--> 235                     stage()
    236                 except _EarlyPipelineCompletion as e:
    237                     return e.result

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/compiler.py in stage_nopython_frontend(self)
    447                 self.args,
    448                 self.return_type,
--> 449                 self.locals)
    450 
    451         with self.fallback_context('Function "%s" has invalid return type'

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/compiler.py in type_inference_stage(typingctx, interp, args, return_type, locals)
    803 
    804         infer.build_constraint()
--> 805         infer.propagate()
    806         typemap, restype, calltypes = infer.unify()
    807 

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/typeinfer.py in propagate(self, raise_errors)
    765         if errors:
    766             if raise_errors:
--> 767                 raise errors[0]
    768             else:
    769                 return errors

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/typeinfer.py in propagate(self, typeinfer)
    126                                                    lineno=loc.line):
    127                 try:
--> 128                     constraint(typeinfer)
    129                 except TypingError as e:
    130                     errors.append(e)

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/typeinfer.py in __call__(self, typeinfer)
    435     def __call__(self, typeinfer):
    436         with new_error_context("typing of intrinsic-call at {0}", self.loc):
--> 437             self.resolve(typeinfer, typeinfer.typevars, fnty=self.func)
    438 
    439 

/proj/sot/ska3/flight/lib/python3.6/site-packages/numba/typeinfer.py in resolve(self, typeinfer, typevars, fnty)
    399             desc = context.explain_function_type(fnty)
    400             msg = '\n'.join([head, desc])
--> 401             raise TypingError(msg, loc=self.loc)
    402 
    403         typeinfer.add_type(self.target, sig.return_type, loc=self.loc)

TypingError: Failed at nopython (nopython frontend)
Invalid usage of getitem with parameters (pyobject, int64)
 * parameterized
File "../../../../ska3/flight/lib/python3.6/site-packages/chandra_aca/aca_image.py", line 540
[1] During: typing of intrinsic-call at /proj/sot/ska3/flight/lib/python3.6/site-packages/chandra_aca/aca_image.py (540)

This error may have been caused by the following argument(s):
- argument 3: Unsupported array dtype: >f4
- argument 4: Unsupported array dtype: >f4

I just did something like

ccd_bgd = ACAImage(ccd_bgd.astype(np.float32), col0=-512, row0=-512)

to move forward after I found the example usage in annie. It seems like working with the ccd bgd will be one of the default use cases moving forward so wondering what makes sense for API or a docstring helper.