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

postprocessing not working for 2-year inversions #223

Open
hdelongueville opened this issue Nov 6, 2024 · 2 comments
Open

postprocessing not working for 2-year inversions #223

hdelongueville opened this issue Nov 6, 2024 · 2 comments
Assignees

Comments

@hdelongueville
Copy link
Contributor

When running inversions with a 2-year inversion period, RHIME encounters issues during post-processing. It would be nice to have the flexibility to run inversions with any inversion period.

Traceback (most recent call last):
File "/user/home/qq24644/openghg_inversions/openghg_inversions/hbmcmc/run_hbmcmc.py", line 233, in
mcmc_function(**param)
File "/user/home/qq24644/openghg_inversions/openghg_inversions/hbmcmc/hbmcmc.py", line 550, in fixedbasisMCMC
out = mcmc.inferpymc_postprocessouts(**post_process_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/user/home/qq24644/openghg_inversions/openghg_inversions/hbmcmc/inversion_pymc.py", line 721, in inferpymc_postprocessouts
apriori_flux += flux_array_all[:, :, m] * np.sum(allmonths == m) / len(allmonths)
~~~~~~~~~~~~~~^^^^^^^^^
IndexError: index 2 is out of bounds for axis 2 with size 2

@hdelongueville
Copy link
Contributor Author

It looks like the issue comes from inferpymc_postprocessouts, where if it assumes flux prior is monthly if not annual.

    if flux_array_all.shape[2] == 1:
        print("\nAssuming flux prior is annual and extracting first index of flux array.")
        apriori_flux = flux_array_all[:, :, 0]
    else:
        print("\nAssuming flux prior is monthly.")
        print(f"Extracting weighted average flux prior from {start_date} to {end_date}")
        allmonths = pd.date_range(start_date, end_date).month[:-1].values
        allmonths -= 1  # to align with zero indexed array

        apriori_flux = np.zeros_like(flux_array_all[:, :, 0])

        # calculate the weighted average flux across the whole inversion period
        for m in np.unique(allmonths):
            apriori_flux += flux_array_all[:, :, m] * np.sum(allmonths == m) / len(allmonths)

@hdelongueville
Copy link
Contributor Author

@brendan-m-murphy I know you are working on updating the post-processing part. Do you have an opinion on the best way to solve this without interrupting your work (or maybe this will not impact what you are doing)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants