diff --git a/bin/utils_cli.py b/bin/utils_cli.py index 7d89ecfe..c52f6dbc 100644 --- a/bin/utils_cli.py +++ b/bin/utils_cli.py @@ -433,7 +433,7 @@ def assig_tags(orb_df, traj_orb_df, start_tags): >>> orb = pd.DataFrame({ ... "trajectory_id": [0, 1, 2, 3, 4, 5], ... "a": [1, 1.5, 1.6, 2.8, 35.41, 265.32], - ... "ref_epoch": [0, 2, 3, 5, 4, 1] + ... "ref_epoch": [2460235.42, 2460412.42, 2460842.42, 2460137.42, 2460131.42, 2460095.42] ... }) >>> traj = pd.DataFrame({ ... "trajectory_id": [0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 3, 3, 4, 5, 3, 5, 4, 5, 4, 3, 1, 2, 3, 4, 5, 5, 2], @@ -445,15 +445,12 @@ def assig_tags(orb_df, traj_orb_df, start_tags): >>> orb_test = pd.read_parquet("fink_fat/test/utils_cli_test_orb.parquet") >>> traj_test = pd.read_parquet("fink_fat/test/utils_cli_test_traj.parquet") - >>> orb_test["ssoCandId"] = orb_test["ssoCandId"].str.replace("2022", str(datetime.date.today().year), regex=False) - >>> traj_test["ssoCandId"] = traj_test["ssoCandId"].str.replace("2022", str(datetime.date.today().year), regex=False) - >>> assert_frame_equal(orb_test, new_orb) >>> assert_frame_equal(traj_test, new_traj) """ orb_df = orb_df.sort_values("ref_epoch") - all_tags = generate_tags(start_tags, start_tags + len(orb_df)) + all_tags = generate_tags(start_tags, start_tags + len(orb_df), orb_df["ref_epoch"]) int_id_to_tags = { tr_id: tag for tr_id, tag in zip(orb_df["trajectory_id"], all_tags) } diff --git a/fink_fat/__init__.py b/fink_fat/__init__.py index e0b98f4e..6acad165 100644 --- a/fink_fat/__init__.py +++ b/fink_fat/__init__.py @@ -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.14.0" +__version__ = "0.15.0" diff --git a/fink_fat/others/id_tags.py b/fink_fat/others/id_tags.py index a6f1ffa3..df51e697 100644 --- a/fink_fat/others/id_tags.py +++ b/fink_fat/others/id_tags.py @@ -1,20 +1,24 @@ -import datetime +import numpy as np +from astropy.time import Time -def int_to_tags(traj_id): + +def int_to_tags(traj_id, jd): """ Convert an integer into a Fink-FAT trajectory identifier. The identifier format is : "FFYYYYXXXXXXX" where 'FF' is for 'Fink-FAT', - 'YYYY' is the full year (2022), + 'DDMMYYYY' is the full date (01012022), and 'XXXXXXX' is the number of trajectories since the beginning of the year in the base-26. Parameters ---------- traj_id : integer trajectories identifier as an integer + jd : float + the discovery date of the trajectory Returns ------- @@ -23,20 +27,12 @@ def int_to_tags(traj_id): Examples -------- - >>> r = int_to_tags(15) - >>> test_value = 'FF{}aaaaaap'.format(datetime.date.today().year) - >>> test_value == r - True - - >>> r =int_to_tags(27) - >>> test_value = 'FF{}aaaaabb'.format(datetime.date.today().year) - >>> test_value == r - True - - >>> r = int_to_tags(652) - >>> test_value = 'FF{}aaaaazc'.format(datetime.date.today().year) - >>> test_value == r - True + >>> int_to_tags(15, 2460135.98) + 'FF10072023aaaaaap' + >>> int_to_tags(27, 2460135.98) + 'FF10072023aaaaabb' + >>> int_to_tags(652, 2460135.98) + 'FF10072023aaaaazc' """ res_tag = "" for _ in range(7): @@ -46,10 +42,11 @@ def int_to_tags(traj_id): res_tag += chr(r + 97) traj_id = q - return "FF" + str(datetime.date.today().year) + res_tag[::-1] + discovery = Time(jd, format="jd").datetime + return "FF{:02d}{:02d}{}{}".format(discovery.day, discovery.month, discovery.year, res_tag[::-1]) -def generate_tags(begin, end): +def generate_tags(begin, end, jd): """ Generate a list of tags between begin and end @@ -60,6 +57,8 @@ def generate_tags(begin, end): start tags end : integer end tags + jd : float list + list of discovery date Returns ------- @@ -68,13 +67,10 @@ def generate_tags(begin, end): Examples -------- - >>> l = generate_tags(3, 6) - >>> year = datetime.date.today().year - >>> test_value = ['FF{}aaaaaad'.format(year), 'FF{}aaaaaae'.format(year), 'FF{}aaaaaaf'.format(year)] - >>> test_value == l - True + >>> generate_tags(3, 6, [2460135.42, 2460137.57, 2460148.72]) + ['FF09072023aaaaaad', 'FF12072023aaaaaae', 'FF23072023aaaaaaf'] """ - return [int_to_tags(i) for i in range(begin, end)] + return [int_to_tags(i, date) for date, i in zip(jd, np.arange(begin, end))] if __name__ == "__main__": # pragma: no cover diff --git a/fink_fat/test/cli_test/fink_fat_out_test/mpc/orbital.parquet b/fink_fat/test/cli_test/fink_fat_out_test/mpc/orbital.parquet index 8a418989..2bff40fa 100644 Binary files a/fink_fat/test/cli_test/fink_fat_out_test/mpc/orbital.parquet and b/fink_fat/test/cli_test/fink_fat_out_test/mpc/orbital.parquet differ diff --git a/fink_fat/test/cli_test/fink_fat_out_test/mpc/trajectory_orb.parquet b/fink_fat/test/cli_test/fink_fat_out_test/mpc/trajectory_orb.parquet index b9c7a856..76c32cd9 100644 Binary files a/fink_fat/test/cli_test/fink_fat_out_test/mpc/trajectory_orb.parquet and b/fink_fat/test/cli_test/fink_fat_out_test/mpc/trajectory_orb.parquet differ diff --git a/fink_fat/test/cli_test/test_cli.py b/fink_fat/test/cli_test/test_cli.py index 2cbfd163..7e5189c8 100644 --- a/fink_fat/test/cli_test/test_cli.py +++ b/fink_fat/test/cli_test/test_cli.py @@ -2,7 +2,6 @@ from pandas.testing import assert_frame_equal import shutil import sys -import datetime import traceback import logging @@ -118,13 +117,6 @@ "{}mpc/trajectory_orb.parquet".format(data_test_path) ) - orb_test["ssoCandId"] = orb_test["ssoCandId"].str.replace( - "2022", str(datetime.date.today().year), regex=False - ) - obs_orb_test["ssoCandId"] = obs_orb_test["ssoCandId"].str.replace( - "2022", str(datetime.date.today().year), regex=False - ) - try: assert_frame_equal( old_obs.sort_values("candid").round(decimals=5), diff --git a/fink_fat/test/utils_cli_test_orb.parquet b/fink_fat/test/utils_cli_test_orb.parquet index f061d13f..39a44f41 100644 Binary files a/fink_fat/test/utils_cli_test_orb.parquet and b/fink_fat/test/utils_cli_test_orb.parquet differ diff --git a/fink_fat/test/utils_cli_test_traj.parquet b/fink_fat/test/utils_cli_test_traj.parquet index 345d01c8..d87bad4f 100644 Binary files a/fink_fat/test/utils_cli_test_traj.parquet and b/fink_fat/test/utils_cli_test_traj.parquet differ