8000 Support CxoTime in DateTime and modernize by taldcroft · Pull Request #42 · sot/chandra_time · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support CxoTime in DateTime and modernize #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 13, 2020
Merged

Conversation

taldcroft
Copy link
Member
@taldcroft taldcroft commented May 19, 2020

Description

Allow instantiating a DateTime object from a CxoTime object, and conversely getting a CxoTime object from DateTime using tm.cxotime.

One disappointing issue is that I discovered that CxoTime (astropy Time) is quite slow in creating scalar time objects, up to a factor of 15 slower (300 us vs. 20 us). For most applications this won't matter.

Testing

  • Passes unit tests on MacOS
  • Functional testing (added new unit tests).

Fixes #

time_in.sidereal_time
time_in.format
time_in.shape
return str(time_in.secs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I am opposed, but why do all these checks?

If you want to check that this is an astropy.time.Time instance, you can use isinstance. If what you want to check is the behavior, then isn't time_in.secs enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to be extremely sure the object is an astropy Time subclass without actually importing astropy.time.Time. Just looking for a secs attribute is not strong enough because there are many unrelated classes that have a secs attribute. However almost no random classes will have all those attributes.

That is indeed a bit adhoc / hacky. Maybe there is a better way, like digging through .__class__.__mro__ to find 'astropy.time.core.Time'. I think that works, as long as astropy never refactors or changes the module name core.py.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That reminds me the intent was to be slightly sneaky and actually use time_in.cxcsec to allow initialization from any astropy Time subclass since cxcsec is built-in. For initializing DateTime any Time object should be sufficient, but going the other way will result in a CxoTime coming out.

Copy link
Contributor
@jeanconn jeanconn May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Seems like both those thoughts ("without importing astropy.time" and "allow initialization from any subclass") could just make their way into the comment for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since this was a WIP...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the WIP. I need to check again that testing coverage is OK but I don't have any outstanding items for implementation in mind.

@taldcroft taldcroft changed the title WIP: support CxoTime in DateTime Support CxoTime in DateTime May 20, 2020
@taldcroft taldcroft changed the title Support CxoTime in DateTime Support CxoTime in DateTime and modernize May 21, 2020
@taldcroft
Copy link
Member Author

With apologies, I ended up migrating the unit tests to pytest in order to get things working. So this ends up making this into a multi-issue PR.

@taldcroft
Copy link
Member Author

I addressed the comments and simplified the implementation so it is much cleaner and more isolated from the original code.

@taldcroft taldcroft merged commit e7f7aa8 into master Jun 13, 2020
@taldcroft taldcroft deleted the cxotime-support branch June 13, 2020 14:44
@javierggt javierggt mentioned this pull request Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0