Пример #1
0
def percent_to_mmolpmol(ds, MF_out, RH_in, Ta_in, ps_in):
    """
    Purpose:
     Calculate H2O mole fraction from relative humidity (RH).
    """
    nRecs = int(ds.root["Attributes"]["nc_nrecs"])
    zeros = numpy.zeros(nRecs, dtype=numpy.int32)
    ones = numpy.ones(nRecs, dtype=numpy.int32)
    for item in [RH_in, Ta_in, ps_in]:
        if item not in list(ds.root["Variables"].keys()):
            msg = " Requested series " + item + " not found, " + MF_out + " not calculated"
            logger.error(msg)
            return 0
    # get the relative humidity and check the units
    RH = pfp_utils.GetVariable(ds, RH_in)
    RH = pfp_utils.convert_units_func(ds, RH, "percent")
    # get the temperature and check the units
    Ta = pfp_utils.GetVariable(ds, Ta_in)
    Ta = pfp_utils.convert_units_func(ds, Ta, "degC")
    # get the absoulte humidity
    AH_data = pfp_mf.absolutehumidityfromrelativehumidity(
        Ta["Data"], RH["Data"])
    # get the atmospheric pressure and check the units
    ps = pfp_utils.GetVariable(ds, ps_in)
    ps = pfp_utils.convert_units_func(ds, ps, "kPa")
    # get the output variable (created in pfp_ts.DoFunctions())
    MF = pfp_utils.GetVariable(ds, MF_out)
    # do the business
    MF["Data"] = pfp_mf.h2o_mmolpmolfromgpm3(AH_data, Ta["Data"], ps["Data"])
    MF["Flag"] = numpy.where(
        numpy.ma.getmaskarray(MF["Data"]) == True, ones, zeros)
    MF["Attr"]["units"] = "mmol/mol"
    # put the output variable back into the data structure
    pfp_utils.CreateVariable(ds, MF)
    return 1
Пример #2
0
def gH2Opm3_to_mmolpmol(ds, MF_out, AH_in, Ta_in, ps_in):
    """
    Purpose:
     Calculate H2O mole fraction in mml/mol from absolute humidity in g/m^3.
    Usage:
     pfp_func_units.gH2Opm3_to_mmolpmol(ds, MF_out, AH_in, Ta_in, ps_in)
    Author: PRI
    Date: August 2019
    """
    nRecs = int(ds.root["Attributes"]["nc_nrecs"])
    zeros = numpy.zeros(nRecs, dtype=numpy.int32)
    ones = numpy.ones(nRecs, dtype=numpy.int32)
    for item in [AH_in, Ta_in, ps_in]:
        if item not in ds.root["Variables"].keys():
            msg = " Requested series " + item + " not found, " + MF_out + " not calculated"
            logger.error(msg)
            return 0
    AH = pfp_utils.GetVariable(ds, AH_in)
    AH = pfp_utils.convert_units_func(ds, AH, "g/m^3")
    Ta = pfp_utils.GetVariable(ds, Ta_in)
    Ta = pfp_utils.convert_units_func(ds, Ta, "degC")
    ps = pfp_utils.GetVariable(ds, ps_in)
    ps = pfp_utils.convert_units_func(ds, ps, "kPa")
    MF = pfp_utils.GetVariable(ds, MF_out)
    MF["Data"] = pfp_mf.h2o_mmolpmolfromgpm3(AH["Data"], Ta["Data"],
                                             ps["Data"])
    MF["Flag"] = numpy.where(
        numpy.ma.getmaskarray(MF["Data"]) == True, ones, zeros)
    MF["Attr"]["units"] = "mmol/mol"
    pfp_utils.CreateVariable(ds, MF)
    return 1
