Skip to content

Commit

Permalink
1058 filtro por incerteza na predicao (#1063)
Browse files Browse the repository at this point in the history
* build(new-column-added-to-the-database-with-new-values-computed): closest_approach_uncertainty_km is with its computations is added to the database and prediction occultation details

BREAKING CHANGE:

* feat(new-filter-field): closest_approach_uncertainty_km field added to occultation views

* refactor(frontend/src/contexts/PredictionContext.js): Inclusao do campo closest approach uncertainty no arquivo predictionContext

* refactor(frontend/src/components/ClosestApproachUncertaintyField/): Criação do componente com o campo de closest approach uncertainty

* refactor(frontend/src/components/PredictionEventsFilter/index.js): Inclusao de chamada do componente closest approach uncertainty no componente principal dos filtros de predição

* Fixed layout and filter by closest approach

* refactor(frontend/src/components/ClosestApproachUncertaintyField/index.js): Alteração no nome do campo closest approach uncertainty

---------

Co-authored-by: Rodrigo Boufleur <rcboufleur@gmail.com>
Co-authored-by: josiane-silwa <josiannesilwa@gmail.com>
  • Loading branch information
3 people authored Aug 30, 2024
1 parent 6bc366e commit 0821c4f
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.18 on 2024-08-28 13:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("tno", "0006_auto_20240822_1847"),
]

operations = [
migrations.AddField(
model_name="occultation",
name="closest_approach_uncertainty_km",
field=models.FloatField(
blank=True,
default=None,
help_text="Uncertainty in geocentric closest approach (km)",
null=True,
verbose_name="Closest approach uncertainty in km",
),
),
]
8 changes: 8 additions & 0 deletions backend/tno/models/occultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,14 @@ class Occultation(models.Model):
default=None,
help_text="Indicates the probability that the event will happen at the indicated path",
)

closest_approach_uncertainty_km = models.FloatField(
verbose_name="Closest approach uncertainty in km",
null=True,
blank=True,
default=None,
help_text="Uncertainty in geocentric closest approach (km)",
)
# ------------------------------------------------------
# Colunas que aparentemente não esto sendo preenchidas
# ------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions backend/tno/views/occultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class OccultationFilter(django_filters.FilterSet):

magnitude_drop = django_filters.RangeFilter(field_name="magnitude_drop")

closest_approach_uncertainty_km = django_filters.RangeFilter(
field_name="closest_approach_uncertainty_km"
)

longitude = django_filters.NumberFilter(
method="longitude_filter", label="Longitude"
)
Expand Down Expand Up @@ -137,6 +141,7 @@ class Meta:
"magnitude_drop",
"diameter",
"event_duration",
"closest_approach_uncertainty_km",
"local_solar_time",
"nightside",
"jobid",
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/components/ClosestApproachUncertaintyField/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import PropTypes from 'prop-types'
import TextField from '@mui/material/TextField'

function ClosestApproachUncertaintyField({ value, onChange }) {
const handleChange = (e) => {
let newValue = e.target.value

if (newValue === '') {
onChange(undefined)
}
if (newValue !== '') {
onChange(parseFloat(newValue))
}
}

return (
<TextField
type='number'
label='Uncertainty (km)'
variant='outlined'
value={value !== undefined ? parseFloat(value) : ''}
onChange={handleChange}
fullWidth
/>
)
}

ClosestApproachUncertaintyField.defaultProps = {
value: undefined
}
ClosestApproachUncertaintyField.propTypes = {
value: PropTypes.number,
onChange: PropTypes.func.isRequired
}

export default ClosestApproachUncertaintyField
23 changes: 20 additions & 3 deletions frontend/src/components/PredictionEventsFilter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { PredictionEventsContext } from '../../contexts/PredictionContext'
import SolarTimeFilter from '../SolarTimeFilter'
import Divider from '@mui/material/Divider'
import Button from '@mui/material/Button'
import ClosestApproachUncertaintyField from '../ClosestApproachUncertaintyField/index'

function PredictionEventsFilter() {
const { queryOptions, setQueryOptions, clearFilter } = useContext(PredictionEventsContext)
Expand Down Expand Up @@ -156,7 +157,7 @@ function PredictionEventsFilter() {
<Grid item xs={12}>
<Divider />
</Grid>
<Grid item xs={3} container>
<Grid item xs={12} md={6} lg={4}>
<MaginitudeDropSelect
value={queryOptions.filters.maginitudeDropMin}
onChange={(newValue) => {
Expand All @@ -172,7 +173,7 @@ function PredictionEventsFilter() {
}}
/>
</Grid>
<Grid item xs={3} container>
<Grid item xs={12} md={6} lg={4}>
<EventDurationField
value={queryOptions.filters.eventDurationMin}
onChange={(e) => {
Expand All @@ -188,7 +189,23 @@ function PredictionEventsFilter() {
}}
/>
</Grid>
<Grid item xs={6} container>
<Grid item xs={12} md={6} lg={4}>
<ClosestApproachUncertaintyField
value={queryOptions.filters.closestApproachUncertainty}
onChange={(value) => {
setQueryOptions((prev) => {
return {
...prev,
filters: {
...prev.filters,
closestApproachUncertainty: value
}
}
})
}}
/>
</Grid>
<Grid item xs={12} md={6} lg={8}>
<ObjectDiameterFilter
value={{
diameterMin: queryOptions.filters.diameterMin,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/contexts/PredictionContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function PredictionEventsProvider({ children }) {
maginitudeDropMin: undefined,
diameterMin: undefined,
diameterMax: undefined,
closestApproachUncertainty: undefined,
eventDurationMin: undefined,
geo: false,
latitude: undefined,
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/pages/PredictionEvents/Detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ function PredictionEventDetail() {
{
title: 'Uncertainty in closest approach (1σ)',
value: `${
occultation.closest_approach_uncertainty
? (() => {
const ca_uncert =
Math.tan((occultation.closest_approach_uncertainty * Math.PI) / (180 * 60 * 60)) * (occultation.delta * 149597870.7)
return ca_uncert < 1 ? `${(ca_uncert * 1000).toFixed(0)} (m)` : `${ca_uncert.toFixed(0)} (km)`
})()
occultation.closest_approach_uncertainty_km
? occultation.closest_approach_uncertainty_km < 1
? `${(occultation.closest_approach_uncertainty_km * 1000).toFixed(0)} (m)`
: `${occultation.closest_approach_uncertainty_km.toFixed(0)} (Km)`
: null
}`
},
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/services/api/Occultation.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ const parsePredictEventsFilters = (params) => {
newFilters.event_duration_min = filters.eventDurationMin
}

if (filters.closestApproachUncertainty !== undefined && filters.closestApproachUncertainty !== '') {
newFilters.closest_approach_uncertainty_km_max = filters.closestApproachUncertainty
}

// Filtro por Object Diameter Range min, max
if (filters.diameterMin !== undefined && filters.diameterMin !== '') {
newFilters.diameter_min = filters.diameterMin
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 @@ -978,6 +978,7 @@ def register_occultations(self, start_period: str, end_period: str, jobid: int):
"moon_illuminated_fraction",
"probability_of_centrality",
"hash_id",
"closest_approach_uncertainty_km",
]
)

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 @@ -68,7 +68,7 @@ def import_occultations(self, data):
# )

sql = (
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, apparent_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, event_duration, moon_separation, sun_elongation, closest_approach_uncertainty, moon_illuminated_fraction, probability_of_centrality, hash_id) "
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, apparent_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, event_duration, moon_separation, sun_elongation, closest_approach_uncertainty, moon_illuminated_fraction, probability_of_centrality, hash_id, closest_approach_uncertainty_km) "
"FROM STDIN with (FORMAT CSV, DELIMITER '|', HEADER);"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def run_occultation_path_coeff(
df["event_duration"] = None
df["instant_uncertainty"] = None
df["closest_approach_uncertainty"] = None
df["closest_approach_uncertainty_km"] = None
df["moon_separation"] = None
df["sun_elongation"] = None
df["moon_illuminated_fraction"] = None
Expand Down Expand Up @@ -177,6 +178,7 @@ def run_occultation_path_coeff(
"event_duration": None,
"instant_uncertainty": None,
"closest_approach_uncertainty": None,
"closest_approach_uncertainty_km": None,
"moon_separation": None,
"sun_elongation": None,
"moon_illuminated_fraction": None,
Expand Down Expand Up @@ -264,6 +266,7 @@ def run_occultation_path_coeff(
# e calcula a incerteza no instante central
e_ra_target, e_dec_target = None, None
closest_approach_uncertainty = None
closest_approach_uncertainty_km = None
instant_uncertainty = None
if has_uncertainties:
datetime_object = dt.fromisoformat(row["date_time"])
Expand Down Expand Up @@ -292,6 +295,9 @@ def run_occultation_path_coeff(
e_dec_star=df_gaia_csv["dec_error"][star_index] / 1000,
)

closest_approach_uncertainty_km = np.tan(
(closest_approach_uncertainty * np.pi) / (180 * 60 * 60)
) * (row["delta"] * 149597870.7)
# instant_uncertainty = get_instant_uncertainty(row["position_angle"], row["delta"], row["velocity"],
# e_ra_target, e_dec_target, e_ra_star=df_gaia_csv["ra_error"][star_index]/1000, e_dec_star=df_gaia_csv["dec_error"][star_index]/1000)

Expand All @@ -303,6 +309,7 @@ def run_occultation_path_coeff(
"event_duration": event_duration,
"instant_uncertainty": instant_uncertainty,
"closest_approach_uncertainty": closest_approach_uncertainty,
"closest_approach_uncertainty_km": closest_approach_uncertainty_km,
"moon_separation": moon_separation,
"sun_elongation": sun_elongation,
"moon_illuminated_fraction": moon_illuminated_fraction,
Expand Down Expand Up @@ -373,6 +380,9 @@ def run_occultation_path_coeff(
df["closest_approach_uncertainty"] = df_coeff[
"closest_approach_uncertainty"
]
df["closest_approach_uncertainty_km"] = df_coeff[
"closest_approach_uncertainty_km"
]
df["moon_separation"] = df_coeff["moon_separation"]
df["sun_elongation"] = df_coeff["sun_elongation"]
df["moon_illuminated_fraction"] = df_coeff["moon_illuminated_fraction"]
Expand Down Expand Up @@ -594,6 +604,7 @@ def run_occultation_path_coeff(
"moon_illuminated_fraction",
"probability_of_centrality",
"hash_id",
"closest_approach_uncertainty_km",
]
)

Expand Down

0 comments on commit 0821c4f

Please sign in to comment.