Beispiel #1
0
def plot_latlon_cubes(cube_1, cube_2, cfg, data_names, obs_name=None):
    """
    Plot lat-lon vars for control, experiment, and obs

    Also plot Difference plots (control-exper, control-obs)
    cube_1: first cube (dataset: dat1)
    cube_2: second cube (dataset: dat2)
    cfg: configuration dictionary
    data_names: var + '_' + dat1 + '_vs_' + dat2
    """
    plot_name = cfg['analysis_type'] + '_' + data_names + '.png'
    plot_title = cfg['analysis_type'] + ': ' + data_names
    cubes = [cube_1, cube_2]

    # plot difference: cube_1 - cube_2; use numpy.ma.abs()
    diffed_cube = imath.subtract(cube_1, cube_2)
    plot_contour(diffed_cube, 'Difference ' + plot_title,
                 os.path.join(cfg['plot_dir'], 'Difference_' + plot_name))

    # plot each cube
    var = data_names.split('_')[0]
    if not obs_name:
        cube_names = [data_names.split('_')[1], data_names.split('_')[3]]
        for cube, cube_name in zip(cubes, cube_names):
            plot_contour(
                cube, cube_name + ' ' + cfg['analysis_type'] + ' ' + var,
                os.path.join(cfg['plot_dir'], cube_name + '_' + var + '.png'))
    else:
        # obs is always cube_2
        plot_contour(
            cube_2, obs_name + ' ' + cfg['analysis_type'] + ' ' + var,
            os.path.join(cfg['plot_dir'], obs_name + '_' + var + '.png'))
Beispiel #2
0
def plot_latlon_cubes(cube_1,
                      cube_2,
                      cfg,
                      data_names,
                      obs_name=None,
                      season=None):
    """
    Plot lat-lon vars for control, experiment, and obs.

    Also plot Difference plots (control-exper, control-obs)
    cube_1: first cube (dataset: dat1)
    cube_2: second cube (dataset: dat2)
    cfg: configuration dictionary
    data_names: var + '_' + dat1 + '_vs_' + dat2
    """
    if not season:
        plot_name = "_".join([cfg['analysis_type'], data_names]) + '.png'
        plot_title = "alltime " + cfg['analysis_type'] + ': ' + data_names
        plot_file_path = os.path.join(cfg['plot_dir'], "alltime",
                                      'Difference_' + plot_name)
    else:
        plot_name = "_".join([cfg['analysis_type'], data_names, season]) + \
                    '.png'
        plot_title = season + " " + cfg['analysis_type'] + ': ' + data_names
        plot_file_path = os.path.join(cfg['plot_dir'], season,
                                      'Difference_' + plot_name)
    cubes = [cube_1, cube_2]

    # plot difference: cube_1 - cube_2; use numpy.ma.abs()
    diffed_cube = imath.subtract(cube_1, cube_2)

    plot_contour(diffed_cube, 'Difference ' + plot_title, plot_file_path)
    save_plotted_cubes(diffed_cube, cfg, 'Difference_' + plot_name)

    # plot each cube
    var = data_names.split('_')[0]
    if not obs_name:
        cube_names = [data_names.split('_')[1], data_names.split('_')[3]]
        for cube, cube_name in zip(cubes, cube_names):
            if not season:
                plot_file_path = os.path.join(
                    cfg['plot_dir'], "alltime",
                    "_".join([cube_name, var]) + ".png")
                plot_contour(cube,
                             " ".join([cube_name, cfg['analysis_type'],
                                       var]), plot_file_path)
            else:
                plot_file_path = os.path.join(
                    cfg['plot_dir'], season,
                    "_".join([cube_name, var, season]) + ".png")
                plot_contour(
                    cube,
                    " ".join([season, cube_name, cfg['analysis_type'],
                              var]), plot_file_path)
            save_plotted_cubes(cube, cfg, os.path.basename(plot_file_path))
    else:
        # obs is always cube_2
        if not season:
            plot_file_path = os.path.join(cfg['plot_dir'], "alltime",
                                          "_".join([obs_name, var]) + ".png")
            plot_contour(cube_2,
                         " ".join([obs_name, cfg['analysis_type'],
                                   var]), plot_file_path)
        else:
            plot_file_path = os.path.join(
                cfg['plot_dir'], season,
                "_".join([obs_name, var, season]) + ".png")
            plot_contour(
                cube_2, " ".join([season, obs_name, cfg['analysis_type'],
                                  var]), plot_file_path)
        save_plotted_cubes(cube_2, cfg, os.path.basename(plot_file_path))
Beispiel #3
0
 def test_no_match(self):
     cube1, cube2 = self.SetUpNonMatching()
     with self.assertRaises(ValueError):
         subtract(cube1, cube2)
Beispiel #4
0
 def test_reversed_points(self):
     cube1, cube2 = self.SetUpReversed()
     with self.assertRaises(ValueError):
         subtract(cube1, cube2)
import iris
import iris.analysis.maths as maths

'''
In this simple model, we shall assume that the amount of cold
water being advected is proportional to the difference between
the mesured heat and the expected heat. 
'''

measured_heat = iris.load('/home/michael/Desktop/git/Masters/Heat/Heat_cubes.nc')[2]
expected_heat = iris.load('/home/michael/Desktop/git/Masters/Heat/expected_heat.nc')[0]

volume_cold_water = maths.subtract(measured_heat, expected_heat)
volume_cold_water.rename('Cold Water Volume')
volume_cold_water.units = 'm3'

iris.save(volume_cold_water, 'volume_cold_water.nc')