Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ARM-DOE/ACT
Browse files Browse the repository at this point in the history
  • Loading branch information
zssherman committed Oct 30, 2024
2 parents 5a2ae3d + 849e4ec commit f4f1ba0
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 171 deletions.
134 changes: 132 additions & 2 deletions act/plotting/timeseriesdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
from copy import deepcopy
from re import search, search as re_search

import numpy as np
import pandas as pd
from scipy import stats
import matplotlib as mpl
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.patches import Rectangle
from matplotlib.collections import PatchCollection
from matplotlib import colors as mplcolors
from mpl_toolkits.axes_grid1 import make_axes_locatable
from scipy.interpolate import NearestNDInterpolator
Expand Down Expand Up @@ -1847,3 +1850,130 @@ def fill_between(
ax.set_title(set_title)
self.axes[subplot_index] = ax
return self.axes[subplot_index]

def plot_stripes(
self,
field,
dsname=None,
subplot_index=(0,),
set_title=None,
reference_period=None,
cmap='bwr',
cbar_label=None,
colorbar=True,
**kwargs,
):
"""
Makes a climate stripe plot with or without a baseline period specified
Parameters
----------
field : str
The name of the field to plot.
dsname : None or str
If there is more than one datastream in the display object the
name of the datastream needs to be specified. If set to None and
there is only one datastream ACT will use the sole datastream
in the object.
subplot_index : 1 or 2D tuple, list, or array
The index of the subplot to set the x range of.
set_title : str
The title for the plot.
reference_period : list
List of a start and end date for a reference period ['2020-01-01', '2020-04-01']
If this is set, the plot will subtract the mean of the reference period from the
field to create an anomaly calculation.
cmap : string
Colormap to use for plotting. Defaults to bwr
cbar_label : str
Option to overwrite default colorbar label.
colorbar : boolean
Option to not plot the colorbar. Default is to plot it
**kwargs : keyword arguments
The keyword arguments for :func:`plt.plot` (1D timeseries) or
:func:`plt.pcolormesh` (2D timeseries).
Returns
-------
ax : matplotlib axis handle
The matplotlib axis handle of the plot.
"""
if dsname is None and len(self._ds.keys()) > 1:
raise ValueError(
'You must choose a datastream when there are 2 '
'or more datasets in the TimeSeriesDisplay '
'object.'
)
elif dsname is None:
dsname = list(self._ds.keys())[0]

# Get data and dimensions
data = self._ds[dsname][field]
dim = list(self._ds[dsname][field].dims)
xdata = self._ds[dsname][dim[0]]

start = int(mdates.date2num(xdata.values[0]))
end = int(mdates.date2num(xdata.values[-1]))
delta = stats.mode(xdata.diff('time').values)[0] / np.timedelta64(1, 'D')

# Calculate mean for reference period and subtract from the data
if reference_period is not None:
reference = data.sel(time=slice(reference_period[0], reference_period[1])).mean('time')
data.values = data.values - reference.values

# Get the current plotting axis, add day/night background and plot data
if self.fig is None:
self.fig = plt.figure()

if self.axes is None:
self.axes = np.array([plt.axes()])
self.fig.add_axes(self.axes[0])

# Set ax to appropriate axis
ax = self.axes[subplot_index]

# Plot up data using rectangles
col = PatchCollection(
[Rectangle((y, 0), delta, 1) for y in np.arange(start, end + 1, delta)]
)
col.set_array(data)
col.set_cmap(cmap)
col.set_clim(np.nanmin(data), np.nanmax(data))
ax.add_collection(col)

locator = mdates.AutoDateLocator(minticks=3)
formatter = mdates.AutoDateFormatter(locator)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)

ax.set_ylim(0, 1)
ax.set_yticks([])
ax.set_xlim(start, end + 1)

# Set Title
if set_title is None:
set_title = ' '.join(
[
dsname,
field,
'Stripes on',
dt_utils.numpy_to_arm_date(self._ds[dsname].time.values[0]),
]
)
ax.set_title(set_title)

# Set Colorbar
if colorbar:
if 'units' in data.attrs:
ytitle = ''.join(['(', data.attrs['units'], ')'])
else:
ytitle = field
if cbar_label is None:
cbar_title = ytitle
else:
cbar_title = ''.join(['(', cbar_label, ')'])
self.add_colorbar(col, title=cbar_title, subplot_index=subplot_index)

