Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

now keeping tile, petal, and loc #1060

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 11 additions & 11 deletions py/picca/delta_extraction/astronomical_objects/desi_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DesiForest(Forest):
targetid: int
Targetid of the object

tile: list of int
tileid: list of int
Identifier of the tile used in the observation. None for no info
"""
def __init__(self, **kwargs):
Expand Down Expand Up @@ -68,10 +68,10 @@ def __init__(self, **kwargs):
"Missing variable 'targetid'")
del kwargs["targetid"]

self.tile = []
if kwargs.get("tile") is not None:
self.tile.append(kwargs.get("tile"))
del kwargs["tile"]
self.tileid = []
if kwargs.get("tileid") is not None:
self.tileid.append(kwargs.get("tileid"))
del kwargs["tileid"]

# call parent constructor
kwargs["los_id"] = self.targetid
Expand All @@ -98,7 +98,7 @@ def coadd(self, other):
f"{type(other).__name__}")
self.night += other.night
self.petal += other.petal
self.tile += other.tile
self.tileid += other.tileid
super().coadd(other)

def get_header(self):
Expand Down Expand Up @@ -129,9 +129,9 @@ def get_header(self):
'comment': 'Observation petal(s)'
},
{
'name': 'TILE',
'value': "-".join(str(tile) for tile in self.tile),
'comment': 'Observation tile(s)'
'name': 'TILEID',
'value': "-".join(str(tileid) for tileid in self.tileid),
'comment': 'Observation tileid(s)'
},
]

Expand All @@ -152,7 +152,7 @@ def get_metadata(self):
self.targetid,
"-".join(str(night) for night in self.night),
"-".join(str(petal) for petal in self.petal),
"-".join(str(tile) for tile in self.tile),
"-".join(str(tileid) for tileid in self.tileid),
]
return metadata

Expand All @@ -168,7 +168,7 @@ def get_metadata_dtype(cls):
data
"""
dtype = super().get_metadata_dtype()
dtype += [('TARGETID', int), ('NIGHT', 'S12'), ('PETAL', 'S12'), ('TILE', 'S12')]
dtype += [('TARGETID', int), ('NIGHT', 'S12'), ('PETAL', 'S12'), ('TILEID', 'S12')]
return dtype

