@@ -0,0 +1,2247 @@
+%22%22%22%0AClasses and functions for archetypes.%0A%22%22%22%0A%0Aimport sys%0Aimport os%0Afrom glob import glob%0Aimport fitsio%0Aimport scipy as sp%0Afrom scipy.interpolate import interp1d%0A%0Aclass Archetype():%0A    %22%22%22%0A%0A    %22%22%22%0A    def __init__(self, filename):%0A        %22%22%22%0A%0A        %22%22%22%0A%0A        ### Load the file%0A        h = fitsio.FITS(filename)%0A%0A        hdr = h%5B'ARCHETYPES'%5D.read_header()%0A        self.flux = sp.array(h%5B'ARCHETYPES'%5D%5B'ARCHETYPE'%5D%5B:%5D)%0A        self._rrtype = hdr%5B'RRTYPE'%5D.strip()%0A        self._subtype = sp.array(sp.char.strip(h%5B'ARCHETYPES'%5D%5B'SUBTYPE'%5D%5B:%5D.astype(str)))%0A%0A        self.wave = sp.asarray(hdr%5B'CRVAL1'%5D + hdr%5B'CDELT1'%5D*sp.arange(self.flux.shape%5B1%5D))%0A        if 'LOGLAM' in hdr and hdr%5B'LOGLAM'%5D != 0:%0A            self.wave = 10**self.wave%0A%0A        h.close()%0A%0A        self._narch = self.flux.shape%5B0%5D%0A        self._nwave = self.flux.shape%5B1%5D%0A        self._full_type = sp.char.add(self._rrtype+':::',self._subtype)%0A        self._full_type%5Bself._subtype==''%5D = self._rrtype%0A%0A        ### Dic of templates%0A        self.archetype = %7B%7D%0A        self.archetype%5B'INTERP'%5D = sp.array(%5BNone%5D*self._narch)%0A        for i in range(self._narch):%0A            self.archetype%5B'INTERP'%5D%5Bi%5D = interp1d(self.wave,self.flux%5Bi,:%5D,fill_value='extrapolate',kind='linear')%0A%0A        return%0A%0Adef find_archetypes(archetypes_dir=None):%0A    %22%22%22Return list of rrarchetype-%5C*.fits archetype files%0A%0A    Search directories in this order, returning results from first one found:%0A        - archetypes_dir%0A        - $RR_ARCHETYPE_DIR%0A        - %3Credrock_code%3E/archetypes/%0A%0A    Args:%0A        archetypes_dir (str): optional directory containing the archetypes.%0A%0A    Returns:%0A        list: a list of archetype files.%0A%0A    %22%22%22%0A    if archetypes_dir is None:%0A        if 'RR_ARCHETYPE_DIR' in os.environ:%0A            archetypes_dir = os.environ%5B'RR_ARCHETYPE_DIR'%5D%0A        else:%0A            thisdir = os.path.dirname(__file__)%0A            archdir = os.path.join(os.path.abspath(thisdir), 'archetypes')%0A            if os.path.exists(archdir):%0A                archetypes_dir = archdir%0A            else:%0A                raise IOError(%22ERROR: can't find archetypes_dir, $RR_ARCHETYPE_DIR, or %7Brrcode%7D/archetypes/%22)%0A%0A    return sorted(glob(os.path.join(archetypes_dir, 'rrarchetype-*.fits')))%0A

add an archetype clas