annotate utils.py @ 0:f40d05521dca draft default tip

planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
author astroteam
date Fri, 25 Apr 2025 19:33:20 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
1 import numpy as np
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
2 from astroquery.ipac.ned import Ned
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
3
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
4
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
5 def find_redshift(src_name: str):
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
6 result_table = Ned.query_object(src_name)
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
7 # Check if there are results
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
8 if result_table is not None:
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
9 # Extract the redshift from the result table
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
10 z = float(result_table["Redshift"].data[0])
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
11 if np.isnan(z):
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
12 raise NotImplementedError(
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
13 f"Failed to find redshift for {src_name}")
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
14 else:
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
15 raise ValueError(f"Object named {src_name} not found in NED database")
f40d05521dca planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit de01e3c02a26cd6353a6b9b6f8d1be44de8ccd54
astroteam
parents:
diff changeset
16 return z