Пример #3
0
def mgCO2pm3_to_umolpmol(ds, MF_out, CO2_in, Ta_in, ps_in):
    """
    Purpose:
     Calculate CO2 mole fraction in uml/mol from mass density in mgCO2/m3.
    Usage:
     pfp_func_units.mgCO2pm3_to_umolpmol(ds, MF_out, CO2_in, Ta_in, ps_in)
    Author: PRI
    Date: August 2019
    """
    nRecs = int(ds.root["Attributes"]["nc_nrecs"])
    zeros = numpy.zeros(nRecs, dtype=numpy.int32)
    ones = numpy.ones(nRecs, dtype=numpy.int32)
    for item in [CO2_in, Ta_in, ps_in]:
        if item not in ds.root["Variables"].keys():
            msg = " Requested series " + item + " not found, " + MF_out + " not calculated"
            logger.error(msg)
            return 0
    CO2 = pfp_utils.GetVariable(ds, CO2_in)
    CO2 = pfp_utils.convert_units_func(ds, CO2, "mg/m^3")
    Ta = pfp_utils.GetVariable(ds, Ta_in)
    Ta = pfp_utils.convert_units_func(ds, Ta, "degC")
    ps = pfp_utils.GetVariable(ds, ps_in)
    ps = pfp_utils.convert_units_func(ds, ps, "kPa")
    MF = pfp_utils.GetVariable(ds, MF_out)
    MF["Data"] = pfp_mf.co2_ppmfrommgCO2pm3(CO2["Data"], Ta["Data"],
                                            ps["Data"])
    MF["Flag"] = numpy.where(
        numpy.ma.getmaskarray(MF["Data"]) == True, ones, zeros)
    MF["Attr"]["units"] = "umol/mol"
    pfp_utils.CreateVariable(ds, MF)
    return 1
Пример #4
0
def gH2Opm3_to_mmolpm3(ds, H2O_out, AH_in):
    """
    Purpose:
     Calculate H2O molar density in mmol/m^3 from absolute humidity in g/m^3.
    Usage:
     pfp_func_units.gH2Opm3_to_mmolpm3(ds, MD_out, AH_in)
    Author: PRI
    Date: September 2020
    """
    for item in [AH_in]:
        if item not in ds.root["Variables"].keys():
            msg = " Requested series " + item + " not found, " + H2O_out + " not calculated"
            logger.error(msg)
            return 0
    var_in = pfp_utils.GetVariable(ds, AH_in)
    got_variance = False
    if var_in["Label"][-3:] == "_Vr" and var_in["Attr"]["units"] in [
            "g^2/m^6", "gH2O^2/m^6"
    ]:
        got_variance = True
        var_in["Data"] = numpy.ma.sqrt(var_in["Data"])
        var_in["Attr"]["units"] = "g/m^3"
    var_out = pfp_utils.convert_units_func(ds,
                                           var_in,
                                           "mmol/m^3",
                                           mode="quiet")
    var_out["Label"] = H2O_out
    if got_variance:
        var_out["Data"] = var_out["Data"] * var_out["Data"]
        var_out["Attr"]["units"] = "mmol^2/m^6"
    pfp_utils.CreateVariable(ds, var_out)
    return 1
Пример #5
0
def mmolpm3_to_gH2Opm3(ds, AH_out, H2O_in):
    """
    Purpose:
     Function to convert mmol/m^3 (molar density) to g/m^3 (mass density).
    Usage:
     pfp_func_units.mmolpm3_to_gpm3(ds, AH_out, H2O_in)
    Author: PRI
    Date: August 2020
    """
    for item in [H2O_in]:
        if item not in list(ds.root["Variables"].keys()):
            msg = " Requested series " + item + " not found, " + AH_out + " not calculated"
            logger.error(msg)
            return 0
    var_in = pfp_utils.GetVariable(ds, H2O_in)
    got_variance = False
    if var_in["Label"][-3:] == "_Vr" and var_in["Attr"][
            "units"] == "mmol^2/m^6":
        got_variance = True
        var_in["Data"] = numpy.ma.sqrt(var_in["Data"])
        var_in["Attr"]["units"] = "mmol/m^3"
    var_out = pfp_utils.convert_units_func(ds, var_in, "g/m^3", mode="quiet")
    var_out["Label"] = AH_out
    if got_variance:
        var_out["Data"] = var_out["Data"] * var_out["Data"]
        var_out["Attr"]["units"] = "g^2/m^6"
    pfp_utils.CreateVariable(ds, var_out)
    return 1
