Exemple #1
0
 def setUp(self) -> None:
     self.testfile = '3-GLDAS.SoilMoi0_10cm_inst_with_1-C3S.sm_with_2-SMOS.Soil_Moisture.nc'
     self.testfile_path = os.path.join(os.path.dirname(__file__), '..',
                                       'tests', 'test_data', 'tc',
                                       self.testfile)
     self.plotdir = tempfile.mkdtemp()
     self.img = QA4SMImg(self.testfile_path)
     self.plotter = QA4SMPlotter(self.img, self.plotdir)
Exemple #2
0
 def setUp(self) -> None:
     self.testfile = '0-SMAP.soil_moisture_with_1-C3S.sm.nc'
     self.testfile_path = os.path.join(os.path.dirname(__file__), '..',
                                       'tests', 'test_data', 'basic',
                                       self.testfile)
     self.plotdir = tempfile.mkdtemp()
     self.img = QA4SMImg(self.testfile_path)
     self.plotter = QA4SMPlotter(self.img, self.plotdir)
     self.ref_dataset_grid_stepsize = self.img.ref_dataset_grid_stepsize
Exemple #3
0
def plot_all(
        filepath:str,
        metrics:list=None,
        extent:tuple=None,
        out_dir:str=None,
        out_type:str='png',
        save_all:bool=True,
        **plotting_kwargs
) -> (list, list):
    """
    Creates boxplots for all metrics and map plots for all variables.
    Saves the output in a folder-structure.

    Parameters
    ----------
    filepath : str
        path to the *.nc file to be processed.
    metrics : set or list, optional (default: None)
        metrics to be plotted. If None, all metrics with data are plotted
    extent : tuple, optional (default: None)
        Area to subset the values for -> (min_lon, max_lon, min_lat, max_lat)
    out_dir : str, optional (default: None)
        Path to output generated plot. If None, defaults to the current working directory.
    out_type: str or list
        extensions which the files should be saved in
    save_all: bool, optional. Default is True.
        all plotted images are saved to the output directory
    plotting_kwargs: arguments for plotting functions.

    Returns
    -------
    fnames_boxplots: list
    fnames_mapplots: list
        lists of filenames for created mapplots and boxplots
    """
    # initialise image and plotter
    fnames_bplot, fnames_mapplot = [], []
    periods = extract_periods(filepath)
    for period in periods:
        img = QA4SMImg(
            filepath,
            period=period,
            extent=extent,
            ignore_empty=True
        )
        plotter = QA4SMPlotter(
            image=img,
            out_dir=os.path.join(out_dir, str(period)) if period else out_dir
        )

        if metrics is None:
            metrics = img.metrics
        # iterate metrics and create files in output directory

        for metric in metrics:
            metric_bplots, metric_mapplots = plotter.plot_metric(
                metric=metric,
                out_types=out_type,
                save_all=save_all,
                **plotting_kwargs
            )
            # there can be boxplots with no mapplots
            if metric_bplots:
                fnames_bplot.extend(metric_bplots)
            if metric_mapplots:
                fnames_mapplot.extend(metric_mapplots)
        
    return fnames_bplot, fnames_mapplot