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

Plot class for ramp visualization and data analysis routines (isse #63) #89

Merged
merged 5 commits into from
Nov 8, 2023

Conversation

mohammadamint
Copy link
Collaborator

The new features added will allow the user to perform some data analysis and visualization routines:

changes

*. ramp/post_process/post_process.py

  • the class Plot is the main class carrying on the plotting and data analysis functionalities with custom APIs providing access to some pd.DataFrame features also easy to plot functions conencting to plotly and matplotlibe methods.

  • different plotting classes that include a specific plot type visualiztion using two different engines (plotly & matplotlib)

*. ramp.init.py

  • adding the Plot class to the init.

documentation

  • the functions API docuemntation is added to the API documentaiton
  • A full example titled "Plot class" is added to the example gallery describing the full potential of the new functionalities


valid_units = ('kW',"W","MW","GW","TW")
class Run:

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be good to add a docsting to the class so that the people can run help(Run)

To me these methods should be added to the existing Usecase class because here Run is simply a Usecase instance with only one User. If it is integrated into Usecase then the usage I envision for the future is to always take a Usecase class which has a method run and for which one can define datatimeIndexes. The method generate_profiles could be included into Usecase.generate_daily_load_profiles method for example

A Plot object
"""

if file.split(".")[-1] == "csv":
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also use file.endswith(".csv")

This is just a side comment

elif file.split(".")[-1] == "xlsx":

df = pd.read_excel(file,sheet_name=sheet_name,index_col=0,header=0)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe an error message if the extension is not supported?

class LinePlot:
"""Line plot functions for Plotly and matplotlib engine
"""
def plotly(df,**layout):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def plotly(df,**layout):
def plotly(self, df,**layout):

If this is a method class, you should add self, same goes for many occurences

"""
df = self.df.copy()

df = eval(f"df{conversion}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
df = eval(f"df{conversion}")
df = df * conversion

Using eval can lead to safety issues, it is considered good practice not to use it in code that you publish. As you only use it once, there is certainly a way around using eval we can find :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure!




class LinePlot:
Copy link
Collaborator

Choose a reason for hiding this comment

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

You seem to only use LinePlot, AreaPlot and ShadowPlot classes once in each of the corresponding methods of the class Plot. To me it would make the code easier to read/understand if those are discarded and their code simply added inside the line, area and shadow methods of Plot. Especially because most of the logic of lineis inLinePlot`. if there is a bigger plan for future use of such classes let me know, otherwise I would strongly recommand moving the code into the methods

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

would you keep to different functions for plotly and matplotlib for each type of plot, or simply use an if/else statement inside a plot function for the two options.

the main reason for having separate classes was to encapsulate the two plotting engine for each plot type, mainly for making it more readable.

df = df.sort_values(by=column,ascending=False)
df.index = [i for i in range(1,len(df.index)+1)]

return getattr(LinePlot,engine)(df,**kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here you could for example use return self.line(df,**kwargs) and make such that line does not take df=self.df it df is recieved as an argument

Copy link
Collaborator

@Bachibouzouk Bachibouzouk left a comment

Choose a reason for hiding this comment

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

Hello @mohammadamint , great work!

I made some comments to integrate your work in a more maintainable way, let me know if anything is unclear.

Shouldn't we move the rest of the functions like export_series into Plot class as this function turns anyway the profiles into a DataFrame and uses to_csv method. We should then look for other uses of post_processing function in the examples and fix them, to avoid that people use both ways. I would suggest to keep old ways to not break code but that we replace the code inside the function and use Plot methods inside those "deprecated" functions.

We should maybe discuss live in which order to merge the PRs and rebase your PR on top of the latest development branch if your branch is to be the last one to be merged. Let us contact each other via email to find a moment which fits us both :)

If you don't have time at the moment I could also make a PR onto this PR with my suggested changes.

@mohammadamint
Copy link
Collaborator Author

Hello @mohammadamint , great work!

I made some comments to integrate your work in a more maintainable way, let me know if anything is unclear.

Shouldn't we move the rest of the functions like export_series into Plot class as this function turns anyway the profiles into a DataFrame and uses to_csv method. We should then look for other uses of post_processing function in the examples and fix them, to avoid that people use both ways. I would suggest to keep old ways to not break code but that we replace the code inside the function and use Plot methods inside those "deprecated" functions.

We should maybe discuss live in which order to merge the PRs and rebase your PR on top of the latest development branch if your branch is to be the last one to be merged. Let us contact each other via email to find a moment which fits us both :)

If you don't have time at the moment I could also make a PR onto this PR with my suggested changes.

Hi @Bachibouzouk

Thanks for the nice comments. I would like to implement them before merging the PR, as they seem very useful to improve the readability of the code. I can do it in the upcoming days if it is fine!

Regarding the use of the existing functionalities into the Plot class, I absolutely agree with that, I can explore and work on this if needed.

I have quiet an open agenda this week! so we can meet almost everyday based on your availability!

mohammadamint added a commit that referenced this pull request Oct 24, 2023
- Improving the Plot class docstring
- Improving the error handling with invalid inputs by user regarding the
  file extensions and plot engine
- Improving the readability of the plotting scripts by merging the plot
  classes into Plot methods
@@ -90,6 +90,9 @@ def export_series(stoch_profiles_series, j=None, fname=None, ofname=None):
else:
print("No path to a file was provided to write the results")
<<<<<<< HEAD
<<<<<<< HEAD
Copy link
Collaborator

Choose a reason for hiding this comment

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

You have pushed conflicted files here

@Bachibouzouk
Copy link
Collaborator

@mohammadamint - if you rebased the branch onto development, how come there are still conflicts?

@Bachibouzouk Bachibouzouk linked an issue Oct 30, 2023 that may be closed by this pull request
@mohammadamint
Copy link
Collaborator Author

@mohammadamint - if you rebased the branch onto development, how come there are still conflicts?

Yes! Indeed. Not sure how that happened, but the conflicts are very easy to solve. if everything else, I can solve the conflict and merge it.

@Bachibouzouk
Copy link
Collaborator

Yes! Indeed. Not sure how that happened, but the conflicts are very easy to solve. if everything else, I can solve the conflict and merge it.

What is wierd is that it shows 25 commits, whereas I remember there where two, rebasing should keep the number of commits constant

@Bachibouzouk
Copy link
Collaborator

@mohammadamint - I did rebase locally on a copy of ramp_visualization with git rebase -i development and I only needed to fix one easy conflict in the ramp/post_process/post_process.py, the result is 2 commits on top of development did you pull the latest version of development locally before you rebased?

@mohammadamint
Copy link
Collaborator Author

@mohammadamint - I did rebase locally on a copy of ramp_visualization with git rebase -i development and I only needed to fix one easy conflict in the ramp/post_process/post_process.py, the result is 2 commits on top of development did you pull the latest version of development locally before you rebased?

Yes I did. but, I am not able to fix the conflicts that arose after rebasing properly. Would creating a new branch from the latest development work?

@Bachibouzouk
Copy link
Collaborator

Would creating a new branch from the latest development work?

I am not sure what you did, did you force push the ramp_visualisation rebased branch ? I can also force push mine, but then my name will be intertwined in the commit (still leaving you as the author though

@mohammadamint
Copy link
Collaborator Author

Would creating a new branch from the latest development work?

I am not sure what you did, did you force push the ramp_visualisation rebased branch ? I can also force push mine, but then my name will be intertwined in the commit (still leaving you as the author though

As soon as the solution works, it doesn't matter :-) .

@Bachibouzouk Bachibouzouk force-pushed the ramp_visualization branch 2 times, most recently from 3ad01e7 to 1c3d195 Compare October 31, 2023 16:47
@mohammadamint
Copy link
Collaborator Author

Is the conflict still there? @Bachibouzouk

@Bachibouzouk
Copy link
Collaborator

Is the conflict still there? @Bachibouzouk

Yes I reforced push your branch because I had to prepare dinner and I will tackle this now

Bachibouzouk pushed a commit that referenced this pull request Oct 31, 2023
- Improving the Plot class docstring
- Improving the error handling with invalid inputs by user regarding the
  file extensions and plot engine
- Improving the readability of the plotting scripts by merging the plot
  classes into Plot methods
@Bachibouzouk
Copy link
Collaborator

@mohammadamint - now it is fixed (I still have locally the old branch ramp_visualization in case)

@Bachibouzouk Bachibouzouk self-requested a review October 31, 2023 21:09
Copy link
Collaborator

@Bachibouzouk Bachibouzouk left a comment

Choose a reason for hiding this comment

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

Thanks for the modifications @mohammadamint

Is the class Run being used at all? I couldn't find an instance of Run( in the whole project. I would say we leave it here and merge it into UseCase in a subsequent PR :)

@mohammadamint
Copy link
Collaborator Author

Thanks for the modifications @mohammadamint

Is the class Run being used at all? I couldn't find an instance of Run( in the whole project. I would say we leave it here and merge it into UseCase in a subsequent PR :)

Indeed I kept for the future UseCase uses.

@Bachibouzouk
Copy link
Collaborator

@mohammadamint - maybe we can merge the test PR first, then we rebase this one onto development and see that none of the tests is broken (which I would find surprising, but we never know). Then you could also edit the changelog to add a line about your contribution? What do you think?

@mohammadamint
Copy link
Collaborator Author

@mohammadamint - maybe we can merge the test PR first, then we rebase this one onto development and see that none of the tests is broken (which I would find surprising, but we never know). Then you could also edit the changelog to add a line about your contribution? What do you think?

Sure!

@FLomb
Copy link
Contributor

FLomb commented Nov 6, 2023

The tests-related PRs have all been approved. You may proceed with rebasing and then we could merge this one too (:

@mohammadamint
Copy link
Collaborator Author

The tests-related PRs have all been approved. You may proceed with rebasing and then we could merge this one too (:

Shall I wait for your your PR on docs also to be merged?

@FLomb
Copy link
Contributor

FLomb commented Nov 6, 2023

The tests-related PRs have all been approved. You may proceed with rebasing and then we could merge this one too (:

Shall I wait for your your PR on docs also to be merged?

yes, I think that would make sense. Is for one between you and @Bachibouzouk to review that one before merging.

@FLomb
Copy link
Contributor

FLomb commented Nov 8, 2023

So I think that the only needed step here is not to update the PR to incorporate the newest commits to development, right?

@mohammadamint
Copy link
Collaborator Author

So I think that the only needed step here is not to update the PR to incorporate the n

Yes. I have some issues with rebasing, and if it is ok, I will wait till tomorrow to check this with Pierre. I see that some of the commits I had on this PR are kind of lost.

mohammadamint and others added 4 commits November 8, 2023 21:56
The new features added will allow the user to perform some data analysis
and visualization routines:

changes
------
*. ramp/post_process/post_process.py

- the class Plot is the main class carrying on the plotting and data
analysis functionalities with custom APIs providing access to some
pd.DataFrame features also easy to plot functions conencting to plotly
and matplotlibe methods.

- different plotting classes that include a specific plot type
  visualiztion using two different engines (plotly & matplotlib)

*. ramp.__init__.py
- adding the Plot class to the init.

documentation
-------------
- the functions API docuemntation is added to the API documentaiton
- A full example titled "Plot class" is added to the example gallery
  describing the full potential of the new functionalities
- Improving the Plot class docstring
- Improving the error handling with invalid inputs by user regarding the
  file extensions and plot engine
- Improving the readability of the plotting scripts by merging the plot
  classes into Plot methods
@Bachibouzouk
Copy link
Collaborator

I see that some of the commits I had on this PR are kind of lost.

Are there still lost @mohammadamint ? This rebase is onto the latest version developement branch

@mohammadamint
Copy link
Collaborator Author

I see that some of the commits I had on this PR are kind of lost.

Are there still lost @mohammadamint ? This rebase is onto the latest version developement branch

I see that some of the commits I had on this PR are kind of lost.

Are there still lost @mohammadamint ? This rebase is onto the latest version developement branch

@Bachibouzouk All correct now!

@Bachibouzouk
Copy link
Collaborator

Ok now only the problem of RTD then. by looking at the dependencies locally, I see that docs/source/api_document is missing all the Plot methods, could this be that we just need to commit them?

@mohammadamint
Copy link
Collaborator Author

Ok now only the problem of RTD then. by looking at the dependencies locally, I see that docs/source/api_document is missing all the Plot methods, could this be that we just need to commit them?

@Bachibouzouk I see that the docs action is also failed. It can't find the API doc for Appliance.eq! Is that normal?

@Bachibouzouk
Copy link
Collaborator

@Bachibouzouk I see that the docs action is also failed. It can't find the API doc for Appliance.eq! Is that normal?

@mohammadamint The problem was the missing plotly dependency in the doc requirements, this is now fixed, the honor of merging is yours :) Congrats once more!

@mohammadamint
Copy link
Collaborator Author

@Bachibouzouk I see that the docs action is also failed. It can't find the API doc for Appliance.eq! Is that normal?

@mohammadamint The problem was the missing plotly dependency in the doc requirements, this is now fixed, the honor of merging is yours :) Congrats once more!

Thanks for your great support, and looking forward to your git course ;-)

@mohammadamint mohammadamint merged commit a57b121 into development Nov 8, 2023
3 checks passed
@Bachibouzouk Bachibouzouk deleted the ramp_visualization branch November 8, 2023 21:29
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.

Creating RAMP postprocessor
3 participants