Exemplo n.º 1
0
 def test_create_from_expr():
     src = ifs_source.read("88.128", "sqrt(sq(var165)+sq(var166))")
     eq_(src.get_grib_code(), grib_code(88, 128))
     eq_(src.get_root_codes(), [grib_code(165, 128), grib_code(166, 128)])
     eq_(getattr(src, "expr"), "var88=sqrt(sq(var165)+sq(var166))")
     eq_(src.grid(), "point")
     eq_(src.spatial_dims, 2)
Exemplo n.º 2
0
 def test_create_from_expr3():
     src = ifs_source.read("var88", "sqrt(sq(var128131)+sq(var128132))")
     eq_(src.get_grib_code(), grib_code(88, 128))
     eq_(src.get_root_codes(), [grib_code(131, 128), grib_code(132, 128)])
     eq_(getattr(src, "expr"), "var88=sqrt(sq(var131)+sq(var132))")
     eq_(src.grid(), "spec")
     eq_(src.spatial_dims, 3)
Exemplo n.º 3
0
def find_sp_variable(task):
    global ifs_gridpoint_files_, ifs_spectral_files_, surface_pressure, ln_surface_pressure, auto_filter_
    ifs_ps_source = cmor_source.ifs_source.create(134)
    setattr(ifs_ps_source, cmor_source.expression_key, "var134=exp(var152)")
    setattr(ifs_ps_source, "root_codes", [cmor_source.grib_code(134)])
    if auto_filter_:
        if grib_filter.spvar is None:
            log.error("Could not find surface pressure in model output...")
            return
        log.info("Found surface pressure in file %s" % grib_filter.spvar[2])
        setattr(task, cmor_task.filter_output_key, [grib_filter.spvar[2]])
        if grib_filter.spvar[0] == 152:
            task.source = ifs_ps_source
        task.source.grid_ = 1 if grib_filter.spvar[2] == ifs_spectral_files_ else 0
        return
    log.info("Looking for surface pressure variable in input files...")
    command = cdoapi.cdo_command()
    code_string = command.show_code(ifs_spectral_files_.values()[0])
    codes = [cmor_source.grib_code(int(c)) for c in code_string[0].split()]
    if surface_pressure in codes:
        log.info("Found surface pressure in spectral files")
        setattr(task, cmor_task.filter_output_key, ifs_spectral_files_.values())
        task.source.grid_ = 1
        return
    if ln_surface_pressure in codes:
        log.info("Found lnsp in spectral file")
        setattr(task, cmor_task.filter_output_key, ifs_spectral_files_.values())
        task.source = ifs_ps_source
        return
    log.info("Did not find sp or lnsp in spectral file: assuming gridpoint file contains sp")
    setattr(task, cmor_task.filter_output_key, ifs_gridpoint_files_.values())
    task.source.grid_ = 0
Exemplo n.º 4
0
 def test_create_from_expr():
     src = ifs_source.read("88.128", "sqrt(sq(var165)+sq(var166))")
     assert src.get_grib_code() == grib_code(88, 128)
     assert set(src.get_root_codes()) == {
         grib_code(165, 128), grib_code(166, 128)
     }
     assert getattr(src, "expr") == "var88=sqrt(sq(var165)+sq(var166))"
     assert src.grid() == "point"
     assert src.spatial_dims == 2
Exemplo n.º 5
0
 def test_create_from_expr3():
     src = ifs_source.read("var88", "sqrt(sq(var128131)+sq(var128132))")
     assert src.get_grib_code() == grib_code(88, 128)
     assert set(src.get_root_codes()) == {
         grib_code(131, 128), grib_code(132, 128)
     }
     assert getattr(src, "expr") == "var88=sqrt(sq(var131)+sq(var132))"
     assert src.grid() == "spec"
     assert src.spatial_dims == 3
Exemplo n.º 6
0
 def test_create_from_expr6():
     src = ifs_source.read("88", "(var144==0)*sqrt(sq(var131)+sq(var132))")
     eq_(src.get_grib_code(), grib_code(88, 128))
     eq_(src.get_root_codes(),
         [grib_code(144, 128),
          grib_code(131, 128),
          grib_code(132, 128)])
     eq_(getattr(src, "expr"),
         "var88=(var144==0)*sqrt(sq(var131)+sq(var132))")
     eq_(src.spatial_dims, 3)
