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

Ensure flux dims order #128

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

# Version 0.2.0


- added work-around for error in post-processing caused by the order of the flux dimensions deviating from 'lat', 'lon', 'time'. [#PR 128](https://github.com/openghg/openghg_inversions/pull/128)

- removed `julian2time` function from `convert.py` because it used code that was deprecated by `matplotlib`. This function is still available at `github.com/ACRG-Bristol/acrg/acrg/time/convert.py`. [#PR 129](https://github.com/openghg/openghg_inversions/pull/129)

- `met_model` is now used by `data_processing_surface_notracer`; it is an optional argument, passed as a list with the same length as the number of sites. [#PR 125](https://github.com/openghg/openghg_inversions/pull/125)
Expand Down
9 changes: 9 additions & 0 deletions openghg_inversions/hbmcmc/inversion_pymc.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,15 @@ def inferpymc_postprocessouts(
emds = fp_data[".flux"][emissions_name[0]]
flux_array_all = emds.data.flux.values

# HACK: assume that smallest flux dim is time, then re-order flux so that
# time is the last coordinate
flux_dim_shape = flux_array_all.shape
flux_dim_positions = range(len(flux_dim_shape))
smallest_dim_position = min(list(zip(flux_dim_positions, flux_dim_shape)), key=(lambda x: x[1]))[0]

flux_array_all = np.moveaxis(flux_array_all, smallest_dim_position, -1)
# end HACK

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]
Expand Down
9 changes: 6 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,19 @@ def session_config_mocker(using_zarr_store) -> Iterator[None]:
# "metmodel": "ukv",
}
flux_metadata = {"species": "ch4", "source": "total-ukghg-edgar7", "domain": "europe"}
flux_dim_shuffle_metadata = {"species": "ch4", "source": "total-ukghg-edgar7-shuffled", "domain": "europe"}

obs_data_path = _raw_data_path / "obs_tac_ch4_185m_2019-01-01_2019-02-01_data.nc"
bc_data_path = _raw_data_path / "bc_ch4_europe_cams_2019-01-01_2019-12-31_data.nc"
footprints_data_path = _raw_data_path / "footprints_tac_europe_name_185m_2019-01-01_2019-01-07_data.nc"
flux_data_path = _raw_data_path / "flux_total_ch4_europe_edgar7_2019-01-01_2019-12-31_data.nc"
flux_dim_shuffled_data_path = _raw_data_path / "flux_total_ch4_europe_edgar7_2019-01-01_2019-12-31_data_dim_shuffled.nc"

data_info = {
"surface": [standardise_surface, obs_metadata, obs_data_path],
"boundary_conditions": [standardise_bc, bc_metadata, bc_data_path],
"emissions": [standardise_flux, flux_metadata, flux_data_path],
"flux": [standardise_flux, flux_metadata, flux_data_path],
"flux_dim_shuffle": [standardise_flux, flux_dim_shuffle_metadata, flux_dim_shuffled_data_path],
"footprints": [standardise_footprint, footprints_metadata, footprints_data_path],
}

Expand All @@ -128,7 +131,7 @@ def session_object_store(session_config_mocker) -> None:
add_data = True
found_dtypes = []
else:
add_data = results.results.shape[0] != 4
add_data = results.results.shape[0] != 5
try:
found_dtypes = results.results["data_type"].to_list()
except KeyError:
Expand All @@ -137,7 +140,7 @@ def session_object_store(session_config_mocker) -> None:
# check if there are four pieces of data in the object store
# if not, add the missing data
if add_data:
to_add = set(["surface", "boundary_conditions", "emissions", "footprints"]) - set(found_dtypes)
to_add = set(["surface", "boundary_conditions", "flux", "flux_dim_shuffle", "footprints"]) - set(found_dtypes)

for dtype in to_add:
standardise_fn = data_info[dtype][0]
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/test_full_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def test_full_inversion(mcmc_args):
fixedbasisMCMC(**mcmc_args)


def test_full_inversion_flux_dim_shuffled(mcmc_args):
mcmc_args["emissions_name"] = ["total-ukghg-edgar7-shuffled"]
fixedbasisMCMC(**mcmc_args)


def test_full_inversion_with_min_error_calc(mcmc_args):
mcmc_args["calculate_min_error"] = True
out = fixedbasisMCMC(**mcmc_args)
Expand All @@ -40,9 +45,11 @@ def test_full_inversion_with_min_error_calc(mcmc_args):
def test_full_inversion_pblh_filter(mcmc_args):
mcmc_args["filters"] = ["pblh"]


def test_full_inversion_pblh_min_filter(mcmc_args):
mcmc_args["filters"] = ["pblh_min"]


def test_full_inversion_pblh_inlet_diff_filter(mcmc_args):
mcmc_args["filters"] = ["pblh_inlet_diff"]

Expand Down
Loading