Ejemplo n.º 1
0
    def adjust_commute_from_work(self, data, no_variation=False):
        """
        This function adjusts the household parameters to reflect the sampled parameters \
        (mean and standard deviation of start time, end time, and \
        duration, respectively), from the CHAD data for the commuting from work \
        activity.

        :param data: relevant parameters for each person in the household for \
        commuting from work. The tuple contains the following: mean start time, standard \
        deviation of start time, mean end time, standard deviation of end time, mean duration, \
        and standard deviation of duration for each person in the household.
        :type data: tuple of numpy.ndarray, numpy.ndarray, numpy.ndarray, \
        numpy.ndarray, numpy.ndarray, numpy.ndarray
        :param bool no_variation: whether (if True) or not (if False) intra-individual \
        variation is set to zero among the activities

        :return:
        """

        # the activity-related parameters (in hours)
        start_mean, start_std, end_mean, end_std, dt_mean, dt_std = data

        # set standard deviation to zero
        if no_variation:
            dt_std[:] = 0

        # set the commuting from work mean duration (in minutes)
        self.params.commute_from_work_dt_mean = mg.hours_to_minutes(dt_mean)

        # set the commuting from work standard deviation for duration (in minutes)
        self.params.commute_from_work_dt_std = mg.hours_to_minutes(dt_std)

        return
Ejemplo n.º 2
0
    def adjust_sleep(self, data, no_variation=False):
        """
        This function adjusts the household parameters to reflect the sampled parameters \
        (mean and standard deviation of start time, end time, and \
        duration, respectively), from the CHAD data for the sleeping \
        activity.

        :param data: relevant parameters for each person in the household for \
        sleeping. The tuple contains the following: mean start time, standard \
        deviation of start time, mean end time, standard deviation of end time, mean duration, \
        and standard deviation of duration for each person in the household.
        :type data: tuple of numpy.ndarray, numpy.ndarray, numpy.ndarray, \
        numpy.ndarray, numpy.ndarray, numpy.ndarray
        :param bool no_variation: whether (if True) or not (if False) intra-individual \
        variation is set to zero among the activities

        :return:
        """

        # the amount of minutes in 1 hour
        HOUR_2_MIN = temporal.HOUR_2_MIN

        # the activity-related parameters (in hours)
        start_mean, start_std, end_mean, end_std, dt_mean, dt_std = data

        # set the standard deviations to zero (time is in hours)
        if no_variation:
            start_std[:] = 0
            end_std[:] = 0

        # since the start time may occur over midnight, express time as [-12, 12)
        start_mean = mg.from_periodic(start_mean)

        # for the demographics with a "work" or "school" occupation
        # set the sleep end time to the breakfast start time
        if self.demographic in [dmg.ADULT_WORK, dmg.CHILD_SCHOOL]:

            # breakfast start time in HOURS [0, 24)
            bf_start = np.array([x.t_start
                                 for x in self.params.breakfasts]) / HOUR_2_MIN

            # sleep end time is the breakfast start time
            # make sure time is in [0, 24) format
            end_mean = bf_start

        # set the mean start time (in minutes)
        self.params.sleep_start_mean = mg.hours_to_minutes(start_mean)

        # set the standard deviation of start time (in minutes)
        self.params.sleep_start_std = mg.hours_to_minutes(start_std)

        # set the mean end time (in minutes)
        self.params.sleep_end_mean = mg.hours_to_minutes(end_mean)

        # set the standard deviation of end time (in mintues)
        self.params.sleep_end_std = mg.hours_to_minutes(end_std)

        return
Ejemplo n.º 3
0
    def adjust_work(self, data, no_variation=False):
        """
        This function adjusts the household parameters to reflect the sampled parameters \
        (mean and standard deviation of start time, end time, and \
        duration, respectively), from the CHAD data for the working \
        activity.

        :param data: relevant parameters for each person in the household for \
        working. The tuple contains the following: mean start time, standard \
        deviation of start time, mean end time, standard deviation of end time, mean duration, \
        and standard deviation of duration for each person in the household.
        :type data: tuple of numpy.ndarray, numpy.ndarray, numpy.ndarray, \
        numpy.ndarray, numpy.ndarray, numpy.ndarray
        :param bool no_variation: whether (if True) or not (if False) intra-individual \
        variation is set to zero among the activities

        :return:
        """

        # the activity-related parameters (in hours)
        start_mean, start_std, end_mean, end_std, dt_mean, dt_std = data

        # set the standard deviations to zero (time is in hours)
        if no_variation:
            start_std[:] = 0
            end_std[:] = 0

        # set the jobs for working adults
        if self.demographic == dmg.ADULT_WORK:
            job_id = occupation.STANDARD_JOB

        # set the jobs for school-age children
        elif self.demographic == dmg.CHILD_SCHOOL:
            job_id = occupation.STUDENT

        # set the job in the ABMHAP parameters
        self.params.job_id = (job_id, ) * self.params.num_people

        # set the mean start time (in minutes)
        self.params.work_start_mean = mg.hours_to_minutes(start_mean)

        # set the standard deviation of start time (in minutes)
        self.params.work_start_std = mg.hours_to_minutes(start_std)

        # set the mean end time (in minutes)
        self.params.work_end_mean = mg.hours_to_minutes(end_mean)

        # set the standard deviation of end time (in minutes)
        self.params.work_end_std = mg.hours_to_minutes(end_std)

        return
