import os

class Constants(object):
	"""All the constants necessary for the LineAnalysis scripts."""

	def getCassisDir():
		"""Function allowing the user to extract the right CASSIS directory path"""

		from eu.omp.irap.cassis.properties import Software
		CASSIS_DIR = Software.getCassisPath()

		return CASSIS_DIR

	CASSIS_DIR              = getCassisDir()
	CONTINUUM_DIR           = os.path.join(CASSIS_DIR, "delivery", "continuum")
	TELESCOPE_DIR           = os.path.join(CASSIS_DIR, "delivery", "telescope")
	MANDATORY_PARAMETERS    = ["nmol", "temp", "tex", "tkin", "fwhm", "vlsr", "size"]
	OPTIONAL_PARAMETERS     = ["iso"]
	COLLISIONER_PREFIX      = "n_"
	COLLISIONER_NAMES       = ["H2", "p_H2", "o_H2", "e", "H", "He", "H+"]
	COLLISIONER_PARAMETERS  = [COLLISIONER_PREFIX + c for c in COLLISIONER_NAMES]
	USER_START_INDEX        = 1 # The user wants to start from 1 instead if 0
	MODEL_TEMP              = {"lte": "tex", "radex": "tkin"}
	ORDERED_PARAMETER_NAMES = ["nmol", "tex", "tkin", "fwhm", "size", "vlsr", "iso"] + COLLISIONER_PARAMETERS
	ALL_PARAMETERS          = MANDATORY_PARAMETERS + OPTIONAL_PARAMETERS + COLLISIONER_PARAMETERS

	@classmethod
	def renameTemp(cls, name, model):
		"""Rename the parameter temp to the right temperature name 
		depending on the current model and the model temperature

		Inputs:
			name	   - the name of the parameter
			model      - the current model

		Returns:
			If name == "temp" the right temperature name.
			else the input name.

		"""
		if name == "temp":
			return cls.MODEL_TEMP[model.lower()]
		else:
			return name


def product(*args):
    """product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
    product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111

    """
    pools = map(tuple, args)
    result = [[]]
    for pool in pools:
        result = [x+[y] for x in result for y in pool]
    for prod in result:
        yield tuple(prod)


def sortParameterNames(names):
	return [name for name in Constants.ORDERED_PARAMETER_NAMES if name in names]

# vim: set noet fdm=indent:
