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

[FEAT] Add plot that shows the max depth of each profile #159

Merged
merged 10 commits into from
Dec 16, 2024

Conversation

tillmrtz
Copy link
Contributor

@tillmrtz tillmrtz commented Dec 3, 2024

Bildschirmfoto 2024-12-03 um 10 49 53

@tillmrtz tillmrtz marked this pull request as draft December 3, 2024 09:53
@MOchiara
Copy link
Member

MOchiara commented Dec 3, 2024

To do:

  • Move the max depth computation to glidertest/tools.py
  • Create a test for the function in tool.py (tests/test_tools.py)
  • Create a test for the plot (tests/test_plots.py)
  • Add the function to notebooks/demo.ipynb to demonstrate the use of it

@@ -1305,3 +1305,38 @@ def plot_ioosqc(data, suspect_threshold=[25], fail_threshold=[50], title='', ax=
if force_plot:
plt.show()
return fig, ax

def plot_max_depth_per_profile(ds: xr.Dataset, bins= 20, **kw: dict) -> tuple({plt.Figure, plt.Axes}):
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add ax as a parameter
ax=None

And add below the

if ax is None:
            fig, ax = plt.subplots()
            force_plot = True
else: 
            fig = plt.gcf()
            force_plot = False

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check the other examples and the end you would put also

if force_plot:
            plt.show()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to:
if ax is None:
fig, ax = plt.subplots(1,2)
force_plot = True
I hope this is correct, since I want to plots, like in plot_outlier_duration()

ax[0].set_xlabel('Profile Number')
ax[0].set_ylabel('Max Depth')
ax[0].set_title('Max Depth per Profile')
ax[0].grid()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to avoid repetition you can do a
[a.grid() for a in ax]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

max_depths = group_profiles.values
profile_nums = group_profiles.profile_num.values
with plt.style.context(glidertest_style_file):
fig, ax = plt.subplots(1, 2, figsize=(18, 6))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The figure size is already specified in the glidertest_style_file and is 14,10
We do change it in the function when we make them smaller (ex. plot_basic_vars)
I suggest we keep the standard size and resize later if desired by specifying the figure size

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted the figsize adjustment

with plt.style.context(glidertest_style_file):
fig, ax = plt.subplots(1, 2, figsize=(18, 6))
ax[0].plot(profile_nums, max_depths,**kw)
ax[0].set_xlabel('Profile Number')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are generally using capital letter only for the first 'word' so maybe change to 'Profile number'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

fig, ax = plt.subplots(1, 2, figsize=(18, 6))
ax[0].plot(profile_nums, max_depths,**kw)
ax[0].set_xlabel('Profile Number')
ax[0].set_ylabel('Max Depth')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before maybe use 'Max depth' and add units in round paranthesis

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chnaged

ax[0].plot(profile_nums, max_depths,**kw)
ax[0].set_xlabel('Profile Number')
ax[0].set_ylabel('Max Depth')
ax[0].set_title('Max Depth per Profile')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with the capitall letters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

ax[1].hist(max_depths, bins=bins)
ax[1].set_xlabel('Max Depth')
ax[1].set_ylabel('Number of Profiles')
ax[1].set_title('Histogram of Max Depth per Profile')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ax[1] labels and title without the extra capital letters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

@tillmrtz tillmrtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revised the max_depth_per_profile

fig = plt.gcf()
force_plot = False

ax[0].plot(profile_nums, max_depths,**kw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid creating a new variable and just say:
ax[0].plot(max_depths.profile_num, max_depths,**kw)

@MOchiara
Copy link
Member

Looks good! You now want to make the tests and add this function to the demo
No stress doing it now, we can fix this PR next week as well

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor Author

@tillmrtz tillmrtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created the test function and added the max-depth plot to demo notebook

@tillmrtz tillmrtz marked this pull request as ready for review December 16, 2024 12:52
@MOchiara MOchiara self-requested a review December 16, 2024 14:08
@tillmrtz
Copy link
Contributor Author

tillmrtz commented Dec 16, 2024

All changes approved

@tillmrtz tillmrtz closed this Dec 16, 2024
@callumrollo callumrollo reopened this Dec 16, 2024
@MOchiara MOchiara merged commit 1b4e750 into OceanGlidersCommunity:main Dec 16, 2024
20 checks passed
@MOchiara MOchiara linked an issue Dec 17, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overview plot of max depth per profile
3 participants