2. Misc Functions - HeloiseS/FUSS GitHub Wiki

The FUSS.polmisc module mainly contains the class PolData (discussed in section 4), but also defines a bunch of little functions I find useful on a day to day basis; some of them are also used in PolData.


get_spctr()

I use this to import flux spectrum from a text file. Allows easy cropping (with wlmin and wlmax) and normalising (using scale).

Input File Format:   λ,   f,   (optional: Δ f)

Parameters

  • filename (string): Name of the text file containing the spectrum
  • wlmin (int/foat, optional): Lower wavelength cutoff. Default = 0
  • wlmax (int/foat, optional): Upper wavelength cutoff. Default = 100,000
  • err (boolean, optional): If there is an error column, set to True. Default = False
  • scale (boolean, optional): Normalises the spectrum. Default = True

Returns

  • 1D-Arrays:   λ,   f,   (optional: Δ f)

get_pol()

I use this to import polarisation data from the text files created by lin_specpol. Allows easy cropping (with wlmin and wlmax).

Input File Format:   λ,   p,   Δ p,   q,   Δ q,   u,   Δ u,   θ,   Δθ

Parameters

  • filename (string): Name of the text file containing the spectrum
  • wlmin (int/float, optional): Lower wavelength cutoff. Default = 0
  • wlmax (int/float, optional): Upper wavelength cutoff. Default = 100,000

Returns

  • 1D-Arrays:   λ,   p,   Δ p,   q,   Δ q,   u,   Δ u,   θ,   Δθ

dopcor()

This function applies Doppler Correction to an array of data.

Parameters

  • val (array): val is an array of data containing at least 2 columns (e.g 1 column for wavelength and the other for flux). The first column must contain the wavelength bins.
  • z (float): The redshift.

Returns

  • Array: An array equivalent to val, but whose wavelength bin have been corrected for recessional velocity.

dopcor_file()

This function applies Doppler Correction to date input from a file and outputs the result to the file "dc_[filename]"

Parameters

  • filename (string): File containing the data to Doppler Correct. The first column must contain the wavelength bins.
  • z (float): The redshift.

Returns

  • None

ylim_def()

Finds appropriate limits for a plot of f against wl. matplotlib.pyplotsets limits automatically based on the maximum and minimum values within the whole ranged covered by the data, however if there are spurious points one might not be so keen to have them in the frame as to actually see the spectrum of polarisation data properly. This functions finds new limits for the plot by looking at the extreme values within the range of interest (defined by the user). The minimum and maximum (ymin and ymax) are returned, but not applied; they need to be used in, e.g plt.ylim([ymin, ymax])

Parameters

  • wl (*1D-array): x-values. Here called "wl" because for me it's generally a wavelength.
  • f (*1D-array): y-values. Here called "f" because for me it's generally a flux.
  • wlmin (float/int, optional): Lower wavelength of the range of interest.
  • wlmax (float/int, optional): Upper wavelength of the range of interest.

Returns

  • float: ymin, ymax

rot_data()

Rotates 2D data set by θ (in radians). I used the variable names q and u because I mostly use this to rotate Stokes parameters. Parameters

  • q (1D-array): x-values.
  • u (1D-array): y-values.
  • θ (float): Angle of rotation in radians

Returns

  • 1D-Arrays: rotated q, rotated u

norm_ellipse()

Creates n data scattered in an ellipsoidal fashion and normally distributed around (xc,yc). The data are described by 2 normal distributions N1 and N2,and rotated by &#952.

Parameters

  • xc (1D-array): x coordinate of the centre of the ellipse. Also mean of N1.
  • yc (1D-array): y coordinate of the centre of the ellipse. Also mean of N2.
  • a (float): standard deviation of N1.
  • b (float): standard deviation of N2.
  • θ (float): rotation angle in radian
  • n (int): Number of data points created.

Returns

  • 1D-Arrays: x coordinates, y coordinates

Interactive Functions

The following functions are small interactive routines written to make some calculations less tedious and/or more reliable than if I had to type it in the calculator.

ep_date()

This one is made to find the epoch with respect a given date (e.g + or - X days with respect to V-band maximum) or a date given an epoch.

First you'll be prompted for the date at V-band maximum (but that can be any reference data you want). Then you have the following options:

  1. Calculate the epoch in days. (Inputs: Date of epoch)
  2. Calculate a date from an epoch. (Inputs: Epoch in days - can be negative)
  3. Update the V-band max date.
  4. Exit.

You can pick an option by just typing the corresponding number in the terminal and pressing Enter, then you'll be prompted for the input corresponding to your query.


vel()

This routine calculates the velocity of an element given the observed wavelength and the rest wavelength of this particular species. The observed and rest wavelength entered should have the same unit.