Skip to content

Commit c38e521

Browse files
committed
add to the readme
1 parent 3dc9023 commit c38e521

File tree

1 file changed

+111
-1
lines changed

1 file changed

+111
-1
lines changed

README.md

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ $ cd freanalysis_clouds; pip install .; cd ..
3636
$ cd freanalysis_radiation; pip install .; cd ..
3737
```
3838

39-
# Running an analysis plugin
39+
### For Workflow Developers
40+
41+
#### Running an analysis plugin
4042
In order to run a plugin, you must first create a data catalog and can then perform
4143
the analysis:
4244

@@ -57,3 +59,111 @@ reqs = plugin_requirements(name)
5759
print(reqs)
5860
run_plugin(name, "catalog.json", "pngs")
5961
```
62+
63+
### For Analysis Script Developers
64+
65+
### How to use this framework.
66+
The idea behind ths framework is to treat each analysis script as a plugin, which can
67+
be discovered dynamically by the workflow. Each analysis script is expected to be
68+
its own fully developed python package, which has a name that starts with
69+
`freanalysis_`. At runtime, the workflow will search through all of its installed
70+
python packages, looking specifically for packages whose names begin with
71+
`freanalysis_`. It will then search each of these found `freanalysis_` packages
72+
for a class that inherits from the `AnalysisScript` base class provided by the
73+
`analysis_scripts` package, and attempt to construct one of these objects.
74+
75+
### Creating A New Analysis Script For This Framework.
76+
A python package is a directory that contains an `__init__.py` file. In this example,
77+
we will make a new analysis script called `freanalysis_readme_example`. To do this,
78+
let's setup up a directory:
79+
80+
```bash
81+
freanalysis_readme_example
82+
-- README.md # Explain what this analysis script does.
83+
-- pyproject.toml # Tell python how to build/install this analysis script.
84+
-- freanalysis_readme_example # This directory is the actual python package.
85+
-- __init__.py # This file makes its parent directory a python package.
86+
```
87+
88+
Once we have this directory tree, we can fill in the necessary files.
89+
90+
91+
##### README.
92+
93+
94+
##### pyproject.toml
95+
96+
97+
##### Defining the analysis script class
98+
Custom analysis scripts classes can be created that inherit the `AnalysisScript` base
99+
class provided by the `analysis_scripts` package. Override its contructor,
100+
`requires`, and `run_analysis` methods. For example:
101+
102+
```python3
103+
from analysis_scripts import AnalysisScript
104+
105+
106+
class NewAnalysisScript(AnalysisScript):
107+
"""Analysis script for some task.
108+
109+
Attributes:
110+
description: Longer form description for the analysis.
111+
title: Title that describes the analysis.
112+
"""
113+
def __init__(self):
114+
"""Instantiates an object. The user should provide a description and title."""
115+
self.description = "This analysis does something cool."
116+
self.title = "Brief, but descriptive name for the analysis."
117+
118+
def requires(self):
119+
"""Provides metadata describing what is needed for this analysis to run.
120+
121+
Returns:
122+
A json string describing the metadata.
123+
"""
124+
return json.dumps({
125+
"settings": {
126+
"activity_id": "<fill this>",
127+
"institution_id": "<fill this>",
128+
"source_id": "<fill this>",
129+
"experiment_id": "<fill this>",
130+
"frequency": "<fill this>",
131+
"modeling_realm": "<fill this>",
132+
"table_id": "<fill this>",
133+
"member_id": "<fill this>",
134+
"grid_label": "<fill this>",
135+
"temporal_subset": "<fill this>",
136+
"chunk_freq": "<fill this>",
137+
"platform": "<fill this>",
138+
"cell_methods": "<fill this>"
139+
},
140+
"dimensions": {
141+
# These are just examples, you can put more/different ones.
142+
"lat": {"standard_name": "latitude"},
143+
"lon": {"standard_name": "longitude"},
144+
"time": {"standard_name": "time"}
145+
},
146+
"varlist": {
147+
"<fill this>": {
148+
"standard_name": "<a standard name>",
149+
"units": "<some units>",
150+
"dimensions": ["time", "lat", "lon"]
151+
},
152+
}
153+
})
154+
155+
def run_analysis(self, catalog, png_dir, reference_catalog=None):
156+
"""Runs the analysis and generates all plots and associated datasets.
157+
158+
Args:
159+
catalog: Path to a model output catalog.
160+
png_dir: Directory to store output png figures in.
161+
reference_catalog: Path to a catalog of reference data.
162+
163+
Returns:
164+
A list of png figures.
165+
"""
166+
Do some stuff to create the figures.
167+
return ["figure1.png", "figure2.png",]
168+
```
169+

0 commit comments

Comments
 (0)