inaos / iron-array

2 stars 0 forks source link

Honor the favor flag during operations #419

Closed FrancescAlted closed 3 years ago

FrancescAlted commented 3 years ago

The next describes the issue:

ia.set_config(favor=ia.Favors.SPEED)
precip_mean = (precip1_sp + precip2_sp + precip3_sp) / 3
precip_mean_speed = precip_mean.eval()
print(f"{precip_mean_speed.cratio:.2f}")    # prints 3.91

ia.set_config(favor=ia.Favors.CRATIO)
precip_mean = (precip1_sp + precip2_sp + precip3_sp) / 3
precip_mean_cr = precip_mean.eval()
print(f"{precip_mean_cr.cratio:.2f}")  # prints 3.91

ia.set_config(favor=ia.Favors.CRATIO, clevel=5, codec=ia.Codecs.ZSTD, filters=[ia.Filters.BITSHUFFLE])
precip_mean = (precip1_sp + precip2_sp + precip3_sp) / 3
precip_mean_cr2 = precip_mean.eval()
print(f"{precip_mean_cr2.cratio:.2f}")  #  prints 8.71, which should be the correct value for favor=CRATIO in the second case above
aleixalcacer commented 3 years ago

To fix it you can reset the config after each evaluation:

ia.set_config(...)
precip_mean = (precip1_sp + precip2_sp + precip3_sp) / 3
precip_mean_cr = precip_mean.eval()
print(f"{precip_mean_cr.cratio:.2f}")
ia.reset_config_defaults()

But a better option is to use the with statement:

with ia.config(...):
    precip_mean = (precip1_sp + precip2_sp + precip3_sp) / 3
    precip_mean_speed = precip_mean.eval()
    print(f"{precip_mean_speed.cratio:.2f}")