self.axes[subplot_index] = ax
return self.axes[subplot_index]
2 changes: 1 addition & 1 deletion act/qc/qc_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def create_qc_summary(

history_value = (
f"Quality control summary implemented by ACT-{version} at "
f"{datetime.datetime.utcnow().replace(microsecond=0)} UTC"
f"{datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)} UTC"
)

if 'history' in list(return_ds.attrs.keys()):
Expand Down
3 changes: 2 additions & 1 deletion act/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ def change_units(
self._ds[var_name].attrs = attrs
except (
KeyError,
TypeError,
pint.errors.DimensionalityError,
pint.errors.UndefinedUnitError,
np.core._exceptions.UFuncTypeError,
np._core._exceptions.UFuncTypeError,
):
if raise_error:
raise ValueError(
Expand Down
31 changes: 13 additions & 18 deletions docs/environment_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,31 @@ dependencies:
- pyproj
- numpy
- scipy
- matplotlib>=3.5.1
- matplotlib
- netcdf4
- dask
- xarray
- ipython
- notebook
- pint=0.8.1
- skyfield
- scikit-posthocs
- pip
- shapely<1.8.3
- moviepy
- cmweather
- metpy
- sphinx-design
- nbsphinx
- arm_pyart
- sphinx<7.2
- sphinx-gallery
- sphinx-copybutton
- pydata-sphinx-theme
- myst-nb
- nbsphinx
- pip
- pip:
- mpl2nc
- lazy_loader
- metpy>=1.2
- arm-pyart
- sphinx<7.2
- sphinx_gallery
- sphinx-copybutton
- pydata-sphinx-theme<0.9.0
- myst_nb
- ablog
- sphinx_design
- nbsphinx
- pooch
- icartt
- cmweather
- sphinxcontrib-devhelp==1.0.5
- sphinxcontrib-htmlhelp==2.0.4
- sphinxcontrib-qthelp==1.0.6
- sphinxcontrib-serializinghtml==1.1.9
- git+https://github.com/ARM-DOE/arm-test-data.git
165 changes: 34 additions & 131 deletions docs/source/_static/act-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,144 +3,47 @@
font-family: Poppins, sans-serif;
}

/* ARM header color */
.bg-arm {
background-color: #182b55;
}

:root {
--pst-color-navbar-link: 255, 255, 255;
--pst-color-text-base: 24, 43, 85;
--pst-color-h3: var(--pst-color-text-base);
--pst-color-h4: var(--pst-color-text-base);
--pst-color-h5: var(--pst-color-text-base);
--pst-color-h6: var(--pst-color-text-base);
--pst-color-paragraph: var(--pst-color-text-base);
}

/* Override the default color set in the original theme for title */
.navbar-brand>.title {
color: rgba(255, 255, 255) !important;
font-weight: 400 !important;
font-style: bold;
/* Define "ARM Blue" RGB values */
:root {
--arm-blue-rgb: 18, 65, 117;
}

/* Override the default color set in the original theme */
.navbar-nav>.active>.nav-link {
color: rgba(255, 255, 255) !important;
font-weight: 400 !important;
font-style: italic;
}

.fa-github-square:before {
color: rgba(255, 255, 255) !important;
font-weight: 400 !important;
}

.fa-twitter-square:before {
color: rgba(255, 255, 255) !important;
font-weight: 400 !important;
}

/* Override the default logo height */
.navbar-brand {
height: 50px;
}

/* Enhance the links to function docs in the gallery examples */
div[class^="highlight"] a {
background-color: #EEEEEE;
}

/* Control the appearance of the version alert banner */
#banner .alert-version, .alert-news {
margin: 1em;
padding: 0.5em;
font-family: "Work Sans", sans-serif;
font-weight: 600; font-size: 16px;
}

.intro-card {
background: #d8e5e8;
border: none;
border-radius: 0;
padding: 30px 10px 10px 10px;
margin: 10px 0px;
}

.intro-card .card-text {
margin: 20px 0px;
}

.card-button {
background-color: #fafafa;
border: none;
color: #484848;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 0.9rem;
border-radius: 0.5rem;
max-width: 220px;
padding: 0.5rem 0rem;
margin-top: auto;
}

.card-button a {
color: #484848;
}

.card-button p {
margin-top: 0;
margin-bottom: 0rem;
color: #484848;
}

/* Tweaks to the appearance of the sidebars */
.bd-sidebar {
flex: 0 0 20%;
border-right: none;
}

.bd-toc .tocsection {
border-left: none;
}

.bd-toc .section-nav {
border-left: none;
}

/* Can remove once theme releases new version */
/* xarray output display in bootstrap */
.xr-wrap[hidden] {
display: block !important;
/* ARM header color */
.bg-header {
background: rgb(var(--arm-blue-rgb))
}

.xr-var-data pre {
border: none;
box-shadow: none;
}
.theme-switch-button {
border-color: rgb(var(--arm-blue-rgb)) !important;
}

.bd-header .navbar-nav>.nav-item>.nav-link,
.bd-header .dropdown-toggle,

/* Styling the API Changes Table */
.api-table tr:nth-child(3n + 1){
background: #EEF5F5;
}
.navbar-nav .dropdown-menu {
background-color: var(--pst-color-background);
}

.api-table tr:nth-child(3n + 2){
opacity: 0.65;
}
/* Increase contrast of links in code snippets */
div[class^="highlight"] a {
background-color: rgb(var(--arm-blue-rgb), 0.2);
color: var(--pst-color-text-muted);
}

code.literal:not(.xref) span.pre {
color: #000;
}
/* Control the appearance of the version alert banner */
#banner .alert-version, .alert-news {
margin: 1em;
padding: 0.5em;
font-family: "Work Sans", sans-serif;
font-weight: 600; font-size: 16px;
}

.api-table tr:nth-child(3n + 2)>td span:first-child::before{
content: url(old.png);
zoom: 0.25;
}
/* Tweaks to the appearance of the sidebars */
.bd-sidebar {
flex: 0 0 20%;
border-right: none;
}

.api-table tr:nth-child(3n + 3)>td span:first-child::before{
content: url(new.png);
zoom: 0.21;
}
.bd-sidebar-secondary div {
border-left: none;
}
Loading

0 comments on commit f4f1ba0

Please sign in to comment.