Skip to content

Commit

Permalink
update tags to be more persistent in time (#120)
Browse files Browse the repository at this point in the history
* update tags to be more persistentin time

* pep8 requirements

* update test cli data according to the new tags

* remove tags issue

* pep8 requirements

* bump to 0.15.0
  • Loading branch information
FusRoman authored Jul 11, 2023
1 parent 3d26be6 commit 06556ae
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 39 deletions.
7 changes: 2 additions & 5 deletions bin/utils_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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)
}
Expand Down
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.14.0"
__version__ = "0.15.0"
46 changes: 21 additions & 25 deletions fink_fat/others/id_tags.py
Original file line number Diff line number Diff line change
@@ -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
-------
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -60,6 +57,8 @@ def generate_tags(begin, end):
start tags
end : integer
end tags
jd : float list
list of discovery date
Returns
-------
Expand All @@ -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
Expand Down
Binary file modified fink_fat/test/cli_test/fink_fat_out_test/mpc/orbital.parquet
Binary file not shown.
Binary file not shown.
8 changes: 0 additions & 8 deletions fink_fat/test/cli_test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pandas.testing import assert_frame_equal
import shutil
import sys
import datetime

import traceback
import logging
Expand Down Expand Up @@ -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),
Expand Down
Binary file modified fink_fat/test/utils_cli_test_orb.parquet
Binary file not shown.
Binary file modified fink_fat/test/utils_cli_test_traj.parquet
Binary file not shown.

0 comments on commit 06556ae

Please sign in to comment.