Module pyl4c.data.fixtures

Commonly used global constants. New users should change ANCILLARY_DATA_PATHS if it doesn't match their file system.

Source for EASE-Grid 2.0 parameters:

<https://nsidc.org/ease/ease-grid-projection-gt>

NOTE: EASE-Grid 2.0 parameters do not match exactly those specified at NSIDC because, in fact, they must be 1000 or 9000, depending on the grid size, in order to get the right number of rows and columns in the output image. Grid resolution is only a whole number for the polar (north or south hemisphere) grids.

ANCILLARY_DATA_PATHS is loaded from a file, pyl4c/data/files/ancillary_file_paths.yaml, which describes the location on the local file system of certain ancillary files (and naming conventions within those files):

smap_l4c_ancillary_data_file_path: "SPL4C_Vv4040_SMAP_L4_C.Ancillary.h5"
smap_l4c_1km_ancillary_data_lc_path: "MCD12Q1_M01_lc_dom_uint8"
smap_l4c_9km_ancillary_data_lc_path: "MOD12Q1_M09_lc_dom_uint8"
smap_l4c_1km_ancillary_data_x_coord_path: "SMAP_L4_C_LON_14616_x_34704_M01_flt32"
smap_l4c_1km_ancillary_data_y_coord_path: "SMAP_L4_C_LAT_14616_x_34704_M01_flt32"
smap_l4c_9km_ancillary_data_x_coord_path: "SMAP_L4_C_LON_1624_x_3856_M09_flt32"
smap_l4c_9km_ancillary_data_y_coord_path: "SMAP_L4_C_LAT_1624_x_3856_M09_flt32"
smap_l4c_9km_pft_subgrid_counts_CONUS: "SMAP_L4C_Vv4040_1km_subgrid_PFT_counts_CONUS.h5"
smap_l4c_9km_sparse_col_index: "MCD12Q1_M09land_col.uint16"
smap_l4c_9km_sparse_row_index: "MCD12Q1_M09land_row.uint16"
transcom_netcdf_path: "CarbonTracker_TransCom_and_other_regions.nc"

Functions

def parameter_mapped(name,
pft_array,
bplut=OrderedDict([('_version', '4'), ('LUE', array([[ nan, 1.71, 1.38, 1.71, 1.19, 1.95, 1.68, 2.53, 3.6 , nan]])), ('CUE', array([[ nan, 0.7 , 0.57, 0.79, 0.78, 0.65, 0.6 , 0.72, 0.71, nan]])), ('tmin', array([[ nan, 235., 230., 259., 260., 259., 251., 246., 266., nan], [ nan, 309., 303., 301., 284., 304., 302., 314., 319., nan]])), ('vpd', array([[ nan, 0.000e+00, 1.500e+01, 8.690e+02, 1.500e+03, 4.000e+00, 0.000e+00, 2.280e+02, 1.500e+03, nan], [ nan, 4.169e+03, 7.000e+03, 3.452e+03, 5.401e+03, 4.282e+03, 4.229e+03, 4.516e+03, 7.000e+03, nan]])), ('smrz', array([[ nan, -30., 18., -30., -26., 22., -30., -15., 10., nan], [ nan, 74., 26., 49., 87., 72., 76., 30., 68., nan]])), ('smsf', array([[ nan, -50., -46., -9., -50., -15., -3., -42., -49., nan], [ nan, 46., 59., 43., 53., 48., 51., 41., 30., nan]])), ('ft', array([[ nan, 0.58, 0.36, 0.55, 0.9 , 0.91, 0.85, 0.77, 1. , nan], [ nan, 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , nan]])), ('tsoil', array([[ nan, 265.04, 477.83, 238.81, 267.26, 292.82, 232.24, 263.97, 329.63, nan]])), ('decay_rates', array([[ nan, 0.027 , 0.028 , 0.028 , 0.03 , 0.015 , 0.025 , 0.019 , 0.035 , nan], [ nan, 0.0108 , 0.0112 , 0.0112 , 0.012 , 0.006 , 0.01 , 0.0076 , 0.014 , nan], [ nan, 0.000251, 0.00026 , 0.00026 , 0.000279, 0.00014 , 0.000233, 0.000177, 0.000326, nan]])), ('f_metabolic', array([[ nan, 0.49, 0.71, 0.67, 0.67, 0.62, 0.76, 0.78, 0.78, nan]])), ('f_structural', array([[ nan, 0.3 , 0.3 , 0.7 , 0.3 , 0.35, 0.55, 0.5 , 0.8 , nan]]))]))
Expand source code
def parameter_mapped(name, pft_array, bplut = BPLUT):
    '''
    Given a BPLUT parameter and a PFT array, returns an array with the
    corresponding parameter values for each PFT code.

    Parameters
    ----------
    name : str
        The name of the BPLUT parameter
    pft_array : numpy.ndarray
        Array of any size or shape with numeric elements corresponding to
        PFT codes
    bplut : dict
        (Optional) A collection of BPLUT parameters

    Returns
    -------
    numpy.ndarray
        Array of same size, shape as pft_array but with parameter values
        in place of PFT codes
    '''
    param = bplut[name]
    # Basically, index the <name> array, in PFT order, by PFT numeric codes
    return np.asarray(param)[:,np.ravel(pft_array)].reshape(pft_array.shape)