Exemplo n.º 7
0
 def test_create_from_expr4():
     src = ifs_source.read("var129124",
                           "var126094 + var126099 + var126106 + var126110")
     assert src.get_grib_code() == grib_code(124, 129)
     assert set(src.get_root_codes()) == {
         grib_code(94, 126),
         grib_code(99, 126),
         grib_code(106, 126),
         grib_code(110, 126)
     }
     assert getattr(src, "expr") == "var124=var94+var99+var106+var110"
     assert src.grid() == "point"
     assert src.spatial_dims == 3
Exemplo n.º 8
0
 def test_create_from_expr4():
     src = ifs_source.read("var129124",
                           "var126094 + var126099 + var126106 + var126110")
     eq_(src.get_grib_code(), grib_code(124, 129))
     eq_(src.get_root_codes(), [
         grib_code(94, 126),
         grib_code(99, 126),
         grib_code(106, 126),
         grib_code(110, 126)
     ])
     eq_(getattr(src, "expr"), "var124=var94+var99+var106+var110")
     eq_(src.grid(), "point")
     eq_(src.spatial_dims, 3)
Exemplo n.º 9
0
 def test_create_from_expr_masked():
     src = ifs_source.read("88",
                           "(var144==0)*sqrt(sq(var131)+sq(var132))",
                           mask_expr="var172>0.5")
     assert src.get_grib_code() == grib_code(88, 128)
     assert set(src.get_root_codes()) == {
         grib_code(144, 128),
         grib_code(131, 128),
         grib_code(132, 128),
         grib_code(172, 128)
     }
     assert getattr(
         src, "expr") == "var88=(var144==0)*sqrt(sq(var131)+sq(var132))"
     assert src.spatial_dims == 3
Exemplo n.º 10
0
def get_record_key(gribfile, gridtype):
    codevar, codetab = grib_tuple_from_int(
        gribfile.get_field(grib_file.param_key))
    levtype, level = gribfile.get_field(
        grib_file.levtype_key), gribfile.get_field(grib_file.level_key)
    if levtype == grib_file.pressure_level_hPa_code:
        level *= 100
        levtype = grib_file.pressure_level_Pa_code
    if levtype == 112 or levtype == grib_file.depth_level_code:
        level = 0
        levtype = grib_file.depth_level_code
    if codevar in [49, 165, 166]:
        level = 10
        levtype = grib_file.height_level_code
    if codevar in [167, 168, 201, 202]:
        level = 2
        levtype = grib_file.height_level_code
    if codevar == 9:
        level = 0
        levtype = grib_file.surface_level_code
    if levtype == grib_file.pv_level_code:  # Mapping pv-levels to surface: we don't support more than one pv-level
        level = 0
        levtype = grib_file.surface_level_code
    # Fix for spectral height level fields in gridpoint file:
    if cmor_source.grib_code(codevar) in cmor_source.ifs_source.grib_codes_sh and \
            gridtype != cmor_source.ifs_grid.spec and \
            levtype == grib_file.hybrid_level_code:
        levtype = grib_file.height_level_code
    return codevar, codetab, levtype, level
