BASTA FIle I/O functions

Auxiliary functions for file operations

fileio.freqs_ascii_to_xml(directory, starid, freqsfile: str | None = None, covfile: str | None = None, ratiosfile: str | None = None, cov010file: str | None = None, cov02file: str | None = None, symmetric_errors=True, check_radial_orders=False, quiet=False)[source]

Creates frequency xml-file based on ascii-files.

Parameters:
  • directory (str) – Absolute path of the location of the ascii-files. This is also the location where the xml-file will be created. The directory must contain the ascii-file with the extension ‘.fre’ (containing frequencies), and may contain the ascii-files with the extensions ‘.cov’ (frequency covariances), ‘.ratios’, ‘.cov010’, and ‘.cov02’ (ratios and their covariances).

  • starid (str) – id of the star. The ascii files must be named ‘starid.xxx’ and the generated xml-file will be named ‘starid.xml’

  • symmetric_errors (bool, optional) – If True, the ascii files are assumed to only include symmetric errors. Otherwise, asymmetric errors are assumed. Default is True.

  • check_radial_orders (bool or float, optional) – If True, the routine will correct the radial order printed in the xml, based on the calculated epsilon value, with its own dnufit. If float, does the same, but uses the inputted float as dnufit.

  • quiet (bool, optional) – Toggle to silence the output (useful for running batches)

fileio.no_models(starid, inputparams, errormessage)[source]

If no models are found in the grid, create an outputfile with nans (for consistency reasons).

The approach mirrors process_output.compute_posterior()

Parameters:
  • starid (str) – Unique identifier for this target.

  • inputparams (dict) – Dictionary of all controls and input.

  • errormessage (str) – String explaining error which will be written to the .err-file

fileio.read_allseismic(fitfreqs, freqplots, verbose=False, debug=False)[source]

Routine to all necesary data from individual frequencies for the desired fit

Parameters:
  • fitfreqs (dict) – Contains all frequency related input needed for reading.

  • freqplots (list) – List of frequency-dependent fits

  • verbose (bool, optional) – If True, extra text will be printed to log (for developers).

  • debug (bool, optional) – Activate additional output for debugging (for developers)

Returns:

  • obskey (array) – Array containing the angular degrees and radial orders of obs

  • obs (array) – Individual frequencies and uncertainties.

  • obsfreqdata (dict) – Requested frequency-dependent data such as glitches, ratios, and epsilon difference. It also contains the covariance matrix and its inverse of the individual frequency modes. The keys correspond to the science case, e.g. r01, glitch, or e012. Inside each case, you find the data (data), the covariance matrix (cov), and its inverse (covinv).

  • obsfreqmeta (dict) – The requested information about which frequency products to fit or plot, unpacked for easier access later.

  • dnudata (scalar) – Large frequency separation obtained by fitting the radial mode observed frequencies. Similar to dnufit, but from data and not from the theoretical frequencies in the grid of models.

  • dnudata_err (scalar) – Uncertainty on dnudata.

fileio.read_freq(filename, excludemodes=None, onlyradial=False, covarfre=False)[source]

Routine to extract the frequencies in the desired n-range, and the corresponding covariance matrix

Parameters:
  • filename (str) – Name of file to read

  • excludemodes (str or None, optional) – Name of file containing the (l, n) values of frequencies to be omitted in the fit. If None, no modes will be excluded.

  • onlyradial (bool) – Flag to determine to only fit the l=0 modes

  • covarfre (bool, optional) – Read also the covariances in the individual frequencies

Returns:

  • obskey (array) – Array containing the angular degrees and radial orders of obs

  • obs (array) – Individual frequencies

  • covarfreq (array) – Array including covariances in the frequencies. If covarfre is False then a diagonal matrix is produced

fileio.read_freq_xml(filename)[source]

Read frequencies from an xml file

Parameters:

filename (str) – Name of file to read

Returns:

  • frequencies (array) – Individual frequencies

  • errors (array) – Uncertainties in the frequencies

  • orders (array) – Radial orders

  • degrees (array) – Angular degree

fileio.write_star_to_errfile(starid, inputparams, errormessage)[source]

Write starid and error message to .err-file

Parameters:
  • starid (str) – Unique identifier for this target.

  • inputparams (dict) – Dictionary of all controls and input.

  • errormessage (str) – String explaining error which will be written to the .err-file

Creation of XML input files