Пример #6
0
def mgCO2pm3_to_mmolpm3(ds, CO2_out, CO2_in):
    """
    Purpose:
     Calculate CO2 molar density in mmol/m3 from CO2 concentration in mg/m3.
    Usage:
     pfp_func_units.mgCO2pm3_to_mmolpm3(ds, CO2_out, CO2_in)
    Author: PRI
    Date: September 2020
    """
    for item in [CO2_in]:
        if item not in ds.root["Variables"].keys():
            msg = " Requested series " + item + " not found, " + CO2_out + " not calculated"
            logger.error(msg)
            return 0
    var_in = pfp_utils.GetVariable(ds, CO2_in)
    got_variance = False
    if var_in["Label"][-3:] == "_Vr" and var_in["Attr"]["units"] in [
            "mg^2/m^6", "mgCO2^2/m^6"
    ]:
        got_variance = True
        var_in["Data"] = numpy.ma.sqrt(var_in["Data"])
        var_in["Attr"]["units"] = "mg/m^3"
    var_out = pfp_utils.convert_units_func(ds,
                                           var_in,
                                           "mmol/m^3",
                                           mode="quiet")
    var_out["Label"] = CO2_out
    if got_variance:
        var_out["Data"] = var_out["Data"] * var_out["Data"]
        var_out["Attr"]["units"] = "mmol^2/m^6"
    pfp_utils.CreateVariable(ds, var_out)
    return 1
Пример #7
0
def percent_to_m3pm3(ds, Sws_out, Sws_in):
    """
    Purpose:
     Function to convert Sws in units of "percent" (1 to 100) to "frac" (0 to 1).
    Usage:
     pfp_func_units.percent_to_m3pm3(ds, Sws_out, Sws_in)
    Author: PRI
    Date: April 2020
    """
    var_in = pfp_utils.GetVariable(ds, Sws_in)
    var_out = pfp_utils.convert_units_func(ds, var_in, "m^3/m^3", mode="quiet")
    var_out["Label"] = Sws_out
    pfp_utils.CreateVariable(ds, var_out)
    return 1
Пример #8
0
def Pa_to_kPa(ds, ps_out, ps_in):
    """
    Purpose:
     Function to convert pressure from Pa to kPa.
    Usage:
     pfp_func_units.Pa_to_kPa(ds, ps_out, ps_in)
    Author: PRI
    Date: February 2018
    """
    var_in = pfp_utils.GetVariable(ds, ps_in)
    var_out = pfp_utils.convert_units_func(ds, var_in, "kPa", mode="quiet")
    var_out["Label"] = ps_out
    pfp_utils.CreateVariable(ds, var_out)
    return 1
Пример #9
0
def kgpm3_to_gpm3(ds, AH_out, AH_in):
    """
    Purpose:
     Function to convert absolute humidity from kg/m^3 to g/m^3.
    Usage:
     pfp_func_units.kgpm3_to_gpm3(ds, AH_out, AH_in)
    Author: PRI
    Date: August 2020
    """
    var_in = pfp_utils.GetVariable(ds, AH_in)
    var_out = pfp_utils.convert_units_func(ds, var_in, "g/m^3", mode="quiet")
    var_out["Label"] = AH_out
    pfp_utils.CreateVariable(ds, var_out)
    return 1
Пример #10
0
def fraction_to_percent(ds, RH_out, RH_in):
    """
    Purpose:
     Function to convert RH in units of "frac" (0 to 1) to "percent" (1 to 100).
    Usage:
     pfp_func_units.fraction_to_percent(ds, RH_out, RH_in)
    Author: PRI
    Date: August 2019
    """
    var_in = pfp_utils.GetVariable(ds, RH_in)
    var_out = pfp_utils.convert_units_func(ds, var_in, "percent", mode="quiet")
    var_out["Label"] = RH_out
    pfp_utils.CreateVariable(ds, var_out)
    return 1
