From fc42fa257f3ff0eb9a78d1c1ce9ea09b4dd2f533 Mon Sep 17 00:00:00 2001 From: Pramod Gupta Date: Sun, 22 Dec 2024 17:00:02 -0700 Subject: [PATCH 1/7] mwm_openfiber.py: --- .../target_selection/cartons/mwm_openfiber.py | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 python/target_selection/cartons/mwm_openfiber.py diff --git a/python/target_selection/cartons/mwm_openfiber.py b/python/target_selection/cartons/mwm_openfiber.py new file mode 100644 index 00000000..7dfdb9e1 --- /dev/null +++ b/python/target_selection/cartons/mwm_openfiber.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# @Author: Pramod Gupta (psgupta@uw.edu) +# @Date: 2024-12-20 +# @Filename: mwm_openfiber.py +# @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause) + +import peewee + +from sdssdb.peewee.sdss5db.catalogdb import ( + Catalog, + CatalogToGaia_DR3, + Gaia_DR3, +) + +from target_selection.cartons import BaseCarton + + +# See catalog.py for the name of peewee model names corresponding +# to postgres table names: +# https://github.com/sdss/sdssdb/blob/master/python/sdssdb/peewee/sdss5db/catalogdb.py + + +class Openfibertargets_mwm_mdwarfs_plato_apogee_Carton(BaseCarton): + """ + Shorthand name: openfibertargets_mwm_mdwarfs_plato_apogee + Existing carton code: + Link: Stellar Parameters and Abundances for PLATO M-dwarf targets + Simplified Description of selection criteria: + ADQL query in Gaia archive for Gaia DR3: + + select sq.source_id, sq.ra, sq.dec + from ( + select source_id, ra, dec, + bp_rp as bp_rp_0, + phot_g_mean_mag - (-0.17276 + 0.47885*(bp_rp) + -0.71953power(bp_rp,2) + + 0.24374power(bp_rp,3) + -0.04458power(bp_rp,4) + + 0.00317power(bp_rp,5)) as v0mag, + phot_g_mean_mag + 5 * LOG10(parallax) - 10 as g0absmag + from gaiadr3.gaia_source + where + l>=255.9-23 and l<=255.9+23 and b>=-24.6-23 and b<=-24.6+23 + and parallax > 0 + ) as sq + where + sq.v0mag <= 16 + and sq.g0absmag > -8.62sq.bp_rp_0 +24.96 + and sq.g0absmag >= 2.334sq.bp_rp_0 +2.259 + + Return columns: Gaia DR3 galactic coordinates, + Gaia BP-RP, parallax, G magnitude + Metadata: can_offset=False + Priority: 6085 + Cadence: bright_1x1 + Instrument: APOGEE + Program: open_fiber + Lead contact: Diogo Souto + """ + + name = 'openfibertargets_mwm_mdwarfs_plato_apogee' + category = 'science' + instrument = 'APOGEE' + cadence = 'bright_1x1' + program = "open_fiber" + mapper = 'MWM' + priority = 6085 + can_offset = False + + # target_selection propagates the following columns if they are generated + # during the query (with exactly the below name) + # g, r, i, z, h, j, k, bp, rp gaia_g, optical_prov + # + # If any g,r, i, z, optical_prov are missing, then the code will + # try to find them in SDSS, PS1, and Gaia. + # + # Hence, we use the names gaia_g, bp, rp below. + + def build_query(self, version_id, query_region=None): + query = ( + CatalogToGaia_DR3.select( + CatalogToGaia_DR3.catalogid, + Gaia_DR3.source_id, + Gaia_DR3.ra.alias("gaia_dr3_ra"), + Gaia_DR3.dec.alias("gaia_dr3_dec"), + Gaia_DR3.pmra.alias("gaia_dr3_pmra"), + Gaia_DR3.pmdec.alias("gaia_dr3_pmdec"), + Gaia_DR3.bp_rp.alias("bp_rp_0"), + Gaia_DR3.phot_g_mean_mag.alias("gaia_g"), + Gaia_DR3.phot_bp_mean_mag.alias("bp"), + Gaia_DR3.phot_rp_mean_mag.alias("rp"), + ) + .join(Gaia_DR3, + on=(CatalogToGaia_DR3.target_id == Gaia_DR3.source_id)) + .where( + CatalogToGaia_DR3.version_id == version_id, + CatalogToGaia_DR3.best >> True, + Gaia_DR3.parallax > 0, + Gaia_DR3.l >= 255.9-23, + Gaia_DR3.l <= 255.9+23, + Gaia_DR3.b >= -24.6-23, + Gaia_DR3.b <= -24.6+23, + Gaia_DR3.phot_g_mean_mag + + 5 * peewee.fn.LOG10(Gaia_DR3.parallax) - 10 > + -8.62 * Gaia_DR3.bp_rp + 24.96, + Gaia_DR3.phot_g_mean_mag + + 5 * peewee.fn.LOG10(Gaia_DR3.parallax) - 10 >= + 2.334 * Gaia_DR3.bp_rp + 2.259, + Gaia_DR3.phot_g_mean_mag - + (-0.17276 + 0.47885*(Gaia_DR3.bp_rp) + + (-0.71953)*peewee.fn.power(Gaia_DR3.bp_rp, 2) + + 0.24374*peewee.fn.power(Gaia_DR3.bp_rp, 3) + + (-0.04458)*peewee.fn.power(Gaia_DR3.bp_rp, 4) + + 0.00317*peewee.fn.power(Gaia_DR3.bp_rp, 5)) < 16 + ) + ) + + # Gaia_DR3 peewee model class corresponds to + # table catalogdb.gaia_dr3_source. + + if query_region: + query = query.join_from(CatalogToGaia_DR3, Catalog).where( + peewee.fn.q3c_radial_query( + Catalog.ra, + Catalog.dec, + query_region[0], + query_region[1], + query_region[2], + ) + ) + + return query From 21780a55f0729c3f9674755191c094e1c620868d Mon Sep 17 00:00:00 2001 From: Pramod Gupta Date: Sun, 22 Dec 2024 17:01:12 -0700 Subject: [PATCH 2/7] mwm_openfiber.py: openfibertargets_mwm_mdwarfs_plato_apogee --- python/target_selection/cartons/mwm_openfiber.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/target_selection/cartons/mwm_openfiber.py b/python/target_selection/cartons/mwm_openfiber.py index 7dfdb9e1..c69aebbc 100644 --- a/python/target_selection/cartons/mwm_openfiber.py +++ b/python/target_selection/cartons/mwm_openfiber.py @@ -25,7 +25,6 @@ class Openfibertargets_mwm_mdwarfs_plato_apogee_Carton(BaseCarton): """ Shorthand name: openfibertargets_mwm_mdwarfs_plato_apogee - Existing carton code: Link: Stellar Parameters and Abundances for PLATO M-dwarf targets Simplified Description of selection criteria: ADQL query in Gaia archive for Gaia DR3: From e362e3afcc363e39ab373c5d5ca4830f2376e248 Mon Sep 17 00:00:00 2001 From: Pramod Gupta Date: Sun, 22 Dec 2024 17:04:54 -0700 Subject: [PATCH 3/7] ruff format mwm_openfiber.py --- .../target_selection/cartons/mwm_openfiber.py | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/python/target_selection/cartons/mwm_openfiber.py b/python/target_selection/cartons/mwm_openfiber.py index c69aebbc..d29f85c9 100644 --- a/python/target_selection/cartons/mwm_openfiber.py +++ b/python/target_selection/cartons/mwm_openfiber.py @@ -57,12 +57,12 @@ class Openfibertargets_mwm_mdwarfs_plato_apogee_Carton(BaseCarton): Lead contact: Diogo Souto """ - name = 'openfibertargets_mwm_mdwarfs_plato_apogee' - category = 'science' - instrument = 'APOGEE' - cadence = 'bright_1x1' + name = "openfibertargets_mwm_mdwarfs_plato_apogee" + category = "science" + instrument = "APOGEE" + cadence = "bright_1x1" program = "open_fiber" - mapper = 'MWM' + mapper = "MWM" priority = 6085 can_offset = False @@ -89,28 +89,29 @@ def build_query(self, version_id, query_region=None): Gaia_DR3.phot_bp_mean_mag.alias("bp"), Gaia_DR3.phot_rp_mean_mag.alias("rp"), ) - .join(Gaia_DR3, - on=(CatalogToGaia_DR3.target_id == Gaia_DR3.source_id)) + .join(Gaia_DR3, on=(CatalogToGaia_DR3.target_id == Gaia_DR3.source_id)) .where( CatalogToGaia_DR3.version_id == version_id, CatalogToGaia_DR3.best >> True, Gaia_DR3.parallax > 0, - Gaia_DR3.l >= 255.9-23, - Gaia_DR3.l <= 255.9+23, - Gaia_DR3.b >= -24.6-23, - Gaia_DR3.b <= -24.6+23, - Gaia_DR3.phot_g_mean_mag + - 5 * peewee.fn.LOG10(Gaia_DR3.parallax) - 10 > - -8.62 * Gaia_DR3.bp_rp + 24.96, - Gaia_DR3.phot_g_mean_mag + - 5 * peewee.fn.LOG10(Gaia_DR3.parallax) - 10 >= - 2.334 * Gaia_DR3.bp_rp + 2.259, - Gaia_DR3.phot_g_mean_mag - - (-0.17276 + 0.47885*(Gaia_DR3.bp_rp) + - (-0.71953)*peewee.fn.power(Gaia_DR3.bp_rp, 2) + - 0.24374*peewee.fn.power(Gaia_DR3.bp_rp, 3) + - (-0.04458)*peewee.fn.power(Gaia_DR3.bp_rp, 4) + - 0.00317*peewee.fn.power(Gaia_DR3.bp_rp, 5)) < 16 + Gaia_DR3.l >= 255.9 - 23, + Gaia_DR3.l <= 255.9 + 23, + Gaia_DR3.b >= -24.6 - 23, + Gaia_DR3.b <= -24.6 + 23, + Gaia_DR3.phot_g_mean_mag + 5 * peewee.fn.LOG10(Gaia_DR3.parallax) - 10 + > -8.62 * Gaia_DR3.bp_rp + 24.96, + Gaia_DR3.phot_g_mean_mag + 5 * peewee.fn.LOG10(Gaia_DR3.parallax) - 10 + >= 2.334 * Gaia_DR3.bp_rp + 2.259, + Gaia_DR3.phot_g_mean_mag + - ( + -0.17276 + + 0.47885 * (Gaia_DR3.bp_rp) + + (-0.71953) * peewee.fn.power(Gaia_DR3.bp_rp, 2) + + 0.24374 * peewee.fn.power(Gaia_DR3.bp_rp, 3) + + (-0.04458) * peewee.fn.power(Gaia_DR3.bp_rp, 4) + + 0.00317 * peewee.fn.power(Gaia_DR3.bp_rp, 5) + ) + < 16, ) ) From 8e39b5ed13222fa7da9be99b4eb77baea92d43d5 Mon Sep 17 00:00:00 2001 From: Pramod Gupta Date: Sun, 22 Dec 2024 17:43:30 -0700 Subject: [PATCH 4/7] mwm_openfiber.py: edit comments --- python/target_selection/cartons/mwm_openfiber.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/python/target_selection/cartons/mwm_openfiber.py b/python/target_selection/cartons/mwm_openfiber.py index d29f85c9..5735735e 100644 --- a/python/target_selection/cartons/mwm_openfiber.py +++ b/python/target_selection/cartons/mwm_openfiber.py @@ -66,15 +66,6 @@ class Openfibertargets_mwm_mdwarfs_plato_apogee_Carton(BaseCarton): priority = 6085 can_offset = False - # target_selection propagates the following columns if they are generated - # during the query (with exactly the below name) - # g, r, i, z, h, j, k, bp, rp gaia_g, optical_prov - # - # If any g,r, i, z, optical_prov are missing, then the code will - # try to find them in SDSS, PS1, and Gaia. - # - # Hence, we use the names gaia_g, bp, rp below. - def build_query(self, version_id, query_region=None): query = ( CatalogToGaia_DR3.select( From 8a3ac9c7d0ea20d60ef68a0424af89d24560c4e6 Mon Sep 17 00:00:00 2001 From: Pramod Gupta Date: Mon, 23 Dec 2024 05:46:36 -0700 Subject: [PATCH 5/7] mwm_openfiber.py: edit openfibertargets_mwm_mdwarfs_plato_apogee --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- python/target_selection/cartons/mwm_openfiber.py | 8 +++++++- .../target_selection/config/target_selection.yml | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2320d014..426b68aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 1.3.20 - December 20, 2024 + +### New + +* added target_selection plan 1.2.18 +* added carton openfibertargets_mwm_mdwarfs_plato_apogee + ## 1.3.19 - December 14, 2024 ### ✨ Improved diff --git a/pyproject.toml b/pyproject.toml index 5b0c8a3c..4c972291 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sdss-target-selection" -version = "1.3.20a0" +version = "1.3.20" description = "Code to perform target selection for BHM/MWM using catalogdb" authors = ["José Sánchez-Gallego "] license = "BSD 3-Clause" diff --git a/python/target_selection/cartons/mwm_openfiber.py b/python/target_selection/cartons/mwm_openfiber.py index 5735735e..d2142dcb 100644 --- a/python/target_selection/cartons/mwm_openfiber.py +++ b/python/target_selection/cartons/mwm_openfiber.py @@ -66,6 +66,9 @@ class Openfibertargets_mwm_mdwarfs_plato_apogee_Carton(BaseCarton): priority = 6085 can_offset = False + # In the below query, + # Gaia_DR3.l is for galactic longitude + # Gaia_DR3.b is for galactic latitude def build_query(self, version_id, query_region=None): query = ( CatalogToGaia_DR3.select( @@ -75,10 +78,13 @@ def build_query(self, version_id, query_region=None): Gaia_DR3.dec.alias("gaia_dr3_dec"), Gaia_DR3.pmra.alias("gaia_dr3_pmra"), Gaia_DR3.pmdec.alias("gaia_dr3_pmdec"), - Gaia_DR3.bp_rp.alias("bp_rp_0"), Gaia_DR3.phot_g_mean_mag.alias("gaia_g"), Gaia_DR3.phot_bp_mean_mag.alias("bp"), Gaia_DR3.phot_rp_mean_mag.alias("rp"), + Gaia_DR3.bp_rp, + Gaia_DR3.parallax, + Gaia_DR3.l, + Gaia_DR3.b ) .join(Gaia_DR3, on=(CatalogToGaia_DR3.target_id == Gaia_DR3.source_id)) .where( diff --git a/python/target_selection/config/target_selection.yml b/python/target_selection/config/target_selection.yml index 5ff2b941..541aa211 100644 --- a/python/target_selection/config/target_selection.yml +++ b/python/target_selection/config/target_selection.yml @@ -1,3 +1,19 @@ +'1.2.18': + xmatch_plan: 1.0.0 + cartons: + - openfibertargets_mwm_mdwarfs_plato_apogee + open_fiber_path: /uufs/chpc.utah.edu/common/home/sdss50/sdsswork/target/open_fiber/postv1/draft2/ + schema: sandbox + magnitudes: + h: [catalog_to_twomass_psc, twomass_psc, twomass_psc.h_m] + j: [catalog_to_twomass_psc, twomass_psc, twomass_psc.j_m] + k: [catalog_to_twomass_psc, twomass_psc, twomass_psc.k_m] + bp: [catalog_to_gaia_dr3_source, gaia_dr3_source, gaia_dr3_source.phot_bp_mean_mag] + rp: [catalog_to_gaia_dr3_source, gaia_dr3_source, gaia_dr3_source.phot_rp_mean_mag] + gaia_g: [catalog_to_gaia_dr3_source, gaia_dr3_source, gaia_dr3_source.phot_g_mean_mag] + database_options: + work_mem: '2000MB' + '1.2.17': xmatch_plan: 1.0.0 cartons: From 654cbb31550f7f370418850ce71b99de7c1b943e Mon Sep 17 00:00:00 2001 From: Pramod Gupta Date: Mon, 23 Dec 2024 14:08:25 -0700 Subject: [PATCH 6/7] mwm_openfiber.py: edit openfibertargets_mwm_mdwarfs_plato_apogee --- python/target_selection/cartons/mwm_openfiber.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/target_selection/cartons/mwm_openfiber.py b/python/target_selection/cartons/mwm_openfiber.py index d2142dcb..2794c2fc 100644 --- a/python/target_selection/cartons/mwm_openfiber.py +++ b/python/target_selection/cartons/mwm_openfiber.py @@ -84,7 +84,7 @@ def build_query(self, version_id, query_region=None): Gaia_DR3.bp_rp, Gaia_DR3.parallax, Gaia_DR3.l, - Gaia_DR3.b + Gaia_DR3.b, ) .join(Gaia_DR3, on=(CatalogToGaia_DR3.target_id == Gaia_DR3.source_id)) .where( From e9aa1c3a683cde2274079251209a89e45dcc9941 Mon Sep 17 00:00:00 2001 From: Pramod Gupta Date: Sun, 29 Dec 2024 10:04:56 -0700 Subject: [PATCH 7/7] mwm_openfiber.py: edit openfibertargets_mwm_mdwarfs_plato_apogee --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 426b68aa..f3dd6292 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 1.3.20 - December 20, 2024 +## 1.3.20 - December 29, 2024 ### New