sblunt / orbitize

Orbit-fitting for directly imaged objects
https://orbitize.info
Other
74 stars 43 forks source link

Type issue with num_period #335

Closed tomasstolker closed 1 year ago

tomasstolker commented 1 year ago

Hey @sblunt, just a minor issue I ran into: when setting after_date in tau_to_tp, it causes an error if the input are arrays instead of floats because num_periods = int() requires a float. This would fix it I think:

if isinstance(num_periods, np.ndarray):
  num_periods = np.ceil(num_periods).astype('int')
else:
   num_periods = int(np.ceil(num_periods))
semaphoreP commented 1 year ago

Ah, originally, the function definition does not allow arrays for after_date but this can be easily changed. PR #336 adds this functionality (we don't even need the else because the np.float64 output by np.ceil for single values has the astype function as well.

tomasstolker commented 1 year ago

Great, thanks a lot!

Sorry I didn't explain it properly I realize now. The problem that I ran into was a case where after_date is a float instead of None, while tau, ref_epoch, and period are arrays. In that case num_periods became an array and caused the error.

I agree that for after_date it is typically not required to use an array but your fix seems fine and adds even a bit more flexibility to the function 👍.

Thanks again 😊

sblunt commented 1 year ago

fixed in #336