-
Notifications
You must be signed in to change notification settings - Fork 33
some small fixes and edits to work with modap #236
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
base: main
Are you sure you want to change the base?
Changes from 25 commits
20f8ede
e892e99
7665016
9d3e4fe
9b0e1ae
ed15368
b9cc862
4ee4a1b
a5ccaa8
30494c2
c313eec
bb490e4
393e0d9
b413559
93c0a9d
16dda46
cc46376
542d0e5
835d3b3
cb39292
ae48bfe
a058c1d
7789b91
15e7448
69fa6b6
fd020a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,9 +187,13 @@ def extinction_correction(filt, EBV, RV=3.1, max_wave=None, required=True): | |
|
|
||
| source_flux = 1. | ||
| #calculate linear correction | ||
| delta = np.trapezoid(throughput * source_flux * | ||
| 10 ** (-0.4 * Alambda), x=wave) / np.trapezoid( | ||
| throughput * source_flux, x=wave) | ||
| if getattr(np, "trapz", None) is not None: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe worth adding a deprecation warning here. I believe this is for Numpy < 2.0, and so I don't see a reason to support this long term.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, switching over to the scipy implementation if the naming there is a little more stable. |
||
| delta = np.trapz(throughput * source_flux * | ||
| 10 ** (-0.4 * Alambda), wave) / np.trapz( | ||
| throughput * source_flux, wave) | ||
| else: | ||
| delta = np.trapezoid(throughput * source_flux * 10 ** (-0.4 * Alambda), wave) / np.trapezoid( | ||
| throughput * source_flux, wave) | ||
|
|
||
| correction = 1./delta | ||
|
|
||
|
|
@@ -212,7 +216,7 @@ def correct_photom_table(photom, EBV, name, max_wave=None, required=True): | |
| Required keys: 'Name', filters | ||
| EBV (float): | ||
| E(B-V) (can get from frb.galaxies.nebular.get_ebv which uses IRSA Dust extinction query | ||
| name (str):\ | ||
| name (str): | ||
| Name of the object to correct | ||
| required (bool, optional): | ||
| Crash out if the transmission curve is not present | ||
|
|
@@ -250,12 +254,13 @@ def correct_photom_table(photom, EBV, name, max_wave=None, required=True): | |
| continue | ||
| except: | ||
| embed(header='187 in photom') | ||
| # SDSS | ||
| if 'SDSS' in filt: | ||
| if 'extinction_{}'.format(filt[-1]) in photom.keys(): | ||
| print("Appying SDSS-provided extinction correction") | ||
| cut_photom[key] -= cut_photom['extinction_{}'.format(filt[-1])] | ||
| continue | ||
| print('Correcting filter {} for Galactic extinction'.format(filt)) | ||
| # SDSS ### removing this because SDSS correction is sometimes different for very dusty sightlines, but TBD | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would trust SDSS extinction estimates more because I imagine they got their E(B-V) values at the location where they took their spectra as opposed to our method of using the nearest measurement within a few degrees. Worth looking into why they are different. |
||
| # if 'SDSS' in filt: | ||
| # if 'extinction_{}'.format(filt[-1]) in photom.keys(): | ||
| # print("Appying SDSS-provided extinction correction") | ||
| # cut_photom[key] -= cut_photom['extinction_{}'.format(filt[-1])] | ||
| # continue | ||
| # Hack for LRIS | ||
| if 'LRIS' in filt: | ||
| _filter = 'LRIS_{}'.format(filt[-1]) | ||
|
|
@@ -268,6 +273,7 @@ def correct_photom_table(photom, EBV, name, max_wave=None, required=True): | |
| required=required) | ||
| mag_dust = 2.5 * np.log10(1. / dust_correct) | ||
| cut_photom[key] += mag_dust | ||
|
|
||
| # Add it back in | ||
| photom[idx] = cut_photom | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,4 +165,4 @@ def r_vs_dm(outfile='fig_r_vs_z.png', | |
| ''' Run me ''' | ||
| # Command line execution | ||
| if __name__ == '__main__': | ||
| r_vs_dm() | ||
| r_vs_dm() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check that there's a corresponding entry in the new |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,11 @@ def match_ids(IDs, match_IDs, require_in_match=True): | |
| """ | ||
| rows = -1 * np.ones_like(IDs).astype(int) | ||
| # Find which IDs are in match_IDs | ||
| in_match = np.in1d(IDs, match_IDs) | ||
| try: | ||
| in_match = np.isin(IDs, match_IDs) | ||
| except AttributeError: | ||
| # Older NumPy versions | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was under the impression that |
||
| in_match = np.in1d(IDs, match_IDs) | ||
| if require_in_match: | ||
| if np.sum(~in_match) > 0: | ||
| raise IOError("qcat.match_ids: One or more input IDs not in match_IDs") | ||
|
|
@@ -213,8 +217,8 @@ def xmatch_catalogs(cat1:Table, cat2:Table, dist:units.Quantity = 5*units.arcsec | |
| dist1 = None | ||
| dist2 = None | ||
| # Get corodinates | ||
| cat1_coord = SkyCoord(cat1[RACol1]*units.deg, cat1[DecCol1]*units.deg, distance=dist1) | ||
| cat2_coord = SkyCoord(cat2[RACol2]*units.deg, cat2[DecCol2]*units.deg, distance=dist2) | ||
| cat1_coord = SkyCoord(cat1[RACol1], cat1[DecCol1], unit='deg', distance=dist1) | ||
| cat2_coord = SkyCoord(cat2[RACol2], cat2[DecCol2], unit='deg', distance=dist2) | ||
|
|
||
| # Match 2D | ||
| idx, d2d, d3d = cat1_coord.match_to_catalog_sky(cat2_coord) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,14 +20,19 @@ | |
| photom = {} | ||
| photom['DELVE'] = {} | ||
| photom['DELVE']['DELVE_ID'] = 'quick_object_id' | ||
| # photom['DELVE']['DELVE_ID'] = 'coadd_object_id' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like these comments are not changing the original functionality or documenting anything. I suggest getting rid of the comment blocks in this file. |
||
| photom['DELVE']['ra'] = 'ra' | ||
| photom['DELVE']['dec'] = 'dec' | ||
| photom['DELVE']['ebv'] = 'ebv' # Schegel, Finkbeiner, Davis (1998) | ||
| # photom['DELVE']['ebv'] = '_sfd98' | ||
| DELVE_bands = ['g', 'r', 'i', 'z'] | ||
| for band in DELVE_bands: | ||
| photom['DELVE'][f'DELVE_{band}'] = f'mag_auto_{band}' #mag | ||
| photom['DELVE'][f'DELVE_{band}_err'] = f'magerr_auto_{band}' #magerr | ||
| photom['DELVE'][f'class_star_{band}'] = f'class_star_{band}' #morphology class | ||
| ## 'bdf_mag_' 'bdf_mag_err_' 'gap_mag_' 'gap_mag_err_' 'mag_detmodel_' 'magerr_detmodel_' | ||
| # photom['DELVE'][f'DELVE_{band}'] = 'bdf_mag_'+band | ||
| # photom['DELVE'][f'DELVE_{band}_err'] = 'bdf_mag_err_'+band | ||
|
|
||
|
|
||
| class DELVE_Survey(dlsurvey.DL_Survey): | ||
|
|
@@ -48,8 +53,10 @@ def __init__(self, coord, radius, **kwargs): | |
| self.survey = 'DELVE' | ||
| self.bands = DELVE_bands | ||
| self.svc = sia.SIAService("https://datalab.noao.edu/sia/delve_dr2") | ||
| # self.svc = sia.SIAService("https://datalab.noao.edu/sia/delve_dr3") | ||
| self.qc_profile = "default" | ||
| self.database = "delve_dr2.objects" | ||
| # self.database = "delve_dr3.coadd_objects" | ||
| self.default_query_fields = list(photom['DELVE'].values()) | ||
|
|
||
| def get_catalog(self, query=None, query_fields=None, print_query=False,**kwargs): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,7 @@ def get_catalog(self,query_fields=None, print_query=False): | |
| query_fields = _DEFAULT_query_fields | ||
| else: | ||
| query_fields = _DEFAULT_query_fields+query_fields | ||
|
|
||
| import astropy.units as u | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this import being used anywhere in the file? If not, please remove. |
||
| data = {} | ||
| data['ra'] = self.coord.ra.value | ||
| data['dec'] = self.coord.dec.value | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,13 +270,64 @@ def search_all_surveys(coord:SkyCoord, radius:u.Quantity, include_radio:bool=Fal | |
| # Fill in any empty separations and sort them. | ||
| combined_cat['separation'] = coord.separation(SkyCoord(combined_cat['ra'], combined_cat['dec'], unit='deg')).to(u.arcmin) | ||
| combined_cat.sort('separation') | ||
|
|
||
| combined_cat = pick_best_row_by_phot(combined_cat) | ||
| # Make the ra, dec, separation the first columns | ||
| colnames = combined_cat.colnames | ||
| other_cols = np.setdiff1d(colnames, ['ra', 'dec', 'separation']) | ||
| combined_cat = combined_cat[['ra', 'dec', 'separation']+other_cols.tolist()] | ||
|
|
||
| return combined_cat | ||
|
|
||
| def pick_best_row_by_phot(cat, mag_cols=None, max_sep=None): | ||
| """ | ||
| From a catalog sorted by separation, pick the best row | ||
| based on having any good photometry in the specified | ||
| magnitude columns. | ||
| Args: | ||
| cat (Table): Astropy table sorted by separation. | ||
| mag_cols (list, optional): List of magnitude column names | ||
| to consider for "good photometry". If None, | ||
| will use all valid filters from frb.galaxies.defs. | ||
| max_sep (Quantity, optional): Maximum separation | ||
| to consider. If None, no maximum separation | ||
| is applied. | ||
|
|
||
| Returns: | ||
| best_row (Table): A 1-row table with the best row. | ||
| """ | ||
| if len(cat) == 0: | ||
| return cat | ||
|
|
||
| if mag_cols is None: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure there's a |
||
| from frb.galaxies.defs import valid_filters | ||
| mag_cols = valid_filters | ||
|
|
||
| # require separation column already computed in arcmin/arcsec/whatever | ||
| sep = cat['separation'] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not guaranteed to be present for some surveys, I think. I really need to make the survey catalogs and method inputs uniform. 😬 |
||
| if max_sep is not None: | ||
| inrad = sep <= max_sep | ||
| else: | ||
| inrad = np.ones(len(cat), dtype=bool) | ||
|
|
||
| # “has any good mag” | ||
| has_good = np.zeros(len(cat), dtype=bool) | ||
| for c in mag_cols: | ||
| if c in cat.colnames: | ||
| m = np.array(cat[c]) | ||
| good = np.isfinite(m) & (m < 900) & (m > -10) | ||
| has_good |= good | ||
|
|
||
| ok = inrad & has_good | ||
| if not np.any(ok): | ||
| # fall back: just nearest, but you’ll know it’s junk | ||
| i = np.argmin(sep) | ||
| else: | ||
| # nearest among rows with any good photometry | ||
| i = np.argmin(sep[ok]) | ||
| i = np.where(ok)[0][i] | ||
|
|
||
| return cat[i:i+1] # returns a 1-row table | ||
|
|
||
|
|
||
| def PS1_tile(coord:SkyCoord, side:u.Quantity=1*u.deg, **kwargs)->Table: | ||
| """ | ||
|
|
@@ -331,4 +382,4 @@ def PS1_tile(coord:SkyCoord, side:u.Quantity=1*u.deg, **kwargs)->Table: | |
| else: | ||
| continue | ||
| combined_table = remove_duplicates(combined_table, 'Pan-STARRS_ID') | ||
| return combined_table | ||
| return combined_table | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little hacky so are you certain there's no internal CIGALE plot argument that does this already? If not, feel free to just resolve this comment.