diff --git a/python/target_selection/cartons/tools.py b/python/target_selection/cartons/tools.py index 14764255..5175eb6d 100644 --- a/python/target_selection/cartons/tools.py +++ b/python/target_selection/cartons/tools.py @@ -232,8 +232,8 @@ def build_query(self, version_id, query_region=None): self.database.execute_sql(f'CREATE INDEX ON "{temp_table}" ("Gaia_DR3_Source_ID")') self.database.execute_sql(f'CREATE INDEX ON "{temp_table}" ("Gaia_DR2_Source_ID")') - self.database.execute_sql(f'CREATE INDEX ON "{temp_table}" ("LegacySurvey_DR8_ID")') self.database.execute_sql(f'CREATE INDEX ON "{temp_table}" ("LegacySurvey_DR10_ID")') + self.database.execute_sql(f'CREATE INDEX ON "{temp_table}" ("LegacySurvey_DR8_ID")') self.database.execute_sql(f'CREATE INDEX ON "{temp_table}" ("PanSTARRS_DR2_ID")') self.database.execute_sql(f'CREATE INDEX ON "{temp_table}" ("TwoMASS_ID")') vacuum_table(self.database, temp_table, vacuum=False, analyze=True) @@ -251,8 +251,8 @@ def build_query(self, version_id, query_region=None): .select(Catalog.catalogid, temp.Gaia_DR3_Source_ID.alias('gaia_dr3_source_id'), temp.Gaia_DR2_Source_ID.alias('gaia_source_id'), - temp.LegacySurvey_DR8_ID.alias('ls_id8'), temp.LegacySurvey_DR10_ID.alias('ls_id10'), + temp.LegacySurvey_DR8_ID.alias('ls_id8'), temp.PanSTARRS_DR2_ID.alias('catid_objid'), temp.TwoMASS_ID.alias('designation'), Catalog.ra, @@ -292,18 +292,6 @@ def build_query(self, version_id, query_region=None): CatalogToTIC_v8.best.is_null(), Catalog.version_id == version_id)) - query_legacysurvey_dr8 = \ - (query_common - .join(CatalogToLegacy_Survey_DR8) - .join(Legacy_Survey_DR8) - .join(temp, - on=(temp.LegacySurvey_DR8_ID == Legacy_Survey_DR8.ls_id)) - .switch(Catalog) - .where(CatalogToLegacy_Survey_DR8.version_id == version_id, - (CatalogToLegacy_Survey_DR8.best >> True) | - CatalogToLegacy_Survey_DR8.best.is_null(), - Catalog.version_id == version_id)) - query_legacysurvey_dr10 = \ (query_common .join(CatalogToLegacy_Survey_DR10) @@ -316,6 +304,18 @@ def build_query(self, version_id, query_region=None): CatalogToLegacy_Survey_DR10.best.is_null(), Catalog.version_id == version_id)) + query_legacysurvey_dr8 = \ + (query_common + .join(CatalogToLegacy_Survey_DR8) + .join(Legacy_Survey_DR8) + .join(temp, + on=(temp.LegacySurvey_DR8_ID == Legacy_Survey_DR8.ls_id)) + .switch(Catalog) + .where(CatalogToLegacy_Survey_DR8.version_id == version_id, + (CatalogToLegacy_Survey_DR8.best >> True) | + CatalogToLegacy_Survey_DR8.best.is_null(), + Catalog.version_id == version_id)) + query_panstarrs_dr2 = \ (query_common .join(CatalogToPanstarrs1) @@ -348,12 +348,12 @@ def build_query(self, version_id, query_region=None): len_gaia_dr2 =\ len(self._table[self._table['Gaia_DR2_Source_ID'] > 0]) - len_legacysurvey_dr8 =\ - len(self._table[self._table['LegacySurvey_DR8_ID'] > 0]) - len_legacysurvey_dr10 =\ len(self._table[self._table['LegacySurvey_DR10_ID'] > 0]) + len_legacysurvey_dr8 =\ + len(self._table[self._table['LegacySurvey_DR8_ID'] > 0]) + len_panstarrs_dr2 =\ len(self._table[self._table['PanSTARRS_DR2_ID'] > 0]) @@ -367,11 +367,11 @@ def build_query(self, version_id, query_region=None): # There must be exactly one non-zero id per row else raise an exception. if ((len_gaia_dr3 + len_gaia_dr2 + - len_legacysurvey_dr8 + len_legacysurvey_dr10 + + len_legacysurvey_dr10 + len_legacysurvey_dr8 + len_panstarrs_dr2 + len_twomass_psc) != len_table): raise TargetSelectionError('error in get_file_carton(): ' + '(len_gaia_dr3 + len_gaia_dr2 + ' + - 'len_legacysurvey_dr8 + len_legacysurvey_dr10 +' + + 'len_legacysurvey_dr10 + len_legacysurvey_dr8 +' + 'len_panstarrs_dr2 + len_twomass_psc) != ' + 'len_table') @@ -385,16 +385,16 @@ def build_query(self, version_id, query_region=None): else: is_gaia_dr2 = False - if (len_legacysurvey_dr8 > 0): - is_legacysurvey_dr8 = True - else: - is_legacysurvey_dr8 = False - if (len_legacysurvey_dr10 > 0): is_legacysurvey_dr10 = True else: is_legacysurvey_dr10 = False + if (len_legacysurvey_dr8 > 0): + is_legacysurvey_dr8 = True + else: + is_legacysurvey_dr8 = False + if (len_panstarrs_dr2 > 0): is_panstarrs_dr2 = True else: @@ -419,18 +419,18 @@ def build_query(self, version_id, query_region=None): else: query = query | query_gaia_dr2 - if (is_legacysurvey_dr8 is True): - if (query is None): - query = query_legacysurvey_dr8 - else: - query = query | query_legacysurvey_dr8 - if (is_legacysurvey_dr10 is True): if (query is None): query = query_legacysurvey_dr10 else: query = query | query_legacysurvey_dr10 + if (is_legacysurvey_dr8 is True): + if (query is None): + query = query_legacysurvey_dr8 + else: + query = query | query_legacysurvey_dr8 + if (is_panstarrs_dr2 is True): if (query is None): query = query_panstarrs_dr2 @@ -449,8 +449,8 @@ def build_query(self, version_id, query_region=None): raise TargetSelectionError('error in get_file_carton(): ' + '(is_gaia_dr3 is False) and ' + '(is_gaia_dr2 is False) and ' + - '(is_legacysurvey_dr8 is False) and ' + '(is_legacysurvey_dr10 is False) and ' + + '(is_legacysurvey_dr8 is False) and ' + '(is_panstarrs_dr2 is False) and ' + '(is_twomass_psc is False)')