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

Add field offsets #72

Merged
merged 4 commits into from
Jun 25, 2024
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.3.6] - 2024-06-25

## What's Changed
* Added field/tile seperation calculation and columns
* Added an auto-purge to temp-image files in imager

## [2.3.5] - 2024-06-21

### What's Changed
Expand Down
8 changes: 8 additions & 0 deletions arrakis/columns_possum.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@
"description": "Separation from tile centre",
"ucd": "pos.angDistance",
},
"l_tile_centre": {
"description": "RA offset from tile centre",
"ucd": "pos.eq.ra;pos.offset",
},
"m_tile_centre": {
"description": "Dec offset from tile centre",
"ucd": "pos.eq.dec;pos.offset",
},
"s_code": {
"description": "Source complexity classification",
"ucd": "meta.code.class",
Expand Down
2 changes: 1 addition & 1 deletion arrakis/configs/petrichor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cluster_kwargs:
worker_extra_args: ["--lifetime", "11.5h", "--lifetime-stagger", "2m"]
adapt_kwargs:
minimum_jobs: 1
maximum_jobs: 36
maximum_jobs: 18
wait_count: 20
target_duration: "300s"
interval: "30s"
7 changes: 2 additions & 5 deletions arrakis/imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,6 @@ def image_beam(
# Evaluate the temp directory if a ENV variable is used
temp_dir_images = parse_env_path(temp_dir_images)
if temp_dir_images != out_dir:
# Add a new subdir to the temp directory
# Attempt to prevent other tasks from overwriting each other
ms_hash = hashlib.md5(ms.resolve(strict=True).as_posix().encode()).hexdigest()
temp_dir_images = temp_dir_images / ms_hash
temp_dir_images.mkdir(parents=True, exist_ok=True)
# Copy the MS to the temp directory
ms_temp = temp_dir_images / ms.name
logger.info(f"Copying {ms} to {ms_temp}")
Expand Down Expand Up @@ -456,6 +451,8 @@ def image_beam(
all_fits_files = list(temp_dir_images.glob(f"{prefix.name}*.fits"))
for fits_file in tqdm(all_fits_files, desc="Copying images", file=TQDM_OUT):
shutil.copy(fits_file, out_dir)
# Purge the temp directory
fits_file.unlink()

# Update the prefix
prefix = out_dir / prefix.name
Expand Down
71 changes: 65 additions & 6 deletions arrakis/makecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,60 @@ def write_votable(rmtab: TableLike, outfile: str) -> None:
replace_nans(outfile)


def update_tile_separations(rmtab: TableLike, field_col: Collection) -> TableLike:
"""
Update the tile separations in the catalogue

Args:
rmtab (TableLike): Table to update
field_col (Collection): Field collection

Returns:
TableLike: Updated table

"""
logger.info("Updating tile separations")
field_names = np.unique(rmtab["tile_id"].data)

field_data = pd.DataFrame(
field_col.find(
{"FIELD_NAME": {"$in": list(field_names)}},
)
)
field_data.drop_duplicates(subset=["FIELD_NAME"], inplace=True)
field_data.set_index("FIELD_NAME", inplace=True)

field_coords = SkyCoord(
ra=field_data["RA_DEG"], dec=field_data["DEC_DEG"], unit=(u.deg, u.deg)
)
field_data["coords"] = field_coords

coords = SkyCoord(ra=rmtab["ra"], dec=rmtab["dec"], unit=(u.deg, u.deg))

rmtab.add_column(
Column(
data=np.zeros_like(rmtab["ra"]) * np.nan, name="l_tile_centre", unit=u.deg
)
)
rmtab.add_column(
Column(
data=np.zeros_like(rmtab["ra"]) * np.nan, name="m_tile_centre", unit=u.deg
)
)

for field_name, row in field_data.iterrows():
field_coord = row["coords"]
tab_idx = rmtab["tile_id"] == field_name
tile_sep = coords[tab_idx].separation(field_coord)
tile_l, tile_m = coords[tab_idx].spherical_offsets_to(field_coord)
rmtab["l_tile_centre"][tab_idx] = tile_l
rmtab["m_tile_centre"][tab_idx] = tile_m
rmtab["separation_tile_centre"][tab_idx] = tile_sep
rmtab["beamdist"][tab_idx] = tile_sep

return rmtab


@flow(name="Make catalogue")
def main(
field: str,
Expand Down Expand Up @@ -859,21 +913,23 @@ def main(
beams_col, island_col, comp_col = get_db(
host=host, epoch=epoch, username=username, password=password
)
field_col = get_field_db(
host=host,
epoch=epoch,
username=username,
password=password,
)

# Check for SBID match
if sbid is not None:
field_col = get_field_db(
host=host,
epoch=epoch,
username=username,
password=password,
)
sbid_check = validate_sbid_field_pair(
field_name=field,
sbid=sbid,
field_col=field_col,
)
if not sbid_check:
raise ValueError(f"SBID {sbid} does not match field {field}")

logger.info("Starting beams collection query")
tick = time.time()
query = {"$and": [{f"beams.{field}": {"$exists": True}}]}
Expand Down Expand Up @@ -1043,6 +1099,9 @@ def main(
rmtab["sbid"] = sbid
rmtab["field_name"] = field

# Add tile separations
rmtab = update_tile_separations(rmtab, field_col)

# Fix sigma_add
rmtab = sigma_add_fix(rmtab)

Expand Down
Loading