astro-datalab / notebooks-latest

Default set of Data Lab notebooks, by DL team and contributed by users
BSD 3-Clause "New" or "Revised" License
60 stars 48 forks source link

Specify the query for the 'DESI-EDR' dataset? #253

Open Cyanglll opened 2 months ago

Cyanglll commented 2 months ago

`from sparcl.client import SparclClient import pandas as pd import matplotlib.pyplot as plt import os

client = SparclClient() print(client.all_datasets) help(client.find)

stars = pd.read_csv("Z:\Blue straggler\ra_dec_match.csv", header=None, names=["ra", "dec"])

fits_folder = "Z:\Blue straggler\DESI\FITS" png_folder = "Z:\Blue straggler\DESI\PNG" os.makedirs(fits_folder, exist_ok=True) os.makedirs(png_folder, exist_ok=True)

for index, row in stars.iterrows(): ra = row['ra'] dec = row['dec']

constraints = {'ra': [ra, ra], 'dec': [dec, dec], 'data_release': ['DESI-EDR']}
found = client.find(constraints=constraints, outfields=['sparcl_id'], limit=None)

if found.records:
    for record in found.records:
        results = client.retrieve(uuid_list=[record.sparcl_id], include=['flux', 'wavelength'])

        flux = results.records[0].flux
        wavelength = results.records[0].wavelength
        plt.figure()
        plt.plot(wavelength, flux)
        plt.xlabel('Wavelength (Angstrom)')
        plt.ylabel('Flux')
        plt.title(f'Spectrum for RA: {ra}, Dec: {dec}')
        plt.savefig(os.path.join(png_folder, f"{ra}_{dec}.png"))
        plt.close()
else:
    print(f"No spectra found for RA: {ra}, Dec: {dec}")

`

Excuse me, where should I specify to query the 'DESI-ADR' dataset? Can you provide a tutorial on cross referencing DESI spectra based on "ra dec",please?

rnikutta commented 2 months ago

Hi @Cyanglll thanks for reaching out. You can do cross-matches based on RA and Dec using Data Lab xmatch service. Either online: https://datalab.noirlab.edu/xmatch.php or using Python (e.g. on our NB server). An example notebook is: https://github.com/astro-datalab/notebooks-latest/blob/master/04_HowTos/CrossmatchTables/How_to_crossmatch_tables.ipynb

The table that has DESI-EDR positions is sparcl.main: https://datalab.noirlab.edu/query.php?name=sparcl.main

Please note also that we have a helpdesk where you can find previous questions and answers, and also submit new questions: https://datalab.noirlab.edu/help/

Please don't hesitate to contact us again if you require more help.