How to use the mc3.utils.default_parnames function in mc3

To help you get started, we’ve selected a few mc3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pcubillos / mc3 / tests / test_utils.py View on Github external
def test_parnames():
    np.testing.assert_equal(mu.default_parnames(3),
                    np.array(['Param 1', 'Param 2', 'Param 3']))
github pcubillos / mc3 / mc3 / plots / plots.py View on Github external
# Don't plot if there are no pairs:
  if npars == 1:
      return None, None

  if ranges is None:
      ranges = np.repeat(None, npars)
  else: # Set default ranges if necessary:
      for i in range(npars):
          if ranges[i] is None:
              ranges[i] = (np.nanmin(posterior[0::thinning,i]),
                           np.nanmax(posterior[0::thinning,i]))

  # Set default parameter names:
  if pnames is None:
      pnames = mu.default_parnames(npars)

  # Set palette color:
  palette = plt.cm.viridis_r
  palette.set_under(color='w')
  palette.set_bad(color='w')

  # Gather 2D histograms:
  hist = []
  xran, yran, lmax = [], [], []
  for irow in range(1, npars):
      for icol in range(irow):
          ran = None
          if ranges[icol] is not None:
              ran = [ranges[icol], ranges[irow]]
          h, x, y = np.histogram2d(posterior[0::thinning,icol],
              posterior[0::thinning,irow], bins=nbins, range=ran, **histkeys)
github pcubillos / mc3 / mc3 / plots / plots.py View on Github external
zchain    = zchain   [good]
      # Sort the posterior by chain:
      zsort = np.lexsort([zchain])
      posterior = posterior[zsort]
      zchain    = zchain   [zsort]
      # Get location for chains separations:
      xsep = np.where(np.ediff1d(zchain[0::thinning]))[0]

  # Get number of parameters and length of chain:
  nsamples, npars = np.shape(posterior)
  # Number of samples (thinned):
  xmax = len(posterior[0::thinning])

  # Set default parameter names:
  if pnames is None:
      pnames = mu.default_parnames(npars)

  npanels = 12  # Max number of panels per page
  npages = int(1 + (npars-1)/npanels)

  # Make the trace plot:
  axes = []
  ipar = 0
  for page in range(npages):
      fig = plt.figure(fignum+page, figsize=(8.5,11.0))
      plt.clf()
      plt.subplots_adjust(left=0.15, right=0.95, bottom=0.05, top=0.97,
                          hspace=0.15)
      while ipar < npars:
          ax = plt.subplot(npanels, 1, ipar%npanels+1)
          axes.append(ax)
          ax.plot(posterior[0::thinning,ipar], fmt, ms=ms)
github pcubillos / mc3 / mc3 / sampler_driver.py View on Github external
if ncpu >= mpr.cpu_count():
      log.warning("The number of requested CPUs ({:d}) is >= than the number "
                  "of available CPUs ({:d}).  Enforced ncpu to {:d}.".
                 format(ncpu, mpr.cpu_count(), mpr.cpu_count()-1))
      ncpu = mpr.cpu_count() - 1

  nparams = len(params)
  ndata   = len(data)

  # Setup array of parameter names:
  if   pnames is None     and texnames is not None:
      pnames = texnames
  elif pnames is not None and texnames is None:
      texnames = pnames
  elif pnames is None     and texnames is None:
      pnames = texnames = mu.default_parnames(nparams)
  pnames   = np.asarray(pnames)
  texnames = np.asarray(texnames)

  if pmin is None:
      pmin = np.tile(-np.inf, nparams)
  if pmax is None:
      pmax = np.tile( np.inf, nparams)
  pmin = np.asarray(pmin)
  pmax = np.asarray(pmax)
  if (np.any(np.isinf(pmin)) or np.any(np.isinf(pmax))) and sampler=='dynesty':
      log.error('Parameter space must be constrained by pmin and pmax.')

  if pstep is None:
      pstep = 0.1 * np.abs(params)
  pstep = np.asarray(pstep)
github pcubillos / mc3 / mc3 / plots / plots.py View on Github external
xpdf = [None]*npars
  if not isinstance(pdf, list):  # Put single arrays into list
      pdf  = [pdf]
      xpdf = [xpdf]
  # Histogram keywords depending whether one wants the HPD or not:
  hkw = {'edgecolor':'navy', 'color':'b'}
  # Bestfit keywords:
  bkw = {'zorder':2, 'color':'orange'}
  if quantile is not None:
      hkw = {'histtype':'step', 'lw':lw, 'edgecolor':'b'}
      bkw = {'zorder':-1, 'color':'red'}
  hkw.update(histkeys)

  # Set default parameter names:
  if pnames is None:
      pnames = mu.default_parnames(npars)

  # Xranges:
  if ranges is None:
      ranges = np.repeat(None, npars)

  # Set number of rows:
  nrows, ncolumns, npanels = 4, 3, 12
  npages = int(1 + (npars-1)/npanels)

  if axes is None:
      figs = []
      axes = []
      for j in range(npages):
          fig = plt.figure(fignum+j, figsize=(8.5, 11.0))
          figs.append(fig)
          fig.clf()