Given a BPLUT parameter and a PFT array, returns an array with the corresponding parameter values for each PFT code.

Parameters

name : str
The name of the BPLUT parameter
pft_array : numpy.ndarray
Array of any size or shape with numeric elements corresponding to PFT codes
bplut : dict
(Optional) A collection of BPLUT parameters

Returns

numpy.ndarray
Array of same size, shape as pft_array but with parameter values in place of PFT codes
def restore_bplut(csv_file_path, version_id=None)
Expand source code
def restore_bplut(csv_file_path, version_id = None):
    '''
    Translates a BPLUT CSV file to a Python internal representation
    (OrderedDict instance).

    Parameters
    ----------
    csv_file_path : str
        File path to the CSV representation of the BPLUT
    version_id : str
        (Optional) Version identifier for the BPLUT

    Returns
    -------
    OrderedDict
    '''
    contents = []
    with open(csv_file_path, 'r') as stream:
        reader = csv.DictReader(
            filter(lambda row: row[0] != '#', stream),
            fieldnames = BPLUT_HEADER)
        for row in reader:
            contents.append(row)

    result = BPLUT.copy()
    result['_version'] = 'UNKNOWN' if version_id is None else version_id
    result['LUE'] = np.array([[
        contents[p-1]['LUEmax'] if p in range(1, 9) else np.nan
        for p in range(0, 10)
    ]], dtype = np.float32).round(4)
    result['CUE'] = np.array([[
        (1 - float(contents[p-1]['fraut'])) if p in range(1, 9) else np.nan
        for p in range(0, 10)
    ]], dtype = np.float32).round(4)
    result['tmin'] = np.array([
        [contents[p-1]['Tmin_min_K'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
        [contents[p-1]['Tmin_max_K'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
    ], dtype = np.float32).round(1)
    result['vpd'] = np.array([
        [contents[p-1]['VPD_min_Pa'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
        [contents[p-1]['VPD_max_Pa'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
    ], dtype = np.float32).round(2)
    result['smrz'] = np.array([
        [contents[p-1]['SMrz_min'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
        [contents[p-1]['SMrz_max'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
    ], dtype = np.float32).round(1)
    result['smsf'] = np.array([
        [contents[p-1]['SMtop_min'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
        [contents[p-1]['SMtop_max'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
    ], dtype = np.float32).round(1)
    result['ft'] = np.array([
        [contents[p-1]['FT_min'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
        [contents[p-1]['FT_max'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
    ], dtype = np.float32).round(3)
    result['tsoil'] = np.array([[
        contents[p-1]['Tsoil_beta0'] if p in range(1, 9) else np.nan
        for p in range(0, 10)
    ]], dtype = np.float32).round(1)
    result['f_metabolic'] = np.array([[
        contents[p-1]['fmet'] if p in range(1, 9) else np.nan
        for p in range(0, 10)
    ]], dtype = np.float32).round(3)
    result['f_structural'] = np.array([[
        contents[p-1]['fstr'] if p in range(1, 9) else np.nan
        for p in range(0, 10)
    ]], dtype = np.float32).round(1)
    result['decay_rates'] = np.array([
        [contents[p-1]['kopt'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
        [contents[p-1]['kstr'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
        [contents[p-1]['kslw'] if p in range(1, 9) else np.nan
            for p in range(0, 10)],
    ], dtype = np.float32).round(3)
    # The "kstr" and "kslw" values are really the fraction of kopt
    #   assigned to the second and third pools
    result['decay_rates'][1,:] = np.multiply(
        result['decay_rates'][0,:], result['decay_rates'][1,:])
    result['decay_rates'][2,:] = np.multiply(
        result['decay_rates'][0,:], result['decay_rates'][2,:])
    return result

Translates a BPLUT CSV file to a Python internal representation (OrderedDict instance).

Parameters

csv_file_path : str
File path to the CSV representation of the BPLUT
version_id : str
(Optional) Version identifier for the BPLUT

Returns

OrderedDict
 
def restore_bplut_flat(csv_file_path, version_id=None)
Expand source code
def restore_bplut_flat(csv_file_path, version_id = None):
    '''
    Translates a BPLUT CSV file to a Python internal representation
    (OrderedDict instance). Compare to `restore_bplut()`, this version
    sets parameter values as flat lists instead of n-dimensional NumPy
    arrays.

    Parameters
    ----------
    csv_file_path : str
        File path to the CSV representation of the BPLUT
    version_id : str
        (Optional) Version identifier for the BPLUT

    Returns
    -------
    OrderedDict
    '''
    params = restore_bplut(csv_file_path, version_id)
    result = dict()
    for key, value in params.items():
        if key not in ('tmin', 'vpd', 'smsf', 'smrz', 'ft'):
            result[key] = value
            continue
        for i, array in enumerate(value.tolist()):
            result[f'{key}{i}'] = np.array(array).reshape((1,len(array)))
    return OrderedDict(result)

Translates a BPLUT CSV file to a Python internal representation (OrderedDict instance). Compare to restore_bplut(), this version sets parameter values as flat lists instead of n-dimensional NumPy arrays.

Parameters

csv_file_path : str
File path to the CSV representation of the BPLUT
version_id : str
(Optional) Version identifier for the BPLUT

Returns

OrderedDict