Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more data cleaning for sky json files
  • Loading branch information
monodera committed Sep 16, 2022
commit bb1202a3ca00e54f7d1020bb236c673645212328
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
import pandas as pd
from logzero import logger


def main(work_dir, work_subdirs, catalog_names, out_dir, version):
Expand Down Expand Up @@ -42,11 +43,36 @@ def main(work_dir, work_subdirs, catalog_names, out_dir, version):

# keys in JSON
# ['objid', 'ra', 'dec', 'magThresh', 'tract']
print(data.keys())
json_keys = data.keys()
print(json_keys)

n_obj = len(data["objid"])

# patch = int(data["imgfile"][-8:-5].replace(",", "0"))
if ("imgfile" in json_keys) and (imgfile is not None):
logger.info(
"imgfile is found. trying to extract tract/patch information."
)
tract = np.full(n_obj, int(data["imgfile"][-13:-9]), dtype=int)
patch = np.full(
n_obj, int(data["imgfile"][-8:-5].replace(",", "0")), dtype=int
)
elif "tract" in json_keys:
logger.info(
"Tract is found in the keys, while patch is not found. Use None for patch."
)
tract = np.full(n_obj, data["tract"])
patch = [None] * n_obj
else:
logger.warning(
"Both tract and patch information are not found. Use None for them."
)
tract = [None] * n_obj
patch = [None] * n_obj

if type(data["magThresh"]) is list:
mag_thresh = data["magThresh"]
else:
mag_thresh = [data["magThresh"]] * n_obj

df = pd.DataFrame(
{
Expand All @@ -55,8 +81,8 @@ def main(work_dir, work_subdirs, catalog_names, out_dir, version):
"ra": data["ra"],
"dec": data["dec"],
"epoch": ["J2000.0"] * n_obj,
"tract": data["tract"],
"patch": [None] * n_obj,
"tract": tract,
"patch": patch,
"target_type_name": ["SKY"] * n_obj,
"input_catalog_name": [catalog_name] * n_obj,
"mag_thresh": [data["magThresh"]] * n_obj,
Expand Down