PythonViewUtils Package
This package includes utilities to display cross-plot using the Python View from Paraview.
geos_posp.visu.pythonViewUtils.Figure2DGenerator module
- class geos_posp.visu.pythonViewUtils.Figure2DGenerator.Figure2DGenerator(dataframe, userChoices)[source]
Bases:
object
Utility to create cross plots using Python View.
We want to plot f(X) = Y where in this class, “X” will be called “variable”, “Y” will be called “curves”.
- Parameters:
dataframe (pd.DataFrame) – data to plot
userChoices (dict[str, list[str]]) – user choices.
geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator module
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.abbreviateLabel(label)[source]
Get the abbreviation of the label according to reservoir nomenclature.
When using labels to plot, the name can tend to be too long. Therefore, to respect the logic of reservoir engineering vocabulary, abbreviations for common property names can be used to shorten the name. The goal is therefore to generate the right abbreviation for the label input.
- Parameters:
label (str) – A label to be plotted. Example- Reservoir__DissolvedMassphaseName0InphaseName1__kg__job123456.out
- Returns:
“phaseName0 in phaseName1”
- Return type:
str
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.adjust_subplots(fig, invertXY)[source]
Adjust the size of the subplot in the fig.
- Parameters:
fig (figure.Figure) – Matplotlib figure
invertXY (bool) – Choice to either intervert or not the X and Y axes
- Returns:
Matplotlib figure with adjustements
- Return type:
figure.Figure
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.applyCustomizationOnLine(line, parameters)[source]
Apply modification methods on a line from parameters.
- Parameters:
line (lines.Line2D) – Matplotlib Line2D
parameters (dict[str, Any]) – dictionary of { “linestyle”: one of [“-“,”–“,”-.”,”:”] “linewidth”: positive int “color”: color code “marker”: one of [“”,”.”,”o”,”^”,”s”,”*”,”D”,”+”,”x”] “markersize”:positive int }
- Returns:
Line2D object modified.
- Return type:
lines.Line2D
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.associatePropertyToAxeType(propertyNames)[source]
Identify property types.
From a list of property names, identify if each of this property corresponds to a certain property type like “Pressure”, “Mass”, “Temperature” etc … and returns a dict where the keys are the property type and the value the list of property names associated to it.
- Parameters:
propertyNames (list[str]) – [“Reservoir__Pressure__Pa__Source1”, “CO2__Mass__kg__Source1”, “Water__Mass__kg__Source1”]
- Returns:
- { “Pressure (Pa)”: [“Reservoir__Pressure__Pa__Source1”],
”Mass (kg)”: [“CO2__Mass__kg__Source1”, “Water__Mass__kg__Source1”] }
- Return type:
dict[str, list[str]]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.associationIdentifiers(propertyNames)[source]
Extract identifiers with associatied curves.
From a list of property names, extracts the identifier (name of the region for flow property or name of a well for well property) and creates a dictionnary with identifiers as keys and the properties containing them for value in a list.
- Parameters:
propertyNames (list[str]) – property names
Example
code-block: (..) – python: [ “WellControls1__BHP__Pa__Source1”, “WellControls1__TotalMassRate__kg/s__Source1”, “WellControls1__TotalSurfaceVolumetricRate__m3/s__Source1”, “WellControls1__SurfaceVolumetricRateCO2__m3/s__Source1”, “WellControls1__SurfaceVolumetricRateWater__m3/s__Source1”, “WellControls2__BHP__Pa__Source1”, “WellControls2__TotalMassRate__kg/s__Source1”, “WellControls2__TotalSurfaceVolumetricRate__m3/s__Source1”, “WellControls2__SurfaceVolumetricRateCO2__m3/s__Source1”, “WellControls2__SurfaceVolumetricRateWater__m3/s__Source1”, “WellControls3__BHP__Pa__Source1”, “WellControls3__TotalMassRate__tons/day__Source1”, “WellControls3__TotalSurfaceVolumetricRate__bbl/day__Source1”, “WellControls3__SurfaceVolumetricRateCO2__bbl/day__Source1”, “WellControls3__SurfaceVolumetricRateWater__bbl/day__Source1”, “Mean__BHP__Pa__Source1”, “Mean__TotalMassRate__tons/day__Source1”, “Mean__TotalSurfaceVolumetricRate__bbl/day__Source1”, “Mean__SurfaceVolumetricRateCO2__bbl/day__Source1”, “Mean__SurfaceVolumetricRateWater__bbl/day__Source1” ]
- Returns:
- property identifiers
Example
{ "WellControls1": { 'BHP (Pa)': [ 'WellControls1__BHP__Pa__Source1' ], 'MassRate (kg/s)': [ 'WellControls1__TotalMassRate__kg/s__Source1' ], 'VolumetricRate (m3/s)': [ 'WellControls1__TotalSurfaceVolumetricRate__m3/s__Source1', 'WellControls1__SurfaceVolumetricRateCO2__m3/s__Source1', 'WellControls1__SurfaceVolumetricRateWater__m3/s__Source1' ] }, "WellControls2": { 'BHP (Pa)': [ 'WellControls2__BHP__Pa__Source1' ], 'MassRate (kg/s)': [ 'WellControls2__TotalMassRate__kg/s__Source1' ], 'VolumetricRate (m3/s)': [ 'WellControls2__TotalSurfaceVolumetricRate__m3/s__Source1', 'WellControls2__SurfaceVolumetricRateCO2__m3/s__Source1', 'WellControls2__SurfaceVolumetricRateWater__m3/s__Source1' ] }, "WellControls3": { 'BHP (Pa)': [ 'WellControls3__BHP__Pa__Source1' ], 'MassRate (tons/day)': [ 'WellControls3__TotalMassRate__tons/day__Source1' ], 'VolumetricRate (bbl/day)': [ 'WellControls3__TotalSurfaceVolumetricRate__bbl/day__Source1', 'WellControls3__SurfaceVolumetricRateCO2__bbl/day__Source1', 'WellControls3__SurfaceVolumetricRateWater__bbl/day__Source1' ] }, "Mean": { 'BHP (Pa)': [ 'Mean__BHP__Pa__Source1' ], 'MassRate (tons/day)': [ 'Mean__TotalMassRate__tons/day__Source1' ], 'VolumetricRate (bbl/day)': [ 'Mean__TotalSurfaceVolumetricRate__bbl/day__Source1', 'Mean__SurfaceVolumetricRateCO2__bbl/day__Source1', 'Mean__SurfaceVolumetricRateWater__bbl/day__Source1' ] } }
- Return type:
dict[str, dict[str, list[str]]]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.basicFigure(df, variableName, curveName)[source]
Creates a plot.
Generates a figure and axes objects from matplotlib that plots one curve along the X axis, with legend and label for X and Y.
- Parameters:
df (pd.DataFrame) – dataframe containing at least two columns, one named “variableName” and the other “curveName”
variableName (str) – Name of the variable column
curveName (str) – Name of the column to display along that variable.
- Returns:
the fig and the ax.
- Return type:
tuple[figure.Figure, axes.Axes]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.buildFontCurves(userChoices)[source]
Builds a Fontproperties object according to user choices on curves.
- Parameters:
userChoices (dict[str, str]) – customization parameters.
- Returns:
FontProperties object for the curves axes.
- Return type:
FontProperties
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.buildFontTitle(userChoices)[source]
Builds a Fontproperties object according to user choices on title.
- Parameters:
userChoices (dict[str, Any]) – customization parameters.
- Returns:
FontProperties object for the title.
- Return type:
FontProperties
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.buildFontVariable(userChoices)[source]
Builds a Fontproperties object according to user choices on variables.
- Parameters:
userChoices (dict[str, Any]) – customization parameters.
- Returns:
FontProperties object for the variable axes.
- Return type:
FontProperties
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.customizeLines(userChoices, labels, linesList)[source]
Customize lines according to user choices.
By applying the user choices, we modify or not the list of lines and return it with the same number of lines in the same order.
- Parameters:
userChoices (dict[str, Any]) – customization parameters.
labels (list[str]) – labels of lines.
linesList (list[lines.Line2D]) – list of lines object.
- Returns:
list of lines object modified.
- Return type:
list[lines.Line2D]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.findClosestPairIntegers(x)[source]
Get the pair of integers that multiply the closest to input value.
Finds the closest pair of integers that when multiplied together, gives a number the closest to the input number (always above or equal).
- Parameters:
x (int) – Positive number.
- Returns:
(highest int, lowest int)
- Return type:
tuple[int, int]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.findExtremasAssociatedProperties(df, associatedProperties)[source]
Find the min and max of properties.
Using an associatedProperties dict containing property types as keys and a list of property names as values, and a pandas dataframe whose column names are composed of those same property names, you can find the min and max values of each property type and return it as a tuple.
- Parameters:
df (pd.DataFrame) – Pandas dataframe
associatedProperties (dict[str, list[str]]) –
{ “Pressure (Pa)”: [“Reservoir__Pressure__Pa__Source1”], “Mass (kg)”: [“CO2__Mass__kg__Source1”, “Water__Mass__kg__Source1”] }
- Returns:
{ “Pressure (Pa)”: (minPressure, maxPressure), “Mass (kg)”: (minMass, maxMass) }
- Return type:
dict[str, tuple[float, float]]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.findExtremasPropertiesForAssociatedIdentifiers(df, associatedIdentifiers, offsetPlotting=False, offsetPercentage=5)[source]
Find min and max of all properties linked to a same identifier.
Using an associatedIdentifiers dict containing associatedProperties dict, we can find the extremas for each property of each identifier. Once we have them all, we compare for each identifier what are the most extreme values and only the biggest and lowest are kept in the end.
- Parameters:
df (pd.DataFrame) – Pandas dataframe
associatedIdentifiers (dict[str, dict[str, list[str]]]) – property identifiers.
offsetPlotting (bool, optional) – When using the values being returned, we might want to add an offset to these values. If set to True, the offsetPercentage is taken into account. Defaults to False.
offsetPercentage (int, optional) – Value by which we will offset the min and max values of each tuple of floats. Defaults to 5.
- Returns:
{ “BHP (Pa)”: (minAllWells, maxAllWells), “TotalMassRate (kg)”: (minAllWells, maxAllWells), “TotalSurfaceVolumetricRate (m3/s)”: (minAllWells, maxAllWells), “SurfaceVolumetricRateCO2 (m3/s)”: (minAllWells, maxAllWells), “SurfaceVolumetricRateWater (m3/s)”: (minAllWells, maxAllWells) }
- Return type:
dict[str, tuple[float, float]]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.findIdentifier(label)[source]
Find identifier inside the label.
When looking at a label, it may contain or not an identifier at the beginning of it. An identifier is either a regionName or a wellName. The goal is to find it and extract it if present.
- Parameters:
label (str) – A label to be plotted. Example- Reservoir__DissolvedMassphaseName0InphaseName1__kg__job123456.out
- Returns:
“Reservoir”
- Return type:
str
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.findJobName(label)[source]
Find the Geos job name at the end of the label.
When looking at a label, it may contain or not a job name at the end of it. The goal is to find it and extract it if present.
- Parameters:
label (str) – A label to be plotted. Example- Reservoir__DissolvedMassphaseName0InphaseName1__kg__job123456.out
- Returns:
“job123456.out”
- Return type:
str
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.findPhasesLabel(label)[source]
Find phase name inside label.
When looking at a label, it may contain or not patterns that indicates the presence of a phase name within it. Therefore, if one of these patterns is present, one or multiple phase names can be found and be extracted.
- Parameters:
label (str) – A label to be plotted. Example- Reservoir__DissolvedMassphaseName0InphaseName1__kg__job123456.out
- Returns:
[phaseName0, phaseName1]
- Return type:
list[str]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.getAxeLimits(ax)[source]
Gets the limits of both X and Y axis as a 4 element tuple.
- Parameters:
ax (axes.Axes) – subplot to get limits.
- Returns:
(xMin, xMax, yMin, yMax)
- Return type:
tuple[float, float, float, float]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.getExtremaAllAxes(axes)[source]
Gets the limits of both X and Y axis as a 2x2 element tuple.
- Parameters:
axes (list[axes.Axes]) – list of subplots to get limits.
- Returns:
tuple[tuple[float, float], tuple[float, float]]:: ((xMin, xMax), (yMin, yMax))
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.invertedBasicFigure(df, variableName, curveName)[source]
Creates a plot with inverted XY axis.
Generates a figure and axes objects from matplotlib that plots one curve along the Y axis, with legend and label for X and Y.
- Parameters:
df (pd.DataFrame) – dataframe containing at least two columns, one named “variableName” and the other “curveName”
variableName (str) – Name of the variable column
curveName (str) – Name of the column to display along that variable.
- Returns:
the fig and the ax.
- Return type:
tuple[figure.Figure, axes.Axes]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.isprime(x)[source]
Checks if a number is primer or not.
- Parameters:
x (int) – Positive number to test.
- Returns:
True if prime, False if not.
- Return type:
bool
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.multipleSubplots(df, userChoices)[source]
Created multiple subplots.
From a dataframe, knowing which curves to plot along which variable, generates a fig and its list of axes with the data plotted.
- Parameters:
df (pd.DataFrame) – dataframe containing at least two columns, one named “variableName” and the other “curveName”.
userChoices (dict[str, Any]) – Choices made by widget selection in PythonViewConfigurator filter.
- Returns:
tuple[figure.Figure, list[axes.Axes], list[lines.Line2D] , list[str]]: the fig and its list of axes.
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.multipleSubplotsInverted(df, userChoices)[source]
Created multiple subplots with inverted X Y axes.
From a dataframe, knowing which curves to plot along which variable, generates a fig and its list of axes with the data plotted.
- Parameters:
df (pd.DataFrame) – dataframe containing at least two columns, one named “variableName” and the other “curveName”.
userChoices (dict[str, Any]) – Choices made by widget selection in PythonViewConfigurator filter.
- Returns:
tuple[figure.Figure, list[axes.Axes], list[lines.Line2D] , list[str]]: the fig and its list of axes.
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.oneSubplot(df, userChoices)[source]
Created a single subplot.
From a dataframe, knowing which curves to plot along which variable, generates a fig and its list of axes with the data plotted.
- Parameters:
df (pd.DataFrame) – dataframe containing at least two columns, one named “variableName” and the other “curveName”
userChoices (dict[str, Any]) – Choices made by widget selection in PythonViewConfigurator filter.
- Returns:
tuple[figure.Figure, list[axes.Axes], list[lines.Line2D] , list[str]]: the fig and its list of axes.
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.oneSubplotInverted(df, userChoices)[source]
Created a single subplot with inverted X Y axes.
From a dataframe, knowing which curves to plot along which variable, generates a fig and its list of axes with the data plotted.
- Parameters:
df (pd.DataFrame) – dataframe containing at least two columns, one named “variableName” and the other “curveName”
userChoices (dict[str, Any]) – Choices made by widget selection in PythonViewConfigurator filter.
- Returns:
tuple[figure.Figure, list[axes.Axes], list[lines.Line2D] , list[str]]: the fig and its list of axes.
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.plotAxe(ax_to_use, x, y, propertyName, cpt_cmap, curvesAspect)[source]
Plot x, y data using input ax_to_use according to curvesAspect.
- Parameters:
ax_to_use (axes.Axes) – subplot to use
x (npt.NDArray[np.float64]) – abscissa data
y (npt.NDArray[np.float64]) – ordinate data
propertyName (str) – name of the property
cpt_cmap (int) – colormap to use
curvesAspect (dict[str, tuple[tuple[float, float, float],str, float, str, float]]) – user choices on curve aspect
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.propertiesPerIdentifier(propertyNames)[source]
Extract identifiers with associatied properties.
From a list of property names, extracts the identifier (name of the region for flow property or name of a well for well property) and creates a dictionnary with identifiers as keys and the properties containing them for value in a list.
- Parameters:
propertyNames (list[str]) –
property names Example
[ "WellControls1__BHP__Pa__Source1", "WellControls1__TotalMassRate__kg/s__Source1", "WellControls2__BHP__Pa__Source1", "WellControls2__TotalMassRate__kg/s__Source1" ]
- Returns:
- property identifiers
Example
{ "WellControls1": [ "WellControls1__BHP__Pa__Source1", "WellControls1__TotalMassRate__kg/s__Source1" ], "WellControls2": [ "WellControls2__BHP__Pa__Source1", "WellControls2__TotalMassRate__kg/s__Source1" ] }
- Return type:
dict[str, list[str]]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.setupAllAxes(first_ax, variableName, associatedProperties, axisX)[source]
Modify axis name and ticks avec X or Y axis of all subplots.
- Parameters:
first_ax (axes.Axes) – subplot id.
variableName (str) – name of the axis.
associatedProperties (dict[str, list[str]]) – Name of the properties
axisX (bool) – X (True) or Y (False) axis to modify.
- Returns:
modified subplots
- Return type:
list[axes.Axes]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.setupAxeToUse(all_ax, axeId, ax_name, axisX)[source]
Modify axis name and ticks avec X or Y axis of subplot axeId in all_ax.
- Parameters:
all_ax (list[axes.Axes]) – list of all subplots
axeId (int) – id of the subplot
ax_name (str) – name of the X or Y axis
axisX (bool) – X (True) or Y (False) axis to modify.
- Returns:
modified subplot
- Return type:
axes.Axes
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.smartLabel(label, userChoices)[source]
Shorten label according to user choices.
Labels name can tend to be too long. Therefore, we need to reduce the size of the label. Depending on the choices made by the user, the identifier and the job name can disappear.
- Parameters:
label (str) – A label to be plotted. Example- Reservoir__DissolvedMassphaseName0InphaseName1__kg__job123456.out
userChoices (dict[str, Any]) – user choices.
- Returns:
“phaseName0 in phaseName1” or “Reservoir phaseName0 in phaseName1” or “phaseName0 in phaseName1 job123456.out” or “Reservoir phaseName0 in phaseName1 job123456.out”
- Return type:
str
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.smartLabelsSorted(labels, lines, userChoices)[source]
Shorten all legend labels and sort them.
To improve readability of the legend for an axe in ParaView, we can apply the smartLegendLabel functionnality to reduce the size of each label. Plus we sort them alphabetically and therefore, we also sort the lines the same way.
- Parameters:
labels (list[str]) – Labels to use ax.legend() like [“Region1__TemperatureAvg__K__job_123456”, “Region1__PressureMin__Pa__job_123456”]
lines (list[lines.Line2D]) – Lines plotted on axes of matplotlib figure like [line1, line2]
userChoices (dict[str, Any]) – Choices made by widget selection in PythonViewConfigurator filter.
- Returns:
Improved labels and sorted labels / lines like ([“Region1 Pmin”, “Region1 Tavg”], [line2, line1])
- Return type:
tuple[list[str], list[lines.Line2D]]
- geos_posp.visu.pythonViewUtils.functionsFigure2DGenerator.smartLayout(x, ratio)[source]
Return the best layout according to the number of subplots.
For multiple subplots, we need to have a layout that can adapt to the number of subplots automatically. This function figures out the best layout possible knowing the number of suplots and the figure ratio.
- Parameters:
x (int) – Positive number.
ratio (float) – width to height ratio of a figure.
- Returns:
(nbr_rows, nbr_columns, number of axes to remove)
- Return type:
tuple[int]