def test_multiple_constraints(self):
     constrs = [
         iris.NameConstraint(standard_name="x_wind"),
         iris.NameConstraint(var_name="var1"),
     ]
     result = _translate_constraints_to_var_callback(constrs)
     self.assertIsNone(result)
 def test_NameConstraint_standard_name_long_name_var_name(self):
     constr = iris.NameConstraint(
         standard_name="x_wind",
         long_name="x component of wind",
         var_name="var1",
     )
     callback = _translate_constraints_to_var_callback(constr)
     result = [callback(var) for var in self.data_variables]
     self.assertArrayEqual(result, [False, False, False, True, False])
 def test_NameConstraint_with_STASH(self):
     constr = iris.NameConstraint(
         standard_name="x_wind", STASH="m01s00i024"
     )
     result = _translate_constraints_to_var_callback(constr)
     self.assertIsNone(result)
 def test_NameConstraint_var_name(self):
     constr = iris.NameConstraint(var_name="var1")
     callback = _translate_constraints_to_var_callback(constr)
     result = [callback(var) for var in self.data_variables]
     self.assertArrayEqual(result, [True, False, True, True, True])
Пример #5
0
 def test_netcdf_with_NameConstraint(self):
     constr = iris.NameConstraint(var_name="cdf_temp_dmax_tmean_abs")
     cubes = iris.load(self.filename, constr)
     self.assertEqual(len(cubes), 1)
     self.assertEqual(cubes[0].var_name, "cdf_temp_dmax_tmean_abs")