Пример #11
0
def percent_to_gH2Opm3(ds, AH_out, RH_in, Ta_in):
    """
    Purpose:
     Function to calculate absolute humidity given relative humidity and
     air temperature.  Absolute humidity is not calculated if any of the
     input series are missing or if the specified output series already
     exists in the data structure.
     The calculated absolute humidity is created as a new series in the
     data structure.
    Usage:
     pfp_func_units.percent_to_gpm3(ds,"AH_HMP_2m","RH_HMP_2m","Ta_HMP_2m")
    Author: PRI
    Date: September 2015
    """
    nRecs = int(ds.root["Attributes"]["nc_nrecs"])
    zeros = numpy.zeros(nRecs, dtype=numpy.int32)
    ones = numpy.ones(nRecs, dtype=numpy.int32)
    for item in [RH_in, Ta_in]:
        if item not in ds.root["Variables"].keys():
            msg = " Requested series " + item + " not found, " + AH_out + " not calculated"
            logger.error(msg)
            return 0
    # get the relative humidity and check the units
    RH = pfp_utils.GetVariable(ds, RH_in)
    RH = pfp_utils.convert_units_func(ds, RH, "percent")
    # get the temperature and check the units
    Ta = pfp_utils.GetVariable(ds, Ta_in)
    Ta = pfp_utils.convert_units_func(ds, Ta, "degC")
    # get the absolute humidity
    AH = pfp_utils.GetVariable(ds, AH_out)
    AH["Data"] = pfp_mf.absolutehumidityfromrelativehumidity(
        Ta["Data"], RH["Data"])
    AH["Flag"] = numpy.where(
        numpy.ma.getmaskarray(AH["Data"]) == True, ones, zeros)
    AH["Attr"]["units"] = "g/m^3"
    pfp_utils.CreateVariable(ds, AH)
    return 1
Пример #12
0
def mmolpmol_to_gH2Opm3(ds, AH_out, MF_in, Ta_in, ps_in):
    """
    Purpose:
     Function to calculate absolute humidity given the water vapour mole
     fraction, air temperature and pressure.  Absolute humidity is not calculated
     if any of the input series are missing or if the specified output series
     already exists in the data structure.
     The calculated absolute humidity is created as a new series in the
     data structure.
    Usage:
     pfp_func_units.mmolpmol_to_gpm3(ds,"AH_IRGA_Av","H2O_IRGA_Av","Ta_HMP_2m","ps")
    Author: PRI
    Date: September 2015
    """
    nRecs = int(ds.root["Attributes"]["nc_nrecs"])
    zeros = numpy.zeros(nRecs, dtype=numpy.int32)
    ones = numpy.ones(nRecs, dtype=numpy.int32)
    for item in [MF_in, Ta_in, ps_in]:
        if item not in list(ds.root["Variables"].keys()):
            msg = " Requested series " + item + " not found, " + AH_out + " not calculated"
            logger.error(msg)
            return 0
    MF = pfp_utils.GetVariable(ds, MF_in)
    MF = pfp_utils.convert_units_func(ds, MF, "mmol/mol")
    Ta = pfp_utils.GetVariable(ds, Ta_in)
    Ta = pfp_utils.convert_units_func(ds, Ta, "degC")
    ps = pfp_utils.GetVariable(ds, ps_in)
    ps = pfp_utils.convert_units_func(ds, ps, "kPa")
    AH = pfp_utils.GetVariable(ds, AH_out)
    AH["Data"] = pfp_mf.h2o_gpm3frommmolpmol(MF["Data"], Ta["Data"],
                                             ps["Data"])
    AH["Flag"] = numpy.where(
        numpy.ma.getmaskarray(AH["Data"]) == True, ones, zeros)
    AH["Attr"]["units"] = "g/m^3"
    pfp_utils.CreateVariable(ds, AH)
    return 1
