Skip to content

Instantly share code, notes, and snippets.

@mmartini-usgs
Created September 7, 2018 15:36
Show Gist options
  • Save mmartini-usgs/fdd43ecf8cbf4d9f63becfc563494d5c to your computer and use it in GitHub Desktop.
Save mmartini-usgs/fdd43ecf8cbf4d9f63becfc563494d5c to your computer and use it in GitHub Desktop.
pyNotebooks/Pathlib_examples.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "raw",
"source": "Pesky path problems alleviated\nSome nice explanations here: https://realpython.com/python-pathlib/"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from pathlib import Path\nimport xarray as xr",
"execution_count": 17,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "p1 = Path(\"C:\\\\projects\\\\python\\\\padding_data\")\np2 = Path(\"C:\\projects\\python\\padding_data\")\nf = \"10811whVwave_p-cal-trm.nc\"",
"execution_count": 18,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(type(p1))\nprint(p1/f)\nprint(type(p2))\nprint(p2/f)",
"execution_count": 19,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "<class 'pathlib.WindowsPath'>\nC:\\projects\\python\\padding_data\\10811whVwave_p-cal-trm.nc\n<class 'pathlib.WindowsPath'>\nC:\\projects\\python\\padding_data\\10811whVwave_p-cal-trm.nc\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ds1 = xr.open_dataset(p1/f,drop_variables={'EPIC_time','EPIC_time2'})",
"execution_count": 20,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ds2 = xr.open_dataset(p2/f,drop_variables={'EPIC_time','EPIC_time2'})",
"execution_count": 21,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ds1.close()\nds2.close()",
"execution_count": 22,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "p = p2/f\nprint(p)",
"execution_count": 28,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "C:\\projects\\python\\padding_data\\10811whVwave_p-cal-trm.nc\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ds = xr.open_dataset(p,drop_variables={'EPIC_time','EPIC_time2'})",
"execution_count": 25,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ds.close()",
"execution_count": 26,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "conda-env-IOOS3A-py",
"display_name": "Python [conda env:IOOS3A]",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.5",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "",
"data": {
"description": "pyNotebooks/Pathlib_examples.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment