Skip to content

Commit

Permalink
Updates for VRE 1.0 (#26)
Browse files Browse the repository at this point in the history
* Minor fixes for pandas & xarray updates

* Use VRE image 1.0.0

* Fix notebook cleanup

* Use dev version of hapiplot

* Add package versions watermarks

* Patch dev version of pyswipe; disable running swarmface

* Use VRE 1.0.1
  • Loading branch information
smithara authored Jan 23, 2024
1 parent 236ba99 commit b79566d
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_dispatch:

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

jobs:
pre-commit:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_dispatch:

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

jobs:
pre-commit:
Expand Down
2 changes: 1 addition & 1 deletion notebooks/01b1_Pandas-and-Plots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
"outputs": [],
"source": [
"# Generate some sample times at hourly intervals over a month\n",
"df[\"time\"] = pd.date_range(\"2020-01-01\", \"2020-02-01\", periods=745, closed=\"left\")\n",
"df[\"time\"] = pd.date_range(\"2020-01-01\", \"2020-02-01\", periods=745, inclusive=\"left\")\n",
"df = df.set_index(\"time\")\n",
"df"
]
Expand Down
2 changes: 1 addition & 1 deletion notebooks/03e1_Demo-FACxTMS_2F.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
" # Extract times from the lower x axis\n",
" # Use them to find the nearest Lat values in the dataframe\n",
" xtick_times = [dt.datetime.strptime(ts.get_text(), datetime_format) for ts in ax.get_xticklabels()]\n",
" ilocs = [df.index.get_loc(t, method=\"nearest\") for t in xtick_times]\n",
" ilocs = [df.index.get_indexer([t], method=\"nearest\")[0] for t in xtick_times]\n",
" lats = df.iloc[ilocs][\"Latitude\"]\n",
" lat_labels = [\"{}°\".format(s) for s in np.round(lats.values, decimals=1)]\n",
" ax2.set_xticklabels(lat_labels)\n",
Expand Down
21 changes: 10 additions & 11 deletions notebooks/03i1_Demo-VOBS.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,8 @@
" _ds[var] = _ds[var].roll({\"NEC\": 1}, roll_coords=False)\n",
" _ds[var].attrs = ds[var].attrs\n",
" # Rename NEC dims & coords to RTP\n",
" _ds = _ds.assign_coords({\"NEC\": [\"Radial\", \"Theta\", \"Phi\"]})\n",
" _ds = _ds.rename_dims({\"NEC\": \"RTP\"}).rename({\"NEC\": \"RTP\"})\n",
" _ds = _ds.set_index({\"RTP\": \"RTP\"}).set_coords(\"RTP\")\n",
" _ds = _ds.rename({\"NEC\": \"RTP\"})\n",
" _ds = _ds.assign_coords({\"RTP\": [\"Radial\", \"Theta\", \"Phi\"]})\n",
" _ds[\"RTP\"].attrs = {\n",
" \"units\": \"\",\n",
" \"description\": \"RTP frame - Radial, Theta, Phi [R,T,P] = [-C,-N,E]\"\n",
Expand All @@ -359,7 +358,7 @@
" )\n",
" data = request.get_between(\n",
" dt.datetime(1999, 1, 1),\n",
" dt.datetime.now(),\n",
" dt.datetime(2024, 1, 1),\n",
" asynchronous=False, show_progress=False\n",
" )\n",
" ds = data.as_xarray(reshape=reshape)\n",
Expand Down Expand Up @@ -423,7 +422,7 @@
"source": [
"rad = {}\n",
"for mission in (\"Orsted\", \"CHAMP\", \"Cryosat\", \"Swarm\", \"Composite\"):\n",
" rad[mission] = int(ALL_VOBS[f\"{mission}_4M\"][\"Radius\"].values[0]/1e3)\n",
" rad[mission] = int(ALL_VOBS[f\"{mission}_4M\"][\"Radius\"][0]/1e3)\n",
"\n",
"plt.figure(figsize=(10,3))\n",
"for mission in (\"Orsted\", \"CHAMP\", \"Cryosat\", \"Swarm\", \"Composite\"):\n",
Expand Down Expand Up @@ -463,34 +462,34 @@
" _ds_1m = ds_1m.sel(RTP=rtp)\n",
" # Observed field\n",
" axes[i, 0].errorbar(\n",
" _ds_1m[\"Timestamp\"].values, _ds_1m[\"B_OB\"].values, _ds_1m[\"sigma_OB\"].values,\n",
" _ds_1m[\"Timestamp\"].values, _ds_1m[\"B_OB\"].values, np.abs(_ds_1m[\"sigma_OB\"].values),\n",
" fmt=\".\", label=\"1M\"\n",
" )\n",
" # Core field\n",
" axes[i, 1].errorbar(\n",
" _ds_1m[\"Timestamp\"].values, _ds_1m[\"B_CF\"].values, _ds_1m[\"sigma_CF\"].values,\n",
" _ds_1m[\"Timestamp\"].values, _ds_1m[\"B_CF\"].values, np.abs(_ds_1m[\"sigma_CF\"].values),\n",
" fmt=\".\",\n",
" )\n",
" # Secular variation (of core field)\n",
" axes[i, 2].errorbar(\n",
" _ds_1m[\"Timestamp_SV\"].values, _ds_1m[\"B_SV\"].values, _ds_1m[\"sigma_SV\"].values,\n",
" _ds_1m[\"Timestamp_SV\"].values, _ds_1m[\"B_SV\"].values, np.abs(_ds_1m[\"sigma_SV\"].values),\n",
" fmt=\".\",\n",
" )\n",
" _ds_4m = ds_4m.sel(RTP=rtp)\n",
" # Observed field\n",
" axes[i, 0].errorbar(\n",
" _ds_4m[\"Timestamp\"].values, _ds_4m[\"B_OB\"].values, _ds_4m[\"sigma_OB\"].values,\n",
" _ds_4m[\"Timestamp\"].values, _ds_4m[\"B_OB\"].values, np.abs(_ds_4m[\"sigma_OB\"].values),\n",
" fmt=\".\", label=\"4M\"\n",
" )\n",
" # Core field\n",
" axes[i, 1].errorbar(\n",
" _ds_4m[\"Timestamp\"].values, _ds_4m[\"B_CF\"].values, _ds_4m[\"sigma_CF\"].values,\n",
" _ds_4m[\"Timestamp\"].values, _ds_4m[\"B_CF\"].values, np.abs(_ds_4m[\"sigma_CF\"].values),\n",
" fmt=\".\",\n",
" )\n",
" axes[i, 1].set_ylim(axes[i, 0].get_ylim())\n",
" # Secular variation (of core field)\n",
" axes[i, 2].errorbar(\n",
" _ds_4m[\"Timestamp_SV\"].values, _ds_4m[\"B_SV\"].values, _ds_4m[\"sigma_SV\"].values,\n",
" _ds_4m[\"Timestamp_SV\"].values, _ds_4m[\"B_SV\"].values, np.abs(_ds_4m[\"sigma_SV\"].values),\n",
" fmt=\".\",\n",
" )\n",
" axes[0, 0].set_ylabel(\"Radial\\n[nT]\")\n",
Expand Down
29 changes: 7 additions & 22 deletions notebooks/03z1_External-Data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,43 +100,28 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install \"hapiplot==0.2.0\" --quiet\n",
"!pip install \"git+https://github.com/hapi-server/plot-python@f95ce860d456dd9278a62897d6f83d416c988273\" --quiet\n",
"\n",
"from hapiplot import hapiplot"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4aeea673",
"metadata": {},
"outputs": [],
"source": [
"hapiplot(data, meta);"
]
},
{
"cell_type": "markdown",
"id": "0e2e6ec5",
"id": "1119a42c-1733-49be-beb4-2370637fe0b0",
"metadata": {},
"source": [
"## Other packages (TODO)\n",
"\n",
"- pysat\n",
"- spacepy\n",
"- mangopy\n",
"- madrigalweb\n",
"- pyaurorax\n",
"- ??? (any suggestions? contact [email protected])"
"(NB: We are using a more recent development version of hapiplot, rather than what is on PyPI)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e60071a3",
"id": "4aeea673",
"metadata": {},
"outputs": [],
"source": []
"source": [
"hapiplot(data, meta);"
]
}
],
"metadata": {
Expand Down
12 changes: 11 additions & 1 deletion notebooks/07a1_SW-chaosmagpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
"Finlay, C.C., Kloss, C., Olsen, N., Hammer, M. Toeffner-Clausen, L., Grayver, A and Kuvshinov, A. (2020), The CHAOS-7 geomagnetic field model and observed changes in the South Atlantic Anomaly, Earth Planets and Space 72, doi:10.1186/s40623-020-01252-9"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext watermark\n",
"%watermark -i -v -p chaosmagpy,numpy,matplotlib"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -149,5 +159,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
12 changes: 11 additions & 1 deletion notebooks/07b1_SW-pyamps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
"Laundal, K. M., Finlay, C. C., Olsen, N. & Reistad, J. P. (2018), Solar wind and seasonal influence on ionospheric currents from Swarm and CHAMP measurements, Journal of Geophysical Research - Space Physics. doi:10.1029/2018JA025387"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext watermark\n",
"%watermark -i -v -p pyamps,numpy,matplotlib"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -77,5 +87,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
22 changes: 21 additions & 1 deletion notebooks/07c1_SW-pyswipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@
"[Code](https://github.com/Dartspacephysiker/pyswipe) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Temporarily patch in fixed version\n",
"!pip install --quiet git+https://github.com/smithara/pyswipe/@hotfix-numpy-1.25"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext watermark\n",
"%watermark -i -v -p pyswipe,numpy,matplotlib"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -537,5 +557,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
85 changes: 23 additions & 62 deletions notebooks/07e1_SW-swarmface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
"Blagau A and Vogt J (2023) SwarmFACE: A Python package for field-aligned currents exploration with Swarm. Front. Astron. Space Sci. 9:1077845. doi: 10.3389/fspas.2022.1077845"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext watermark\n",
"%watermark -i -v -p SwarmFACE,viresclient,numpy,pandas,matplotlib"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -48,79 +58,30 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"The package is currently awaiting updates to make it work here.\n",
"\n",
"Example usage:\n",
"\n",
"```python\n",
"# Settings\n",
"dtime_beg = '2014-05-04T17:48:00'\n",
"dtime_end = '2014-05-04T17:54:00'\n",
"sat = ['C']\n",
"res = 'LR'\n",
"N3d=[0.2276, 0.6924, 0.6847]\n",
"tincl = ['2014-05-04 17:49:50', '2014-05-04 17:52:44']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tincl = ['2014-05-04 17:49:50', '2014-05-04 17:52:44']\n",
"\n",
"# Fetch data and apply algorithm using above settings\n",
"j_df, input_df, param = j1sat(\n",
" dtime_beg, dtime_end, sat, res=res,\n",
" N3d=N3d, tincl=tincl\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The inputs are stored within `input_df`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"input_df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"... and the newly calculated FAC current in `j_df`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"j_df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"... with some extra metadata in `param`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"param"
")\n",
"```\n",
"\n",
"The inputs are stored within `input_df`, and the newly calculated FAC current in `j_df` with some extra metadata in `param`."
]
}
],
Expand Down Expand Up @@ -148,5 +109,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit b79566d

Please sign in to comment.