xml_create.generate_xml(gridfile, asciifile, outputpath, params, fitparams, outparams, outputfile='results.ascii', sunnumax=3090.0, sundnu=135.1, solarmodel=False, missingval=-999.999, centroid=None, uncert=None, plotfmt=None, nameinplot=False, odea=None, intpolparams=None, bayweights=True, priors=None, overwriteparams=None, freqparams=None, glitchparams=None, filters=None, dustframe=None, cornerplots=False, kielplots=False, freqplots=False, optionaloutputs=True, delimiter=None)[source]

Converts an ascii table into an xml input file. Defines the properties of the fit including the type of grid and parameters to be fitted.

Parameters:
  • gridfile (str) – Absolute path of the grid used in the fit.

  • asciifile (str) – Absolute path of ascii table of input values. The table should containing all params specified as an input (see below) and in the same order.

  • outputpath (str) – Absolute path for all output of the code.

  • params (tuple) – Names of the parameters to be read from the asciifile.

  • fitparams (tuple) – Names of the parameters to be fitted. These must exists in the list of parameters in the grid. These lists can be found in constants.

  • outparams (tuple) – A tuple of parameters for which the results of the Bayesian analysis is printed in the outputfile.

  • outputfile (str) – Name of the output file where all outparams will be printed out

  • sunnumax (float) – Value of the solar frequency of maximum power used in the scaling relations

  • sundnu (float) – Value of the solar large frequency separation used in the scaling relations

  • solarmodel (bool) – Activate solar scaling of asteroseismic quantities (dnu’s).

  • missingval (int or float or str) – Used to replace a missing value from the asciifile. It can be an integer, float, or ‘nan’.

  • centroid (str) – Which centroid value of the posterior is to be reported as the result. The standard option is ‘median’ (the Bayesian 50’th percentile), the other option is ‘mean’.

  • uncert (str) – The reported type of uncertaities. The standard option is ‘quantiles’ reporting the Bayesian 16’th and 84’th percentiles of the posterior, while the other option is ‘std’ for the standard deviation.

  • plotfmt (str) – Format of outputted plots, simply given directly to pyplot.savefig. Default is ‘png’ for quick figures. For detailed plots, ‘pdf’ is recommended.

  • nameinplot (bool) – Toggle to include star identifier in plots, not simply in filename of plot.

  • odea (tuple or None) – Specifies the input physics used to compute the grid. o : overshoot efficiency, 0.0 = no overshoot. d : microscopic diffusion, 0.0 = no diffusion. e : eta reimers for mass-loss, 0.0 = no mass-loss. a : alpha enhancement with respect to solar value, 0.0 = no alpha enhancement.

  • intpolparams (dict) – Contains inputted settings for performing interpolation with BASTA. A single dictionary is given, but can be applied star-by-star.

  • bayweights (bool) – Enable the usage of Bayesian weights across tracks or isochrones to properly take into account spacing in the creation of the grid and evolutionary speed.

  • priors (dict) – A dictionary with the name of priors to be considered in the fitting {‘IMF’: ‘string’, ‘param1’: {values}, ‘param2’: {values}, …} which defines the IMF used, and sets the absolute value of the tolerances for the selection of models in the grid to compute the likelihood. Accepted values are ‘min’, ‘max’, and ‘abstol’. If not specified, all models in the grid are evaluated.

  • overwriteparams (dict) – A dictionary in the format {‘param1’ : (value1, uncert1), ‘param2’: (value2, uncert2), …} used to set a value and uncertainty for all stars fitted. It will overwrite the input parameters for the individual stars!

  • freqparams (dict) – A dictionary containing the input for fitting individual frequencies or ratios.

  • grparams (dict) – A dictionary containing control options for fitting glitches along with ratios.

  • filters (tuple of strings) – If calculating distances to stars, specify photometric filters

  • dustframe (str) – Type of reference frame for the dustmap. Possible options

    galactic : The default coordinate system. Input coordinates are expected in galactic coordinates longitude (l) and latitude (b).

    icrs : Input coordinates are expected in celestial right ascension (ra) and declination (dec).

  • cornerplots (tuple) – Names of parameters to be included in the output plots. These can be any of the available parameters of the grid used, and can be found in make_basti() and make_garstec().

  • kielplots (tuple) – Names of fitted parameters to be indicated in the Kiel diagram. If all fitparams are wanted plotted, set to True. False by default.

  • freqplots (bool) – Whether or not to genereate echelle- and ratio-diagrams when fitting frequencies. False by default.

  • optionaloutputs (bool) – Defines if the additional output files are stored

  • delimiter (str or None) – Inputted delimiter if asciifile uses a special delimiter not easily recognised by numpy.genfromtxt