# Path: molyso/mm/tracking_output.py
# def s_to_h(s):
#     """
#     converts seconds to hours
#     :param s: seconds
#     :return: hours
#     """
#     return s / (60.0 * 60.0)
# 
# Path: molyso/generic/etc.py
# class QuickTableDumper(object):
# 
#     """
# 
#     :param recipient:
#     """
#     delimiter = '\t'
#     line_end = '\n'
# 
#     precision = 8
# 
#     def __init__(self, recipient=None):
#         if recipient is None:
#             recipient = sys.stdout
# 
#         self.recipient = recipient
#         self.headers = []
# 
#     def write_list(self, the_list):
#         """
# 
#         :param the_list:
#         """
#         self.recipient.write(self.delimiter.join(map(self.stringify, the_list)) + self.line_end)
# 
#     def add(self, row):
#         """
# 
#         :param row:
#         """
#         if len(self.headers) == 0:
#             self.headers = list(sorted(row.keys()))
#             self.write_list(self.headers)
# 
#         self.write_list(row[k] for k in self.headers)
# 
#     def stringify(self, obj):
#         """
# 
#         :param obj:
#         :return:
#         """
#         if type(obj) in (float, np.float32, np.float64) and self.precision:
#             return str(round(obj, self.precision))
#         else:
#             return str(obj)


import numpy as np
    import cPickle
    import pickle
        import matplotlib.pyplot as plt
                import code
from .tracking_output import s_to_h
from ..generic.etc import QuickTableDumper
                try_new_poschan(0, 1)
            elif event.key == 'M':
                try_new_poschan(0, -1)
            elif event.key == 'o' or event.key == 'O':
                recipient = None

                if event.key == 'O':
                    print("Please enter file name for tabular output [will be overwritten if exists]:")
                    file_name = input()
                    recipient = open(file_name, 'w+')

                out = QuickTableDumper(recipient=recipient)

                for (t_pos, t_chan), t_env in all_envs.items():
                    x_pos = list(tracked_results.keys())[t_pos]
                    x_chan = list(tracked_results[x_pos].channel_accumulator.keys())[t_chan]
                    times = t_env['points'][:t_env['used'], 2].compressed()
                    times = times.reshape(times.size // 2, 2)
                    deltas = times[:, 1] - times[:, 0]
                    mu = np.log(2) / (deltas / (60.0 * 60.0))

                    for num in range(len(mu)):

                        out.add({
                            'position': x_pos,
                            'channel': x_chan,
                            'growth_rate': mu[num],
                            'growth_rate_channel_mean': np.mean(mu),
                            'division_age': s_to_h(deltas[num]),
                            'growth_start': s_to_h(times[num, 0]),

# Path: molyso/mm/tracking_output.py
# def s_to_h(s):
#     """
#     converts seconds to hours
#     :param s: seconds
#     :return: hours
#     """
#     return s / (60.0 * 60.0)
# 
# Path: molyso/generic/etc.py
# class QuickTableDumper(object):
# 
#     """
# 
#     :param recipient:
#     """
#     delimiter = '\t'
#     line_end = '\n'
# 
#     precision = 8
# 
#     def __init__(self, recipient=None):
#         if recipient is None:
#             recipient = sys.stdout
# 
#         self.recipient = recipient
#         self.headers = []
# 
#     def write_list(self, the_list):
#         """
# 
#         :param the_list:
#         """
#         self.recipient.write(self.delimiter.join(map(self.stringify, the_list)) + self.line_end)
# 
#     def add(self, row):
#         """
# 
#         :param row:
#         """
#         if len(self.headers) == 0:
#             self.headers = list(sorted(row.keys()))
#             self.write_list(self.headers)
# 
#         self.write_list(row[k] for k in self.headers)
# 
#     def stringify(self, obj):
#         """
# 
#         :param obj:
#         :return:
#         """
#         if type(obj) in (float, np.float32, np.float64) and self.precision:
#             return str(round(obj, self.precision))
#         else:
#             return str(obj)


# Path: molyso/mm/highlevel_interactive_ground_truth.py
import numpy as np
    import cPickle
    import pickle
        import matplotlib.pyplot as plt
                import code
from .tracking_output import s_to_h
from ..generic.etc import QuickTableDumper

                try_new_poschan(0, 1)
            elif event.key == 'M':
                try_new_poschan(0, -1)
            elif event.key == 'o' or event.key == 'O':
                recipient = None

                if event.key == 'O':
                    print("Please enter file name for tabular output [will be overwritten if exists]:")
                    file_name = input()
                    recipient = open(file_name, 'w+')

                out = QuickTableDumper(recipient=recipient)

                for (t_pos, t_chan), t_env in all_envs.items():
                    x_pos = list(tracked_results.keys())[t_pos]
                    x_chan = list(tracked_results[x_pos].channel_accumulator.keys())[t_chan]
                    times = t_env['points'][:t_env['used'], 2].compressed()
                    times = times.reshape(times.size // 2, 2)
                    deltas = times[:, 1] - times[:, 0]
                    mu = np.log(2) / (deltas / (60.0 * 60.0))

                    for num in range(len(mu)):

                        out.add({
                            'position': x_pos,
                            'channel': x_chan,
                            'growth_rate': mu[num],
                            'growth_rate_channel_mean': np.mean(mu),
                            'division_age': s_to_h(deltas[num]),
                            'growth_start': s_to_h(times[num, 0]),

                            'growth_end': s_to_h(times[num, 1]),