Пример #13
0
def K_to_C(ds, T_out, T_in):
    """
    Purpose:
     Function to convert temperature from K to C.
    Usage:
     pfp_func_units.K_to_C(ds, T_out, T_in)
    Author: PRI
    Date: February 2018
    """
    if T_in not in list(ds.root["Variables"].keys()):
        msg = " Convert_K_to_C: variable " + T_in + " not found, skipping ..."
        logger.warning(msg)
        return 0
    if "<" in T_out or ">" in T_out:
        logger.warning(" ***")
        msg = " *** " + T_in + ": illegal name (" + T_out + ") in function, skipping ..."
        logger.warning(msg)
        logger.warning(" ***")
        return 0
    var_in = pfp_utils.GetVariable(ds, T_in)
    var_out = pfp_utils.convert_units_func(ds, var_in, "degC", mode="quiet")
    var_out["Label"] = T_out
    pfp_utils.CreateVariable(ds, var_out)
    return 1
Пример #14
0
                    "Attr":
                    data[site][label + "_" + str(i) + str(j)]["Attr"]
                }
                # put it into the data structure
                pfp_utils.CreateVariable(dss_ats[site], variable)

# do the units conversion
msg = " Converting units for ps, Ta, Ts and Sws"
logger.info(msg)
for site in sites:
    for i in range(3):
        for j in range(3):
            # surface pressure units Pa to kPa
            ps = pfp_utils.GetVariable(dss_ats[site],
                                       "ps" + "_" + str(i) + str(j))
            ps = pfp_utils.convert_units_func(dss_ats[site], ps, "kPa")
            pfp_utils.CreateVariable(dss_ats[site], ps)
            # air temperature
            Ta = pfp_utils.GetVariable(dss_ats[site],
                                       "Ta" + "_" + str(i) + str(j))
            Ta = pfp_utils.convert_units_func(dss_ats[site], Ta, "degC")
            pfp_utils.CreateVariable(dss_ats[site], Ta)
            # soil temperature
            Ts = pfp_utils.GetVariable(dss_ats[site],
                                       "Ts" + "_" + str(i) + str(j))
            Ts = pfp_utils.convert_units_func(dss_ats[site], Ts, "degC")
            pfp_utils.CreateVariable(dss_ats[site], Ts)
            # soil moisture
            Sws = pfp_utils.GetVariable(dss_ats[site],
                                        "Sws" + "_" + str(i) + str(j))
            Sws = pfp_utils.convert_units_func(dss_ats[site], Sws, "m^3/m^3")
Пример #15
0
    pfp_utils.CreateVariable(dss_ats[site], Fh)
    # latent heat flux
    Fe = pfp_utils.GetVariable(dss_ats[site], "Fe")
    Fe["Data"] = float(-1)*Fe["Data"]/(era5_timestep*60.0)
    pfp_utils.CreateVariable(dss_ats[site], Fe)
    # Precipitation is in m, convert to mm
    Precip = pfp_utils.GetVariable(dss_ats[site], "Precip")
    Precip["Data"] = Precip["Data"]*float(1000)
    pfp_utils.CreateVariable(dss_ats[site], Precip)
# do the units conversion
msg = " Converting units for ps, Ta, Td, Ts and Sws"
logger.info(msg)
for site in sites:
    # surface pressure units Pa to kPa
    ps = pfp_utils.GetVariable(dss_ats[site], "ps")
    ps = pfp_utils.convert_units_func(dss_ats[site], ps, "kPa")
    pfp_utils.CreateVariable(dss_ats[site], ps)
    # air temperature
    Ta = pfp_utils.GetVariable(dss_ats[site], "Ta")
    Ta = pfp_utils.convert_units_func(dss_ats[site], Ta, "degC")
    pfp_utils.CreateVariable(dss_ats[site], Ta)
    # dew point temperature
    Td = pfp_utils.GetVariable(dss_ats[site], "Td")
    Td = pfp_utils.convert_units_func(dss_ats[site], Td, "degC")
    pfp_utils.CreateVariable(dss_ats[site], Td)
    # soil temperature level 1
    Ts = pfp_utils.GetVariable(dss_ats[site], "Ts")
    Ts = pfp_utils.convert_units_func(dss_ats[site], Ts, "degC")
    pfp_utils.CreateVariable(dss_ats[site], Ts)
    # soil temperature level 2
    Ts2 = pfp_utils.GetVariable(dss_ats[site], "Ts2")
