Skip to content

Commit

Permalink
tools.py: change order of column LegacySurvey_DR10_ID for manual cart…
Browse files Browse the repository at this point in the history
…on fits file (#445)
  • Loading branch information
astronomygupta authored Jun 16, 2024
1 parent 32c4713 commit 124247f
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions python/target_selection/cartons/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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])

Expand All @@ -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')

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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)')

Expand Down

0 comments on commit 124247f

Please sign in to comment.