Beispiel #1
0
def test_graphs_generation():
    """Test the graphs generation."""

    TEST_DIR_PATH = 'graphs_generation'

    # Inputs of the test
    POSTPROCESSING_DIRPATH = os.path.join(TEST_DIR_PATH, 'postprocessing')
    ORGANS_POSTPROCESSING_FILENAME = 'organs_postprocessing.csv'
    HIDDENZONES_POSTPROCESSING_FILENAME = 'hiddenzones_postprocessing.csv'
    ELEMENTS_POSTPROCESSING_FILENAME = 'elements_postprocessing.csv'
    SOILS_POSTPROCESSING_FILENAME = 'soils_postprocessing.csv'

    # Outputs of the test
    GRAPHS_DIRPATH = os.path.join(TEST_DIR_PATH, 'graphs')

    # Retrieve post-processing dataframes
    postprocessing_df_dict = {}

    for postprocessing_filename in (ORGANS_POSTPROCESSING_FILENAME,
                                    HIDDENZONES_POSTPROCESSING_FILENAME,
                                    ELEMENTS_POSTPROCESSING_FILENAME,
                                    SOILS_POSTPROCESSING_FILENAME):
        postprocessing_filepath = os.path.join(POSTPROCESSING_DIRPATH,
                                               postprocessing_filename)
        postprocessing_df = pd.read_csv(postprocessing_filepath)
        postprocessing_file_basename = postprocessing_filename.split('.')[0]
        postprocessing_df_dict[
            postprocessing_file_basename] = postprocessing_df

    try:
        # Generate graphs for validation
        cnwheat_postprocessing.generate_graphs(
            hiddenzones_df=postprocessing_df_dict[
                HIDDENZONES_POSTPROCESSING_FILENAME.split('.')[0]],
            organs_df=postprocessing_df_dict[
                ORGANS_POSTPROCESSING_FILENAME.split('.')[0]],
            elements_df=postprocessing_df_dict[
                ELEMENTS_POSTPROCESSING_FILENAME.split('.')[0]],
            soils_df=postprocessing_df_dict[
                SOILS_POSTPROCESSING_FILENAME.split('.')[0]],
            graphs_dirpath=GRAPHS_DIRPATH)

    except KeyError as ke:
        warnings.warn(str(ke))
        return
    def graphs(axes_postprocessing_df,
               hiddenzones_postprocessing_df,
               organs_postprocessing_df,
               elements_postprocessing_df,
               soils_postprocessing_df,
               graphs_dirpath='.'):
        """
        Generate the graphs and save them into `graphs_dirpath`.

        :param pandas.DataFrame axes_postprocessing_df: CN-Wheat outputs at axis scale
        :param pandas.DataFrame hiddenzones_postprocessing_df: CN-Wheat outputs at hidden zone scale
        :param pandas.DataFrame organs_postprocessing_df: CN-Wheat outputs at organ scale
        :param pandas.DataFrame elements_postprocessing_df: CN-Wheat outputs at element scale
        :param pandas.DataFrame soils_postprocessing_df: CN-Wheat outputs at soil scale
        :param str graphs_dirpath: the path of the directory to save the generated graphs in

        """
        cnwheat_postprocessing.generate_graphs(
            axes_df=axes_postprocessing_df,
            hiddenzones_df=hiddenzones_postprocessing_df,
            organs_df=organs_postprocessing_df,
            elements_df=elements_postprocessing_df,
            soils_df=soils_postprocessing_df,
            graphs_dirpath=graphs_dirpath)
Beispiel #3
0
        postprocessing_df_dict = {}

        for postprocessing_filename in (ORGANS_POSTPROCESSING_FILENAME,
                                        HIDDENZONES_POSTPROCESSING_FILENAME,
                                        ELEMENTS_POSTPROCESSING_FILENAME,
                                        SOILS_POSTPROCESSING_FILENAME):
            postprocessing_filepath = os.path.join(POSTPROCESSING_DIRPATH,
                                                   postprocessing_filename)
            postprocessing_df = pd.read_csv(postprocessing_filepath)
            postprocessing_file_basename = postprocessing_filename.split(
                '.')[0]
            postprocessing_df_dict[
                postprocessing_file_basename] = postprocessing_df

        print('Retrieve last computed post-processing dataframes... DONE!')

    print('Generate graphs for validation...')

    cnwheat_postprocessing.generate_graphs(
        hiddenzones_df=postprocessing_df_dict[
            HIDDENZONES_POSTPROCESSING_FILENAME.split('.')[0]],
        organs_df=postprocessing_df_dict[ORGANS_POSTPROCESSING_FILENAME.split(
            '.')[0]],
        elements_df=postprocessing_df_dict[
            ELEMENTS_POSTPROCESSING_FILENAME.split('.')[0]],
        soils_df=postprocessing_df_dict[SOILS_POSTPROCESSING_FILENAME.split(
            '.')[0]],
        graphs_dirpath=GRAPHS_DIRPATH)

    print('Generate graphs for validation... DONE!')