Exemplo n.º 11
0
def get_record_key(gribfile, gridtype):
    codevar, codetab = grib_tuple_from_ints(
        gribfile.get_field(grib_file.param_key),
        gribfile.get_field(grib_file.table_key))
    levtype, level = gribfile.get_field(
        grib_file.levtype_key), gribfile.get_field(grib_file.level_key)
    if levtype == grib_file.pressure_level_hPa_code:
        level *= 100
        levtype = grib_file.pressure_level_Pa_code
    if levtype == 112 or levtype == grib_file.depth_level_code or \
            (codetab == 128 and codevar in [35, 36, 37, 38, 39, 40, 41, 42, 139, 170, 183, 236]):
        level = 0
        levtype = grib_file.depth_level_code
    if codevar in [49, 165, 166]:
        level = 10
        levtype = grib_file.height_level_code
    if codevar in [167, 168, 201, 202]:
        level = 2
        levtype = grib_file.height_level_code
    if codevar == 9:
        level = 0
        levtype = grib_file.surface_level_code
    if levtype == grib_file.pv_level_code:  # Mapping pv-levels to surface: we don't support more than one pv-level
        level = 0
        levtype = grib_file.surface_level_code
    cosp_levels = {40: 84000, 41: 56000, 42: 22000}
    if codetab == 126 and codevar in cosp_levels.keys():
        level = cosp_levels[codevar]
        levtype = grib_file.pressure_level_Pa_code
    # Fix for spectral height level fields in gridpoint file:
    if cmor_source.grib_code(codevar) in cmor_source.ifs_source.grib_codes_sh and \
            gridtype != cmor_source.ifs_grid.spec and levtype == grib_file.hybrid_level_code:
        levtype = grib_file.height_level_code
    return codevar, codetab, levtype, level
Exemplo n.º 12
0
def perform_ifs_tasks(datadir, expname,
                      refdate=None,
                      postprocmode=postproc.recreate,
                      tempdir="/tmp/ece2cmor",
                      taskthreads=4,
                      cdothreads=4):
    global log, tasks, table_dir, prefix, masks
    validate_setup_settings()
    validate_run_settings(datadir, expname)
    ifs_tasks = [t for t in tasks if t.source.model_component() == "ifs"]
    log.info("Selected %d IFS tasks from %d input tasks" % (len(ifs_tasks), len(tasks)))
    if len(ifs_tasks) == 0:
        return
    tableroot = os.path.join(table_dir, prefix)
    if enable_masks:
        ifs2cmor.masks = {k: masks[k] for k in masks if masks[k]["source"].model_component() == "ifs"}
    else:
        ifs2cmor.masks = {}
    if (not ifs2cmor.initialize(datadir, expname, tableroot, refdate if refdate else datetime.datetime(1850, 1, 1),
                                tempdir=tempdir, autofilter=auto_filter)):
        return
    postproc.postproc_mode = postprocmode
    postproc.cdo_threads = cdothreads
    area_task = cmor_task.cmor_task(cmor_source.ifs_source(cmor_source.grib_code(129)),
                                    get_cmor_target("areacella", "fx"))
    ifs2cmor.execute(ifs_tasks + [area_task], nthreads=taskthreads)
Exemplo n.º 13
0
 def test_load_tsl_table_override():
     ece2cmorlib.initialize_without_cmor()
     try:
         tasks = taskloader.load_tasks_from_drq({
             "6hrPlevPt": ["tsl"],
             "Lmon": ["tsl"]
         })
         eq_(len(tasks), 2)
         for t in tasks:
             if t.target.table == "6hrPlevPt":
                 ok_(not hasattr(t.source, "expr"))
                 ok_(t.source.get_grib_code() == cmor_source.grib_code(139))
             else:
                 ok_("merge" in getattr(t.source, "expr"))
     finally:
         ece2cmorlib.finalize_without_cmor()
Exemplo n.º 14
0
def find_sp_variable(task):
    global ifs_gridpoint_file_, ifs_spectral_file_, surface_pressure, ln_surface_pressure
    log.info("Looking for surface pressure variable in input files...")
    command = cdo.Cdo()
    code_string = command.showcode(input=ifs_spectral_file_)
    codes = [cmor_source.grib_code(int(c)) for c in code_string[0].split()]
    if surface_pressure in codes:
        log.info("Found surface pressure in spectral file")
        setattr(task, "path", ifs_spectral_file_)
        task.source.grid_ = 1
        return
    if ln_surface_pressure in codes:
        log.info("Found lnsp in spectral file")
        setattr(task, "path", ifs_spectral_file_)
        task.source = cmor_source.ifs_source.read("var134=exp(var152)")
        return
    log.info(
        "Did not find sp or lnsp in spectral file: assuming gridpoint file contains sp"
    )
    setattr(task, cmor_task.output_path_key, ifs_gridpoint_file_)
    task.source.grid_ = 0
