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

MDA8 timestamp and superfluous values #1265

Merged
merged 6 commits into from
Jul 15, 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
17 changes: 17 additions & 0 deletions pyaerocom/stats/mda8/mda8.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

import numpy as np
import pandas as pd
import xarray as xr

from pyaerocom.colocation.colocated_data import ColocatedData
Expand Down Expand Up @@ -49,6 +50,7 @@ def mda8_colocated_data(coldat: ColocatedData, /, obs_var: str, mod_var: str) ->
cd = ColocatedData(_calc_mda8(coldat.data))
cd.data.attrs["var_name"] = [obs_var, mod_var]
cd.metadata["var_name_input"] = [obs_var, mod_var]

return cd


Expand Down Expand Up @@ -76,9 +78,24 @@ def _calc_mda8(data: xr.DataArray) -> xr.DataArray:
> ends i.e. the first calculation period for any one day will be the period from
> 17:00 on the previous day to 01:00 on that day; the last calculation period for
> any one day will be the period from 16:00 to 24:00 on that day.

Note:
-----
Calculated values will only be returned for days which have at least one datapoint
in the input dataarray to ensure that the ts does not expand.
"""
mda8 = _daily_max(_rolling_average_8hr(data))

mda8.attrs["ts_type"] = "daily"

# Ensure time dimension represents the midpoint of the interval.
mda8.coords.update({"time": mda8.get_index("time") + pd.tseries.frequencies.to_offset("12h")})

# Keep only values for days that existed in the original time series.
mda8 = mda8.sel(
time=np.isin(mda8.coords["time.date"].values, np.unique(data.coords["time.date"].values))
)
heikoklein marked this conversation as resolved.
Show resolved Hide resolved

return mda8


Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_readgridded.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_file_info(reader_reanalysis: ReadGridded):
@lustre_unavail
def test_years_available(reader_reanalysis: ReadGridded):
# go up to 2023 because 2022 is now available. Will likely need to be updated in the future
years = list(range(2003, 2024))
years = list(range(2003, 2025))
assert reader_reanalysis.years_avail == years


Expand Down
4 changes: 1 addition & 3 deletions tests/stats/mda8/test_mda8.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ def test_coldata_to_mda8(coldata):
assert isinstance(mda8, ColocatedData)
assert mda8.metadata["ts_type"] == "daily"
assert mda8.metadata["var_name"] == ["vmro3mda8", "vmro3mda8"]
assert mda8.shape == (2, 9, 1)
assert mda8.shape == (2, 8, 1)

assert mda8.data.values[0, :, 0] == pytest.approx(
[
np.nan,
np.nan,
np.nan,
1.18741556,
Expand All @@ -109,7 +108,6 @@ def test_coldata_to_mda8(coldata):

assert mda8.data.values[1, :, 0] == pytest.approx(
[
np.nan,
1.57327333,
1.28884431,
1.28741556,
Expand Down
Loading