openghg / openghg_inversions

University of Bristol Atmospheric Chemistry Research Group RHIME Inversion code (with openghg dependency)
MIT License
5 stars 0 forks source link

Inversion fails when a whole month of footprint is missing for a site #196

Closed alexdanjou closed 3 months ago

alexdanjou commented 3 months ago

Some footprints are missing a whole month (e.g. GAT, inert species, november 2019 on _shared_storezarr object store on BC4 at ACRG.) between the supposed start_date and end_date registered in the object store metatdata. The object stores should not have such holes, however it does and it causes the following error for the precited case :

Traceback (most recent call last):
  File "/user/home/bq24992/openghg_inversions/openghg_inversions/hbmcmc/run_hbmcmc.py", line 233, in <module>
    mcmc_function(**param)
  File "/user/home/bq24992/openghg_inversions/openghg_inversions/hbmcmc/hbmcmc.py", line 303, in fixedbasisMCMC
    ) = get_data.data_processing_surface_notracer(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/bq24992/openghg_inversions/openghg_inversions/get_data.py", line 375, in data_processing_surface_notracer
    scenario_combined = model_scenario.footprints_data_merge()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/bq24992/openghg/openghg/analyse/_scenario.py", line 1578, in footprints_data_merge
    combined_dataset = self.combine_obs_footprint(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/bq24992/openghg/openghg/analyse/_scenario.py", line 805, in combine_obs_footprint
    aligned_obs, aligned_footprint = self._align_obs_footprint(resample_to=resample_to, platform=platform)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/bq24992/openghg/openghg/analyse/_scenario.py", line 712, in _align_obs_footprint
    footprint_startdate = Timestamp(footprint_data.time[0].values)
                                    ~~~~~~~~~~~~~~~~~~~^^^
  File "/user/home/bq24992/.local/lib/python3.12/site-packages/xarray/core/dataarray.py", line 876, in __getitem__
    return self.isel(indexers=self._item_key_to_dict(key))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/bq24992/.local/lib/python3.12/site-packages/xarray/core/dataarray.py", line 1509, in isel
    variable = self._variable.isel(indexers, missing_dims=missing_dims)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/bq24992/.local/lib/python3.12/site-packages/xarray/core/variable.py", line 1033, in isel
    return self[key]
           ~~~~^^^^^
  File "/user/home/bq24992/.local/lib/python3.12/site-packages/xarray/core/variable.py", line 800, in __getitem__
    data = indexing.apply_indexer(indexable, indexer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/bq24992/.local/lib/python3.12/site-packages/xarray/core/indexing.py", line 1029, in apply_indexer
    return indexable[indexer]
           ~~~~~~~~~^^^^^^^^^
  File "/user/home/bq24992/.local/lib/python3.12/site-packages/xarray/core/indexing.py", line 1785, in __getitem__
    result = self.array[key]
             ~~~~~~~~~~^^^^^
  File "/user/home/bq24992/micromamba/envs/openghg_inv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 5389, in __getitem__
    return getitem(key)
           ^^^^^^^^^^^^
  File "/user/home/bq24992/micromamba/envs/openghg_inv/lib/python3.12/site-packages/pandas/core/arrays/datetimelike.py", line 381, in __getitem__
    result = cast("Union[Self, DTScalarOrNaT]", super().__getitem__(key))
                                                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/user/home/bq24992/micromamba/envs/openghg_inv/lib/python3.12/site-packages/pandas/core/arrays/_mixins.py", line 284, in __getitem__
    result = self._ndarray[key]
             ~~~~~~~~~~~~~^^^^^
IndexError: index 0 is out of bounds for axis 0 with size 0

Small fix would be to check that time dimension is not empty when retrieving the footprints data.

alexdanjou commented 3 months ago

Closed with #195