@classmethod
Expand Down
8 changes: 7 additions & 1 deletion py/picca/delta_extraction/data_catalogues/desi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def format_data(self,

# Loop over quasars in catalogue fragment
for row in catalogue:
# Find which row in tile contains this quasar
# Find which row in catalogue contains this quasar
# It should be there by construction
targetid = row["TARGETID"]
w_t = np.where(targetid_spec == targetid)[0]
Expand Down Expand Up @@ -338,6 +338,12 @@ def format_data(self,
"z": row['Z'],
}
args["log_lambda"] = np.log10(spec['WAVELENGTH'])
if "TILEID" in row:
args["tileid"] = row['TILEID']
if "PETAL_LOC" in row:
args["petal"] = row['PETAL_LOC']
if "NIGHT" in row:
args["night"] = row['NIGHT']

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add e.g. FIBER or EXPID? Are these fields all read earlier from HDU2 (EXP_FIBERMAP) of the coadd-files, or just when reading spectra-files?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked and here we'd just copy over info from the catalogue, is all this info in the actual quasar cats? or would we need to assemble the data from the coadd-files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly, the FIBER would be nice to have. I'm not sure about the EXPID. @julienguy , what do you think?

if self.analysis_type == "BAO 3D":
forest = DesiForest(**args)
Expand Down
7 changes: 6 additions & 1 deletion py/picca/tests/delta_extraction/abstract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ def compare_fits(self, orig_file, new_file):
orig_header = orig_hdul[hdu_name].header
new_header = new_hdul[hdu_name].header
for key in orig_header:
self.assertTrue(key in new_header)
if not key in new_header:
print(f"\nOriginal file: {orig_file}")
print(f"New file: {new_file}")
print(f"\n For header {orig_header['EXTNAME']}")
print(f"\n Missing key {key} in new header")
self.assertTrue(key in new_header)
if not key in ["CHECKSUM", "DATASUM"]:
if (orig_header[key] != new_header[key] and
(isinstance(orig_header[key], str) or not
Expand Down
34 changes: 17 additions & 17 deletions py/picca/tests/delta_extraction/astronomical_object_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def get_kwargs_rebin(wave_solution, which_spectrum, rebin=1, is_p1d=False, is_de
# define contructors for DesiForest
def get_desi_kwargs_input(wave_solution, which_spectrum, is_p1d=False):
""" This function creates the sparse input spectrum for DESI.
Also includes targetid, night, petal and tile information.
Also includes targetid, night, petal and tileid information.

Arguments
---------
Expand All @@ -276,14 +276,14 @@ def get_desi_kwargs_input(wave_solution, which_spectrum, is_p1d=False):
"targetid": TARGETID,
"night": 0,
"petal": 0,
"tile": 0,
"tileid": 0,
})
elif which_spectrum == "2":
kwargs_desi_forest.update({
"targetid": TARGETID,
"night": 1,
"petal": 2,
"tile": 3,
"tileid": 3,
})
else:
return None
Expand All @@ -292,7 +292,7 @@ def get_desi_kwargs_input(wave_solution, which_spectrum, is_p1d=False):

def get_desi_kwargs_rebin(wave_solution, which_spectrum, rebin=1, is_p1d=False):
""" This function creates the rebinned spectrum for DESI.
Also includes targetid, night, petal and tile information.
Also includes targetid, night, petal and tileid information.

Arguments
---------
Expand Down Expand Up @@ -323,14 +323,14 @@ def get_desi_kwargs_rebin(wave_solution, which_spectrum, rebin=1, is_p1d=False):
"targetid": TARGETID,
"night": [0, 1],
"petal": [0, 2],
"tile": [0, 3],
"tileid": [0, 3],
})
else:
kwargs_desi_forest.update({
"targetid": TARGETID,
"night": [0],
"petal": [0],
"tile": [0],
"tileid": [0],
})

kwargs_desi_forest["los_id"] = TARGETID
Expand Down Expand Up @@ -556,8 +556,8 @@ def assert_forest_object(self, test_obj, kwargs):
self.assertTrue(test_obj.night == kwargs.get("night"))
self.assertTrue(isinstance(test_obj.petal, list))
self.assertTrue(test_obj.petal == kwargs.get("petal"))
self.assertTrue(isinstance(test_obj.tile, list))
self.assertTrue(test_obj.tile == kwargs.get("tile"))
self.assertTrue(isinstance(test_obj.tileid, list))
self.assertTrue(test_obj.tileid == kwargs.get("tileid"))
self.assertTrue(test_obj.targetid == kwargs.get("targetid"))

if isinstance(test_obj, Pk1dForest):
Expand Down Expand Up @@ -725,9 +725,9 @@ def assert_get_header(self, test_obj):
self.assertTrue(header[index + 3].get("name") == "PETAL")
petal = "-".join([f"{petal}" for petal in test_obj.petal])
self.assertTrue(header[index + 3].get("value") == petal)
self.assertTrue(header[index + 4].get("name") == "TILE")
tile = "-".join([f"{tile}" for tile in test_obj.tile])
self.assertTrue(header[index + 4].get("value") == tile)
self.assertTrue(header[index + 4].get("name") == "TILEID")
tileid = "-".join([f"{tileid}" for tileid in test_obj.tileid])
self.assertTrue(header[index + 4].get("value") == tileid)
index += 4

def test_astronomical_object(self):
Expand Down Expand Up @@ -840,16 +840,16 @@ def test_desi_forest(self):
test_obj.rebin()
self.assert_forest_object(test_obj, kwargs_desi_forest_rebin)

# create a DesiForest with missing night, petal and tile
# create a DesiForest with missing night, petal and tileid
kwargs = kwargs_desi_forest.copy()
del kwargs["night"], kwargs["petal"], kwargs["tile"]
del kwargs["night"], kwargs["petal"], kwargs["tileid"]
test_obj = DesiForest(**kwargs)
test_obj.rebin()

kwargs = kwargs_desi_forest_rebin.copy()
kwargs["night"] = []
kwargs["petal"] = []
kwargs["tile"] = []
kwargs["tileid"] = []
self.assert_forest_object(test_obj, kwargs)

# create a DesiForest with missing DesiForest variables
Expand Down Expand Up @@ -1035,16 +1035,16 @@ def test_desi_pk1d_forest(self):
test_obj = DesiPk1dForest(**kwargs)
test_obj.rebin()

# create a DesiPk1dForest with missing night, petal and tile
# create a DesiPk1dForest with missing night, petal and tileid
kwargs = kwargs_desi_pk1d_forest.copy()
del kwargs["night"], kwargs["petal"], kwargs["tile"]
del kwargs["night"], kwargs["petal"], kwargs["tileid"]
test_obj = DesiPk1dForest(**kwargs)
test_obj.rebin()

kwargs = kwargs_desi_pk1d_forest_rebin.copy()
kwargs["night"] = []
kwargs["petal"] = []
kwargs["tile"] = []
kwargs["tileid"] = []
self.assert_forest_object(test_obj, kwargs)

# create a DesiForest with missing DesiPk1dForest variables
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading