def monthly_output_allowed(model_run):
    """
    Determine whether monthly output is allowed for the model run
    :param model_run: Model Run being created
    :return: True if allowed, otherwise False
    """
    run_start = model_run.get_python_parameter_value(constants.JULES_PARAM_RUN_START)
    run_end = model_run.get_python_parameter_value(constants.JULES_PARAM_RUN_END)
    if utils.is_first_of_month(run_start):
        return True
    else:
        next_month = utils.next_first_of_month(run_start)
        return next_month <= run_end
예제 #2
0
    def alter_yearly_monthly_output_profiles(self, parameters):
        """
        Adjusts the output profiles to avoid JULES errors like:
        "Jules error:file_ts_open: When using data_period=-1, data must start at 00:00:00 on 1st of month"
        caused by asking for output profiles that aren't valid for the selected run starts and ends
        :param parameters: List of parameters
        :return:
        """
        run_start = utils.get_first_parameter_value_from_parameter_list(parameters,
                                                                        constants.JULES_PARAM_RUN_START)
        run_end = utils.get_first_parameter_value_from_parameter_list(parameters,
                                                                      constants.JULES_PARAM_RUN_END)

        output_starts_to_add = []

        for parameter in parameters:
            if parameter.namelist.name == constants.JULES_PARAM_OUTPUT_PERIOD[0]:
                if parameter.name == constants.JULES_PARAM_OUTPUT_PERIOD[1]:
                    for pv_output_period in parameter.parameter_values:
                        period = pv_output_period.get_value_as_python()
                        group_id = pv_output_period.group_id
                        if period == constants.JULES_YEARLY_PERIOD:
                            if not utils.is_first_of_year(run_start):
                                next_year = utils.next_first_of_year(run_start)
                                if next_year <= run_end:
                                    output_start = ParameterValue()
                                    output_start.set_value_from_python(next_year)
                                    output_start.group_id = group_id
                                    output_starts_to_add.append(output_start)
                        elif period == constants.JULES_MONTHLY_PERIOD:
                            if not utils.is_first_of_month(run_start):
                                next_month = utils.next_first_of_month(run_start)
                                if next_month <= run_end:
                                    output_start = ParameterValue()
                                    output_start.set_value_from_python(next_month)
                                    output_start.group_id = group_id
                                    output_starts_to_add.append(output_start)

        # Add parameter values (output_start)
        for parameter in parameters:
            if parameter.namelist.name == constants.JULES_PARAM_OUTPUT_START[0]:
                if parameter.name == constants.JULES_PARAM_OUTPUT_START[1]:
                    parameter.parameter_values += output_starts_to_add

        return parameters