Пример #16
0
def change_variable_attributes(std, ds):
    """
    Purpose:
     Clean up the variable attributes.
    Usage:
    Author: PRI
    Date: November 2018
    """
    # coerce units into a standard form
    msg = " Parse variable attributes"
    logger.info(msg)
    labels = list(ds.series.keys())
    for label in labels:
        variable = pfp_utils.GetVariable(ds, label)
        # parse variable attributes to new format
        variable["Attr"] = parse_variable_attributes(variable["Attr"])
        pfp_utils.CreateVariable(ds, variable)

    # coerce units into a standard form
    msg = " Changing variable units"
    logger.info(msg)
    old_units = list(std["Variables"]["units_map"].keys())
    deprecated_units = pfp_utils.string_to_list(std["Variables"]["deprecated"]["units"])
    labels = list(ds.series.keys())
    for label in labels:
        variable = pfp_utils.GetVariable(ds, label)
        old_unit = variable["Attr"]["units"]
        if old_unit in old_units:
            variable["Attr"]["units"] = std["Variables"]["units_map"][old_unit]
            pfp_utils.CreateVariable(ds, variable)
        elif old_unit in deprecated_units or len(old_unit) == 0:
            variable["Attr"]["units"] = "1"
            pfp_utils.CreateVariable(ds, variable)

    # do any units conversion required
    msg = " Converting units"
    logger.info(msg)
    stdv = std["Variables"]
    stdva = std["Variables"]["attributes"]
    labels = list(ds.series.keys())
    vattrs = pfp_utils.string_to_list(stdv["units_convert"]["labels"])
    for label in labels:
        variable = pfp_utils.GetVariable(ds, label)
        for vattr in vattrs:
            #if label[:len(vattr)] == vattr:
            if label.split("_")[0] == vattr:
                old_units = variable["Attr"]["units"]
                std_units = stdva[vattr]["units"]
                if old_units != std_units:
                    msg = " Converting " + label + " to units of " + std_units
                    logger.info(msg)
                    variable = pfp_utils.convert_units_func(ds, variable, std_units)
                    pfp_utils.CreateVariable(ds, variable)

    # rename existing long_name to description, introduce a
    # consistent long_name attribute
    msg = " Long name, description and units"
    logger.info(msg)
    stdva = std["Variables"]["attributes"]
    vattr_list = list(stdva.keys())
    labels = list(ds.series.keys())
    descr = "description_" + ds.globalattributes["processing_level"]
    for label in labels:
        variable = pfp_utils.GetVariable(ds, label)
        # existing long_name to description
        variable["Attr"][descr] = variable["Attr"]["long_name"]
        for item in vattr_list:
            if label == item:
                for key in list(stdva[item].keys()):
                    if key == "units":
                        if "_Sd" not in label and "_Vr" not in label:
                            old_units = variable["Attr"]["units"]
                            new_units = pfp_utils.string_to_list(stdva[item]["units"])
                            if old_units not in new_units and old_units != "1":
                                msg = "Units '" + old_units + "' not found for variable " + label
                                logger.warning(msg)
                                continue
                            if old_units in new_units:
                                if "standard_name" in stdva[item]:
                                    idx = new_units.index(old_units)
                                    standard_names = pfp_utils.string_to_list(stdva[item]["standard_name"])
                                    variable["Attr"]["standard_name"] = standard_names[idx]
                    elif key == "standard_name":
                        if "_Sd" in label or "_Vr" in label:
                            # remove standard_name for standard deviations and variances
                            if "standard_name" in variable["Attr"]:
                                variable["Attr"].pop("standard_name")
                    else:
                        variable["Attr"][key] = stdva[item][key]
                # remove standard_name attribute if not defined for this variable
                if (("standard_name" in variable["Attr"]) and ("standard_name" not in stdva[item])):
                    variable["Attr"].pop("standard_name")                
            elif label.split("_")[0] == item:
                for key in list(stdva[item].keys()):
                    if key == "units":
                        if "_Sd" not in label and "_Vr" not in label:
                            old_units = variable["Attr"]["units"]
                            new_units = pfp_utils.string_to_list(stdva[item]["units"])
                            if old_units not in new_units and old_units != "1":
                                msg = "Units '" + old_units + "' not found for variable " + label
                                logger.warning(msg)
                                continue
                            if old_units in new_units:
                                if "standard_name" in stdva[item]:
                                    idx = new_units.index(old_units)
                                    standard_names = pfp_utils.string_to_list(stdva[item]["standard_name"])
                                    variable["Attr"]["standard_name"] = standard_names[idx]
                    elif key == "standard_name":
                        if "_Sd" in label or "_Vr" in label:
                            # remove standard_name for standard deviations and variances
                            if "standard_name" in variable["Attr"]:
                                variable["Attr"].pop("standard_name")
                    else:
                        variable["Attr"][key] = stdva[item][key]
                # remove standard_name attribute if not defined for this variable
                if (("standard_name" in variable["Attr"]) and ("standard_name" not in stdva[item])):
                    variable["Attr"].pop("standard_name")
        pfp_utils.CreateVariable(ds, variable)

    # parse variable attributes to new format, remove deprecated variable attributes
    # and fix valid_range == "-1e+35,1e+35"
    msg = " Remove deprecated, check valid_range"
    logger.info(msg)
    tmp = std["Variables"]["deprecated"]["attributes"]
    deprecated = pfp_utils.string_to_list(tmp)
    labels = list(ds.series.keys())
    for label in labels:
        variable = pfp_utils.GetVariable(ds, label)
        ## parse variable attributes to new format
        #variable["Attr"] = parse_variable_attributes(variable["Attr"])
        # remove deprecated variable attributes
        for vattr in deprecated:
            if vattr in list(variable["Attr"].keys()):
                del variable["Attr"][vattr]
        # fix valid_range == "-1e+35,1e+35"
        if "valid_range" in variable["Attr"]:
            valid_range = variable["Attr"]["valid_range"]
            if valid_range == "-1e+35,1e+35":
                d = numpy.ma.min(variable["Data"])
                mn = pfp_utils.round2significant(d, 4, direction='down')
                d = numpy.ma.max(variable["Data"])
                mx = pfp_utils.round2significant(d, 4, direction='up')
                variable["Attr"]["valid_range"] = repr(mn) + "," + repr(mx)
        pfp_utils.CreateVariable(ds, variable)

    # ugly hack to deal with CO2_IRGA_Av, CO2_IRGA_Sd and CO2_IRGA_Vr units
    msg = " Converting CO2 units"
    logger.info(msg)
    labels = list(ds.series.keys())
    for label in labels:
        if (label.split("_")[0] == "CO2"):
            co2 = pfp_utils.GetVariable(ds, label)
            if ((label == "CO2") and (co2["Attr"]["units"] == "mg/m^3")):
                co2 = pfp_utils.convert_units_func(ds, co2, "umol/mol")
                pfp_utils.CreateVariable(ds, co2)
            elif ((label[-3:] == "_Av") and (co2["Attr"]["units"] == "mg/m^3")):
                co2 = pfp_utils.convert_units_func(ds, co2, "umol/mol")
                pfp_utils.CreateVariable(ds, co2)
            elif ((label[-3:] == "_Sd") and (co2["Attr"]["units"] == "mg/m^3")):
                co2 = pfp_utils.convert_units_func(ds, co2, "mmol/m^3")
                # convert_units_func() will add a standard name when units=mmol/m^3
                # here we dump standard_name for a standard deviation
                if "standard_name" in co2["Attr"]:
                    co2["Attr"].pop("standard_name")
                pfp_utils.CreateVariable(ds, co2)
            elif ((label[-3:] == "_Vr") and (co2["Attr"]["units"] == "mg^2/m^6")):
                msg = " Converting " + label + " from " + co2["Attr"]["units"]
                msg += " to mmol^2/m^6"
                logger.info(msg)
                co2["Data"] = numpy.ma.sqrt(co2["Data"])
                co2["Attr"]["units"] = "mg/m^3"
                co2 = pfp_utils.convert_units_func(ds, co2, "mmol/m^3")
                co2["Data"] = co2["Data"]*co2["Data"]
                co2["Attr"]["units"] = "mmol^2/m^6"
                # convert_units_func() will add a standard name when units=mmol/m^3
                # here we dump standard_name for a variance
                if "standard_name" in co2["Attr"]:
                    co2["Attr"].pop("standard_name")
                pfp_utils.CreateVariable(ds, co2)
            else:
                if co2["Attr"]["units"] not in ["umol/mol", "mmol/m^3", "mmol^2/m^6", "1"]:
                    msg = " Unrecognised units for " + label
                    msg += " (" + co2["Attr"]["units"] + ")"
                    logger.warning(msg)

    # set the statistic_type variable attribute for standard deviations and
    # variances and remove standard_name if present
    msg = " Setting statistic_type"
    logger.info(msg)
    labels = list(ds.series.keys())
    for label in labels:
        variable = pfp_utils.GetVariable(ds, label)
        if label[-3:] == "_Sd":
            variable["Attr"]["statistic_type"] = "standard_deviation"
            if "standard_name" in variable["Attr"]:
                variable["Attr"].pop("standard_name")
            pfp_utils.CreateVariable(ds, variable)
        elif label[-3:] == "_Vr":
            variable["Attr"]["statistic_type"] = "variance"
            if "standard_name" in variable["Attr"]:
                variable["Attr"].pop("standard_name")
            pfp_utils.CreateVariable(ds, variable)
        else:
            pass

    # remove undefined attributes
    msg = " Remove undefined attributes"
    logger.info(msg)
    stdvd = std["Variables"]["deprecated"]
    units_deprecated = pfp_utils.string_to_list(stdvd["units"])
    height_deprecated = pfp_utils.string_to_list(stdvd["height"])
    miscellaneous_deprecated = pfp_utils.string_to_list(stdvd["miscellaneous"])
    standard_name_deprecated = pfp_utils.string_to_list(stdvd["standard_name"])
    labels = list(ds.series.keys())
    for label in labels:
        variable = pfp_utils.GetVariable(ds, label)
        attrs = list(variable["Attr"].keys())
        for attr in attrs:
            if attr == "units":
                if ((variable["Attr"][attr] in units_deprecated) or
                    (len(str(variable["Attr"][attr])) == 0)):
                    variable["Attr"].pop(attr)
            elif attr == "height":
                if ((variable["Attr"][attr] in height_deprecated) or
                    (len(str(variable["Attr"][attr])) == 0)):
                    variable["Attr"].pop(attr)
            elif attr == "standard_name":
                if ((variable["Attr"][attr] in standard_name_deprecated) or
                    (len(str(variable["Attr"][attr])) == 0)):
                    variable["Attr"].pop(attr)
            elif len(str(variable["Attr"][attr])) == 0:
                variable["Attr"].pop(attr)
            else:
                if ((variable["Attr"][attr] in miscellaneous_deprecated) or
                    (len(str(variable["Attr"][attr])) == 0)):
                    variable["Attr"].pop(attr)
        pfp_utils.CreateVariable(ds, variable)

    # append '%' symbol to coverage_L2 and coverage_L3 variable sttributes
    msg = " Appending % to coverage statistics"
    logger.info(msg)
    labels = list(ds.series.keys())
    for label in labels:
        variable = pfp_utils.GetVariable(ds, label)
        attrs = list(variable["Attr"].keys())
        for attr in attrs:
            if "coverage_" in attr:
                if "%" not in variable["Attr"][attr]:
                    variable["Attr"][attr] += "%"
        pfp_utils.CreateVariable(ds, variable)
    return