Skip to content
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

updated linting #166

Merged
merged 1 commit into from
Dec 28, 2020
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
4 changes: 1 addition & 3 deletions binder/Live_Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,7 @@
"# Note: The vertical mean is automatically weighted.\n",
"fig = plt.figure(figsize=mapsize)\n",
"xr_kwargs = dict(robust=True, center=False, cmap=\"inferno\")\n",
"anim = od100m.animate.horizontal_section(\n",
" varName=\"Ertel_PV\", meanAxes=\"Z\", **xr_kwargs\n",
")\n",
"anim = od100m.animate.horizontal_section(varName=\"Ertel_PV\", meanAxes=\"Z\", **xr_kwargs)\n",
"plt.close()"
]
},
Expand Down
1,460 changes: 1,459 additions & 1 deletion binder/Tutorial.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ci/environment-py36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ dependencies:
- codecov
- flake8
- ffmpeg
- black<20.8b1
- black
- aiohttp
- pandas
- matplotlib
- xmitgcm
- pip
- pip:
- git+https://github.com/MITgcm/xmitgcm.git
- black-nb
- pre-commit
4 changes: 2 additions & 2 deletions ci/environment-py37.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ dependencies:
- codecov
- flake8
- ffmpeg
- black<20.8b1
- black
- aiohttp
- pandas
- matplotlib
- xmitgcm
- pip
- pip:
- git+https://github.com/MITgcm/xmitgcm.git
- black-nb
- pre-commit
4 changes: 2 additions & 2 deletions ci/environment-py38.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ dependencies:
- codecov
- flake8
- ffmpeg
- black<20.8b1
- black
- aiohttp
- pandas
- matplotlib
- xmitgcm
- pip
- pip:
- git+https://github.com/MITgcm/xmitgcm.git
- black-nb
- pre-commit
7 changes: 2 additions & 5 deletions docs/Kogur.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,7 @@
" ms=ms,\n",
" label=\"path1\",\n",
")\n",
"_ = ax.plot(\n",
" ds[\"XC\"].squeeze(), ds[\"YC\"].squeeze(), \"k.\", ms=ms, label=\"mooring\"\n",
")\n",
"_ = ax.plot(ds[\"XC\"].squeeze(), ds[\"YC\"].squeeze(), \"k.\", ms=ms, label=\"mooring\")\n",
"_ = ax.scatter(\n",
" ds[\"X_Vtransport\"].where(ds[\"dir_Vtransport\"] == 1),\n",
" ds[\"Y_Vtransport\"].where(ds[\"dir_Vtransport\"] == 1),\n",
Expand Down Expand Up @@ -805,8 +803,7 @@
"lines = cum_oflow_moor.squeeze().plot.line(hue=\"path\", linewidth=3)\n",
"tot_mean_oflow_moor = cum_oflow_moor.isel(mooring=-1).mean(\"path\")\n",
"title = ax.set_title(\n",
" \"TOTAL MEAN OVERFLOW TRANSPORT: {0:.1f} Sv\"\n",
" \"\".format(tot_mean_oflow_moor.values)\n",
" \"TOTAL MEAN OVERFLOW TRANSPORT: {0:.1f} Sv\" \"\".format(tot_mean_oflow_moor.values)\n",
")"
]
},
Expand Down
11 changes: 3 additions & 8 deletions docs/Particles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -502,16 +502,12 @@
"mask_DSO = xr.where(od_lag.dataset[\"Sigma0\"] >= DSO_threshold, 1, 0)\n",
"\n",
"# Mask particles always in the overflow\n",
"mask_dense = xr.where(\n",
" mask_DSO.sum(\"time\") == len(od_lag.dataset[\"time\"]), 1, 0\n",
")\n",
"mask_dense = xr.where(mask_DSO.sum(\"time\") == len(od_lag.dataset[\"time\"]), 1, 0)\n",
"\n",
"# Mask mixed particles\n",
"mask_mixed = xr.where(\n",
" np.logical_and(\n",
" np.logical_and(\n",
" mask_DSO.isel(time=0) == 1, mask_DSO.isel(time=-1) == 0\n",
" ),\n",
" np.logical_and(mask_DSO.isel(time=0) == 1, mask_DSO.isel(time=-1) == 0),\n",
" mask_DSO.sum(\"time\") <= len(od_lag.dataset[\"time\"]) / 2,\n",
" ),\n",
" 1,\n",
Expand Down Expand Up @@ -700,8 +696,7 @@
" contour_kwargs=contour_kwargs,\n",
" )\n",
"tit = \"\\n\".join(\n",
" [\"c) \"]\n",
" + [f\"{col}: {tit}\" for _, (col, tit) in enumerate(zip(colors, titles))]\n",
" [\"c) \"] + [f\"{col}: {tit}\" for _, (col, tit) in enumerate(zip(colors, titles))]\n",
")\n",
"ax.set_title(tit)\n",
"\n",
Expand Down
25 changes: 6 additions & 19 deletions docs/Statistics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,7 @@
"print(\"\\nVariables added:\")\n",
"for var in od_snapshot.dataset.data_vars:\n",
" if any(\n",
" [\n",
" (var == v or var == f\"weight_{v}\" or var == f\"w_mean_{v}\")\n",
" for v in var_list\n",
" ]\n",
" [(var == v or var == f\"weight_{v}\" or var == f\"w_mean_{v}\") for v in var_list]\n",
" ):\n",
" print(\n",
" \"{:>15}: {} [{}]\".format(\n",
Expand Down Expand Up @@ -639,25 +636,17 @@
" print(\"%s\" % (units))\n",
"\n",
" # Plot the PDF\n",
" p0 = ax.plot(\n",
" bin_mid, var_hist, \"-\", color=hist_color, label=\"PDF\", linewidth=4\n",
" )\n",
" p0 = ax.plot(bin_mid, var_hist, \"-\", color=hist_color, label=\"PDF\", linewidth=4)\n",
" ax.set_xlabel(var_name + \" [\" + units + \"]\", fontsize=15)\n",
" ax.set_ylabel(\n",
" \"Probability distribution function\", fontsize=15, color=hist_color\n",
" )\n",
" ax.set_ylabel(\"Probability distribution function\", fontsize=15, color=hist_color)\n",
" ax.tick_params(axis=\"y\", labelcolor=hist_color)\n",
" ax.grid(True)\n",
" ax.set_xlim(var_limits)\n",
"\n",
" # Compute and plot the CDF\n",
" ax2 = ax.twinx()\n",
" p1 = ax2.plot(\n",
" var_qiles2, qiles2, \"-\", color=qiles_color, label=\"CDF\", linewidth=4\n",
" )\n",
" ax2.set_ylabel(\n",
" \"Cumulative distribution function\", fontsize=15, color=qiles_color\n",
" )\n",
" p1 = ax2.plot(var_qiles2, qiles2, \"-\", color=qiles_color, label=\"CDF\", linewidth=4)\n",
" ax2.set_ylabel(\"Cumulative distribution function\", fontsize=15, color=qiles_color)\n",
" ax2.tick_params(axis=\"y\", labelcolor=qiles_color)\n",
" ax2.set_xlim(var_limits)\n",
"\n",
Expand All @@ -666,9 +655,7 @@
" l1 = ax.axvline(var_mean, linestyle=\"-\", color=\"w\", linewidth=2)\n",
" l2 = ax.axvline(var_median, linestyle=\"--\", color=stat_color3, linewidth=2)\n",
" l3 = ax.axvline(var_mode, linestyle=\"--\", color=stat_color4, linewidth=2)\n",
" ax.legend(\n",
" (l2, l3, p2), (\"median\", \"mode\", \"mean +/- std\"), loc=\"upper left\"\n",
" )"
" ax.legend((l2, l3, p2), (\"median\", \"mode\", \"mean +/- std\"), loc=\"upper left\")"
]
},
{
Expand Down
14 changes: 3 additions & 11 deletions docs/Tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,7 @@
}
],
"source": [
"ds = ospy.compute.gradient(\n",
" od, varNameList=[\"Temp\", \"S\", \"Sigma0\"], axesList=[\"time\"]\n",
")\n",
"ds = ospy.compute.gradient(od, varNameList=[\"Temp\", \"S\", \"Sigma0\"], axesList=[\"time\"])\n",
"print(ds.data_vars)"
]
},
Expand Down Expand Up @@ -1010,15 +1008,9 @@
}
],
"source": [
"ds = ospy.compute.weighted_mean(\n",
" od, varNameList=[\"Temp\", \"S\"], storeWeights=False\n",
")\n",
"ds = ospy.compute.weighted_mean(od, varNameList=[\"Temp\", \"S\"], storeWeights=False)\n",
"for var in ds.data_vars:\n",
" print(\n",
" \"{} = {} {}\".format(\n",
" var, ds[var].values, ds[var].attrs.pop(\"units\", \"\")\n",
" )\n",
" )"
" print(\"{} = {} {}\".format(var, ds[var].values, ds[var].attrs.pop(\"units\", \"\")))"
]
},
{
Expand Down
28 changes: 22 additions & 6 deletions oceanspy/llc_rearrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ class LLCtransformation:
""" A class containing the transformation of LLCgrids"""

def __init__(
self, ds, varlist, transformation, centered="Atlantic", faces="all", drop=False,
self,
ds,
varlist,
transformation,
centered="Atlantic",
faces="all",
drop=False,
):
self._ds = ds # xarray.DataSet
self._varlist = varlist # variables names to be transformed
Expand All @@ -17,9 +23,14 @@ def __init__(

@classmethod
def arctic_centered(
self, ds, varlist, centered="Arctic", faces="all", drop=False,
self,
ds,
varlist,
centered="Arctic",
faces="all",
drop=False,
):
""" Transforms the dataset by removing faces as a dimension, into a
"""Transforms the dataset by removing faces as a dimension, into a
new dataset centered at the arctic, while preserving the grid.
"""
Nx = len(ds["X"])
Expand Down Expand Up @@ -149,9 +160,14 @@ def arctic_centered(

@classmethod
def arctic_crown(
self, ds, varlist, centered, faces="all", drop=False,
self,
ds,
varlist,
centered,
faces="all",
drop=False,
):
""" Transforms the dataset in which faces appears as a dimension into
"""Transforms the dataset in which faces appears as a dimension into
one without faces, with grids and variables sharing a common grid
orientation.
"""
Expand Down Expand Up @@ -370,7 +386,7 @@ def init_vars(ds, DSNEW, varlist):


def drop_size(ds):
""" Drops a row and/or column from interior (scalar) points, creating
"""Drops a row and/or column from interior (scalar) points, creating
len(X)<len(Xp1) of staggered grids
"""
coords = {}
Expand Down
2 changes: 1 addition & 1 deletion oceanspy/subsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def particle_properties(od, times, Ypart, Xpart, Zpart, **kwargs):


def get_maskH(ds, add_Hbdr, add_Vbdr, XRange, YRange):
""" Define this function to avoid repeated code. First time this runs,
"""Define this function to avoid repeated code. First time this runs,
the objective is to figure out which faces survive the cutout. This info
is then passed, when transforming llc-grids, to llc_rearrange. Second
time this code runs, it gets applied on a dataset without faces as a
Expand Down
5 changes: 2 additions & 3 deletions oceanspy/tests/test_llc_rearrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
],
)
def test_original_dims(od, var, expected):
""" test original dimensions
"""
"""test original dimensions"""
dims = Dims([dim for dim in od._ds[var].dims][::-1])
assert dims == expected

Expand Down Expand Up @@ -383,7 +382,7 @@ def test_init_vars(od, tNX, tNY, X0, varlist):


def _is_connect(faces, rotated=False):
""" do faces in a facet connect? Not applicable to arc cap, and only
"""do faces in a facet connect? Not applicable to arc cap, and only
applicable to either rotated or not rotated facets"""
if rotated is False:
A_fac = _np.array([0, 1, 2])
Expand Down
5 changes: 4 additions & 1 deletion oceanspy/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ def test_hor_sec_warn(od_in):
with pytest.warns(UserWarning):
plt.close()
ax = horizontal_section(
od_in, varName="Eta", contourName="Depth", subplot_kws={"projection": None},
od_in,
varName="Eta",
contourName="Depth",
subplot_kws={"projection": None},
)
assert isinstance(ax, xr.plot.FacetGrid)

Expand Down