# Path: DiscEvolution/planet_formation.py
# class Planets(object):
#     """Data for growing planets.
# 
#     Holds the location, core & envelope mass, and composition of growing
#     planets.
# 
#     args:
#         Nchem : number of chemical species to track, default = None
#     """
#     def __init__(self, Nchem=None):
#         self.R  = np.array([], dtype='f4')
#         self.M_core = np.array([], dtype='f4')
#         self.M_env  = np.array([], dtype='f4')
#         self.t_form = np.array([], dtype='f4')
# 
#         self._N = 0
# 
#         if Nchem:
#             self.X_core = np.array([[] for _ in range(Nchem)], dtype='f4')
#             self.X_env  = np.array([[] for _ in range(Nchem)], dtype='f4')
#         else:
#             self.X_core = None
#             self.X_env  = None
#         self._Nchem = Nchem
# 
#     def add_planet(self, t, R, Mcore, Menv, X_core=None, X_env=None):
#         """Add a new planet"""
#         if self._Nchem:
#             self.X_core = np.c_[self.X_core, X_core]
#             self.X_env  = np.c_[self.X_env, X_env]
# 
#         self.R      = np.append(self.R, R)
#         self.M_core = np.append(self.M_core, Mcore)
#         self.M_env  = np.append(self.M_env, Menv)
#         
#         self.t_form = np.append(self.t_form, np.ones_like(Menv)*t)
# 
#         self._N += 1
# 
#     def append(self, planets):
#         """Add a list of planets from another planet object"""
#         self.add_planet(planets.t_form, planets.R,
#                         planets.M_core, planets.M_env,
#                         planets.X_core, planets.X_env)
# 
#     @property
#     def M(self):
#         return self.M_core + self.M_env
# 
#     @property
#     def N(self):
#         """Number of planets"""
#         return self._N
# 
#     @property
#     def chem(self):
#         return self._Nchem > 0
# 
#     def __getitem__(self, idx):
#         """Get a sub-set of the planets"""
#         sub = Planets(self._Nchem)      
# 
#         sub.R      = self.R[idx]
#         sub.M_core = self.M_core[idx]
#         sub.M_env  = self.M_env[idx]
#         sub.t_form = self.t_form[idx]
#         if self.chem:
#             sub.X_core = self.X_core[...,idx]
#             sub.X_env  = self.X_env[...,idx]
# 
#         try:
#             sub._N = len(sub.R)
#         except TypeError:
#             sub._N = 1
# 
#         return sub
# 
#     def __iter__(self):
#         for i in range(self.N):
#             yield self[i]


import sys, os
import re
import numpy as np
import DiscEvolution.chemistry as chem
from DiscEvolution.planet_formation import Planets

    @property
    def Num_Snaps(self):
        return self._Nmax

                    
class DiscReader(Reader):
    """Read disc snaphshots from file"""
    # By default assume no chemistry
    def __init__(self, DIR, base='disc', chem_on=False):
        super(DiscReader, self).__init__(DiscSnap, DIR, base, chem_on)

class PlanetReader(Reader):
    """Read disc snaphshots from file"""
    def __init__(self, DIR, base='planets'):
        super(PlanetReader, self).__init__(PlanetSnap, DIR, base)

    def compute_planet_evo(self):
        """Compute the time evolution of each planet"""
        planets = []
        times = []
        Np = 0
        for n in range(self.Num_Snaps):
            try:
                pf = self[n]
                for i in range(pf.planets.N):
                    if i == Np:
                        try:
                            p = Planets(pf.planets[0].X_core.shape[0])
                        except AttributeError:

# Path: DiscEvolution/planet_formation.py
# class Planets(object):
#     """Data for growing planets.
# 
#     Holds the location, core & envelope mass, and composition of growing
#     planets.
# 
#     args:
#         Nchem : number of chemical species to track, default = None
#     """
#     def __init__(self, Nchem=None):
#         self.R  = np.array([], dtype='f4')
#         self.M_core = np.array([], dtype='f4')
#         self.M_env  = np.array([], dtype='f4')
#         self.t_form = np.array([], dtype='f4')
# 
#         self._N = 0
# 
#         if Nchem:
#             self.X_core = np.array([[] for _ in range(Nchem)], dtype='f4')
#             self.X_env  = np.array([[] for _ in range(Nchem)], dtype='f4')
#         else:
#             self.X_core = None
#             self.X_env  = None
#         self._Nchem = Nchem
# 
#     def add_planet(self, t, R, Mcore, Menv, X_core=None, X_env=None):
#         """Add a new planet"""
#         if self._Nchem:
#             self.X_core = np.c_[self.X_core, X_core]
#             self.X_env  = np.c_[self.X_env, X_env]
# 
#         self.R      = np.append(self.R, R)
#         self.M_core = np.append(self.M_core, Mcore)
#         self.M_env  = np.append(self.M_env, Menv)
#         
#         self.t_form = np.append(self.t_form, np.ones_like(Menv)*t)
# 
#         self._N += 1
# 
#     def append(self, planets):
#         """Add a list of planets from another planet object"""
#         self.add_planet(planets.t_form, planets.R,
#                         planets.M_core, planets.M_env,
#                         planets.X_core, planets.X_env)
# 
#     @property
#     def M(self):
#         return self.M_core + self.M_env
# 
#     @property
#     def N(self):
#         """Number of planets"""
#         return self._N
# 
#     @property
#     def chem(self):
#         return self._Nchem > 0
# 
#     def __getitem__(self, idx):
#         """Get a sub-set of the planets"""
#         sub = Planets(self._Nchem)      
# 
#         sub.R      = self.R[idx]
#         sub.M_core = self.M_core[idx]
#         sub.M_env  = self.M_env[idx]
#         sub.t_form = self.t_form[idx]
#         if self.chem:
#             sub.X_core = self.X_core[...,idx]
#             sub.X_env  = self.X_env[...,idx]
# 
#         try:
#             sub._N = len(sub.R)
#         except TypeError:
#             sub._N = 1
# 
#         return sub
# 
#     def __iter__(self):
#         for i in range(self.N):
#             yield self[i]


# Path: scripts/snap_reader.py
import sys, os
import re
import numpy as np
import DiscEvolution.chemistry as chem
from DiscEvolution.planet_formation import Planets


    @property
    def Num_Snaps(self):
        return self._Nmax

                    
class DiscReader(Reader):
    """Read disc snaphshots from file"""
    # By default assume no chemistry
    def __init__(self, DIR, base='disc', chem_on=False):
        super(DiscReader, self).__init__(DiscSnap, DIR, base, chem_on)

class PlanetReader(Reader):
    """Read disc snaphshots from file"""
    def __init__(self, DIR, base='planets'):
        super(PlanetReader, self).__init__(PlanetSnap, DIR, base)

    def compute_planet_evo(self):
        """Compute the time evolution of each planet"""
        planets = []
        times = []
        Np = 0
        for n in range(self.Num_Snaps):
            try:
                pf = self[n]
                for i in range(pf.planets.N):
                    if i == Np:
                        try:
                            p = Planets(pf.planets[0].X_core.shape[0])
                        except AttributeError:

                            p = Planets()