Exemplo n.º 15
0
 def test_surface_pressure():
     code = grib_code(134, 128)
     ok_(code in ifs_source.grib_codes_2D_dyn)
Exemplo n.º 16
0
def write_ppt_files(tasks):
    freqgroups = cmor_utils.group(tasks, get_output_freq)
    for freq1 in freqgroups:
        for freq2 in freqgroups:
            if freq2 > freq1 and freq2 % freq1 == 0:
                freqgroups[freq2] = freqgroups[freq1] + freqgroups[freq2]
    for freq in freqgroups:
        mfp2df, mfpphy, mfp3dfs, mfp3dfp, mfp3dfv = [], [], [], [], []
        alevs, plevs, hlevs = [], [], []
        for task in freqgroups[freq]:
            zaxis, levs = cmor_target.get_z_axis(task.target)
            root_codes = task.source.get_root_codes()
            if not zaxis:
                for code in root_codes:
                    if code in cmor_source.ifs_source.grib_codes_3D:
                        log.warning(
                            "3D grib code %s used in 2D cmor-target %s..."
                            "assuming this is on model levels" %
                            (str(code), task.target.variable))
                        mfp3dfs.append(code)
                    elif code in cmor_source.ifs_source.grib_codes_2D_dyn:
                        log.info(
                            "Adding grib code %s to MFP2DF %dhr ppt file for variable "
                            "%s in table %s" %
                            (str(code), freq, task.target.variable,
                             task.target.table))
                        mfp2df.append(code)
                    elif code in cmor_source.ifs_source.grib_codes_2D_phy:
                        log.info(
                            "Adding grib code %s to MFPPHY %dhr ppt file for variable "
                            "%s in table %s" %
                            (str(code), freq, task.target.variable,
                             task.target.table))
                        mfpphy.append(code)
                    else:
                        log.error("Unknown IFS grib code %s skipped" %
                                  str(code))
            else:
                for code in root_codes:
                    if code in cmor_source.ifs_source.grib_codes_3D:
                        if zaxis in cmor_target.model_axes:
                            log.info(
                                "Adding grib code %s to MFP3DFS %dhr ppt file for variable "
                                "%s in table %s" %
                                (str(code), freq, task.target.variable,
                                 task.target.table))
                            mfp3dfs.append(code)
                            alevs.extend(levs)
                        elif zaxis in cmor_target.pressure_axes:
                            log.info(
                                "Adding grib code %s to MFP3DFP %dhr ppt file for variable "
                                "%s in table %s" %
                                (str(code), freq, task.target.variable,
                                 task.target.table))
                            mfp3dfp.append(code)
                            plevs.extend(levs)
                        elif zaxis in cmor_target.height_axes:
                            log.info(
                                "Adding grib code %s to MFP3DFV %dhr ppt file for variable "
                                "%s in table %s" %
                                (str(code), freq, task.target.variable,
                                 task.target.table))
                            mfp3dfv.append(code)
                            hlevs.extend(levs)
                        else:
                            log.error(
                                "Axis type %s unknown, adding grib code %s"
                                "to model level variables" %
                                (zaxis, str(code)))
                    elif code in cmor_source.ifs_source.grib_codes_2D_dyn:
                        mfp2df.append(code)
                    elif code in cmor_source.ifs_source.grib_codes_2D_phy:
                        mfpphy.append(code)
                    else:
                        log.error("Unknown IFS grib code %s skipped" %
                                  str(code))
        # Always add the geopotential, recommended by ECMWF
        if cmor_source.grib_code(129) not in mfp3dfs:
            mfp2df.append(cmor_source.grib_code(129))
        # Always add the surface pressure, recommended by ECMWF
        mfpphy.append(cmor_source.grib_code(134))
        # Always add the logarithm of surface pressure, recommended by ECMWF
        mfp2df.append(cmor_source.grib_code(152))
        mfp2df = sorted(
            list(
                map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(),
                    set(mfp2df))))
        mfpphy = sorted(
            list(
                map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(),
                    set(mfpphy))))
        mfp3dfs = sorted(
            list(
                map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(),
                    set(mfp3dfs))))
        mfp3dfp = sorted(
            list(
                map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(),
                    set(mfp3dfp))))
        mfp3dfv = sorted(
            list(
                map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(),
                    set(mfp3dfv))))
        plevs = sorted(list(set([float(s) for s in plevs])))[::-1]
        hlevs = sorted(list(set([float(s) for s in hlevs])))
        namelist = {"CFPFMT": "MODEL"}
        if any(mfp2df):
            namelist["NFP2DF"] = len(mfp2df)
            namelist["MFP2DF"] = mfp2df
        if any(mfpphy):
            namelist["NFPPHY"] = len(mfpphy)
            namelist["MFPPHY"] = mfpphy
        if any(mfp3dfs):
            namelist["NFP3DFS"] = len(mfp3dfs)
            namelist["MFP3DFS"] = mfp3dfs
            namelist["NRFP3S"] = -1
        if any(mfp3dfp):
            namelist["NFP3DFP"] = len(mfp3dfp)
            namelist["MFP3DFP"] = mfp3dfp
            namelist["RFP3P"] = plevs
        if any(mfp3dfs):
            namelist["NFP3DFV"] = len(mfp3dfv)
            namelist["MFP3DFV"] = mfp3dfv
            namelist["RFP3V"] = hlevs
        nml = f90nml.Namelist({"NAMFPC": namelist})
        nml.uppercase, nml.end_comma = True, True
        f90nml.write(nml, "pptdddddd%04d" % (100 * freq, ))
