Skip to content

Commit

Permalink
bugs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rbardaji committed May 3, 2021
1 parent f9a7b56 commit 7207d29
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mooda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
es_create_indexes, EMSO, widget_qc, widget_emso, widget_emso_qc, \
widget_save, iplot_line

__version__ = '1.12.3'
__version__ = '1.12.4'
2 changes: 1 addition & 1 deletion mooda/waterframe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WaterFrame:
from .iplot import (
iplot_location, iplot_timeseries, iplot, iplot_scatter, iplot_line,
iplot_data_intervals, iplot_scatter_mapbox, iplot_bar_polar,
iplot_histogram, iplot_candlestick)
iplot_histogram, iplot_candlestick, iplot_box, iplot_correlation_headmap)

def __init__(self, df=None, metadata=None, vocabulary=None):
""" Constructor """
Expand Down
2 changes: 2 additions & 0 deletions mooda/waterframe/iplot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
from .iplot_bar_polar import iplot_bar_polar
from .iplot_histogram import iplot_histogram
from .iplot_candlestick import iplot_candlestick
from .iplot_box import iplot_box
from .iplot_correlation_headmap import iplot_correlation_headmap
44 changes: 44 additions & 0 deletions mooda/waterframe/iplot/iplot_box.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from plotly.validators.scatter.marker import SymbolValidator
from sklearn.linear_model import LinearRegression


def iplot_box(self, parameter="", color=None, **kwds):
"""
It uses plotly.express.box.
Parameters
----------
parameter: str
color: str
Name of a column in self.data, or a pandas Series or array_like
object. Values from this column or array_like are used to assign
color to marks.
If color == 'auto' and parameter != "", color = 'DEPTH'
Returns
-------
fig: plotly.graph_objects.Figure
"""

if parameter:
if color == 'auto':
color = 'DEPTH'

_df = self.data.copy()
_df.reset_index(inplace=True)
data_frame = _df[[parameter, 'TIME', 'DEPTH']].copy()
# Define x and yof box
x = parameter

fig = px.box(data_frame=data_frame, x=x, color=color, **kwds)

else:
if color == 'auto':
color = None
fig = px.box(**kwds)

return fig
34 changes: 34 additions & 0 deletions mooda/waterframe/iplot/iplot_correlation_headmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from plotly.validators.scatter.marker import SymbolValidator
from sklearn.linear_model import LinearRegression


def iplot_correlation_headmap(self, parameters=[], **kwds):
"""
It uses plotly.express.imshow.
Parameters
----------
parameter: str
Returns
-------
fig: plotly.graph_objects.Figure
"""

if parameters:

_df = self.data.copy()
_df.reset_index(inplace=True)
data_frame = _df[parameters].copy()
corr = data_frame.corr()

fig = px.imshow(corr, **kwds)

else:
ig = px.imshow(**kwds)

return fig
34 changes: 29 additions & 5 deletions mooda/waterframe/iplot/iplot_histogram.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import plotly.express as px


def iplot_histogram(self, x='TIME', nbins=None, **kwds):
def iplot_histogram(self, parameter='', nbins=None, show_median=False, **kwds):
"""
It uses plotly.express.histogram.
Each data point is represented as a marker point, whose location is given by the x and y columns
of self.data.
Parameters
----------
x: str
X axes, column or index of data.
parameter: str
x axes, column or index of data.
nbins: int
By default, the number of bins is chosen so that this number is comparable to the
typical number of samples in a bin. This number can be customized, as well as the range of values.
Expand All @@ -22,8 +22,32 @@ def iplot_histogram(self, x='TIME', nbins=None, **kwds):
fig: plotly.graph_objects.Figure
"""

df = self.data.copy()
if parameter:
_df = self.data.copy()
_df.reset_index(inplace=True)
df = _df[[parameter, 'TIME', 'DEPTH']].copy()

fig = px.histogram(df, x=x, nbins=nbins)
fig = px.histogram(df, x=parameter, nbins=nbins, **kwds)

if show_median:
mean = df[parameter].mean()
print(mean)
text = dict(
x=mean, y=0.95, xref='x', yref='paper',
showarrow=False, xanchor='left', text=f'Mean: {mean:.3f}')
shape = dict(
x0=mean,
x1=mean,
y0=0, y1=1,
xref='x',
yref='paper',
line_width=2)

fig.update_layout(
shapes=[shape],
annotations=[text])
else:

fig = px.histogram(dnbins=nbins, **kwds)

return fig
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


NAME = 'mooda'
VERSION = '1.12.3'
VERSION = '1.12.4'
DESCRIPTION = 'Module for Ocean Observatory Data Analysis'
LONG_DESCRIPTION = ("""
MOODA - Module for Ocean Observatory Data Analysis
Expand Down

0 comments on commit 7207d29

Please sign in to comment.