Skip to content

Commit

Permalink
Merge pull request #1313 from metno/emep-long-trends
Browse files Browse the repository at this point in the history
Allow trends to run even if a component does not have any data due to min_yrs constraints
  • Loading branch information
heikoklein authored Aug 21, 2024
2 parents 7c6d8b8 + 2e9608f commit 0277ed6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyaerocom/aeroval/coldatatojson_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def process_coldata(self, coldata: ColocatedData):
)
if min_yrs > 0:
logger.info(
f"Removing stations with less than {min_yrs} years of continuous data, with sequential_yrs = {sequential_yrs}"
f"Removing stations with less than {min_yrs} years of data, with sequential_yrs = {sequential_yrs}"
)
coldata = _remove_less_covered(coldata, min_yrs, sequential_yrs)

Expand Down
7 changes: 3 additions & 4 deletions pyaerocom/aeroval/coldatatojson_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1662,15 +1662,14 @@ def _remove_less_covered(
max_yrs = _find_n_yrs(years)

if min_yrs > max_yrs:
print(f"Dropping {s}; It has only {max_yrs}")
logging.info(f"Dropping {s}; It has only {max_yrs}")
logger.info(f"Dropping {s}; It has only {max_yrs}")
data.data = data.data.drop_sel(station_name=s)

new_stations = data.data.station_name.data

print(f"Removed {len(stations)-len(new_stations)} stations")
logger.info(f"Removed {len(stations)-len(new_stations)} stations")
if len(new_stations) == 0:
raise TrendsError(
logger.warning(
f"No stations left after removing stations with fewer than {min_yrs} years!"
)

Expand Down
4 changes: 3 additions & 1 deletion pyaerocom/geodesy.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def get_country_info_coords(coords):
# (more a list of this)
ret_proto = {"city": "", "country_code": "", "code": ""}

if isnumeric(coords[0]) and len(coords) == 2: # only one coordinate
if len(coords) == 0: # no coordinates
pass
elif isnumeric(coords[0]) and len(coords) == 2: # only one coordinate
lat, lon = coords
try:
dummy = geo.lookup(lat, lon)
Expand Down
6 changes: 3 additions & 3 deletions tests/aeroval/test_coldatatojson_helpers2.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test__remove_less_covered(
assert len(new_stations) == station_nb


def test__remove_less_covered_error():
def test__remove_less_covered_all():
cd = COLDATA["fake_3d_partial_trends_coltime"]()
with pytest.raises(TrendsError, match="No stations left"):
_remove_less_covered(cd, 1000)
new_cd = _remove_less_covered(cd, 1000)
assert new_cd.data.station_name.shape[0] == 0

0 comments on commit 0277ed6

Please sign in to comment.