示例#1
0
def calculate_bee_lifespans_from_hatchdates():
    """
    Uses the Last_day_alive.csv cache and the get_hatchdate functions from bb_utils
    to calculate the lifespan (length-of-life) in days for each bee. The lifespan will be NaN if hatchdate is NaT.

    """
    meta = bb_utils.meta.BeeMetaInfo()
    last_alive_path = detections_cache_path + 'Last_day_alive.csv'
    last_day_alive_df = pd.read_csv(last_alive_path,
                                    parse_dates=['max'],
                                    usecols=['max', 'bee_id'])

    last_day_alive_df.index = last_day_alive_df['bee_id']
    lifespan = pd.DataFrame()
    for ix in last_day_alive_df['bee_id']:
        birthday = meta.get_hatchdate(
            bb_utils.ids.BeesbookID.from_dec_9(ix)).date()
        temp_lifespan = pd.DataFrame(
            [[ix, (last_day_alive_df.loc[ix]['max'].date() - birthday).days]],
            columns=['id', 'lifespan'])
        lifespan = pd.concat([lifespan, temp_lifespan])
    lifespan.index = last_day_alive_df['bee_id']
    lifespan = lifespan['lifespan']
    lifespan = filter_out_fake_deaths(lifespan)
    return lifespan
示例#2
0
def calculate_bee_lifespans_combined():
    last_alive_path = detections_cache_path + 'Last_day_alive.csv'
    first_alive_path = detections_cache_path + 'First_day_alive.csv'

    last_day_alive_df = pd.read_csv(last_alive_path,
                                    parse_dates=['max'],
                                    usecols=['max', 'bee_id'])
    first_day_alive_df = pd.read_csv(first_alive_path,
                                     parse_dates=['min'],
                                     usecols=['min', 'bee_id'])

    last_day_alive_df.index = last_day_alive_df['bee_id']
    first_day_alive_df.index = first_day_alive_df['bee_id']

    meta = bb_utils.meta.BeeMetaInfo()

    lifespan_from_detections = calculate_bee_lifespans_from_detections()

    lifespan = pd.DataFrame()
    for ix in last_day_alive_df['bee_id']:
        birthday = meta.get_hatchdate(
            bb_utils.ids.BeesbookID.from_dec_9(ix)).date()
        if pd.isnull(birthday):
            birthday = first_day_alive_df.loc[ix]['min'].date()
        temp_lifespan = pd.DataFrame(
            [[ix, (last_day_alive_df.loc[ix]['max'].date() - birthday).days]],
            columns=['id', 'lifespan'])
        lifespan = pd.concat([lifespan, temp_lifespan])
    lifespan.index = last_day_alive_df['bee_id']
    lifespan = lifespan['lifespan']
    lifespan = filter_out_fake_deaths(lifespan)
    return lifespan
示例#3
0
def get_all_bee_ids():
    meta = bb_utils.meta.BeeMetaInfo()
    bees = []
    for id in range(0,4096):
        bee_id = bb_utils.ids.BeesbookID.from_dec_9(id)
        if meta.get_hatchdate(bee_id) != np.datetime64('NaT'):
            bees.append(bee_id)
    bee_ids_as_beesbookid_format = list(bees)
    bee_ids_as_ferwar_format = map(lambda i: i.as_ferwar(), bee_ids_as_beesbookid_format) #as ferwar
    return (list(bee_ids_as_ferwar_format), bee_ids_as_beesbookid_format)
示例#4
0
def get_random_bee_ids(amount):
    meta = bb_utils.meta.BeeMetaInfo()
    bees = set()
    while len(bees) < amount:
        bee_id_dec = random.randint(0, 4097)
        bee_id = bb_utils.ids.BeesbookID.from_dec_9(bee_id_dec)
        if meta.get_hatchdate(bee_id) != np.datetime64('NaT'):
            bees.add(bee_id)
    bee_ids_as_beesbookid_format = list(bees)
    bee_ids_as_ferwar_format = map(lambda i: i.as_ferwar(), bee_ids_as_beesbookid_format) #as ferwar
    return (list(bee_ids_as_ferwar_format), bee_ids_as_beesbookid_format)
# ### Get a group of bees to work on and calculate their ages

# In[3]:

#TODO: Filter out dead bees
#TODO: Move this out to a function

#Get all bees/n random bees/forager group 20
(bee_ids_as_ferwar_format, bee_ids_as_beesbookid_format) = get_all_bee_ids()

#Calculate the ages for each bee
bee_days_since_birth = []

#TODO: calculate ages from the dataframe later (after filtering)
for id in bee_ids_as_beesbookid_format:
    bee_days_since_birth.append((datetime_start - meta.get_hatchdate(id)).days)

# ### Load a PRESENCE.csv cache (saved from the DB_TO_DETECTIONS notebook)

# In[86]:

(csv_name, csv_path) = create_presence_cache_filename(num_hours,
                                                      datetime_start,
                                                      num_intervals_per_hour)
print('Starting with ' + csv_path)
presence_df = pd.read_csv(csv_path).iloc[:, 1:]
print(presence_df.shape)
presence_df.head()

# In[87]: