### Import Generator and PhotometricSystem Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Import the necessary functions and classes from the gaiaxpy library to start generating photometry. ```python from gaiaxpy import generate, PhotometricSystem ``` -------------------------------- ### Get available photometric systems Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Retrieve a list of all available photometric systems. ```python PhotometricSystem.get_available_systems() ``` -------------------------------- ### Import find_lines Tool Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Import the `find_lines` function from the gaiaxpy library. This is a necessary setup step before using the function. ```python # Import the tool from gaiaxpy import find_lines ``` -------------------------------- ### Get Available Photometric Systems Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Additional%20systems%20tutorial.html Retrieve a list of all currently available photometric systems, including built-in and loaded additional systems. ```python PhotometricSystem.get_available_systems() ``` -------------------------------- ### Get Version of a Built-in Photometric System Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Additional%20systems%20tutorial.html Retrieve the version of a built-in photometric system. This will return the current version of the GaiaXPy library. ```python PhotometricSystem.SDSS.get_version() ``` -------------------------------- ### Get Version of an Additional Photometric System Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Additional%20systems%20tutorial.html Consult the version of a specific additional photometric system. This is crucial for reproducibility when publishing results. ```python PhotometricSystem.USER_MSSSO.get_version() ``` -------------------------------- ### Calibrate Spectra from DataFrame Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Pass a pandas DataFrame containing raw XP continuous data to the calibrate function. Ensure the DataFrame is loaded correctly, for example, using pandas.read_csv. ```python import pandas as pd f = '/path/to/XP_CONTINUOUS_RAW.csv' df = pd.read_csv(f) # The values in the DataFrame can be edited if the user wishes to do so. calibrated_spectra, sampling = calibrate(df) calibrated_spectra ``` -------------------------------- ### Set Output Path and Format Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Demonstrates how to specify the output path, file name, and format for the calibrated spectra. The file will be automatically overwritten if it exists. ```python calibrated_spectra, _ = calibrate(f, output_path='/path/to', output_file='my_file', output_format='fits') ``` -------------------------------- ### Use Built-in and Additional Systems for Generation Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Additional%20systems%20tutorial.html Import the generate function and create a list of photometric systems, including both built-in systems (e.g., PhotometricSystem.Pristine) and loaded additional systems (e.g., PhotometricSystem.USER_PS1), to be used with the generate function. ```python from gaiaxpy import generate phot_systems_list = [PhotometricSystem.Pristine, PhotometricSystem.USER_PS1] ``` -------------------------------- ### Import photometric systems Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Import the class for handling photometric systems. ```python from gaiaxpy import PhotometricSystem ``` -------------------------------- ### Import the find_fast tool Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Import the necessary tool for finding extrema. This is the first step before using the line finder functionality. ```python # Import the tool from gaiaxpy import find_fast ``` -------------------------------- ### Specify Output Path, File, and Format Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Use output_path, output_file, and output_format to control the destination and naming of the converted file. The output path will be created if it doesn't exist. Existing files will be overwritten. ```python converted_spectra, _ = convert(f, output_path='/path/to', output_file='my_file', output_format='ecsv') ``` -------------------------------- ### Load Additional Photometric Systems Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Additional%20systems%20tutorial.html Load custom photometric systems from a specified directory. This replaces any previously loaded additional systems. ```python f = '/path/to/XP_CONTINUOUS_RAW.ecsv' synthetic_photometry = generate(f, photometric_system=phot_systems_list) synthetic_photometry ``` ```python PhotometricSystem = load_additional_systems() ``` -------------------------------- ### Import Calibrator Tool Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Import the calibrate function from the gaiaxpy library and specify the path to your raw XP continuous data file. ```python # Import the tool from gaiaxpy import calibrate # Path to file with XP CONTINUOUS RAW data (csv, ecsv, fits, or xml) f = '/path/to/XP_CONTINUOUS_RAW.xml' ``` -------------------------------- ### Import Necessary Modules for GaiaXPy Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Additional%20systems%20tutorial.html Import the PhotometricSystem class and the load_additional_systems function from the gaiaxpy library. This is the first step before working with additional photometric systems. ```python from gaiaxpy import PhotometricSystem, load_additional_systems ``` -------------------------------- ### Import generator tool Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Import the tool used to generate synthetic photometry. ```python from gaiaxpy import generate ``` -------------------------------- ### Load Additional Photometric Systems Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Additional%20systems%20tutorial.html Load custom photometric systems by providing the path to the directory containing the system files to the load_additional_systems function. GaiaXPy will recursively search for system files within the specified directory. Ensure that the directory contains valid system files; otherwise, warnings will be issued, and invalid files will be ignored. If duplicate system names are found, an error will be raised, and no systems will be loaded. ```python PhotometricSystem = load_additional_systems('/path/to/additional_filters_directory') ``` -------------------------------- ### Convert Spectra with Custom Sampling Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Demonstrates converting spectra using a custom sampling array. The sampling array must be within the range of -10 to 70. ```python import numpy as np converted_spectra_default, default_sampling = convert(df.iloc[[0]]) converted_spectra, custom_sampling = convert(f, sampling=np.arange(-10, 70, 0.5)) converted_spectra ``` -------------------------------- ### Customize Output Path and Filename Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Specify the output path, filename, and format for the generated synthetic photometry. The directory will be created if it doesn't exist. Existing files will be overwritten. ```python synthetic_photometry = generate(f, photometric_system=phot_system, output_path='/path/to', output_file='my_file', output_format='xml') ``` -------------------------------- ### Import the find_extrema tool Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Import the find_extrema tool, which is used to find extrema and their properties in internally calibrated mean spectra. ```python # Import the tool from gaiaxpy import find_extrema ``` -------------------------------- ### Control File Saving Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Illustrates how to control whether the calibrated spectra are saved to a file using the `save_file` parameter. A warning is raised if `output_file` is provided but `save_file` is False. ```python calibrated_spectra, _ = calibrate(f, output_file='my_file', output_format='.xml', save_file=False) ``` -------------------------------- ### Select photometric systems Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Select a single photometric system or a list of systems for use. ```python phot_system = PhotometricSystem.Gaia_DR3_Vega phot_systems_list = [PhotometricSystem.Pristine, PhotometricSystem.JWST_NIRCAM, PhotometricSystem.Euclid_VIS] ``` -------------------------------- ### Calibrate Spectra from ADQL Query Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Calibrate spectra by providing an ADQL query string. The calibrator can use provided username and password for Cosmos credentials. ```python query_input = "select TOP 2 source_id from gaiadr3.gaia_source where has_xp_continuous = 'True'" calibrated_spectra, sampling = calibrate(query_input) calibrated_spectra ``` -------------------------------- ### Generate Synthetic Photometry from Query Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Generate synthetic photometry by providing a SQL query to fetch data from the Archive. This is useful for selecting specific data subsets. The query must be a valid SQL string. ```python query_input = "select TOP 2 source_id from gaiadr3.gaia_source where has_xp_continuous = 'True'" phot_system_list = [PhotometricSystem.Stromgren, PhotometricSystem.Stromgren_Std] synthetic_photometry = generate(query_input, photometric_system=phot_system_list) synthetic_photometry ``` -------------------------------- ### Plot Flux Spectra with STILTS Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/TOPCAT%20tutorial.html Use STILTS to generate a 2D plot of flux spectra from a FITS file. Ensure the 'sampling' parameter is included in the file for wavelength information. ```bash stilts plot2plane in=calibrator.fits xs='param$sampling' ys=flux layer1=lines ``` -------------------------------- ### Find Extrema with Truncation Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Utilize the find_fast tool with the truncation=True option to simplify spectral representations, which is beneficial for faint sources or those with limited observations. This helps prevent higher-order bases from fitting noise. ```python sources_list = [5853498713190525696, 5762406957886626816] extrema_pwl_tr = find_fast(sources_list, truncation=True) extrema_pwl_tr.head() ``` -------------------------------- ### Calibrate with Truncation Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Shows how to calibrate spectra with and without truncation. Truncation is useful for faint sources to avoid fitting noise. ```python second_source = df.drop([0]) # We'll use only the second source (sourceId 4) in the demonstration non_truncated_spectra, sampling = calibrate(second_source) # truncation is False by default truncated_spectra, _ = calibrate(second_source, truncation=True) ``` -------------------------------- ### Customizing Output Path and File with Linefinder Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Specify `output_path`, `output_file`, and `output_format` to control where and how the results are saved. The output path will be created if it doesn't exist. ```python lines = find_lines([5853498713190525696], output_path='.', output_file='my_file', output_format='ecsv') ``` -------------------------------- ### Basic Conversion with File Path Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Convert spectra from a specified file path. The converter returns sampled spectra as a pandas DataFrame and the sampling used. ```python converted_spectra, sampling = convert(f) converted_spectra ``` -------------------------------- ### Generate Synthetic Photometry for Multiple Systems Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Generate synthetic photometry for a specified input file using a list of photometric systems. The output is saved to a file. ```python # Create a list of photometric systems phot_system_list = [PhotometricSystem.Gaia_DR3_Vega, PhotometricSystem.JKC, PhotometricSystem.Pristine] synthetic_photometry = generate(f, photometric_system=phot_system_list) synthetic_photometry ``` -------------------------------- ### Calibrate with Geometric Sampling Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Demonstrates calibrating spectra using a geometric progression sampling for improved resolution at the blue end. Ensure numpy is imported. ```python import numpy as np sampling = np.geomspace(330,1049.9999999999, 361) calibrated_spectra_geom, sampling = calibrate(f, sampling=sampling) calibrated_spectra_geom ``` -------------------------------- ### Generate Synthetic Photometry from List of Source IDs Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Generate synthetic photometry by passing a list of source IDs. Source IDs can be strings or integers. The generator will query the Archive for these objects. ```python sources_list = ['6030020833890693248', 6030064028385961344] # The source IDs can be string or long. synthetic_photometry = generate(sources_list, photometric_system=PhotometricSystem.JKC_Std) synthetic_photometry ``` -------------------------------- ### Generate Synthetic Photometry for a Single System Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Generate synthetic photometry for a specified input file and a single photometric system. The output is saved to a file. ```python # Path to file with XP CONTINUOUS RAW data (csv, ecsv, fits, or xml) f = '/path/to/XP_CONTINUOUS_RAW.xml' # Select a photometric system phot_system = PhotometricSystem.Gaia_DR3_Vega synthetic_photometry = generate(f, photometric_system=phot_system) synthetic_photometry ``` -------------------------------- ### Convert Spectra using List of Source IDs Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Convert spectra by passing a list of source IDs. The converter will query the Archive for these specific objects. Interactive login credentials may be prompted. ```python sources_list = ['48', 44] # The sourceIds can be string or long. converted_spectra, sampling = convert(sources_list) converted_spectra ``` -------------------------------- ### Import Converter Tool Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Import the necessary convert function from the gaiaxpy library and specify the path to your input data file. ```python # Import the tool from gaiaxpy import convert # Path to file with XP CONTINUOUS RAW data (csv, ecsv, fits, or xml) f = '/path/to/XP_CONTINUOUS_RAW.fits' ``` -------------------------------- ### Calibrate Spectra from List of Source IDs Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Calibrate spectra by passing a list of source IDs. The calibrator will query the Archive for these objects. Source IDs can be strings or integers. Username and password can be provided for authentication. ```python sources_list = ['48', 44] # The sourceIds can be string or long. calibrated_spectra, sampling = calibrate(sources_list) calibrated_spectra ``` -------------------------------- ### Convert Spectra using ADQL Query Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Convert spectra by providing an ADQL query string. This method allows for dynamic selection of data from the Gaia Archive. Interactive login credentials may be prompted. ```python query_input = "select TOP 2 source_id from gaiadr3.gaia_source where has_xp_continuous = 'True'" converted_spectra, sampling = convert(query_input) converted_spectra ``` -------------------------------- ### Find extrema using an ADQL query Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Use an ADQL query to select source IDs from the Gaia Archive. The find_fast function will process the query to find extrema. ```python query_input = "select TOP 2 source_id from gaiadr3.gaia_source where has_xp_continuous = 'True'" extrema_pwl = find_fast(query_input) extrema_pwl.head() ``` -------------------------------- ### Find Lines in QSO Spectra with Redshift Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html When working with QSO spectra, you can specify the source type as 'QSO' and provide redshift(s). By default, a short list of common lines is searched. ```python # A list of sourceIds sources_list = [858200268935710208, 3937755935439564672] ``` -------------------------------- ### Calibrate Spectra from File Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Use the calibrate function with a file path to obtain calibrated spectra and the corresponding sampling. The calibrated spectra is a pandas DataFrame, and the sampling is a NumPy array. ```python calibrated_spectra, sampling = calibrate(f) calibrated_spectra ``` -------------------------------- ### Compare Default and Geometric Sampling Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Compares the results of default sampling versus geometric progression sampling for a single source. Requires the gaiaxpy plotting utility. ```python first_source = df.iloc[[0]] # Select row with index 0 first_spectra, sampling = calibrate(first_source) first_spectra_geom, geom_sampling = calibrate(first_source, sampling=np.geomspace(330,1049.9999999999, 361)) ``` ```python from gaiaxpy import plot_spectra print('Default sampling') # Do not show the legend as there's only one source in the data plot_spectra(first_spectra, sampling=sampling, legend=False) print('Geometric progression (log) sampling') plot_spectra(first_spectra_geom, sampling=geom_sampling, legend=False) ``` -------------------------------- ### Download Filter File using wget Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/SVO%20download.html Use the `wget` command to download a filter file programmatically. The `--content-disposition` option is crucial for preserving the original filename, which contains essential information. Ensure the output directory is specified. ```bash wget --content-disposition -P outputdir/ http://svo2.cab.inta-csic.es/theory/fps/getgaiaxpy.php/?gxpyid=Filter/Filter ``` -------------------------------- ### Find Spectral Lines with Redshift Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Use the find_lines tool to detect spectral lines for quasars (source_type='qso') by providing a list of redshifts. The output includes detailed line properties. ```python zets = [(858200268935710208, 0.06107), (3937755935439564672, 2.698)] lines = find_lines(sources_list, source_type='qso', redshift=zets) lines ``` -------------------------------- ### Find Lines with User-Defined Lines from File Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Specify spectral lines for analysis by providing a file path to the user_lines parameter in the find_lines tool. The file should contain wavelengths and line names, separated by spaces, without a header. ```python sources_list = [5853498713190525696, 5762406957886626816] f = '/path/to/lines_example.txt' lines = find_lines(sources_list, user_lines=f) lines ``` ```text 656.461 H_alpha 486.268 H_beta ``` -------------------------------- ### Find Extrema from FITS File Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Use `find_extrema` to process a FITS file and display the first few rows of the resulting DataFrame. Requires the path to the FITS file. ```python f = '/path/to/XP_CONTINUOUS_RAW.fits' extrema = find_extrema(f) extrema.head() ``` -------------------------------- ### Find extrema using a list of source IDs Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Provide a list of source IDs (as strings or integers) to the find_fast function. The tool will query the Archive for these specific sources. ```python sources_list = ['5853498713190525696', 5762406957886626816] # The sourceIds can be string or long. extrema_pwl = find_fast(sources_list) extrema_pwl.head() ``` -------------------------------- ### Generate synthetic photometry Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Generate synthetic photometry from an input file using specified photometric systems. Ensure that the 'Gaia_DR3_Vega' system is included if you plan to apply error corrections based on Gaia photometry. ```python # File with input data f = '/path/to/XP_CONTINUOUS_ECSV' synthetic_photometry = generate(f, photometric_system=phot_systems_list) ``` -------------------------------- ### Apply Error Correction with Custom Output Path and Filename Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Use this snippet to apply error correction and specify a custom output path, filename, and format. The output path will be created if it doesn't exist. Be aware that existing files with the same path and name will be overwritten. ```python synth_phot_corrected = apply_error_correction(synthetic_photometry, output_path='/output/path', output_file='my_file', output_format='csv') ``` -------------------------------- ### Convert Spectra with Truncation Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Compares spectra conversion with and without truncation. Truncation is useful for faint sources to avoid fitting noise with higher-order bases. It is False by default. ```python first_source = df.drop([0]) # We'll use only the first source (sourceId 4) in the demonstration non_truncated_spectra, sampling = convert(first_source) # truncation is False by default truncated_spectra, _ = convert(first_source, truncation=True) ``` -------------------------------- ### Find Extrema from ADQL Query Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Use an ADQL query to select source IDs from the Archive. The find_extrema function will process the query results. ```python query_input = "select TOP 2 source_id from gaiadr3.gaia_source where has_xp_continuous = 'True'" extrema = find_extrema(query_input) extrema.head() ``` -------------------------------- ### Find extrema using a file path Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Specify the path to a file containing XP CONTINUOUS RAW data (e.g., .fits, .csv, .ecsv, .xml). The find_fast function will read and process the data from the file. ```python f = '/path/to/XP_CONTINUOUS_RAW.fits' extrema_pwl = find_fast(f) extrema_pwl.head() # Only the first few rows of the output are displayed when head() is used. ``` -------------------------------- ### Generate Synthetic Photometry from DataFrame Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Use this to generate synthetic photometry from a pandas DataFrame. The DataFrame can be modified before generation. Ensure the DataFrame contains necessary columns for photometry. ```python import pandas as pd f = '/path/to/XP_CONTINUOUS_RAW.csv' df = pd.read_csv(f) # At this point, the values in the DataFrame can be edited if the user wishes to do so. synthetic_photometry = generate(df, photometric_system=PhotometricSystem.Els_Custom_W09_S2) synthetic_photometry ``` -------------------------------- ### Apply Truncation to Synthetic Photometry Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Enable truncation of the basis set for synthetic photometry generation. This is useful for faint sources or those with few observations to avoid fitting noise. ```python synthetic_photometry = generate(f, photometric_system=phot_system, truncation=True) ``` -------------------------------- ### Find Lines from CSV File using DataFrame Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Load data from a CSV file into a pandas DataFrame and then use `find_lines` to detect spectral lines. Requires pandas and the path to the CSV file. ```python import pandas as pd f = '/path/to/XP_CONTINUOUS_RAW.csv' df = pd.read_csv(f) lines = find_lines(df) lines ``` -------------------------------- ### Find Lines from a File Path Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Provide a file path to the find_lines function to process a specific data file and identify spectral lines. ```python f = '/path/to/XP_CONTINUOUS_RAW.fits' lines = find_lines(f) lines ``` -------------------------------- ### Find Extrema from List of Source IDs Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Provide a list of source IDs (as strings or longs) to the find_extrema function. The tool will query the Archive for the specified objects. ```python sources_list = ['5853498713190525696', 5762406957886626816] # The sourceIds can be string or long. extrema = find_extrema(sources_list) extrema.head() ``` -------------------------------- ### Redefine Additional Systems Path Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Additional%20systems%20tutorial.html When a path for additional filters is already defined, you can choose to redefine it. This prompt asks for user confirmation before setting a new path. ```python PhotometricSystem = load_additional_systems() ``` -------------------------------- ### Find Lines with User-Defined Wavelengths Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Provide a custom list of wavelengths and line names to the user_lines parameter in the find_lines tool for targeted spectral line detection. This allows for analysis of specific, user-specified spectral features. ```python sources_list = [5853498713190525696, 5762406957886626816] new_lines = [(434.0472, 410.1734), ('H_gamma', 'H_delta')] lines = find_lines(sources_list, user_lines=new_lines) lines ``` -------------------------------- ### Analyze Flux Differences Between Truncated Spectra Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Calculates and prints the minimum and maximum absolute differences in flux values between truncated and non-truncated BP spectra, along with their indices. ```python # We'll get the flux values of the BP band of the first spectrum in the data non_truncated_bp_flux = data[(data['source_id'] == 'Non truncated') & (data['xp'] == 'BP')]['flux'].iloc[0] truncated_bp_flux = data[(data['source_id'] == 'Truncated') & (data['xp'] == 'BP')]['flux'].iloc[0] # We can then compute the absolute differences abs_differences = np.abs(non_truncated_bp_flux - truncated_bp_flux) # And find the values and indices of those differences min_diff = np.min(abs_differences) max_diff = np.max(abs_differences) print(f'The length of the sampling is {len(non_truncated_bp_flux)}.') print(f'Minimum difference: {min_diff}. Index of minimum difference: {np.where(abs_differences == min_diff)[0][0]}.') print(f'Maximum difference: {max_diff}. Index of maximum difference: {np.where(abs_differences == max_diff)[0][0]}.') ``` -------------------------------- ### Import error correction tool Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Import the necessary function for applying error correction. ```python from gaiaxpy import apply_error_correction ``` -------------------------------- ### Control Saving of Output File Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Use the `save_file` parameter to control whether the generated output is saved to disk. If `output_file` is provided but `save_file` is `False`, a warning is issued. ```python synthetic_photometry = generate(f, photometric_system=phot_system, output_file='my_file', save_file=False) ``` -------------------------------- ### Saving Spectra Plots with Linefinder Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Set `save_plots=True` in addition to `plot_spectra=True` to save the generated spectra plots to disk. This allows for later review or inclusion in reports. ```python lines = find_lines([5853498713190525696], plot_spectra=True, save_plots=True) ``` -------------------------------- ### Control Saving Output with save_file Parameter Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html The save_file parameter determines if the converted data is written to disk. If output_file is specified but save_file is False, a warning is issued. ```python converted_spectra, _ = convert(f, output_file='my_file', output_format='.csv', save_file=False) ``` ```text UserWarning: Argument output_file was given, but save_file is set to False. Set save_file to True to store the output of the function. ``` -------------------------------- ### Plotting Spectra with Linefinder Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Use `plot_spectra=True` to visualize detected lines directly within the linefinder tool. This option is only available for linefinder and extremafinder. ```python lines = find_lines([5762406957886626816], plot_spectra=True) ``` -------------------------------- ### Remove Additional Photometric Systems Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Additional%20systems%20tutorial.html Manually remove all loaded additional photometric systems. This action is also performed automatically upon program exit. ```python from gaiaxpy import remove_additional_systems PhotometricSystem = remove_additional_systems() ``` -------------------------------- ### Convert Wavelength to Frequency Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/TOPCAT%20tutorial.html Convert pseudo-wavelength values from nm to pseudo-frequency in Hz using the TOPCAT expression language. This calculation involves the reciprocal of the sampling parameter and a constant C_KMS multiplied by 1e12. ```expression multiply(reciprocal(param$sampling), C_KMS*1e12) ``` -------------------------------- ### Plot Spectra with Errors using STILTS Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/TOPCAT%20tutorial.html Generate a plot of flux spectra with associated error bars using STILTS. This command specifies the X and Y data, and additionally defines the error bar data using 'flux_error'. ```bash stilts plot2plane in=calibrator.fits xs='param$sampling' ys=flux \ layer1=lines \ layer2=yerrors yerrhis=flux_error ``` -------------------------------- ### Plot Truncated vs. Non-Truncated Spectra Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Calibrator%20tutorial.html Visualizes the difference between truncated and non-truncated spectra using the plot_spectra utility. Requires pandas for data manipulation. ```python import pandas as pd from gaiaxpy import plot_spectra # Construct a DataFrame so we can plot both sources using just one function call data = pd.concat([non_truncated_spectra, truncated_spectra]).reset_index(drop=True) # As both spectra we want to plot have the same sourceId, we'll rename them to get descriptive labels data['source_id'][0] = 'Non truncated' data['source_id'][1] = 'Truncated' plot_spectra(data, sampling=sampling, multi=True) ``` -------------------------------- ### Take Logarithm of Flux Array Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/TOPCAT%20tutorial.html Apply a base-10 logarithm to each element of the flux array using the TOPCAT expression language. This can help in visualizing data with a large dynamic range. ```expression arrayFunc("log10(x)", flux) ``` -------------------------------- ### Verify equivalence of corrected dataframes Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Compare two DataFrames containing corrected synthetic photometry to ensure they are identical. ```python print(f'Are both frames equal? {synth_phot_corrected.equals(synth_phot_corrected_infer)}') ``` -------------------------------- ### Controlling File Saving with Linefinder Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Use the `save_file` parameter to explicitly enable or disable saving the results. If `output_file` is specified but `save_file` is `False`, a warning will be issued. ```python lines = find_lines([5853498713190525696], output_path='.', output_file='my_file', output_format='ecsv', save_file=False) ``` -------------------------------- ### Find Lines from a List of Source IDs Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Pass a list of source IDs (strings or integers) to the find_lines function to query the Archive for these objects and identify spectral lines. ```python sources_list = ['5853498713190525696', 5762406957886626816] # The source IDs can be either strings or long integers. lines = find_lines(sources_list) lines ``` -------------------------------- ### Convert Wavelength from nm to Angstrom Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/TOPCAT%20tutorial.html Use the TOPCAT expression language to convert pseudo-wavelength values from nanometers (nm) to Angstroms (Å). This involves multiplying the 'param$sampling' values by 10.0. ```expression multiply(param$sampling, 10.0) ``` -------------------------------- ### Apply error correction by inferring systems Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Apply error correction to synthetic photometry, allowing the function to infer the photometric systems directly from the data. This may result in warnings for systems lacking correction tables. ```python synth_phot_corrected_infer = apply_error_correction(synthetic_photometry) ``` -------------------------------- ### Find extrema using a pandas DataFrame Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Pass a pandas DataFrame containing XP CONTINUOUS RAW data to the find_fast function. Ensure the DataFrame is properly loaded. ```python import pandas as pd f = '/path/to/XP_CONTINUOUS_RAW.csv' df = pd.read_csv(f) extrema_pwl = find_fast(df) extrema_pwl.head() ``` -------------------------------- ### Apply error correction to synthetic photometry Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Apply error correction to the generated synthetic photometry. The photometric systems must be explicitly passed if they include 'Gaia_DR3_Vega' and are not inferred from the data. Warnings will be raised for systems without correction tables. ```python # Add the system phot_systems_list = [PhotometricSystem.Pristine, PhotometricSystem.JWST_NIRCAM, PhotometricSystem.Euclid_VIS, PhotometricSystem.Gaia_DR3_Vega] # Recompute synthetic_photometry = generate(f, photometric_system=phot_systems_list) # Now we can apply the error correction synth_phot_corrected = apply_error_correction(synthetic_photometry, photometric_system=phot_systems_list) ``` -------------------------------- ### Convert Spectra from Pandas DataFrame Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Load spectra from a CSV file into a pandas DataFrame and then use the convert function. The DataFrame values can be edited before conversion. ```python import pandas as pd f = '/path/to/XP_CONTINUOUS_RAW.csv' df = pd.read_csv(f) # The values in the DataFrame can be edited if the user wishes to do so. converted_spectra, sampling = convert(df) converted_spectra ``` -------------------------------- ### Apply Error Correction to Synthetic Photometry Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Generator%20tutorial.html Activate empirical corrections to uncertainties when generating synthetic photometry. A warning is raised for systems that cannot be corrected. ```python # To apply the error correction, first create a list of systems. phot_system_list = [PhotometricSystem.Euclid_VIS, PhotometricSystem.Els_Custom_W09_S2] synthetic_phot_corrected = generate(df, photometric_system=phot_system_list, error_correction=True) synthetic_phot_corrected # A warning is raised for each of the systems that cannot be corrected. No changes are made to these systems. ``` -------------------------------- ### Plot Truncated vs. Non-Truncated Spectra Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Plots both truncated and non-truncated spectra for comparison. Source IDs are renamed for clarity in the plot labels. ```python from gaiaxpy import plot_spectra # Construct a DataFrame so we can plot both sources using just one function call data = pd.concat([non_truncated_spectra, truncated_spectra]).reset_index(drop=True) # As both spectra we want to plot have the same sourceId, we'll rename them to get descriptive labels data['source_id'][0:2] = 'Non truncated' data['source_id'][2:4] = 'Truncated' plot_spectra(data, sampling=sampling, multi=True) ``` -------------------------------- ### Plot Converted Spectra Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Plots the converted spectra using the gaiaxpy plot_spectra utility. The 'multi=True' argument allows multiple spectra to be displayed on the same canvas. ```python from gaiaxpy import plot_spectra # multi allows the spectra to appear in the same canvas plot_spectra(converted_spectra, sampling=custom_sampling, multi=True) ``` -------------------------------- ### Calculate Upper Bound of Spectrum Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/TOPCAT%20tutorial.html Calculate the upper bound of a spectrum by adding the error values to the flux values using the TOPCAT expression language. This is useful for visualizing error ranges. ```expression add(flux, flux_error) ``` -------------------------------- ### Find Extrema from Pandas DataFrame Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Linefinder%20tutorial.html Pass a pandas DataFrame containing XP CONTINUOUS RAW data to the find_extrema function. The DataFrame values can be edited before processing. ```python import pandas as pd f = '/path/to/XP_CONTINUOUS_RAW.csv' df = pd.read_csv(f) # The values in the DataFrame can be edited if the user wishes to do so. extrema = find_extrema(df) extrema.head() ``` -------------------------------- ### Apply Error Correction Without Saving Output Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Error%20correction%20tutorial.html Use this snippet to apply error correction but prevent the results from being saved to a file. A warning will be raised if an output file is specified but save_file is set to False. ```python synth_phot_corrected = apply_error_correction(synthetic_photometry, output_file='my_file', save_file=False) ``` -------------------------------- ### Save Converted Spectra Plot Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/Converter%20tutorial.html Saves the plot of converted spectra to a specified output path without displaying it. Use 'show_plot=False' to prevent the plot from appearing. ```python plot_spectra(converted_spectra, sampling=custom_sampling, multi=True, output_path='/path/to', show_plot=False) ``` -------------------------------- ### Normalize Spectrum by Mean Value Source: https://gaia-dpci.github.io/GaiaXPy-website/tutorials/TOPCAT%20tutorial.html Normalize a spectrum by its mean value using the TOPCAT expression language. This scales the flux values so that the mean flux is 1, which is useful for comparing spectral shapes. ```expression multiply(flux, 1./mean(flux)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.