Пример #6
0
def analysis(outpath):

    """
    This function takes the pre-processed HWT data and produces some analysis.
    Plots that I want from this:

    - Anomaly from control with lead time (all days), for all variables (domain average), or just
      plotting the control alongside the faulty and corrected experiment.

    Can run locally but stretches resources (4G RAM), best to run on SPICE using:
    sbatch --qos=normal --mem=8G --ntasks=2 --time=120
    """

    # EXP (u-bt240, u-bv107, u-bz435), days, lead time, layers (if appropriate)
    SMC = np.zeros((3, 43, 37, 4))
    ST  = np.zeros((3, 43, 37, 4))
    TS  = np.zeros((3, 43, 37))
    DP  = np.zeros((3, 43, 37))

    # Control Simulation - u-bt240 (all UM)
    index = 0
    for month in ['04','05']:
        for day in range(1,32):

            try:
                print('Loading u-bt240, M '+month+' D '+str(day).zfill(2)+' (SMC)')
                cubes = iris.load(outpath+'/u-bt240_2020'+month+str(day).zfill(2)+'T0000Z_ST_SMC.pp',
                                  iris.NameConstraint(standard_name='moisture_content_of_soil_layer'))[0]

                SMC[0, index, :, :] = np.mean(np.mean(cubes.data,axis=3),axis=2)

                print('Loading u-bt240, M '+month+' D '+str(day).zfill(2)+' (ST)')
                cubes = iris.load(outpath+'/u-bt240_2020'+month+str(day).zfill(2)+'T0000Z_ST_SMC.pp',
                                  iris.NameConstraint(standard_name='soil_temperature'))[0]

                ST[0, index, :, :] = np.mean(np.mean(cubes.data,axis=3),axis=2)

                print('Loading u-bt240, M '+month+' D '+str(day).zfill(2)+' (TS)')
                cubes = iris.load(outpath+'/u-bt240_2020'+month+str(day).zfill(2)+'T0000Z_T_DP_1p5m.pp',
                                  iris.NameConstraint(standard_name='air_temperature'))[0]

                TS[0, index, :] = np.mean(np.mean(cubes.data,axis=2),axis=1)

                print('Loading u-bt240, M '+month+' D '+str(day).zfill(2)+' (TS)')
                cubes = iris.load(outpath+'/u-bt240_2020'+month+str(day).zfill(2)+'T0000Z_T_DP_1p5m.pp',
                                  iris.NameConstraint(standard_name='dew_point_temperature'))[0]

                DP[0, index, :] = np.mean(np.mean(cubes.data,axis=2),axis=1)

                index = index+1

            except OSError:
                pass

    # Poorly Simulation - u-bv107
    index = 0
    for month in ['04','05']:
        for day in range(1,32):

            try:
                print('Loading u-bv107, M '+month+' D '+str(day).zfill(2)+' (SMC)')
                cubes = iris.load(outpath+'/u-bv107_2020'+month+str(day).zfill(2)+'T0000Z_ST_SMC.pp',
                                  iris.NameConstraint(standard_name='moisture_content_of_soil_layer'))[0]

                SMC[1, index, :, :] = np.mean(np.mean(cubes.data,axis=3),axis=2)

                print('Loading u-bv107, M '+month+' D '+str(day).zfill(2)+' (ST)')
                cubes = iris.load(outpath+'/u-bv107_2020'+month+str(day).zfill(2)+'T0000Z_ST_SMC.pp',
                                  iris.NameConstraint(standard_name='soil_temperature'))[0]

                ST[1, index, :, :] = np.mean(np.mean(cubes.data,axis=3),axis=2)

                print('Loading u-bv107, M '+month+' D '+str(day).zfill(2)+' (TS)')
                cubes = iris.load(outpath+'/u-bv107_2020'+month+str(day).zfill(2)+'T0000Z_T_DP_1p5m.pp',
                                  iris.NameConstraint(standard_name='air_temperature'))[0]

                TS[1, index, :] = np.mean(np.mean(cubes.data,axis=2),axis=1)

                print('Loading u-bv107, M '+month+' D '+str(day).zfill(2)+' (TS)')
                cubes = iris.load(outpath+'/u-bv107_2020'+month+str(day).zfill(2)+'T0000Z_T_DP_1p5m.pp',
                                  iris.NameConstraint(standard_name='dew_point_temperature'))[0]

                DP[1, index, :] = np.mean(np.mean(cubes.data,axis=2),axis=1)

                index = index+1

            except OSError:
                pass

    # Corrected Simulation - u-bz435
    index = 0
    for month in ['04','05']:
        for day in range(1,32):

            try:
                print('Loading u-bz435, M '+month+' D '+str(day).zfill(2)+' (SMC)')
                cubes = iris.load(outpath+'/u-bz435_2020'+month+str(day).zfill(2)+'T0000Z_ST_SMC.pp',
                                  iris.NameConstraint(standard_name='moisture_content_of_soil_layer'))[0]

                SMC[2, index, :, :] = np.mean(np.mean(cubes.data,axis=3),axis=2)

                print('Loading u-bz435, M '+month+' D '+str(day).zfill(2)+' (ST)')
                cubes = iris.load(outpath+'/u-bz435_2020'+month+str(day).zfill(2)+'T0000Z_ST_SMC.pp',
                                  iris.NameConstraint(standard_name='soil_temperature'))[0]

                ST[2, index, :, :] = np.mean(np.mean(cubes.data,axis=3),axis=2)

                print('Loading u-bz435, M '+month+' D '+str(day).zfill(2)+' (TS)')
                cubes = iris.load(outpath+'/u-bz435_2020'+month+str(day).zfill(2)+'T0000Z_T_DP_1p5m.pp',
                                  iris.NameConstraint(standard_name='air_temperature'))[0]

                TS[2, index, :] = np.mean(np.mean(cubes.data,axis=2),axis=1)

                print('Loading u-bz435, M '+month+' D '+str(day).zfill(2)+' (TS)')
                cubes = iris.load(outpath+'/u-bz435_2020'+month+str(day).zfill(2)+'T0000Z_T_DP_1p5m.pp',
                                  iris.NameConstraint(standard_name='dew_point_temperature'))[0]

                DP[2, index, :] = np.mean(np.mean(cubes.data,axis=2),axis=1)

                index = index+1

            except OSError:
                pass

    # Save postprocessed output
    np.save(outpath+'/SMC.npy', SMC)
    np.save(outpath+'/ST.npy', ST)
    np.save(outpath+'/TS.npy', TS)
    np.save(outpath+'/DP.npy', DP)