Skip to content

Commit

Permalink
Merge branch 'main' into all-contributors/add-tom-andersson
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-andersson authored Oct 12, 2023
2 parents f780d57 + 6beae81 commit 966476e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
{
"projectName": "deepsensor",
"projectOwner": "tom-andersson",
"skipCI": true,
"files": [
"README.md"
],
"commitType": "docs",
"commitConvention": "angular",
"contributorsPerLine": 7,
"contributorsSortAlphabetically": true,
"contributors": [
{
"login": "kallewesterling",
"name": "Kalle Westerling",
"avatar_url": "https://avatars.githubusercontent.com/u/7298727?v=4",
"profile": "http://www.westerling.nu",
"contributions": [
"code",
"doc"
]
},
{
"login": "tom-andersson",
"name": "Tom Andersson",
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: nikeee/setup-pandoc@v1
- name: "Install dependencies"
run: pip install -r requirements.txt
- name: "Install sphinx"
Expand All @@ -23,4 +24,4 @@ jobs:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build/
force_orphan: true
force_orphan: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ DeepSensor is funded by [The Alan Turing Institute](https://www.turing.ac.uk/).
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://www.bas.ac.uk/profile/tomand"><img src="https://avatars.githubusercontent.com/u/26459412?v=4?s=100" width="100px;" alt="Tom Andersson"/><br /><sub><b>Tom Andersson</b></sub></a><br /><a href="#code-tom-andersson" title="Code">💻</a> <a href="#research-tom-andersson" title="Research">🔬</a> <a href="#maintenance-tom-andersson" title="Maintenance">🚧</a> <a href="#bug-tom-andersson" title="Bug reports">🐛</a> <a href="#test-tom-andersson" title="Tests">⚠️</a> <a href="#tutorial-tom-andersson" title="Tutorials">✅</a> <a href="#doc-tom-andersson" title="Documentation">📖</a> <a href="#review-tom-andersson" title="Reviewed Pull Requests">👀</a> <a href="#talk-tom-andersson" title="Talks">📢</a> <a href="#question-tom-andersson" title="Answering Questions">💬</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://www.westerling.nu"><img src="https://avatars.githubusercontent.com/u/7298727?v=4?s=100" width="100px;" alt="Kalle Westerling"/><br /><sub><b>Kalle Westerling</b></sub></a><br /><a href="#code-kallewesterling" title="Code">💻</a> <a href="#doc-kallewesterling" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
20 changes: 16 additions & 4 deletions deepsensor/data/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def sample_df(
idx = rng.choice(df.index, N)
X_c = df.loc[idx].reset_index()[["x1", "x2"]].values.T.astype(self.dtype)
Y_c = df.loc[idx].values.T
elif sampling_strat in ["all", "split"]:
elif isinstance(sampling_strat, str) and sampling_strat in ["all", "split"]:
# NOTE if "split", we assume that the context-target split has already been applied to the df
# in an earlier scope with access to both the context and target data. This is maybe risky!
X_c = df.reset_index()[["x1", "x2"]].values.T.astype(self.dtype)
Expand Down Expand Up @@ -1011,10 +1011,18 @@ def sample_variable(var, sampling_strat, seed):
raise ValueError(f"split_frac must be between 0 and 1, got {split_frac}")
if self.links is None:
b1 = any(
[strat == _ for _ in ["split", "gapfill"] for strat in context_sampling]
[
strat in ["split", "gapfill"]
for strat in context_sampling
if isinstance(strat, str)
]
)
b2 = any(
[strat == _ for _ in ["split", "gapfill"] for strat in target_sampling]
[
strat in ["split", "gapfill"]
for strat in target_sampling
if isinstance(strat, str)
]
)
if b1 or b2:
raise ValueError(
Expand All @@ -1028,7 +1036,11 @@ def sample_variable(var, sampling_strat, seed):
target_sampling[target_idx],
)
if any(
[strat == _ for _ in ["split", "gapfill"] for strat in link_strats]
[
strat in ["split", "gapfill"]
for strat in link_strats
if isinstance(strat, str)
]
):
# If one of the sampling strategies is "split" or "gapfill", the other must
# use the same splitting strategy
Expand Down
11 changes: 7 additions & 4 deletions docs/getting-started/tutorials/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"outputs": [],
"source": [
"import sys, os\n",
"sys.path.append(os.path.abspath(\"../../../\"))"
"sys.path.append(os.path.abspath(\"../../../\"))\n",
"\n",
"import logging\n",
"logging.captureWarnings(True)"
]
},
{
Expand Down Expand Up @@ -60,13 +63,13 @@
"# Generate training tasks with up to 10% of grid cells passed as context and all grid cells\n",
"# passed as targets\n",
"train_tasks = []\n",
"for date in pd.date_range(\"2013-01-01\", \"2014-11-30\")[::7]:\n",
"for date in pd.date_range(\"2013-01-01\", \"2014-11-30\")[::14]:\n",
" task = task_loader(date, context_sampling=np.random.uniform(0.0, 0.1), target_sampling=\"all\")\n",
" train_tasks.append(task)\n",
"\n",
"# Train model\n",
"for epoch in range(10):\n",
" train_epoch(model, train_tasks, progress_bar=True)\n",
"for epoch in range(1):\n",
" train_epoch(model, train_tasks)\n",
"\n",
"# Predict on new task with 10% of context data and a dense grid of target points\n",
"test_task = task_loader(\"2014-12-31\", 0.1)\n",
Expand Down

0 comments on commit 966476e

Please sign in to comment.