Skip to content
Open
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
34 changes: 34 additions & 0 deletions satpy/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Utility functions for area definitions."""
import warnings

from pyresample.area_config import AreaNotFound, _create_area_def_from_dict, _read_yaml_area_file_content

from ._config import config_search_paths, get_config_path


Expand All @@ -29,7 +33,37 @@ def get_area_file():
else:
return get_config_path("areas.def")

def deprecate_area_name(fun):
"""Decorator to deprecate area names.

This function is used to retire area names or warn about changed area names.
"""
def area_with_new_name(area_name):
try:
return fun(area_name)
except AreaNotFound:
area_file_name = get_area_file()
areas_dict = _read_yaml_area_file_content(area_file_name)
area_dict = None
for new_area_name, v in areas_dict.items():

if "old_name" in v.keys() and area_name in v["old_name"]:# == area_name:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment should be removed.

area_dict = areas_dict.get(new_area_name)
del area_dict["old_name"]
break

if area_dict is not None:
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(f"This area name is being deprecated in Satpy v1.0. Pleas use the new area name:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warnings.warn(f"This area name is being deprecated in Satpy v1.0. Pleas use the new area name:"
warnings.warn(f"This area name is being deprecated in Satpy v1.0. Please use the new area name:"

f" {new_area_name}", DeprecationWarning, stacklevel=2)
warnings.simplefilter("default", DeprecationWarning)
Comment on lines +56 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the warnings.catch_warnings context manager, so any previously existing user settings are not lost.

return _create_area_def_from_dict(new_area_name, area_dict)
else:
raise AreaNotFound('Area "{0}" not found in file "{1}"'.format(area_name, area_file_name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be easier to read with an f-strring.


return area_with_new_name

@deprecate_area_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it confusing to define a decorator that is used exactly once and unlikely to be reused elsewhere. Wouldn't it be clearer to simply integrate this into get_area_def, then refactoring that function if it becomes too large?

def get_area_def(area_name):
"""Get the definition of *area_name* from file.

Expand Down
Loading
Loading