
from __future__ import (absolute_import, print_function, division)

import numpy as np
from astropy.io import fits
import matplotlib.pyplot as plt
from astropy.table import Table
import h5py

__all__ = ['PhotDG']

class PhotDG:
    """
    Read in the DirtyGrid cube from a HDF5 file

    Returns
    -------
        (self.)seds: a list that grows with the SED you choose to extract
        (self.)dgrid: the HDF5 file:  with attributes corresponding to the 
                parameters values; with each dataset corresponding to each band

    """

    def __init__(self, datafile='data/dirtygrid_29mar17.hdf5'):
        f = h5py.File(datafile, "r+")
        # Create the objects
        self.seds = []
        self.dgrid = f

        # convert binary strings to regular strings
        # does not work, need to find the way to do this...
        #self.dgrid.attrs['grain'] = [str(a)
        #                             for a in self.dgrid.attrs['grain']]

    def print_parameters(self):

        print('SEDs in erg/s/micrometer')
        print('')
        print('-- Discrete parameters')
        print('    - Grain types: ' + str(self.dgrid.attrs['grain']))
        print('    - Geometries: ' + str(self.dgrid.attrs['geom']))
        print('    - Star formation types: '
              + str(self.dgrid.attrs['sf_type']))