Plots’ operations

Merging plots

CasysPlot can be merged together in order to display them on the same plot. This merge operation is done using the add_plot() method.
Add a plot to the current one.

The provided plot is copied with its current parameters. Modifying it afterward
won't affect the added plot, you have to set it before.

Parameters
----------
cplot
    CasysPlot to add.
shared_ax
    Axis to share with the current plot (x, y or all).
from casys import CasysPlot

plot_1 = CasysPlot(
    data=ad,
    data_name='Ku-band range std fct swh',
    stat="mean",
)

plot_2 = CasysPlot(
    data=ad,
    data_name='C-band range std fct swh',
    stat="mean"
)

plot_1.add_plot(plot_2, shared_ax="all")
plot_1.show()
_images/cp_operations_2_0.png

Warning

Only CasysPlot of the same family can be merged together (i.e. you cannot merge a geographical box map with an along time curve).
For a additional examples on how to merge plots, visit this notebook.

Concatenating plots’ data

Sometime you might end up with CasysPlot representing the same data for different periods. All of these plots’ data can be concatenated into one with the concatenate_data() method.
Concatenate data from provided plots into the current one.

Parameters
----------
cplots
    List of plots to concatenate.

Warning

Trying to concatenate plots containing different data might lead to unexpected things.

Plots’ arithmetic

Operations on CasysPlot objects can be made without having to access their data attribute.
These operations are applied to the underlying xarray Dataset or DataArray containing the plot’s data.

Example: Manually computing a ratio.

from casys import CasysPlot

plot_1 = CasysPlot(
    data=ad,
    data_name="Rejected data, mean by pass",
    stat="count"
)

plot_2 = CasysPlot(
    data=ad,
    data_name="Number of points, mean by pass",
    stat="count"
)

plot_ratio = (plot_1 / plot_2) * 100
plot_ratio.set_title("Percentage of rejected points")
plot_ratio.set_ylabel("Rejected points (%)")

plot_ratio.show()
_images/cp_operations_4_0.png
Example: A complex calculation that have no scientific meaning but might give you some ideas.
from casys import CasysPlot

# Temporal plots definitions:
sla_mean = CasysPlot(
    data=ad,
    data_name="SLA (6h)",
    stat="mean"
)
sla_std = CasysPlot(
    data=ad,
    data_name="SLA (6h)",
    stat="std"
)
sig_mean = CasysPlot(
    data=ad,
    data_name="SIG0 (6h)",
    stat="mean"
)
sig_count = CasysPlot(
    data=ad,
    data_name="SIG0 (6h)",
    stat="count"
)

# Along track data plots definitions:
cp1 = CasysPlot(data=ad, data_name="SLA")
cp2 = CasysPlot(data=ad, data_name="Wind speed")

# Calculations:
cp_x = (sla_mean + (0.1 * sig_count)) / (sla_std * sig_mean)
cp_x.show()

lat = cp1.data["LATITUDE"]

coef_wind = (cp2 / 23.28)
coef_lat = abs(lat / 190)

cp_coef = cp1 * coef_wind * coef_lat
cp_coef.show()
_images/cp_operations_5_0.png
These operations are implemented using Python operator methods.
Available operations are:
  • Unary operators:

    • neg

    • abs

    • pos

    • invert

  • Binary operator:

    • add

    • sub

    • mul

    • truediv

    • floordiv

    • mod

    • pow

Raw data coordinates adjustment

When working with raw data map plots you might be interested in showing two fields’ values of a same pass.
In order for them to not overlap you can use the adjust_coordinates() method allowing to adjust longitudes and/or latitudes of a plot by a given value.
Adjust plots longitudes and latitudes coordinates.

Parameters
----------
longitude
    Value to add.
latitude
    Value to add.
from casys import AxeParams, CasysPlot, DataParams, DateHandler, PlotParams

pass_77 = (
    DateHandler.from_orf("C_J3_GDRD", 122, 77, pos="first"),
    DateHandler.from_orf("C_J3_GDRD", 122, 77, pos="last"),
)

sig0_plot_par = PlotParams(
    fig_width=5.5,
    fig_height=8,
    x_limits=(80, 110),
    y_limits=(-50, 20),
    color_limits=(0, 17),
    color_map="autumn",
    color_bar=AxeParams(position="right"),
)

sig0_77_plot = CasysPlot(
    data=ad,
    data_name="Sigma 0",
    plot="map",
    plot_params=sig0_plot_par,
    data_params=DataParams(time_limits=pass_77),
)


sla_plot_par = PlotParams(color_limits=(-4, -1), color_bar=AxeParams(position="right"))

sla_77_plot = CasysPlot(
    data=ad,
    data_name="SLA",
    plot="map",
    plot_params=sla_plot_par,
    data_params=DataParams(time_limits=pass_77),
)

# Adjusting sla plot longitudes so they do not overlap each other.
sla_77_plot.adjust_coordinates(longitude=1)

# Adding statistics
sla_77_plot.add_stat_bar()
sig0_77_plot.add_stat_bar()

# Merging plots
sig0_77_plot.add_plot(sla_77_plot)

sig0_77_plot.show()
_images/cp_operations_7_0.png
This example along with some others might be found in the following notebook.