Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to FatesPFTIndexSwapper.py #451

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions tools/FatesPFTIndexSwapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# =======================================================================================

pft_dim_name = 'fates_pft'
prt_dim_name = 'fates_prt_organs'


class timetype:
Expand Down Expand Up @@ -161,19 +162,23 @@ def main(argv):

# Idenfity if this variable has pft dimension
pft_dim_found = -1
prt_dim_found = -1
pft_dim_len = len(fp_in.variables.get(key).dimensions)

for idim, name in enumerate(fp_in.variables.get(key).dimensions):
# Manipulate data
if(name==pft_dim_name):
pft_dim_found = idim

if(name==prt_dim_name):
prt_dim_found = idim


# Copy over the input data
# Tedious, but I have to permute through all combinations of dimension position
if( pft_dim_len == 0 ):
out_var = fp_out.createVariable(key,'f',(fp_in.variables.get(key).dimensions))
out_var.assignValue(float(fp_in.variables.get(key).data))
elif(pft_dim_found==-1):
elif( (pft_dim_found==-1) & (prt_dim_found==-1) ):
out_var = fp_out.createVariable(key,'f',(fp_in.variables.get(key).dimensions))
out_var[:] = in_var[:]
elif( (pft_dim_found==0) & (pft_dim_len==1) ): # 1D fates_pft
Expand All @@ -183,8 +188,9 @@ def main(argv):
tmp_out[id] = fp_in.variables.get(key).data[ipft-1]
out_var[:] = tmp_out


elif( (pft_dim_found==1) & (pft_dim_len==2) ): # 2D hdyro_organ - fate_pft
# 2D hydro_organ - fates_pft
# or.. prt_organ - fates_pft
elif( (pft_dim_found==1) & (pft_dim_len==2) ):
out_var = fp_out.createVariable(key,'f',(fp_in.variables.get(key).dimensions))
dim2_len = fp_in.dimensions.get(fp_in.variables.get(key).dimensions[0])
tmp_out = np.zeros([dim2_len,num_pft_out])
Expand All @@ -200,6 +206,12 @@ def main(argv):
for id,ipft in enumerate(donor_pft_indices):
out_var[id] = fp_in.variables.get(key).data[ipft-1]


elif( (prt_dim_found==0) & (pft_dim_len==2) ): # fates_prt_organs - string_length
out_var = fp_out.createVariable(key,'c',(fp_in.variables.get(key).dimensions))
out_var[:] = in_var[:]


else:
print('This variable has a dimensioning that we have not considered yet.')
print('Please add this condition to the logic above this statement.')
Expand Down