Skip to content

Commit 1022ef0

Browse files
committed
Merge branch 'coordinates'
2 parents 03db8d3 + e65e063 commit 1022ef0

File tree

6 files changed

+70
-29
lines changed

6 files changed

+70
-29
lines changed

README.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<p align="center">
2-
<img src="docs/hostphot_logo.png" alt="drawing" width="300"/>
3-
</p>
1+
<p align="center"><img src="docs/hostphot_logo.png" alt="drawing" width="300"/></p>
42

53
Global and local photometry of galaxies hosting supernovae or other transients
64

@@ -14,9 +12,9 @@ Global and local photometry of galaxies hosting supernovae or other transients
1412
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6992139.svg)](https://doi.org/10.5281/zenodo.6992139)
1513
[![Coverage](https://raw.githubusercontent.com/temuller/hostphot/main/coverage.svg)](https://raw.githubusercontent.com/temuller/hostphot/main/coverage.svg)
1614

17-
1815
Read the full documentation at [hostphot.readthedocs.io](https://hostphot.readthedocs.io/en/latest/). It is recommended to read the **Further Information** section to understand how HostPhot works.
1916
___
17+
2018
## Conda environment
2119

2220
It is recommended to create an environment before installing HostPhot:
@@ -85,7 +83,6 @@ If the user is not happy with the result of the masking, there are a few paramet
8583

8684
Local photometry can be obtained for multiple circular apertures:
8785

88-
8986
```python
9087
import hostphot.photometry.local_photometry as lp
9188

@@ -122,31 +119,30 @@ by Schlafly & Finkbeiner (2011) and the extinction law from Fitzpatrick (1999).
122119

123120
This is the list of surveys in HostPhot:
124121

125-
* DES
126-
* PS1
127-
* SDSS
128-
* GALEX
129-
* 2MASS
130-
* WISE
131-
* unWISE
132-
* Legacy Survey
133-
* Spitzer (SEIP)
134-
* VISTA (VHS, VIDEO, VIKING)
135-
* HST (WFC3 only)
136-
* SkyMapper (not well calibrated for extended sources)
137-
* SPLUS
138-
* UKIDSS
139-
* JWST (NIRCam only)
122+
* DES
123+
* PS1
124+
* SDSS
125+
* GALEX
126+
* 2MASS
127+
* WISE
128+
* unWISE
129+
* Legacy Survey
130+
* Spitzer (SEIP)
131+
* VISTA (VHS, VIDEO, VIKING)
132+
* HST (WFC3 only)
133+
* SkyMapper (not well calibrated for extended sources)
134+
* SPLUS
135+
* UKIDSS
136+
* JWST (NIRCam only)
140137

141138
## Contributing
142139

143-
To contribute, either open an issue or send a pull request (prefered option). You can also contact me directly (check my profile: https://github.com/temuller).
140+
To contribute, either open an issue or send a pull request (prefered option). You can also contact me directly (check my profile: [https://github.com/temuller](https://github.com/temuller)).
144141

145142
### Adding other surveys
146143

147144
If you wish a survey to be added to HostPhot, there are a couple of ways of doing it. 1) You can do a pull request, following the same structure as used for the surveys that are already implemented, or 2) open an issue asking for a survey to be added. Either way, there are a fews things needed to add a survey: where to download the images from (e.g., using `astroquery`), zero-points to convert the images's flux/counts values into magnitudes, the magnitude system (e.g. AB, Vega), the pixel scaling of the images (in units of arcsec/pixel), the filters transmission functions and any other piece of information necessary to properly estimate magnitudes, errors, etc. If you open an issue asking for a survey to be added, please include all this information. For more information, please check the [Adding New Surveys](https://hostphot.readthedocs.io/en/latest/further_information/adding_surveys.html) section of the documentation.
148145

149-
150146
## Citing HostPhot
151147

152148
If you make use of HostPhot, please cite the following [paper](https://joss.theoj.org/papers/10.21105/joss.04508):
@@ -168,6 +164,11 @@ If you make use of HostPhot, please cite the following [paper](https://joss.theo
168164

169165
## What's new
170166

167+
v3.1.2
168+
169+
* Fixing download of GALEX images (issue introduced in v3.1.0 when trying to avoid timeout error - [#13](https://github.com/temuller/hostphot/issues/13)).
170+
* Also storing the coordinates of detected objects in RA,DEC and the ellipse parameters a/b in degrees.
171+
171172
v3.1.1
172173

173174
* Fixing minor bug when calculating dust extinction for Legacy Survey (Issue [#12](https://github.com/temuller/hostphot/issues/12))
@@ -176,7 +177,7 @@ v3.1.1
176177
v3.1.0
177178

178179
* Using DES DR2 instead of DR1
179-
* Downloading images, for some surveys, trying to avoid timeout errors.
180+
* Avoid timeout errors when downloading image cutouts for some surveys.
180181
* Adapting global aperture even if the survey is the same as the reference (mainly to avoid issues with JWST).
181182
* Fixing/adding features from different issues, mainly for HST/JWST ([#8](https://github.com/temuller/hostphot/issues/8), [#9](https://github.com/temuller/hostphot/issues/9), [#10](https://github.com/temuller/hostphot/issues/10), [#11](https://github.com/temuller/hostphot/issues/11) - thanks Lisa!).
182183

src/hostphot/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = "3.1.1"
3+
__version__ = "3.1.2"

src/hostphot/cutouts/galex.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from astropy.coordinates import SkyCoord
99
from astroquery.mast import Observations
1010

11-
from hostphot.utils import open_fits_from_url
1211
from hostphot.surveys_utils import get_survey_filters, check_filters_validity, survey_pixel_scale
1312

1413
import warnings
@@ -93,9 +92,9 @@ def get_GALEX_images(ra: float, dec: float, size: float | u.Quantity = 3,
9392
hdu_list = []
9493
for file in files:
9594
try:
96-
hdu = open_fits_from_url(file)
95+
hdu = fits.open(file)
9796
hdu_list.append(hdu)
98-
except:
97+
except Exception:
9998
pass
10099

101100
# calculate the separation of the galaxy to the image center

src/hostphot/processing/masking.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ def create_mask(
213213
)
214214
sigma /= conv_factor
215215

216-
#masked_data = mask_image(data_sub, nongal_objs, r=r, sigma=sigma)
217216
if len(nongal_objs) > 0:
218217
masked_data = mask_image(data_sub, nongal_objs, r=r, sigma=sigma)
219218
else:

src/hostphot/processing/objects_detection.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
from astropy.io import fits
88
from astropy import units as u
99
from astropy.coordinates import SkyCoord
10+
from astropy.wcs.utils import proj_plane_pixel_scales
11+
1012
from astroquery.gaia import Gaia
1113
from astroquery.mast import Catalogs
1214

1315
import sep
1416
from hostphot._constants import font_family
15-
from hostphot.utils import suppress_stdout
17+
from hostphot.utils import suppress_stdout, add_fields
1618

1719
import warnings
1820
from astropy.utils.exceptions import AstropyWarning
@@ -68,6 +70,19 @@ def extract_objects(
6870
ra=host_ra, dec=host_dec, unit=(u.degree, u.degree), frame="icrs"
6971
)
7072
objs_coords = img_wcs.pixel_to_world(objects["x"], objects["y"])
73+
# add coordinates and ellipse a/b in degrees
74+
sx, sy = proj_plane_pixel_scales(img_wcs) # degrees per pixel
75+
a_deg, b_deg = objects["a"] * sx, objects["b"] * sy
76+
objects = add_fields(objects,
77+
names=["ra", "dec", "a_deg", "b_deg"],
78+
dtypes=["f8", "f8", "f8", "f8"],
79+
data=[objs_coords.ra.value,
80+
objs_coords.dec.value,
81+
a_deg,
82+
b_deg
83+
]
84+
)
85+
7186
distances = host_coords.separation(objs_coords).to(u.arcsec)
7287
dist_arcsec = distances.value
7388

src/hostphot/utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import os
22
import sys
33
import requests
4+
import numpy as np
45
import pandas as pd
56
from io import BytesIO
67
from pathlib import Path
78
import matplotlib.image as img
89
import matplotlib.pyplot as plt
910
from contextlib import contextmanager
1011
from datetime import datetime, timezone
12+
from numpy.lib import recfunctions as rfn
1113

1214
import aplpy
1315
from astropy.io import fits
@@ -46,6 +48,31 @@ def open_fits_from_url(url: str) -> fits.hdu:
4648
hdu = fits.open(BytesIO(r.content))
4749
return hdu
4850

51+
def add_fields(arr: np.ndarray, names: str | list, dtypes: str | list, data: np.ndarray) -> np.ndarray:
52+
"""Add new fields to a NumPy structured array.
53+
54+
Parameters
55+
----------
56+
arr: Original structured array.
57+
names: Name(s) of the new fields.
58+
dtype: Dtype(s) of the new fields (e.g. 'f8', 'i4').
59+
data: Data for the new fields.
60+
61+
Returns
62+
-------
63+
new_arr: New structured array with added fields.
64+
"""
65+
if isinstance(names, str):
66+
names = [names]
67+
if isinstance(dtypes, (str, np.dtype)):
68+
dtypes = [dtypes]
69+
if not isinstance(data, (list, tuple)):
70+
data = [data]
71+
72+
new_arr = rfn.append_fields(arr, names, data, dtypes=dtypes, usemask=False)
73+
74+
return new_arr
75+
4976
@contextmanager
5077
def suppress_stdout():
5178
"""Suppresses annoying outputs.

0 commit comments

Comments
 (0)