Skip to content

Commit

Permalink
Issue/126/dbscan fix (#127)
Browse files Browse the repository at this point in the history
* fix

* bump

* sort before to remove wrong cluster
  • Loading branch information
FusRoman authored Jul 25, 2023
1 parent 89cd521 commit 696b4b8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion fink_fat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "0.15.1"
__version__ = "0.15.2"
5 changes: 1 addition & 4 deletions fink_fat/associations/inter_night_associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,7 @@ def night_to_night_association(
t_before = t.time()

# intra night associations steps with the new observations
(
tracklets,
remaining_new_observations,
) = intra_night_step(
(tracklets, remaining_new_observations,) = intra_night_step(
new_observation,
last_trajectory_id,
intra_night_sep_criterion,
Expand Down
4 changes: 3 additions & 1 deletion fink_fat/others/id_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def int_to_tags(traj_id, jd):
traj_id = q

discovery = Time(jd, format="jd").datetime
return "FF{:02d}{:02d}{}{}".format(discovery.day, discovery.month, discovery.year, res_tag[::-1])
return "FF{:02d}{:02d}{}{}".format(
discovery.day, discovery.month, discovery.year, res_tag[::-1]
)


def generate_tags(begin, end, jd):
Expand Down
53 changes: 44 additions & 9 deletions fink_fat/seeding/dbscan_seeding.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ def dist_3d(sep_lim):
return 2.0 * np.sin(np.radians(sep_lim) / 2.0)


def intra_night_seeding(night_observation, sep_criterion=2.585714285714286 * u.arcmin):
def intra_night_seeding(
night_observation, sep_criterion=(2.585714285714286 * u.arcmin).to("deg")
):
"""
Find the cluster corresponding to the intra-night trajectory.
The required columns in the input dataframe are ra and dec.
The required columns in the input dataframe are ra, dec and jd.
Parameters
----------
Expand All @@ -54,16 +56,34 @@ def intra_night_seeding(night_observation, sep_criterion=2.585714285714286 * u.a
>>> import astropy.units as u
>>> df_test = pd.DataFrame({
... "ra": [1, 2, 30, 11, 12],
... "dec": [1, 2, 30, 11, 12]
... "dec": [1, 2, 30, 11, 12],
... "jd": [0, 1, 2, 3, 4]
... })
>>> intra_night_seeding(df_test, 2 * u.deg)
ra dec trajectory_id
0 1 1 0
1 2 2 0
2 30 30 -1
3 11 11 1
4 12 12 1
ra dec jd trajectory_id
0 1 1 0 0
1 2 2 1 0
2 30 30 2 -1
3 11 11 3 1
4 12 12 4 1
>>> df_test = pd.DataFrame({
... "ra": [1, 2, 30, 11, 12, 20, 21, 22],
... "dec": [1, 2, 30, 11, 12, 20, 21, 22],
... "jd": [0, 1, 2, 3, 4, 5, 5, 6]
... })
>>> intra_night_seeding(df_test, 2 * u.deg)
ra dec jd trajectory_id
0 1 1 0 0
1 2 2 1 0
2 30 30 2 -1
3 11 11 3 1
4 12 12 4 1
5 20 20 5 -1
6 21 21 5 -1
7 22 22 6 -1
"""
assert sep_criterion.unit == u.Unit("deg")

Expand All @@ -76,6 +96,21 @@ def intra_night_seeding(night_observation, sep_criterion=2.585714285714286 * u.a
with pd.option_context("mode.chained_assignment", None):
night_observation["trajectory_id"] = clustering.labels_

# remove bad seeds containing observations in the same exposure time
test_jd_0 = (
night_observation.sort_values("jd")
.groupby("trajectory_id")
.agg(is_same_exp=("jd", lambda x: np.any(np.diff(x) == 0.0)))
.reset_index()
)
test_jd_0 = test_jd_0[test_jd_0["trajectory_id"] != -1.0]
jd_0_traj_id = test_jd_0[test_jd_0["is_same_exp"]]["trajectory_id"]

with pd.option_context("mode.chained_assignment", None):
night_observation.loc[
night_observation["trajectory_id"].isin(jd_0_traj_id), "trajectory_id"
] = -1.0

return night_observation


Expand Down

0 comments on commit 696b4b8

Please sign in to comment.