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

Fixed #948 query star event now use source_id when it is available #950

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions backend/tno/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def radial_query(
schema=None,
columns=None,
limit=None,
source_id=None,
):
s_columns = "*"
if columns != None and len(columns) > 0:
Expand All @@ -437,19 +438,22 @@ def radial_query(
if limit != None:
s_limit = "LIMIT %s" % limit

stm = (
"""SELECT %s FROM %s WHERE q3c_radial_query("%s", "%s", %s, %s, %s) %s """
% (
s_columns,
tablename,
ra_property,
dec_property,
ra,
dec,
radius,
s_limit,
if source_id != None:
stm = f"SELECT {s_columns} FROM {tablename} WHERE source_id = {source_id}"
else:
stm = (
"""SELECT %s FROM %s WHERE q3c_radial_query("%s", "%s", %s, %s, %s) %s """
% (
s_columns,
tablename,
ra_property,
dec_property,
ra,
dec,
radius,
s_limit,
)
)
)

return self.fetch_all_dict(text(stm))

Expand Down
24 changes: 24 additions & 0 deletions backend/tno/migrations/0002_occultation_source_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.18 on 2024-03-27 20:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("tno", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="occultation",
name="source_id",
field=models.PositiveBigIntegerField(
blank=True,
default=None,
help_text="GAIA source id Star candidate",
null=True,
verbose_name="Source ID",
),
),
]
28 changes: 28 additions & 0 deletions backend/tno/migrations/0003_auto_20240327_2023.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.18 on 2024-03-27 20:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("tno", "0002_occultation_source_id"),
]

operations = [
migrations.RemoveField(
model_name="occultation",
name="source_id",
),
migrations.AddField(
model_name="occultation",
name="gaia_source_id",
field=models.PositiveBigIntegerField(
blank=True,
default=None,
help_text="GAIA source id Star candidate",
null=True,
verbose_name="GAIA Source ID",
),
),
]
8 changes: 8 additions & 0 deletions backend/tno/models/occultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ class Occultation(models.Model):
verbose_name="Date Time", auto_now_add=False, null=False, blank=False
)

gaia_source_id = models.PositiveBigIntegerField(
verbose_name="GAIA Source ID",
null=True,
blank=True,
default=None,
help_text="GAIA source id Star candidate",
)

ra_star_candidate = models.CharField(
verbose_name="RA Star Candidate",
max_length=20,
Expand Down
3 changes: 3 additions & 0 deletions backend/tno/views/occultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ def asteroids_with_prediction(self, request):
@action(detail=True, methods=["get"], permission_classes=(AllowAny,))
def get_star_by_event(self, request, pk=None):
pre_occ = self.get_object()

source_id = pre_occ.gaia_source_id
ra = pre_occ.ra_star_deg
dec = pre_occ.dec_star_deg

Expand All @@ -569,6 +571,7 @@ def get_star_by_event(self, request, pk=None):
ra=float(ra),
dec=float(dec),
radius=0.001,
source_id=source_id,
)
if len(rows) > 0:
return Response(rows[0])
Expand Down
10 changes: 8 additions & 2 deletions compose/local/env-template
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ DATABASE_CATALOG_DB=prod_gavo
PARSL_ENV=local
PREDICT_OUTPUTS=/app/outputs/predict_occultations
# DATABASE used Predict Occultation container
DB_ADMIN_URI=postgresql://${DATABASE_ADMIN_USER}:${DATABASE_ADMIN_PASSWORD}@${DATABASE_ADMIN_HOST}:${DATABASE_ADMIN_PORT}/${DATABASE_ADMIN_DB}
DB_CATALOG_URI=postgresql://${DATABASE_CATALOG_USER}:${DATABASE_CATALOG_PASSWORD}@${DATABASE_CATALOG_HOST}:${DATABASE_CATALOG_PORT}/${DATABASE_CATALOG_DB}
# A configuração é diferente por que o container precisa de rede do tipo host, então ele não reconhece o database.
# A porta do banco de dados precisa estar exposta para o host.
# Using Docker host internal.
# DB_ADMIN_URI=postgresql://${DATABASE_ADMIN_USER}:${DATABASE_ADMIN_PASSWORD}@host.docker.internal:${DATABASE_ADMIN_PORT}/${DATABASE_ADMIN_DB}
# DB_CATALOG_URI=postgresql://${DATABASE_CATALOG_USER}:${DATABASE_CATALOG_PASSWORD}@host.docker.internal:${DATABASE_CATALOG_PORT}/${DATABASE_CATALOG_DB}
# Using localhost
DB_ADMIN_URI=postgresql://${DATABASE_ADMIN_USER}:${DATABASE_ADMIN_PASSWORD}@localhost:${DATABASE_ADMIN_PORT}/${DATABASE_ADMIN_DB}
DB_CATALOG_URI=postgresql://${DATABASE_CATALOG_USER}:${DATABASE_CATALOG_PASSWORD}@localhost:${DATABASE_CATALOG_PORT}/${DATABASE_CATALOG_DB}

