Skip to content

Commit

Permalink
Added pyl4c.data.fixtures.restore_bplut_flat()
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-e committed May 6, 2023
1 parent e8ff7c9 commit 502ca99
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion pyl4c/data/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def parameter_mapped(name, pft_array, bplut = BPLUT):
'''
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)
return np.asarray(param)[:,np.ravel(pft_array)].reshape(pft_array.shape)


def restore_bplut(csv_file_path, version_id = None):
Expand Down Expand Up @@ -306,3 +306,32 @@ def restore_bplut(csv_file_path, version_id = None):
result['decay_rates'][2,:] = np.multiply(
result['decay_rates'][0,:], result['decay_rates'][2,:])
return result


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}'] = array
return OrderedDict(result)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pyl4c
version = 0.15.1
version = 0.16.0
author = K. Arthur Endsley
author_email = [email protected]
description = Python tools for working with SMAP L4C data
Expand Down

0 comments on commit 502ca99

Please sign in to comment.