-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add coordinate criteria table in docs (#147)
* add coordinate criteria table in docs * add criteria in index * add regex table and what's new * fix make docstring
- Loading branch information
Showing
10 changed files
with
145 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
|
||
from pandas import DataFrame | ||
|
||
from cf_xarray.accessor import _AXIS_NAMES, _COORD_NAMES, coordinate_criteria, regex | ||
|
||
|
||
def main(): | ||
""" | ||
Make all additional files needed to build the documentations. | ||
""" | ||
|
||
make_criteria_csv() | ||
make_regex_csv() | ||
|
||
|
||
def make_criteria_csv(): | ||
""" | ||
Make criteria tables: | ||
_build/csv/{all,axes,coords}_criteria.csv | ||
""" | ||
|
||
csv_dir = "_build/csv" | ||
os.makedirs(csv_dir, exist_ok=True) | ||
|
||
# Criteria tables | ||
df = DataFrame.from_dict(coordinate_criteria) | ||
df = df.dropna(1, how="all") | ||
df = df.applymap(lambda x: ", ".join(sorted(x)) if isinstance(x, tuple) else x) | ||
df = df.sort_index(0).sort_index(1) | ||
|
||
# All criteria | ||
df.to_csv(os.path.join(csv_dir, "all_criteria.csv")) | ||
|
||
# Axes and coordinates | ||
for keys, name in zip([_AXIS_NAMES, _COORD_NAMES], ["axes", "coords"]): | ||
subdf = df.loc[sorted(keys)].dropna(1, how="all") | ||
subdf = subdf.dropna(1, how="all").transpose() | ||
subdf.to_csv(os.path.join(csv_dir, f"{name}_criteria.csv")) | ||
|
||
|
||
def make_regex_csv(): | ||
""" | ||
Make regex tables: | ||
_build/csv/all_regex.csv | ||
""" | ||
|
||
csv_dir = "_build/csv" | ||
os.makedirs(csv_dir, exist_ok=True) | ||
df = DataFrame(regex, index=[0]) | ||
df = df.applymap(lambda x: f"``{x}``") | ||
df = df.sort_index(1).transpose() | ||
df.to_csv(os.path.join(csv_dir, "all_regex.csv"), header=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
|
||
from cf_xarray.scripts import make_doc | ||
|
||
|
||
def remove_if_exists(paths): | ||
paths = [paths] if isinstance(paths, str) else paths | ||
for path in paths: | ||
if os.path.exists(path): | ||
os.remove(path) | ||
|
||
|
||
def test_make_doc(): | ||
|
||
# Create/remove files from tests/, | ||
# always return to original working directory | ||
owd = os.getcwd() | ||
os.chdir(os.path.dirname(__file__)) | ||
try: | ||
names = [ | ||
"axes_criteria", | ||
"coords_criteria", | ||
"all_criteria", | ||
"all_regex", | ||
] | ||
tables_to_check = [f"_build/csv/{name}.csv" for name in names] | ||
remove_if_exists(tables_to_check) | ||
|
||
make_doc.main() | ||
assert all(os.path.exists(path) for path in tables_to_check) | ||
finally: | ||
os.chdir(owd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.. currentmodule:: xarray | ||
|
||
CF Criteria | ||
----------- | ||
|
||
Attributes | ||
~~~~~~~~~~ | ||
Criteria for identifying variables using CF attributes. | ||
|
||
Axes | ||
==== | ||
|
||
.. csv-table:: | ||
:file: _build/csv/axes_criteria.csv | ||
:header-rows: 1 | ||
:stub-columns: 1 | ||
|
||
Coordinates | ||
=========== | ||
|
||
.. csv-table:: | ||
:file: _build/csv/coords_criteria.csv | ||
:header-rows: 1 | ||
:stub-columns: 1 | ||
|
||
|
||
Names | ||
~~~~~ | ||
Regex used by :meth:`DataArray.cf.guess_coord_axis` and :meth:`Dataset.cf.guess_coord_axis` for identifying variables using their names. | ||
|
||
.. csv-table:: | ||
:file: _build/csv/all_regex.csv | ||
:stub-columns: 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ Table of contents | |
:maxdepth: 2 | ||
|
||
examples/introduction | ||
criteria | ||
whats-new | ||
roadmap | ||
contributing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters