ACRG-Bristol / acrg

Repository containing ACRG analysis code
MIT License
8 stars 0 forks source link

make_paris_outputs fails for hfo1234yf #179

Open joe-pitt opened 3 months ago

joe-pitt commented 3 months ago

Describe the bug make_paris_outputs fails for inversion runs that used species-specific hfo1234yf fps. It works fine for hfo1234yf runs that used inert footprints, and it also works fine for runs using species-specific fps for hcfo1233zde. I have put the relevant runs on BP1 in the following directory: /group/chem/acrg/joe_hfo_output/24.06.1

To Reproduce python ~/acrg/acrg/paris_formatting/make_paris_outputs.py \ -s hfo1234yf \ -r /group/chem/acrg/joe_hfo_output/24.06.1/pop_base \ -t RHIME_NAME_EUROPE_POPULATION_hfo1234yf_yearly \ -c /group/chem/acrg/PARIS_results_sharing/country_masks/country_EUROPE_EEZ_PARIS_gapfilled.nc \ -p "4h" \ -o /group/chem/acrg/joe_hfo_output/24.06.1 \ --pol-obs

Output Traceback (most recent call last): File "/user/home/zh21490/acrg/acrg/paris_formatting/make_paris_outputs.py", line 401, in emissions, concentrations = main( ^^^^^ File "/user/home/zh21490/acrg/acrg/paris_formatting/make_paris_outputs.py", line 271, in main country_output = make_country_output(species, inv_outs, countries, report_mode=report_em_mode) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/user/home/zh21490/acrg/acrg/paris_formatting/make_paris_outputs.py", line 93, in make_country_output countries.get_country_trace(species, inv_out).expand_dims({"time": [time_func(inv_out)]}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/user/home/zh21490/acrg/acrg/paris_formatting/countries.py", line 140, in get_country_trace x_to_country_mat = self.get_x_to_country_mat(inv_out) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/user/home/zh21490/acrg/acrg/paris_formatting/countries.py", line 94, in get_x_to_country_mat result = sparse_xr_dot(self.matrix, self.area_grid inv_out.flux inv_out.basis)


  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/_typed_ops.py", line 252, in __mul__
    return self._binary_op(other, operator.mul)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/dataarray.py", line 4720, in _binary_op
    self, other = align(self, other, join=align_type, copy=False)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/alignment.py", line 882, in align
    aligner.align()
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/alignment.py", line 582, in align
    self.reindex_all()
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/alignment.py", line 557, in reindex_all
    self.results = tuple(
                   ^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/alignment.py", line 558, in <genexpr>
    self._reindex_one(obj, matching_indexes)
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/alignment.py", line 546, in _reindex_one
    return obj._reindex_callback(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/dataarray.py", line 1890, in _reindex_callback
    reindexed = ds._reindex_callback(
                ^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/dataset.py", line 3478, in _reindex_callback
    reindexed_vars = alignment.reindex_variables(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/alignment.py", line 86, in reindex_variables
    new_var = var[indxr]
              ~~~^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/variable.py", line 800, in __getitem__
    data = indexing.apply_indexer(indexable, indexer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/indexing.py", line 1024, in apply_indexer
    return indexable.oindex[indexer]
           ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/indexing.py", line 366, in __getitem__
    return self.getter(key)
           ^^^^^^^^^^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/xarray/core/indexing.py", line 1501, in _oindex_get
    return self.array[key]
           ~~~~~~~~~~^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/sparse/_coo/indexing.py", line 74, in getitem
    mask, adv_idx = _mask(x.coords, index, x.shape)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/zh21490/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/sparse/_coo/indexing.py", line 152, in _mask
    raise IndexError("Only one-dimensional iterable indices supported.")
IndexError: Only one-dimensional iterable indices supported.
joe-pitt commented 3 months ago

From discussion with Brendan: basis functions in the inversion output are aligned with the footprint, whereas the flux is not. So we need to align the flux with the basis functions in make_paris_outputs before multiplying them