Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
FusRoman committed Nov 2, 2023
1 parent 4583d36 commit 9f47ad9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
1 change: 1 addition & 0 deletions fink_fat/associations/association_orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def orbit_associations(
]["ssoCandId"]
assert len(duplicated_id) == 0

# recompute the orbit using local or cluster mode
new_orbit_pdf = switch_local_cluster(config, traj_to_new_orbit)

# remove the failed orbits
Expand Down
4 changes: 2 additions & 2 deletions fink_fat/command_line/cli_main/kalman.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from fink_fat.associations.association_orbit import orbit_associations
from fink_fat.associations.association_kalman import kalman_association
from fink_fat.kalman.init_kalman import init_kalman
from fink_fat.command_line.orbit_cli import kalman_to_orbit
from fink_fat.command_line.orbit_cli import trcand_to_orbit


def get_default_input() -> (
Expand Down Expand Up @@ -332,7 +332,7 @@ def cli_kalman_associations(arguments: dict, config: dict, output_path: str):
trajectory_df = pd.concat([trajectory_df, seeds])
kalman_df = pd.concat([kalman_df, new_kalman_df])

trajectory_df, kalman_df, trajectory_orb, orbits = kalman_to_orbit(
trajectory_df, kalman_df, trajectory_orb, orbits = trcand_to_orbit(
config, trajectory_df, trajectory_orb, kalman_df, orbits, logger, True
)

Expand Down
27 changes: 13 additions & 14 deletions fink_fat/command_line/orbit_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,29 +232,28 @@ def switch_local_cluster(config: dict, traj_orb: pd.DataFrame) -> pd.DataFrame:
return new_orbit_pdf


def kalman_to_orbit(
def trcand_to_orbit(
config: dict,
trajectory_df: pd.DataFrame,
trajectory_orb: pd.DataFrame,
kalman_df: pd.DataFrame,
trparams_df: pd.DataFrame,
orbits: pd.DataFrame,
logger: LoggerNewLine,
verbose: bool,
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame, pd.DataFrame]:
"""
Compute and return the orbits for the trajectories with enough points found by the kalman filters
Compute and return the orbits for the trajectories with enough points found by the prediction functions
Parameters
----------
config : dict
the data from the config file
trajectory_df : pd.DataFrame
trajectories found by the kalman filters
trajectories found by the function predictors
trajectory_orb : pd.DataFrame
trajectories with orbits
kalman_df : pd.DataFrame
the kalman filters parameters
trparams_df : pd.DataFrame
the fit functions parameters
orbits : pd.DataFrame
the orbits parameters
logger : LoggerNewLine
Expand All @@ -265,7 +264,7 @@ def kalman_to_orbit(
Returns
-------
Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame, pd.DataFrame,]
* trajectories found by the kalman filters without those sent to the orbit fitting
* trajectories found by the prediction functions without those sent to the orbit fitting
* kalman filters without those with the associated trajectories sent to the orbit fitting
* trajectories with the ones with orbits
* the orbits parameters with the new ones
Expand All @@ -276,7 +275,7 @@ def kalman_to_orbit(
large_traj = traj_size[traj_size >= orbit_limit]

if len(large_traj) == 0:
return trajectory_df, kalman_df, trajectory_orb, orbits
return trajectory_df, trparams_df, trajectory_orb, orbits

# to be send to the orbit fitting,
# a trajectory must have a number of point above the orbit point limit set in the config file
Expand Down Expand Up @@ -310,16 +309,16 @@ def kalman_to_orbit(
trajectory_df = trajectory_df[
~trajectory_df["trajectory_id"].isin(new_traj_id)
].reset_index(drop=True)
kalman_df = kalman_df[~kalman_df["trajectory_id"].isin(new_traj_id)].reset_index(
trparams_df = trparams_df[~trparams_df["trajectory_id"].isin(new_traj_id)].reset_index(
drop=True
)
failed_orbit = np.setdiff1d(large_traj.index.values, new_traj_id)
mask_failed = kalman_df["trajectory_id"].isin(failed_orbit)
mask_failed = trparams_df["trajectory_id"].isin(failed_orbit)
with pd.option_context("mode.chained_assignment", None):
kalman_df.loc[mask_failed, "orbfit_test"] = (
kalman_df.loc[mask_failed, "orbfit_test"] + 1
trparams_df.loc[mask_failed, "orbfit_test"] = (
trparams_df.loc[mask_failed, "orbfit_test"] + 1
)
return trajectory_df, kalman_df, trajectory_orb, orbits
return trajectory_df, trparams_df, trajectory_orb, orbits


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion fink_fat/roid_fitting/init_roid_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def init_polyast(
night_pdf: pd.DataFrame,
) -> pd.DataFrame:
"""
Initialize kalman filters based on the seeds or tracklets.
Initialize fit functions based on the seeds or tracklets.
required columns: ra, dec, jd, magpsf, fid, trajectory_id
Parameters
Expand Down

0 comments on commit 9f47ad9

Please sign in to comment.