Ejemplo n.º 4
0
def save_output(df, fname):
    """
    This function saves the output of the simulation.

    :param pandas.core.frame.DataFrame df: the activity-diary output of the simulation
    :param str fname: the file name of the saved file. It must end with ".csv"
    """

    # the conversion of 1 hour into minutes
    HOUR_2_MIN = temporal.HOUR_2_MIN

    # copy the data frame to avoid changing the original data in df
    data = df.copy()

    # convert the end time in minutes.
    # Add the + 1 minute to the end time so that 16:00 - 16:59 becomes 16:00 - 17:00
    end = mg.hours_to_minutes(data.end) + 1

    # convert the end time into hours
    data.end = end / HOUR_2_MIN

    # create the directory for the save file if it does not exist
    os.makedirs(os.path.dirname(fname), exist_ok=True)

    # save the data
    data.to_csv(fname, index=False)

    return
Ejemplo n.º 5
0
    def adjust_params(self, start_mean, start_std, end_mean, end_std):
        """
        This function adjusts the values for the mean and standard deviation of both work \
        duration and work start time in the key-word arguments based on the CHAD data \
        that was sampled. These new values will be used in the runs.

        :param numpy.ndarray dt_mean: the work duration mean [minutes] for each person
        :param numpy.ndarray dt_std: the work duration standard deviation [minutes] for each person
        :param numpy.ndarray start_mean: the mean work start time [minutes] for each person
        :param numpy.ndarray start_std: the standard deviation of start time [minutes] for each person

        :return:
        """

        # the amount of minutes in 1 hour
        HOUR_2_MIN = temporal.HOUR_2_MIN

        # the amount of minutes in 1 day
        DAY_2_MIN = temporal.DAY_2_MIN

        # set the start time to be Day 1, Monday, at 14:00
        t_monday = temporal.MONDAY * DAY_2_MIN
        self.params.t_start = t_monday + 4 * HOUR_2_MIN

        # set the standard deviations to zero (time is in hours)
        start_std[:] = 0
        end_std[:] = 0

        # set the mean start time for work (in minutes)
        self.params.work_start_mean = mg.hours_to_minutes(start_mean)

        # set the standard deviation for start time for work (in minutes)
        self.params.work_start_std = mg.hours_to_minutes(start_std)

        # set the mean end time for work (in minutes)
        self.params.work_end_mean = mg.hours_to_minutes(end_mean)

        # set the standard deviation for end time for work (in minutes)
        self.params.work_end_std = mg.hours_to_minutes(end_std)

        return
Ejemplo n.º 6
0
    def adjust_params(self, commute_dt_mean, commute_dt_std, work_start_mean, work_start_std, \
                      work_end_mean, work_end_std):
        """
        This function adjusts the values for the mean and standard deviation of both commute to work \
        duration and start time in the key-word arguments based on the CHAD data \
        that was sampled. These new values will be used in the runs.

        :param numpy.ndarray commute_dt_mean: the commute duration mean [hours] for each person
        :param numpy.ndarray commute_dt_std: the commute duration standard deviation [hours] for each person
        :param numpy.ndarray work_start_mean: the mean work start time [hours] for each person
        :param numpy.ndarray work_start_std: the standard deviation of work start time [hours] for each person
        :param numpy.ndarray work_end_mean: the mean work end time [hours] for each person
        :param numpy.ndarray work_end_std: the standard deviation of work end time [hours] for each person

        :return:
        """

        # the number of minutes in 1 hour and 1 day, respectively
        HOUR_2_MIN, DAY_2_MIN = temporal.HOUR_2_MIN, temporal.DAY_2_MIN

        # set the initial time
        t_monday = temporal.MONDAY * DAY_2_MIN
        self.params.t_start = t_monday + 4 * HOUR_2_MIN

        # set the work parameters for start time (mean start time, standard deviation of start time)
        self.params.work_start_mean = mg.hours_to_minutes(work_start_mean)
        self.params.work_start_std = mg.hours_to_minutes(work_start_std)

        # set the work parameters for end time (mean start time, standard deviation of end time)
        self.params.work_end_mean = mg.hours_to_minutes(work_end_mean)
        self.params.work_end_std = mg.hours_to_minutes(work_end_std)

        # set the commute to work information (mean duration and standard deviation of duration)
        self.params.commute_to_work_dt_mean = mg.hours_to_minutes(
            commute_dt_mean)
        self.params.commute_to_work_dt_std = mg.hours_to_minutes(
            commute_dt_std)

        return