Skip to content
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

Proper motion #2625

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Proper motion #2625

wants to merge 11 commits into from

Conversation

ctoennis
Copy link

This pull request adds a utility to get star positions with proper motion from different catalogues. It allows to cache the catalogue lookup locally and uses cached data before looking up data online again.

CACHE_FILE = Path("~/.psf_stars.ecsv").expanduser()


def cut_stars(stars, pointing=None, radius=None, Bmag_cut=None, Vmag_cut=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to use "select_stars" as a function name. "cut" is a jargon.

from astropy.coordinates import Angle, SkyCoord
from astropy.table import Table
from astropy.time import Time
from astroquery.vizier import Vizier
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a new dependency. It should be included in pyproject.
@maxnoe is it ok to have it? Or we need to download and stash a cached version of the catalog?

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer having the catalog we need as a resource file, it should be fairly small.

It would be good have the code to create it here in any case, but that can be done without hard-requiring astroquery. it should be kept as an optional dependency.

Copy link
Author

Choose a reason for hiding this comment

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

i made a function to make the catalog file in the last commit and added astroquery to the optional dependencies.

The function get_bright_stars() should then only look to the resource file with the function get_table_dataset(), no?
Schould we then have multiple files uploaded for different catalogues?

return stars


def get_bright_stars_with_motion(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a reason to keep the getter without proper motion?

Copy link
Member

Choose a reason for hiding this comment

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

No, that's essentially a bug

Copy link
Author

Choose a reason for hiding this comment

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

ok, i'll get rid of it

Return only stars above a given apparent magnitude. Default: None (all entries)
Bmag_cut: float
Return only stars above a given absolute magnitude. Default: None (all entries)
catalog: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Create an enum with human-readable catalog names.

Copy link
Author

Choose a reason for hiding this comment

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

i made an enum with 3 catalogues. let me know if i should add any specific catalog that would be useful



def test_get_bright_stars_with_motion():
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

If you add more catalogs, it makes sense to test all of them. Also, it would be nice to test a but more details, or add more comments about the expected outcome of the query.

Copy link
Author

Choose a reason for hiding this comment

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

oka, i will get to that part tomorrow morning

@ctoennis
Copy link
Author

I extended the tests to check if stars are moving and to check both catalogues. Also i added to the cached metadata which catalog was used. Right now the function will download the catalog data again if you use a different one.

I was thinking to add to the cached file some part of the filename that marks the catalog used, so that you can cache multiple catalogs.

@ctoennis
Copy link
Author

For the startracker code each star will need an identifier and not all stars have nice common names available. I suggest we use the HIP number for identification as it is the most available identifier for the objects we can use for pointing and PSF fitting.

Copy link
Member

@maxnoe maxnoe left a comment

Choose a reason for hiding this comment

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

I left some comments in-line.

The main point is that the star catalog(s) should remain a resource file for users and the code to create it is run by the developers when we need to update it.

@@ -0,0 +1,4 @@
Add ''get_bright_stars_with_motion'' to ctapipe.utils.astro
Copy link
Member

Choose a reason for hiding this comment

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

Please update the changelog once we have this finalized


__all__ = ["get_bright_stars"]


def get_bright_stars(pointing=None, radius=None, magnitude_cut=None):
CACHE_FILE = Path("~/.psf_stars.ecsv").expanduser()
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be changed. As discussed in the comments, we want to have the catalogs as resource files in the package and only have the code to create them for developers to update those files if needed.

So this should not be needed at all. if we need it, it should be using this function here to obtain an appropriate cache path:

def get_cache_path(url, cache_name="ctapipe", env_override="CTAPIPE_CACHE"):

instead of just storing a hidden file in the user's home


This function is using the Yale bright star catalog, available through ctapipe
data downloads.
if Bmag_cut is not None and "Bmag" in stars.keys():
Copy link
Member

Choose a reason for hiding this comment

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

Are Bmag / BTmag and Vmag / VTmag really the same?

Why was it needed to add the "T" versions?

Copy link
Author

Choose a reason for hiding this comment

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

some catalogs only have the T versions available

Copy link
Member

Choose a reason for hiding this comment

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

But we only deal with two here, which to my knowledge have Bmag and Vmag

Copy link
Author

Choose a reason for hiding this comment

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

here is the link to the hippoarcos catalogue: https://vizier.cds.unistra.fr/viz-bin/VizieR-3?-source=I/239/hip_main&-out.max=50&-out.form=HTML%20Table&-out.add=_r&-out.add=_RAJ,_DEJ&-sort=_r&-oc.form=sexa

It has Vmag, but no Bmag. It has BTmag and VTmag available. The Yale catalogue is here:

https://vizier.cds.unistra.fr/viz-bin/VizieR-3?-source=V/50&-out.max=50&-out.form=HTML%20Table&-out.add=_r&-out.add=_RAJ,_DEJ&-sort=_r&-oc.form=sexa

Here it's only Vmag.

the Nomad catalogue has both Bmag and Vmag:

https://vizier.cds.unistra.fr/viz-bin/VizieR-2

If it you want to not have the T versions i can remove it and add error messages when you try to use Bmag with the Yale and Hippoarcos catalogues.

"pmDE",
"Vmag",
"Bmag",
"BTmag",
Copy link
Member

Choose a reason for hiding this comment

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

Why also the T versions?

catalog=StarCatalogues[catalog].value,
columns=[
"recno",
"RAJ2000",
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the computed "RAJ2000" / "DEJ2000" values.

These are computed by vizier on the fly and are redundant with the original coordinates and the proper motions.

We anyway need to apply proper motion, so it doesn't matter whether we start from the catalog epoch or j2000

stars = vizier.query_constraints(Vmag="0.0..10.0")[0]

if "Bmag" not in stars.keys():
log.exception("The chosen catalog does not have Bmag data")
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong usage of log.exception. log.exception is meant only to be used in an except block to provide additional information to the traceback:
https://docs.python.org/3/library/logging.html#logging.Logger.exception

This should be an actual exception, so throw a KeyError

log.exception("The chosen catalog does not have Vmag data")
stars.meta["Catalog"] = StarCatalogues[catalog].value

stars.write(CACHE_FILE, overwrite=True)
Copy link
Member

Choose a reason for hiding this comment

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

THis should use the (at the moment unused) filename option.

But I would completely remove the filename option and just return the table. Querying the catalog and writing it to a file should be separate.



def get_bright_stars(
pointing=None, radius=None, Bmag_cut=None, Vmag_cut=None, catalog="Yale"
Copy link
Member

Choose a reason for hiding this comment

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

catalog argument should use the enum


def get_bright_stars(
pointing=None, radius=None, Bmag_cut=None, Vmag_cut=None, catalog="Yale"
): # max_magnitude):
Copy link
Member

Choose a reason for hiding this comment

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

remove commented part

Copy link
Member

Choose a reason for hiding this comment

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

For backwards compatibilty, we could think about keeping the max_magnitude argument and adding an magnitude_type= keyword that can either be "Vmag" or "BMag"

copy=False,
)
catalog["ra_dec"] = starpositions
if CACHE_FILE.exists():
Copy link
Member

Choose a reason for hiding this comment

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

This should use the importlib resources system to load the resources file for the specified catalog



class StarCatalogues(Enum):
Yale = "V/50/catalog" # Yale bright star catalogue
Copy link
Member

Choose a reason for hiding this comment

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

Change the comment to be above and have the form #: , this will be picked up by sphinx for the docs

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