Exemplo n.º 17
0
# Logger construction
log = logging.getLogger(__name__)

# Experiment name
exp_name_ = None

# Table root
table_root_ = None

# Files that are being processed in the current execution loop.
ifs_gridpoint_file_ = None
ifs_spectral_file_ = None
ifs_init_gridpoint_file_ = None

# IFS surface pressure grib codes
surface_pressure = cmor_source.grib_code(134)
ln_surface_pressure = cmor_source.grib_code(152)

# IFS grid description data
ifs_grid_descr_ = {}

# Start date of the processed data
start_date_ = None

# Output interval. Denotes the output file periods.
output_interval_ = None

# Output frequency (hrs). Minimal interval between output variables.
output_frequency_ = 6

# Fast storage temporary path
Exemplo n.º 18
0
 def test_specific_humidity(self):
     code=grib_code(135,128)
     src=ifs_source(code)
     eq_(src.grid(),"spec")
     eq_(src.dims(),3)
Exemplo n.º 19
0
 def test_create_from_ints():
     src = ifs_source.create(133, 128)
     eq_(src.get_grib_code(), grib_code(133, 128))
Exemplo n.º 20
0
 def test_create_from_ints():
     src = ifs_source.create(133, 128)
     assert src.get_grib_code() == grib_code(133, 128)
Exemplo n.º 21
0
 def test_snow_depth():
     code = grib_code(141, 128)
     src = ifs_source(code)
     assert src.grid() == "point"
     assert src.spatial_dims == 2
Exemplo n.º 22
0
 def test_specific_humidity():
     code = grib_code(135, 128)
     src = ifs_source(code)
     assert src.grid() == "spec"
     assert src.spatial_dims == 3
Exemplo n.º 23
0
def write_ppt_files(tasks):
    freqgroups = cmor_utils.group(tasks, get_output_freq)
    # Fix for issue 313, make sure to always generate 6-hourly ppt:
    if freqgroups.keys() == [3]:
        freqgroups[6] = []
    if -1 in freqgroups.keys():
        freqgroups.pop(-1)
    freqs_to_remove = []
    for freq1 in freqgroups:
        if freq1 <= 0:
            continue
        for freq2 in freqgroups:
            if freq2 > freq1:
                if freq2 % freq1 == 0:
                    freqgroups[freq2] = freqgroups[freq1] + freqgroups[freq2]
                else:
                    log.error("Frequency %d is not a divisor of frequency %d: this is not supported, "
                              "removing the former" % (freq1, freq2))
                    freqs_to_remove.append(freq1)
    for freq in set(freqs_to_remove):
        freqgroups.pop(freq, None)
    num_slices_tot_sp, num_slices_tot_gp, num_blocks_tot_sp, num_blocks_tot_gp = 0, 0, 0, 0
    min_freq = max(freqgroups.keys())
    prev_freq = 0
    fx_namelist = {}
    for freq in sorted(freqgroups.keys()):
        mfp2df, mfpphy, mfp3dfs, mfp3dfp, mfp3dfh = [], [], [], [], []
        num_slices_sp, num_slices_gp, num_blocks_sp, num_blocks_gp = 0, 0, 0, 0
        alevs, plevs, hlevs = [], [], []
        for task in freqgroups[freq]:
            zaxis, levs = cmor_target.get_z_axis(task.target)
            root_codes = task.source.get_root_codes()
            if not zaxis:
                for code in root_codes:
                    if freq > 0 and code in cmor_source.ifs_source.grib_codes_fx:
                        continue
                    if code in cmor_source.ifs_source.grib_codes_3D:
                        # Exception for orog and areacella, depend only on lowest level of 129:
                        if task.target.variable in ["orog", "areacella"] and code == cmor_source.grib_code(129):
                            mfp2df.append(code)
                        else:
                            log.warning("3D grib code %s used in 2D cmor-target %s..."
                                        "assuming this is on model levels" % (str(code), task.target.variable))
                            mfp3dfs.append(code)
                    elif code in cmor_source.ifs_source.grib_codes_2D_dyn:
                        log.info("Adding grib code %s to MFP2DF %dhr ppt file for variable "
                                 "%s in table %s" % (str(code), freq, task.target.variable, task.target.table))
                        mfp2df.append(code)
                    elif code in cmor_source.ifs_source.grib_codes_2D_phy:
                        log.info("Adding grib code %s to MFPPHY %dhr ppt file for variable "
                                 "%s in table %s" % (str(code), freq, task.target.variable, task.target.table))
                        mfpphy.append(code)
                    else:
                        log.error("Unknown 2D IFS grib code %s skipped" % str(code))
            else:
                for code in root_codes:
                    if freq > 0 and code in cmor_source.ifs_source.grib_codes_fx:
                        continue
                    if code in cmor_source.ifs_source.grib_codes_3D:
                        if zaxis in cmor_target.model_axes:
                            log.info("Adding grib code %s to MFP3DFS %dhr ppt file for variable "
                                     "%s in table %s" % (str(code), freq, task.target.variable, task.target.table))
                            mfp3dfs.append(code)
                            alevs.extend(levs)
                        elif zaxis in cmor_target.pressure_axes:
                            log.info("Adding grib code %s to MFP3DFP %dhr ppt file for variable "
                                     "%s in table %s" % (str(code), freq, task.target.variable, task.target.table))
                            mfp3dfp.append(code)
                            plevs.extend(levs)
                        elif zaxis in cmor_target.height_axes:
                            log.info("Adding grib code %s to MFP3DFH %dhr ppt file for variable "
                                     "%s in table %s" % (str(code), freq, task.target.variable, task.target.table))
                            mfp3dfh.append(code)
                            hlevs.extend(levs)
                        else:
                            log.error("Axis type %s unknown, adding grib code %s"
                                      "to model level variables" % (zaxis, str(code)))
                    elif code in cmor_source.ifs_source.grib_codes_2D_dyn:
                        mfp2df.append(code)
                    elif code in cmor_source.ifs_source.grib_codes_2D_phy:
                        mfpphy.append(code)
                    # case for PEXTRA tendencies is missing
                    else:
                        log.error("Unknown 3D IFS grib code %s skipped" % str(code))
        # Always add the geopotential, recommended by ECMWF
        if cmor_source.grib_code(129) not in mfp3dfs:
            mfp2df.append(cmor_source.grib_code(129))
        # Always add the surface pressure, recommended by ECMWF
        mfpphy.append(cmor_source.grib_code(134))
        # Always add the logarithm of surface pressure, recommended by ECMWF
        mfp2df.append(cmor_source.grib_code(152))
        nfp2dfsp, nfp2dfgp = count_spectral_codes(mfp2df)
        mfp2df = sorted(list(map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(), set(mfp2df))))
        nfpphysp, nfpphygp = count_spectral_codes(mfpphy)
        mfpphy = sorted(list(map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(), set(mfpphy))))
        nfp3dfssp, nfp3dfsgp = count_spectral_codes(mfp3dfs)
        mfp3dfs = sorted(list(map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(), set(mfp3dfs))))
        nfp3dfpsp, nfp3dfpgp = count_spectral_codes(mfp3dfp)
        mfp3dfp = sorted(list(map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(), set(mfp3dfp))))
        nfp3dfhsp, nfp3dfhgp = count_spectral_codes(mfp3dfh)
        mfp3dfh = sorted(list(map(lambda c: c.var_id if c.tab_id == 128 else c.__hash__(), set(mfp3dfh))))
        plevs = sorted(list(set([float(s) for s in plevs])))[::-1]
        hlevs = sorted(list(set([float(s) for s in hlevs])))
        namelist = {"CFPFMT": "MODEL"}
        if any(mfp2df):
            namelist["NFP2DF"] = len(mfp2df)
            namelist["MFP2DF"] = mfp2df
            num_slices_sp += nfp2dfsp
            num_slices_gp += nfp2dfgp
        if any(mfpphy):
            namelist["NFPPHY"] = len(mfpphy)
            namelist["MFPPHY"] = mfpphy
            num_slices_sp += nfpphysp
            num_slices_gp += nfpphygp
        if any(mfp3dfs):
            namelist["NFP3DFS"] = len(mfp3dfs)
            namelist["MFP3DFS"] = mfp3dfs
            # To include all model levels use magic number -99. Opposite, by using the magic number -1 the variable is not saved at any model level:
            namelist["NRFP3S"] = -1
            num_blocks_sp += nfp3dfssp
            num_blocks_gp += nfp3dfsgp
        if any(mfp3dfp):
            namelist["NFP3DFP"] = len(mfp3dfp)
            namelist["MFP3DFP"] = mfp3dfp
            namelist["RFP3P"] = plevs
            num_slices_sp += (nfp3dfpsp * len(plevs))
            num_slices_gp += (nfp3dfpgp * len(plevs))
        if any(mfp3dfh):
            namelist["NFP3DFH"] = len(mfp3dfh)
            namelist["MFP3DFH"] = mfp3dfh
            namelist["RFP3H"] = hlevs
            num_slices_sp += (nfp3dfhsp * len(hlevs))
            num_slices_gp += (nfp3dfhgp * len(hlevs))
        num_slices_tot_sp = num_slices_sp if prev_freq == 0 else \
            (num_slices_sp + ((freq/prev_freq) - 1) * num_slices_tot_sp)
        num_slices_tot_gp = num_slices_gp if prev_freq == 0 else \
            (num_slices_gp + ((freq/prev_freq) - 1) * num_slices_tot_gp)
        num_blocks_tot_sp = num_blocks_sp if prev_freq == 0 else \
            (num_blocks_sp + ((freq/prev_freq) - 1) * num_blocks_tot_sp)
        num_blocks_tot_gp = num_blocks_gp if prev_freq == 0 else \
            (num_blocks_gp + ((freq/prev_freq) - 1) * num_blocks_tot_gp)
        prev_freq = freq
        nml = f90nml.Namelist({"NAMFPC": namelist})
        nml.uppercase, nml.end_comma = True, True
        if freq > 0:
            f90nml.write(nml, "pptdddddd%04d" % (100 * freq,))
        if freq == 0:
            fx_namelist = namelist
        if freq == min_freq:
            # Always add orography and land mask for lowest frequency ppt
            mfpphy.extend([129, 172, 43])
            mfpphy = sorted(list(set(mfpphy)))
            namelist["MFPPHY"] = mfpphy
            namelist["NFPPHY"] = len(mfpphy)
            nml = f90nml.Namelist({"NAMFPC": join_namelists(namelist, fx_namelist)})
            nml.uppercase, nml.end_comma = True, True
            # Write initial state ppt
            f90nml.write(nml, "ppt0000000000")
    average_hours_per_month = 730
    slices_per_month_sp = (average_hours_per_month * num_slices_tot_sp) / prev_freq
    slices_per_month_gp = (average_hours_per_month * num_slices_tot_gp) / prev_freq
    blocks_per_month_sp = (average_hours_per_month * num_blocks_tot_sp) / prev_freq
    blocks_per_month_gp = (average_hours_per_month * num_blocks_tot_gp) / prev_freq
    num_layers = 91
    log.info("")
    log.info("EC-Earth IFS output volume estimates:")
    log.info("---------------------------------------------------------------------------")
    log.info("# spectral GRIB messages p/m:  %d" % (slices_per_month_sp + num_layers * blocks_per_month_sp))
    log.info("# gridpoint GRIB messages p/m: %d" % (slices_per_month_gp + num_layers * blocks_per_month_gp))
    log.info("---------------------------------------------------------------------------")
    log.info("                           T255L91                     T511L91               ")
    log.info("---------------------------------------------------------------------------")
    vol255 = (slices_per_month_sp + num_layers * blocks_per_month_sp) * 0.133 / 1000. +\
             (slices_per_month_gp + num_layers * blocks_per_month_gp) * 0.180 / 1000.
    vol511 = (slices_per_month_sp + num_layers * blocks_per_month_sp) * 0.503 / 1000. +\
             (slices_per_month_gp + num_layers * blocks_per_month_gp) * 0.698 / 1000.
    log.info("                           %.2f GB/yr                %.2f GB/yr        " % (12*vol255, 12*vol511))

   #volume_estimate = open('volume-estimate-ifs.txt','w')
   #volume_estimate.write(' \nEC-Earth3 IFS volume estimates of generated output:{}'.format('\n'))
   #volume_estimate.write('  Volume estimate of the spectral + gridpoint GRIB files for T255L91 grid: {} GB/yr{}'.format(12*vol255, '\n'))
   #volume_estimate.write('  Volume estimate of the spectral + gridpoint GRIB files for T511L91 grid: {} GB/yr{}'.format(12*vol511, '\n\n'))
   #volume_estimate.write('  Number of spectral  GRIB messages per month: {}{}'.format(slices_per_month_sp + num_layers * blocks_per_month_sp, '\n'))
   #volume_estimate.write('  Number of gridpoint GRIB messages per month: {}{}'.format(slices_per_month_gp + num_layers * blocks_per_month_gp, '\n\n'))
   #volume_estimate.close()

    hf = 3.0 # IFS heuristic factor
    volume_estimate = open('volume-estimate-ifs.txt','w')
    volume_estimate.write('{}'.format('\n\n\n'))
    volume_estimate.write('Heuristic volume estimate for the raw EC-Earth3 IFS  output on the T255L91     grid: {:6} GB per year{}'.format(round((12*vol255) / hf, 1), '\n'))
    volume_estimate.write('Heuristic volume estimate for the raw EC-Earth3 IFS  output on the T511L91     grid: {:6} GB per year{}'.format(round((12*vol511) / hf, 1), '\n'))
    volume_estimate.close()
Exemplo n.º 24
0
 def test_snow_depth(self):
     code=grib_code(141,128)
     src=ifs_source(code)
     eq_(src.grid(),"point")
     eq_(src.dims(),2)
Exemplo n.º 25
0
 def test_specific_humidity():
     code = grib_code(135, 128)
     src = ifs_source(code)
     eq_(src.grid(), "spec")
     eq_(src.spatial_dims, 3)
Exemplo n.º 26
0
 def test_snow_depth():
     code = grib_code(141, 128)
     src = ifs_source(code)
     eq_(src.grid(), "point")
     eq_(src.spatial_dims, 2)
Exemplo n.º 27
0
 def test_create_from_var_string():
     src = ifs_source.read("var133")
     assert src.get_grib_code() == grib_code(133, 128)
Exemplo n.º 28
0
 def test_create_from_string():
     src = ifs_source.read("133.128")
     eq_(src.get_grib_code(), grib_code(133, 128))
Exemplo n.º 29
0
 def test_create_from_var_string_masked():
     src = ifs_source.read("var133", mask_expr="var172<=0.5")
     assert set(src.get_root_codes()) == {
         grib_code(133, 128), grib_code(172, 128)
     }