Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 15 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main

env:
DOCKER_IMAGE: 'registry.gitlab.eox.at/esa/vires_vre_ops/vre-swarm-notebook:0.10.11'
DOCKER_IMAGE: 'registry.gitlab.eox.at/esa/vires_vre_ops/vre-swarm-notebook:1.0.8'

jobs:
run:
Expand All @@ -18,7 +18,7 @@ jobs:
run: |
echo ${{ secrets.EOX_REGISTRY_PASSWORD }} | docker login -u ${{ secrets.EOX_REGISTRY_USER }} --password-stdin registry.gitlab.eox.at
docker pull ${{ env.DOCKER_IMAGE }}
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Execute notebooks and build book
run: |
docker run -v $GITHUB_WORKSPACE:/home/jovyan -u root \
Expand All @@ -31,5 +31,16 @@ jobs:
pip install 'jupyter-book==0.15.1' && \
jupyter-book build --verbose .
'
- name: Deploy preview with netlify
run: netlify deploy --dir=_build/html --auth=${{ secrets.NETLIFY_AUTH_TOKEN }} --site=${{ secrets.NETLIFY_SITE_API_ID }}
- name: Deploy preview to Netlify
if: always()
uses: nwtgck/actions-netlify@v3.0
with:
publish-dir: './_build/html'
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
enable-pull-request-comment: true
enable-commit-comment: false
overwrites-pull-request-comment: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_API_ID }}
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,13 @@
},
"outputs": [],
"source": [
"## Uncomment here to autoreload local modules as you edit them\n",
"# %load_ext autoreload\n",
"# %autoreload 2\n",
"\n",
"import datetime as dt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import ipywidgets as widgets\n",
"from viresclient import SwarmRequest\n",
"\n",
"## Use to make interactive matplotlib plots\n",
"## - doesn't work smoothly\n",
"## - investigating using plotly/bokeh instead\n",
"# %matplotlib widget\n",
"\n",
"%load_ext watermark\n",
"%watermark -i -v -p numpy,pandas,xarray,matplotlib,ipywidgets,viresclient"
]
Expand Down Expand Up @@ -116,11 +107,10 @@
" **kwargs\n",
" )\n",
" if use_xarray:\n",
" ds = data.as_xarray().drop(\"Spacecraft\")\n",
" return ds\n",
" return data.as_xarray()\n",
" else:\n",
" # Load data in Pandas Dataframe with X, Y, Z columns\n",
" df = data.as_dataframe(expand=True).drop(columns=\"Spacecraft\")\n",
" df = data.as_dataframe(expand=True)\n",
" df = df.rename(columns={f\"B_NEC_{i}\": j for i, j in zip(\"NEC\", \"XYZ\")})\n",
" return df\n",
"\n",
Expand Down Expand Up @@ -178,20 +168,22 @@
" Returns:\n",
" Figure\n",
" \"\"\"\n",
" observatory = df[\"IAGA_code\"].iloc[0]\n",
" # Restrict to only the XYZ values so that resampling will work\n",
" df = df[[\"X\", \"Y\", \"Z\"]].copy()\n",
" # Evaluate annual means to use later,\n",
" # reindexed with the ending index points for each year\n",
" annual_mean = df.resample(\"1y\").mean()\n",
" annual_mean = df.resample(\"Y\").mean()\n",
" annual_mean.index = [df.loc[str(year)].index[-1] for year in df.index.year.unique()]\n",
" # Subset dataframe to selection\n",
" df = df.loc[start_date:end_date]\n",
" # Cut the annual mean (and reindex) to match df\n",
" # so we can use it directly in ax.fill_between\n",
" annual_mean = annual_mean.loc[str(start_date.year):str(end_date.year)]\n",
" annual_mean = annual_mean.reindex(index=df.index, method=\"backfill\")\n",
" observatory = df[\"IAGA_code\"][0]\n",
" title = f\"Minute data from {observatory}\"\n",
" if hourly_mean:\n",
" df = df.resample(\"1h\").mean()\n",
" df = df.resample(\"h\").mean()\n",
" annual_mean = annual_mean.reindex(index=df.index)\n",
" title += \": averaged over each hour\"\n",
" if show_annual_mean:\n",
Expand Down Expand Up @@ -322,7 +314,11 @@
"outputs": [],
"source": [
"def monthly_means(df=obs_hourly):\n",
" \"\"\"Return MultIndex DataFrame of monthly means over each hourly interval\"\"\"\n",
" \"\"\"Return MultiIndex DataFrame of monthly means over each hourly interval\"\"\"\n",
" # Restrict to only the XYZ values so that resampling will work\n",
" df = df[[\"X\", \"Y\", \"Z\"]].copy()\n",
" # Append Declination\n",
" df[\"D\"] = np.rad2deg(np.arctan2(df[\"Y\"], df[\"X\"]))\n",
" # Append hour of day, and approx fractional year, to use for plotting\n",
" df[\"t_hour\"] = df.index.map(lambda x: x.hour + x.minute/60)\n",
" epoch = pd.to_datetime(0, unit='s').to_julian_date()\n",
Expand All @@ -337,8 +333,6 @@
" monthly[\"D_variation\"] = monthly['D'].values - monthly_all['D'].values.repeat(24)\n",
" return monthly\n",
"\n",
"\n",
"obs_hourly[\"D\"] = np.rad2deg(np.arctan2(obs_hourly[\"Y\"], obs_hourly[\"X\"]))\n",
"obs_monthly = monthly_means(obs_hourly)\n",
"obs_monthly"
]
Expand Down Expand Up @@ -462,7 +456,7 @@
" df = df.copy()\n",
"\n",
" # Evaluate the annual means\n",
" annual_means = df[[\"X\", \"Y\", \"Z\"]].resample(\"1y\").mean()\n",
" annual_means = df[[\"X\", \"Y\", \"Z\"]].resample(\"Y\").mean()\n",
" annual_means = annual_means.rename(columns={\"X\": \"X_mean\", \"Y\": \"Y_mean\", \"Z\": \"Z_mean\"})\n",
" # Identify the year-end index times\n",
" year_ends = [df.loc[str(year)].index[-1] for year in df.index.year.unique()]\n",
Expand Down Expand Up @@ -524,7 +518,7 @@
" (df[\"time\"].dt.day == 1) & (df[\"time\"].dt.hour == 0)\n",
" ).dropna()\n",
" if bartrot in month_starts.keys():\n",
" bartrotday = float(month_starts.loc[bartrot].index.values)\n",
" bartrotday = float(month_starts.loc[bartrot].index.values[0])\n",
" month = month_starts.loc[bartrot].dt.strftime(\"%b\").values[0]\n",
" ax.text(bartrotday, y0.iloc[0] - 85, month, verticalalignment=\"top\")\n",
"\n",
Expand Down Expand Up @@ -592,14 +586,15 @@
" asynchronous=False,\n",
" show_progress=False,\n",
" )\n",
" df = df.resample(\"1y\").mean()\n",
" df = df[[\"X\", \"Y\", \"Z\"]].resample(\"Y\").mean()\n",
" df.index = df.index.year\n",
" df.index.name = \"Year\"\n",
" annual_means[obs] = df\n",
" return annual_means\n",
"\n",
"\n",
"observatories = [\"ESK\", \"NGK\", \"CLF\"]\n",
"# observatories = [\"ESK\", \"NGK\", \"CLF\"] # Why aren't NGK and CLF working?\n",
"observatories = [\"ESK\"]\n",
"annual_means = fetch_annual_means(observatories)"
]
},
Expand Down Expand Up @@ -709,7 +704,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.6"
},
"toc-autonumbering": true,
"toc-showcode": false,
Expand Down
6 changes: 2 additions & 4 deletions geomag-obs-models/02a_K-Index-Calculation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@
" dt.datetime(2003, 1, 1),\n",
" dt.datetime(2004, 1, 1),\n",
" )\n",
" df = data.as_dataframe(expand=True).drop(\n",
" columns=[\"Spacecraft\"]\n",
" )\n",
" df = data.as_dataframe(expand=True)\n",
" df = df.rename(columns={f\"B_NEC_{i}\": j for i, j in zip(\"NEC\", \"XYZ\")})\n",
" return df"
]
Expand Down Expand Up @@ -552,7 +550,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
3 changes: 1 addition & 2 deletions geomag-obs-models/04b_SHA2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"# Import notebook dependencies\n",
"import sys\n",
"import matplotlib.pyplot as plt\n",
"plt.style.use('seaborn-white')\n",
"import numpy as np\n",
"import pandas as pd \n",
"\n",
Expand Down Expand Up @@ -602,7 +601,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions geomag-obs-models/04c_GroundObs-to-Model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
" _ds = df.to_xarray()\n",
" _ds[\"Latitude\"] = 90 - _ds[\"Colat\"]\n",
" _ds[\"Longitude\"] = (_ds[\"Long\"] % 360 + 540) % 360 - 180\n",
" _ds = _ds.drop(\"index\")\n",
" _ds = _ds.drop_vars(\"index\")\n",
" return _ds\n",
"\n",
"input_data = load_data(year=2000.5)\n",
Expand Down Expand Up @@ -393,7 +393,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
12 changes: 6 additions & 6 deletions geomag-obs-models/05a_Swarm-Measurements.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"metadata": {},
"outputs": [],
"source": [
"_ds = ds.drop(\"Timestamp\").sel(NEC=\"C\")\n",
"_ds = ds.drop_vars(\"Timestamp\").sel(NEC=\"C\")\n",
"_ds.hvplot.scatter(\n",
" x=\"Longitude\", y=\"Latitude\", color=\"B_NEC\",\n",
" rasterize=True, colorbar=True, cmap=\"coolwarm\", clabel=\"Vertical (downwards) magnetic field (nT)\"\n",
Expand Down Expand Up @@ -229,7 +229,7 @@
"ds = append_model_evaluations(ds, model_coeffs)\n",
"\n",
"# Plot the \n",
"_ds = ds.drop(\"Timestamp\").sel(NEC=\"C\")\n",
"_ds = ds.drop_vars(\"Timestamp\").sel(NEC=\"C\")\n",
"_ds.hvplot.scatter(\n",
" x=\"Longitude\", y=\"Latitude\", color=\"B_NEC_res_model\",\n",
" rasterize=True, colorbar=True, cmap=\"coolwarm\", clim=(-40, 40), clabel=\"Vertical (B_C) data-model residuals (nT)\",\n",
Expand All @@ -251,7 +251,7 @@
"metadata": {},
"outputs": [],
"source": [
"_ds = ds.drop(\"Timestamp\").sel(NEC=\"E\")\n",
"_ds = ds.drop_vars(\"Timestamp\").sel(NEC=\"E\")\n",
"_ds.hvplot.scatter(\n",
" x=\"Longitude\", y=\"Latitude\", color=\"B_NEC_res_model\",\n",
" rasterize=True, colorbar=True, cmap=\"coolwarm\", clim=(-40, 40), clabel=\"Eastward (B_E) data-model residuals (nT)\",\n",
Expand All @@ -275,7 +275,7 @@
"metadata": {},
"outputs": [],
"source": [
"_ds = ds.drop(\"Timestamp\").sel(NEC=\"E\")\n",
"_ds = ds.drop_vars(\"Timestamp\").sel(NEC=\"E\")\n",
"_ds.hvplot.scatter(\n",
" x=\"MLT\", y=\"Latitude\", color=\"B_NEC_res_model\",\n",
" rasterize=True, colorbar=True, cmap=\"coolwarm\", clim=(-40, 40), clabel=\"Eastward (B_E) data-model residuals (nT)\",\n",
Expand All @@ -289,7 +289,7 @@
"metadata": {},
"outputs": [],
"source": [
"ds.drop(\"Timestamp\").hvplot.scatter(x=\"Latitude\", y=\"B_NEC_res_model\", col=\"NEC\", rasterize=True, colorbar=False, cmap=\"bwr\")"
"ds.drop_vars(\"Timestamp\").hvplot.scatter(x=\"Latitude\", y=\"B_NEC_res_model\", col=\"NEC\", rasterize=True, colorbar=False, cmap=\"bwr\")"
]
},
{
Expand Down Expand Up @@ -350,7 +350,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down