-
Notifications
You must be signed in to change notification settings - Fork 0
Add data API tutorial #52
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b0dbf9a
Add data API tutorial
daniel-thom 5ffebc0
Add how-tos
daniel-thom 40b948d
Update links to data api documentation. Clarify setting environment v…
elainethale d2e7cec
Tweaks to the TOC titles and ordering.
elainethale 6212a18
Update related topic links at the bottom of explanations.
elainethale 6c15afd
Edited how-tos for accuracy.
elainethale 3ceb1b9
Minor edits.
elainethale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| (compare-scenarios)= | ||
| # Compare Scenarios | ||
|
|
||
| Programmatically query and compare results across scenarios. | ||
|
|
||
| ## Load the Project | ||
|
|
||
| ```python | ||
| from stride import Project | ||
| from stride.api import APIClient | ||
|
|
||
| project = Project.load("my_project") | ||
| client = APIClient(project) | ||
| ``` | ||
|
|
||
| ## Query Multiple Scenarios | ||
|
|
||
| ```python | ||
| baseline = client.get_total_consumption(scenario="baseline") | ||
| high_growth = client.get_total_consumption(scenario="high_growth") | ||
| ``` | ||
|
|
||
| ## Calculate Differences | ||
|
|
||
| ```python | ||
| import pandas as pd | ||
|
|
||
| comparison = pd.merge( | ||
| baseline, high_growth, | ||
| on=["geography", "model_year"], | ||
| suffixes=("_baseline", "_high_growth") | ||
| ) | ||
| comparison["difference"] = ( | ||
| comparison["value_high_growth"] - comparison["value_baseline"] | ||
| ) | ||
| comparison["pct_difference"] = ( | ||
| comparison["difference"] / comparison["value_baseline"] * 100 | ||
| ) | ||
| ``` | ||
|
|
||
| ## Visualize the Comparison | ||
|
|
||
| ```python | ||
| import plotly.express as px | ||
|
|
||
| fig = px.scatter( | ||
| comparison, | ||
| x="model_year", | ||
| y="pct_change", | ||
| color="geography", | ||
| title="Consumption Change: High Growth vs Baseline" | ||
| ) | ||
| fig.show() | ||
| ``` | ||
|
|
||
| ## See also | ||
|
|
||
| - {ref}`data-api-tutorial` for more examples. | ||
| - {ref}`launch-dashboard` for the visualization UI. | ||
This file contains hidden or 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,53 @@ | ||
| (customize-palette)= | ||
| # Customize the Color Palette | ||
|
|
||
| Create consistent colors for visualizations. | ||
|
|
||
| ## View Available Palettes | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride palette list | ||
| ``` | ||
|
|
||
| ## Preview a Palette | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride palette view my_project | ||
| ``` | ||
|
|
||
| ## Create a Custom Palette | ||
|
|
||
| Initialize a palette configuration file: | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride palette init my_project | ||
| ``` | ||
|
|
||
| This creates a JSON file you can edit to assign colors to scenarios, geographies, or other dimensions. | ||
|
|
||
| ## Set the Default Palette | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride palette set-default my_project custom_palette | ||
| ``` | ||
|
|
||
| ## Reset to Default | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride palette get-default my_project | ||
| ``` |
This file contains hidden or 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,147 @@ | ||
| (download-datasets)= | ||
| # Download Datasets | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - STRIDE installed and available in your environment | ||
| - For private repositories: GitHub CLI (`gh`) installed and authenticated | ||
|
|
||
| ## List available datasets | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride datasets list-remote | ||
| ``` | ||
|
|
||
| ## Download a known dataset | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride datasets download global | ||
| ``` | ||
|
|
||
| This downloads to ``~/.stride/data`` (or ``STRIDE_DATA_DIR`` if set). Both the full dataset | ||
| and its test subset are downloaded automatically. | ||
|
|
||
| ## Specify a version | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride datasets download global -v v0.2.0 | ||
| ``` | ||
|
|
||
| ## Specify a data directory | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride datasets download global -d /path/to/data | ||
| ``` | ||
|
|
||
| Or set the environment variable: | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. tabs:: | ||
|
|
||
| .. code-tab:: bash Mac/Linux | ||
|
|
||
| $ export STRIDE_DATA_DIR=/path/to/data | ||
|
|
||
| .. code-tab:: bash Windows Command Prompt | ||
|
|
||
| $ set STRIDE_DATA_DIR=/path/to/data | ||
|
|
||
| .. code-tab:: powershell Windows PowerShell | ||
|
|
||
| $ $Env:STRIDE_DATA_DIR = "/path/to/data" | ||
| ``` | ||
|
|
||
| ## Download from a custom repository | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ stride datasets download --url https://github.com/owner/repo --subdirectory data | ||
| ``` | ||
|
|
||
| ```{eval-rst} | ||
| .. note:: | ||
| The ``--subdirectory`` option is required when using ``--url``. | ||
| ``` | ||
|
|
||
| ## Private repositories | ||
|
|
||
| Authenticate with GitHub CLI first: | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ gh auth login | ||
| ``` | ||
|
|
||
| ## Alternative: Clone directly | ||
|
|
||
| If ``gh`` is not available: | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. tabs:: | ||
|
|
||
| .. code-tab:: bash Mac/Linux | ||
|
|
||
| $ git clone https://github.com/dsgrid/stride-data.git | ||
| $ export STRIDE_DATA_DIR=/path/to/stride-data | ||
|
|
||
| .. code-tab:: bash Windows Command Prompt | ||
|
|
||
| $ git clone https://github.com/dsgrid/stride-data.git | ||
| $ set STRIDE_DATA_DIR=/path/to/stride-data | ||
|
|
||
| .. code-tab:: powershell Windows PowerShell | ||
|
|
||
| $ git clone https://github.com/dsgrid/stride-data.git | ||
| $ $Env:STRIDE_DATA_DIR = "/path/to/stride-data" | ||
| ``` | ||
|
|
||
| Or copy to the default location: | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ git clone https://github.com/dsgrid/stride-data.git | ||
| $ mkdir -p ~/.stride/data | ||
| $ cp -r stride-data/global ~/.stride/data/ | ||
| $ cp -r stride-data/global-test ~/.stride/data/ | ||
| ``` | ||
|
|
||
| ## Background | ||
|
|
||
| Known datasets are hosted in the public [stride-data](https://github.com/dsgrid/stride-data) | ||
| repository. The ``list-remote`` command displays each dataset's name, repository, subdirectory, | ||
| description, and available versions. Datasets may have an associated test subset (shown as | ||
| ``test_subdirectory``) which is downloaded automatically alongside the main dataset. | ||
|
|
||
| For private repositories, STRIDE uses GitHub CLI authentication. Check your authentication | ||
| status with: | ||
|
|
||
| ```{eval-rst} | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ gh auth status | ||
| ``` | ||
|
|
||
| ## Learn more | ||
|
|
||
| - {ref}`cli-reference` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if this is uninteresting.