# Path: frbpoppy/misc.py
# def pprint(*s, output=True):
#     """Hack to make for more informative print statements."""
#     f = inspect.stack()[1][1].split('/')[-1]
#     m = '{:13.13} |'.format(f)
# 
#     if output:
#         print(m, *s)
#     else:
#         lines = []
#         for e in s:
#             lines.append('\n'.join([f'{m} {f}' for f in e.split('\n')]))
#         return '\n'.join(lines)
# 
# Path: frbpoppy/paths.py
# class Paths():
#     def __init__(self):
#     def __str__(self):
#     def check(self, path):
#     def store(self, name, default, *args):
#     def data(self, *args):
#     def populations(self, *args):
#     def surveys(self, *args):
#     def models(self, *args):
#     def frbcat(self, *args):
# 
# Path: frbpoppy/population.py
# class Population:
#     """Class to hold a population of FRBs."""
# 
#     def __init__(self):
#         """Initializing."""
#         # Population properties
#         self.name = None
# 
#         # Frequency emission limits [MHz]
#         self.f_max = None
#         self.f_min = None
# 
#         # Store FRB sources
#         self.frbs = FRBs()
#         self.uid = None  # Unique Identifier
# 
#     def __str__(self):
#         """Define how to print a population object to a console."""
#         s = 'Population properties:'
# 
#         # TODO: Code this to print all properties
# 
#         return s
# 
#     def to_df(self):
#         """Gather source values into a pandas dataframe."""
#         df = self.frbs.to_df()
#         return df
# 
#     def save(self, path=None):
#         """
#         Write out source properties as data file.
# 
#         Args:
#             path (str): Path to which to save.
#         """
#         if path is None:
#             # Check if a population has been a survey name
#             if not self.name:
#                 file_name = 'pop'
#             else:
#                 file_name = self.name.lower()
# 
#             if self.uid:
#                 file_name += f'_{self.uid}'
# 
#             path = paths.populations() + f'{file_name}.p'
# 
#         self.to_pickle(path)
# 
#     def to_csv(self, path):
#         """Write a population to a csv file.
# 
#         Args:
#             path (str): Path to which to write
# 
#         """
#         df = self.frbs.to_df()
#         df.to_csv(path)
# 
#     def to_pickle(self, path):
#         """Write a population to a pickled file for future use.
# 
#         Args:
#             path (str): Path to which to write
# 
#         """
#         output = open(path, 'wb')
#         pickle.dump(self, output, 2)
#         output.close()
# 
#     def n_sources(self):
#         """Return the number of FRB sources."""
#         return len(self.frbs.ra)
# 
#     def n_srcs(self):
#         return self.n_sources()
# 
#     def n_bursts(self):
#         """Return the number of bursts."""
#         try:  # Will only work for a repeater population
#             n = np.count_nonzero(~np.isnan(self.frbs.time))
#         except TypeError:
#             n = self.n_sources()
#         return n
# 
#     def n_repeaters(self):
#         """Return the numer of repeaters in a population."""
#         try:
#             return np.sum((~np.isnan(self.frbs.time)).sum(1) > 1)
#         except TypeError:
#             return 0
# 
#     def n_rep(self):
#         return self.n_repeaters()
# 
#     def n_one_offs(self):
#         """Return the numer of one-offs in a population."""
#         try:
#             return np.sum((~np.isnan(self.frbs.time)).sum(1) <= 1)
#         except TypeError:
#             return self.n_sources()
# 
#     def n_oneoffs(self):
#         """Return the numer of one-offs in a population."""
#         return self.n_one_offs()


import os
import pandas as pd
    import IPython
from frbcat import Frbcat as PureFrbcat
from frbpoppy.misc import pprint
from frbpoppy.paths import paths
from frbpoppy.population import Population
        """Match up frbs with surveys."""
        # Merge survey names
        surf = os.path.join(self.path, 'paper_survey.csv')
        self._surveys = pd.read_csv(surf)
        cols = ['frb_name', 'pub_description']

        self.df = pd.merge(self.df, self._surveys, on=cols, how='left')
        # Clean up possible unnamed columns
        self.df = self.df.loc[:, ~self.df.columns.str.contains('unnamed')]

        # Add single survey instruments
        # Bit rough, but will work in a pinch
        def cond(t):
            return (self.df.telescope == t) & (self.df.survey.isnull())
        self.df.at[cond('wsrt-apertif'), 'survey'] = 'wsrt-apertif'
        self.df.at[cond('askap'), 'survey'] = 'askap-incoh'
        self.df.at[cond('chime'), 'survey'] = 'chime'
        self.df.at[cond('srt'), 'survey'] = 'srt'
        self.df.at[cond('effelsberg'), 'survey'] = 'effelsberg'
        self.df.at[cond('gbt'), 'survey'] = 'guppi'
        self.df.at[cond('fast'), 'survey'] = 'crafts'

        # Check whether any FRBs have not yet been assigned
        no_surveys = self.df['survey'].isnull()

        if interrupt and any(no_surveys):
            cols = ['pub_description', 'frb_name']
            ns_df = self.df[no_surveys].drop_duplicates(subset=cols,
                                                        keep='first')


