Basics

All iSpec's functions described in this manual, and some additional ones that cannot be accessed through the visual interface, can be called from a Python script. In the iSpec directory there is a file named 'example.py' which implements an extensive list of examples:

  • read_write_spectrum()
  • convert_air_to_vacuum()
  • plot()
  • cut_spectrum_from_range()
  • cut_spectrum_from_segments()
  • determine_radial_velocity_with_mask()
  • determine_radial_velocity_with_template()
  • correct_radial_velocity()
  • determine_tellurics_shift_with_mask()
  • determine_tellurics_shift_with_template()
  • degrade_resolution()
  • smooth_spectrum()
  • resample_spectrum()
  • coadd_spectra()
  • merge_spectra()
  • normalize_spectrum_using_continuum_regions()
  • normalize_spectrum_in_segments()
  • normalize_whole_spectrum()
  • normalize_whole_spectrum_ignoring_prefixed_strong_lines()
  • normalize_whole_spectrum_with_template()
  • filter_cosmic_rays()
  • find_continuum_regions()
  • find_continuum_regions_in_segments()
  • find_linemasks()
  • fit_lines_determine_ew_and_crossmatch_with_atomic_data(use_ares=False)
  • fit_lines_determine_ew_and_crossmatch_with_atomic_data(use_ares=True)
  • fit_lines_already_crossmatched_with_atomic_data_and_determine_ew(use_ares=False)
  • fit_lines_already_crossmatched_with_atomic_data_and_determine_ew(use_ares=True)
  • calculate_barycentric_velocity()
  • estimate_snr_from_flux()
  • estimate_snr_from_err()
  • estimate_errors_from_snr()
  • clean_spectrum()
  • clean_telluric_regions()
  • adjust_line_masks()
  • create_segments_around_linemasks()
  • synthesize_spectrum(code="spectrum")
  • synthesize_spectrum(code="turbospectrum")
  • synthesize_spectrum(code="sme")
  • synthesize_spectrum(code="moog")
  • synthesize_spectrum(code="synthe")
  • interpolate_spectrum()
  • add_noise_to_spectrum()
  • generate_new_random_realizations_from_spectrum()
  • precompute_synthetic_grid(code="spectrum")
  • precompute_synthetic_grid(code="turbospectrum")
  • precompute_synthetic_grid(code="sme")
  • precompute_synthetic_grid(code="moog")
  • precompute_synthetic_grid(code="synthe")
  • determine_astrophysical_parameters_using_grid()
  • determine_astrophysical_parameters_using_synth_spectra(code="spectrum")
  • determine_astrophysical_parameters_using_synth_spectra(code="turbospectrum")
  • determine_astrophysical_parameters_using_synth_spectra(code="sme")
  • determine_astrophysical_parameters_using_synth_spectra(code="moog")
  • determine_astrophysical_parameters_using_synth_spectra(code="synthe")
  • estimate_initial_ap_with_precomputed_grid_and_determine_ap_using_synth_spectra(code="spectrum")
  • estimate_initial_ap_with_precomputed_grid_and_determine_ap_using_synth_spectra(code="turbospectrum")
  • estimate_initial_ap_with_precomputed_grid_and_determine_ap_using_synth_spectra(code="sme")
  • estimate_initial_ap_with_precomputed_grid_and_determine_ap_using_synth_spectra(code="moog")
  • estimate_initial_ap_with_precomputed_grid_and_determine_ap_using_synth_spectra(code="synthe")
  • determine_abundances_using_synth_spectra(code="spectrum")
  • determine_abundances_using_synth_spectra(code="turbospectrum")
  • determine_abundances_using_synth_spectra(code="sme")
  • determine_abundances_using_synth_spectra(code="moog")
  • determine_abundances_using_synth_spectra(code="synthe")
  • determine_abundances_line_by_line_using_synth_spectra(code="spectrum")
  • determine_abundances_line_by_line_using_synth_spectra(code="turbospectrum")
  • determine_abundances_line_by_line_using_synth_spectra(code="sme")
  • determine_abundances_line_by_line_using_synth_spectra(code="moog")
  • determine_abundances_line_by_line_using_synth_spectra(code="synthe")
  • determine_loggf_line_by_line_using_synth_spectra(code="spectrum")
  • determine_loggf_line_by_line_using_synth_spectra(code="turbospectrum")
  • determine_loggf_line_by_line_using_synth_spectra(code="sme")
  • determine_loggf_line_by_line_using_synth_spectra(code="moog")
  • determine_loggf_line_by_line_using_synth_spectra(code="synthe")
  • determine_astrophysical_parameters_from_ew(code="moog", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_astrophysical_parameters_from_ew(code="moog", use_lines_already_crossmatched_with_atomic_data=False)
  • determine_astrophysical_parameters_from_ew(code="width", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_astrophysical_parameters_from_ew(code="width", use_lines_already_crossmatched_with_atomic_data=False)
  • determine_astrophysical_parameters_from_ew(code="spectrum", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_astrophysical_parameters_from_ew(code="spectrum", use_lines_already_crossmatched_with_atomic_data=False)
  • determine_astrophysical_parameters_from_ew(code="turbospectrum", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_astrophysical_parameters_from_ew(code="turbospectrum", use_lines_already_crossmatched_with_atomic_data=False)
  • determine_abundances_from_ew(code="spectrum", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_abundances_from_ew(code="turbospectrum", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_abundances_from_ew(code="spectrum", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_abundances_from_ew(code="turbospectrum", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_abundances_from_ew(code="moog", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_abundances_from_ew(code="moog", use_lines_already_crossmatched_with_atomic_data=False)
  • determine_abundances_from_ew(code="width", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_abundances_from_ew(code="width", use_lines_already_crossmatched_with_atomic_data=False)
  • determine_abundances_from_ew(code="moog", use_lines_already_crossmatched_with_atomic_data=True)
  • determine_abundances_from_ew(code="width", use_lines_already_crossmatched_with_atomic_data=True)
  • calculate_theoretical_ew_and_depth()
  • paralelize_code()
  • estimate_vmic_from_empirical_relation()
  • estimate_vmac_from_empirical_relation()
  • generate_and_plot_YY_isochrone()
  • interpolate_atmosphere(code="spectrum")
  • interpolate_atmosphere(code="turbospectrum")
  • interpolate_atmosphere(code="moog")

The easiest way to use the script is to duplicate it, and erase all the functions except the ones that fit the user's needs. The variable ispec_dir (inside the script) should point to the right directory where iSpec is installed, for instance:

#--- iSpec directory -------------------------------------------------------------
ispec_dir = '/home/virtual/iSpec/'
sys.path.insert(0, os.path.abspath(ispec_dir))
import ispec

The script can be executed by writing on a terminal "python example.py".