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

Automatic list with overviews of inlcuded area definitions for the documentation #2167

Merged
merged 21 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ doc/source/_build/*
satpy/version.py
doc/source/api/*.rst
doc/source/reader_table.rst
doc/source/area_def_list.rst
51 changes: 51 additions & 0 deletions doc/source/area_def_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2022 Satpy developers
#
# This file is part of satpy.
#
# satpy is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# satpy is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with satpy. If not, see <http://www.gnu.org/licenses/>.
"""Module for autogenerating a list and overview of available area definitions ."""

from pyresample.area_config import _read_yaml_area_file_content
from pyresample.formatting_html import area_repr

from satpy.resample import get_area_def, get_area_file


def generate_area_def_list():
"""Create list of available area definitions with overview plot.

Returns:
str
"""
area_list = []

template = ("{area_name}\n"
"{n:->{header_title_length}}\n\n"
".. raw:: html\n\n"
"{content}\n\n"
" <hr>\n\n")

area_file = get_area_file()[0]
for aname in list(_read_yaml_area_file_content(area_file).keys()):
area = get_area_def(aname)
if hasattr(area, "_repr_html_"):
content = "\n".join([x.rjust(len(x) + 5) for x in area_repr(area, include_header=False).split("\n")])
area_list.append(template.format(area_name=aname, n="", header_title_length=len(aname),
content=content))
else:
pass
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this function rather belong to pyresample?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it doesn't really make sense to include in in pyresample because there is no area definition yaml included and this is only useful to generate a rst with a list of area definitions for the documentation.

Copy link
Member

Choose a reason for hiding this comment

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

It is true that pyresample does not have a default yaml file, but it is pyresample that contains all the functions for reading such yaml files. And also, I would argue that for the sake of separation of concerns, it should be included there.
In practice, I wouldn't be against having a default yaml file with a few generic areas in pyresample by the way, that would probably help potential pyresample users in the future...

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't areas.yaml fit better with pyresample entirely? But pyresample does not have a concept of SATPY_CONFIG_PATH or a config directory search, so it wouldn't know where to find areas.yaml anyway?

Copy link
Member

Choose a reason for hiding this comment

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

Not that anyone asked for my opinion, but I agree with wanting this in pyresample. I'm not a big fan of a default set of areas in pyresample except only as a few examples (like global lon/lat, one LCC, one polar-stereographic, etc)...generic areas. Pyresample is the low-level functionality, but it doesn't know anything about satellite-specific areas or that it is used for "science" at all so to me it is a fine line.

Copy link
Member

Choose a reason for hiding this comment

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

A while ago, I found a small list of generic areas, like europe, north and south america, etc. I'll try to find it again, so we can use that.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

As far as I see, those are just area names without defining anything AreaDefinitiony that we could use.


return "".join(area_list)
4 changes: 4 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
sys.path.append(os.path.abspath('../../'))
sys.path.append(os.path.abspath(os.path.dirname(__file__)))

from area_def_list import generate_area_def_list # noqa: E402
from reader_table import generate_reader_table # noqa: E402

# The version info for the project you're documenting, acts as replacement for
Expand Down Expand Up @@ -80,6 +81,9 @@ def __getattr__(cls, name):
with open("reader_table.rst", mode="w") as f:
f.write(generate_reader_table())

with open("area_def_list.rst", mode="w") as f:
f.write(generate_area_def_list())

# -- General configuration -----------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be extensions
Expand Down
7 changes: 6 additions & 1 deletion satpy/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@

For examples of area definitions, see the file ``etc/areas.yaml`` that is
included with Satpy and where all the area definitions shipped with Satpy are
defined.
defined. The section below gives an overview of these area definitions.

Area definitions included in Satpy
----------------------------------

.. include:: area_def_list.rst

"""
import hashlib
Expand Down