# Postgres Admin Database
# -------------------------------------
Expand Down
1 change: 1 addition & 0 deletions predict_occultation/src/asteroid/asteroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ def register_occultations(self, start_period: str, end_period: str, jobid: int):
"name",
"number",
"date_time",
"gaia_source_id",
"ra_star_candidate",
"dec_star_candidate",
"ra_target",
Expand Down
2 changes: 1 addition & 1 deletion predict_occultation/src/dao/occultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def import_occultations(self, data):
# Sql Copy com todas as colunas que vão ser importadas e o formato do csv.
# IMPORTANTA! A ORDEM DAS COLUNAS PRECISA SER IDENTICA A COMO ESTA NO DB!
sql = (
f"COPY {self.tbl} (name, number, date_time, ra_star_candidate, dec_star_candidate, ra_target, dec_target, closest_approach, position_angle, velocity, delta, g, j_star, h, k_star, long, loc_t, off_ra, off_dec, proper_motion, ct, multiplicity_flag, e_ra, e_dec, pmra, pmdec, ra_star_deg, dec_star_deg, ra_target_deg, dec_target_deg, created_at, aparent_diameter, aphelion, apparent_magnitude, dec_star_to_date, dec_star_with_pm, dec_target_apparent, diameter, e_dec_target, e_ra_target, eccentricity, ephemeris_version, g_mag_vel_corrected, h_mag_vel_corrected, inclination, instant_uncertainty, magnitude_drop, perihelion, ra_star_to_date, ra_star_with_pm, ra_target_apparent, rp_mag_vel_corrected, semimajor_axis, have_path_coeff, occ_path_max_longitude, occ_path_min_longitude, occ_path_coeff, occ_path_is_nightside, occ_path_max_latitude, occ_path_min_latitude, base_dynclass, bsp_planetary, bsp_source, catalog, dynclass, job_id, leap_seconds, nima, obs_source, orb_ele_source, predict_step, albedo, albedo_err_max, albedo_err_min, alias, arg_perihelion, astorb_dynbaseclass, astorb_dynsubclass, density, density_err_max, density_err_min, diameter_err_max, diameter_err_min, epoch, last_obs_included, long_asc_node, mass, mass_err_max, mass_err_min, mean_anomaly, mean_daily_motion, mpc_critical_list, pha_flag, principal_designation, rms, g_star, h_star) "
f"COPY {self.tbl} (name, number, date_time, gaia_source_id, ra_star_candidate, dec_star_candidate, ra_target, dec_target, closest_approach, position_angle, velocity, delta, g, j_star, h, k_star, long, loc_t, off_ra, off_dec, proper_motion, ct, multiplicity_flag, e_ra, e_dec, pmra, pmdec, ra_star_deg, dec_star_deg, ra_target_deg, dec_target_deg, created_at, aparent_diameter, aphelion, apparent_magnitude, dec_star_to_date, dec_star_with_pm, dec_target_apparent, diameter, e_dec_target, e_ra_target, eccentricity, ephemeris_version, g_mag_vel_corrected, h_mag_vel_corrected, inclination, instant_uncertainty, magnitude_drop, perihelion, ra_star_to_date, ra_star_with_pm, ra_target_apparent, rp_mag_vel_corrected, semimajor_axis, have_path_coeff, occ_path_max_longitude, occ_path_min_longitude, occ_path_coeff, occ_path_is_nightside, occ_path_max_latitude, occ_path_min_latitude, base_dynclass, bsp_planetary, bsp_source, catalog, dynclass, job_id, leap_seconds, nima, obs_source, orb_ele_source, predict_step, albedo, albedo_err_max, albedo_err_min, alias, arg_perihelion, astorb_dynbaseclass, astorb_dynsubclass, density, density_err_max, density_err_min, diameter_err_max, diameter_err_min, epoch, last_obs_included, long_asc_node, mass, mass_err_max, mass_err_min, mean_anomaly, mean_daily_motion, mpc_critical_list, pha_flag, principal_designation, rms, g_star, h_star) "
"FROM STDIN with (FORMAT CSV, DELIMITER '|', HEADER);"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def run_occultation_path_coeff(predict_table_path: Path, obj_data: dict):
"name",
"number",
"date_time",
"gaia_source_id",
"ra_star_candidate",
"dec_star_candidate",
"ra_target",
Expand Down
Loading