# Path: frbpoppy/misc.py
# def pprint(*s, output=True):
#     """Hack to make for more informative print statements."""
#     f = inspect.stack()[1][1].split('/')[-1]
#     m = '{:13.13} |'.format(f)
# 
#     if output:
#         print(m, *s)
#     else:
#         lines = []
#         for e in s:
#             lines.append('\n'.join([f'{m} {f}' for f in e.split('\n')]))
#         return '\n'.join(lines)
# 
# Path: frbpoppy/paths.py
# class Paths():
#     def __init__(self):
#     def __str__(self):
#     def check(self, path):
#     def store(self, name, default, *args):
#     def data(self, *args):
#     def populations(self, *args):
#     def surveys(self, *args):
#     def models(self, *args):
#     def frbcat(self, *args):
# 
# Path: frbpoppy/population.py
# class Population:
#     """Class to hold a population of FRBs."""
# 
#     def __init__(self):
#         """Initializing."""
#         # Population properties
#         self.name = None
# 
#         # Frequency emission limits [MHz]
#         self.f_max = None
#         self.f_min = None
# 
#         # Store FRB sources
#         self.frbs = FRBs()
#         self.uid = None  # Unique Identifier
# 
#     def __str__(self):
#         """Define how to print a population object to a console."""
#         s = 'Population properties:'
# 
#         # TODO: Code this to print all properties
# 
#         return s
# 
#     def to_df(self):
#         """Gather source values into a pandas dataframe."""
#         df = self.frbs.to_df()
#         return df
# 
#     def save(self, path=None):
#         """
#         Write out source properties as data file.
# 
#         Args:
#             path (str): Path to which to save.
#         """
#         if path is None:
#             # Check if a population has been a survey name
#             if not self.name:
#                 file_name = 'pop'
#             else:
#                 file_name = self.name.lower()
# 
#             if self.uid:
#                 file_name += f'_{self.uid}'
# 
#             path = paths.populations() + f'{file_name}.p'
# 
#         self.to_pickle(path)
# 
#     def to_csv(self, path):
#         """Write a population to a csv file.
# 
#         Args:
#             path (str): Path to which to write
# 
#         """
#         df = self.frbs.to_df()
#         df.to_csv(path)
# 
#     def to_pickle(self, path):
#         """Write a population to a pickled file for future use.
# 
#         Args:
#             path (str): Path to which to write
# 
#         """
#         output = open(path, 'wb')
#         pickle.dump(self, output, 2)
#         output.close()
# 
#     def n_sources(self):
#         """Return the number of FRB sources."""
#         return len(self.frbs.ra)
# 
#     def n_srcs(self):
#         return self.n_sources()
# 
#     def n_bursts(self):
#         """Return the number of bursts."""
#         try:  # Will only work for a repeater population
#             n = np.count_nonzero(~np.isnan(self.frbs.time))
#         except TypeError:
#             n = self.n_sources()
#         return n
# 
#     def n_repeaters(self):
#         """Return the numer of repeaters in a population."""
#         try:
#             return np.sum((~np.isnan(self.frbs.time)).sum(1) > 1)
#         except TypeError:
#             return 0
# 
#     def n_rep(self):
#         return self.n_repeaters()
# 
#     def n_one_offs(self):
#         """Return the numer of one-offs in a population."""
#         try:
#             return np.sum((~np.isnan(self.frbs.time)).sum(1) <= 1)
#         except TypeError:
#             return self.n_sources()
# 
#     def n_oneoffs(self):
#         """Return the numer of one-offs in a population."""
#         return self.n_one_offs()


# Path: frbpoppy/frbcatpoppy.py
import os
import pandas as pd
    import IPython
from frbcat import Frbcat as PureFrbcat
from frbpoppy.misc import pprint
from frbpoppy.paths import paths
from frbpoppy.population import Population

        """Match up frbs with surveys."""
        # Merge survey names
        surf = os.path.join(self.path, 'paper_survey.csv')
        self._surveys = pd.read_csv(surf)
        cols = ['frb_name', 'pub_description']

        self.df = pd.merge(self.df, self._surveys, on=cols, how='left')
        # Clean up possible unnamed columns
        self.df = self.df.loc[:, ~self.df.columns.str.contains('unnamed')]

        # Add single survey instruments
        # Bit rough, but will work in a pinch
        def cond(t):
            return (self.df.telescope == t) & (self.df.survey.isnull())
        self.df.at[cond('wsrt-apertif'), 'survey'] = 'wsrt-apertif'
        self.df.at[cond('askap'), 'survey'] = 'askap-incoh'
        self.df.at[cond('chime'), 'survey'] = 'chime'
        self.df.at[cond('srt'), 'survey'] = 'srt'
        self.df.at[cond('effelsberg'), 'survey'] = 'effelsberg'
        self.df.at[cond('gbt'), 'survey'] = 'guppi'
        self.df.at[cond('fast'), 'survey'] = 'crafts'

        # Check whether any FRBs have not yet been assigned
        no_surveys = self.df['survey'].isnull()

        if interrupt and any(no_surveys):
            cols = ['pub_description', 'frb_name']
            ns_df = self.df[no_surveys].drop_duplicates(subset=cols,
                                                        keep='first')


            pprint('It seems there are new FRBs!')