-
Notifications
You must be signed in to change notification settings - Fork 2
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
941 append scaling to ws name #951
Open
GuiMacielPereira
wants to merge
20
commits into
main
Choose a base branch
from
941_append_scaling_to_ws_name
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ab02ddf
Introduced class that appends to suffixes to workspaces
GuiMacielPereira 29ded70
Removed commented out sections
GuiMacielPereira 1719bff
Changed main ws operations and started looking into hidden ws
GuiMacielPereira 0f687d3
Changed methods to suitable variable names
GuiMacielPereira a6b9d1b
Removed artifact comment
GuiMacielPereira 5a703ca
Changed naming of scaling ws and added two more methods
GuiMacielPereira b9b4a0c
Updated unit tests
GuiMacielPereira 37beb37
Fixed ws names for scaling
GuiMacielPereira 633ea86
Merge branch 'main' into 941_append_scaling_to_ws_name
GuiMacielPereira fda5254
Fixed artifacts from merge
GuiMacielPereira 83ba1b2
Fixed long line and removed unused import
GuiMacielPereira f2b2527
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] abdb380
Fixed missing blank line
GuiMacielPereira 4e214dc
Updated class for clearer usability
GuiMacielPereira 9883cf5
Fixed Flake8 issues
GuiMacielPereira 84d3fe7
Revert "Fixed Flake8 issues"
GuiMacielPereira dfe981a
Corrected fix for flake8 issues
GuiMacielPereira 9a68e1a
Merge branch 'main' into 941_append_scaling_to_ws_name
GuiMacielPereira f29879e
Updated a recent commit to use the new ws name format
GuiMacielPereira 2b12bdc
Removed outdated comment
GuiMacielPereira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import pickle | ||
import codecs | ||
|
||
from mantid.simpleapi import DeleteWorkspace, RenameWorkspace | ||
|
||
|
||
|
@@ -85,7 +84,7 @@ def attribute_to_log(attrdict, raw_ws, append=False): | |
|
||
def delete_workspace(workspace, ws): | ||
try: | ||
if hasattr(workspace, str(ws)) and ws is not None and ws.name().endswith('_HIDDEN'): | ||
if hasattr(workspace, str(ws)) and ws is not None and WorkspaceNameHandler(ws.name()).isHiddenFromMsl(): | ||
DeleteWorkspace(ws) | ||
ws = None | ||
except RuntimeError: | ||
|
@@ -116,3 +115,60 @@ def __exit__(self, exc_type, exc_val, exc_tb): | |
if self.workspace: | ||
self.workspace.remove_saved_attributes() | ||
return True | ||
|
||
|
||
class WorkspaceNameHandler: | ||
|
||
def __init__(self, ws_name: str): | ||
self.ws_name = ws_name | ||
|
||
def add_prefix(self, prefix) -> str: | ||
return prefix + self.ws_name | ||
|
||
def add_sufix(self, sufix) -> str: | ||
return self.ws_name + sufix | ||
|
||
def scaled(self, scaling_factor: float) -> str: | ||
return self.add_sufix("_ssf_" + f"{scaling_factor:.2f}".replace('.', '_')) | ||
|
||
def subtracted(self, scaling_factor: float) -> str: | ||
return self.add_sufix("_minus_ssf_" + f"{scaling_factor:.2f}".replace('.', '_')) | ||
|
||
def summed(self) -> str: | ||
return self.add_sufix("_sum") | ||
|
||
def rebosed(self) -> str: | ||
return self.add_sufix('_bosed') | ||
|
||
def combined(self) -> str: | ||
return self.add_sufix('_combined') | ||
|
||
def merged(self) -> str: | ||
return self.add_sufix('_merged') | ||
|
||
def isHiddenFromMsl(self) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've swapped from snake case to camel case here, worth having a flick through these if you haven't already: https://developer.mantidproject.org/Standards/PythonStandards.html |
||
return '_HIDDEN' in self.ws_name | ||
|
||
def hideFromMsl(self) -> str: | ||
return self.add_sufix('_HIDDEN') | ||
|
||
def removeHideFlags(self) -> str: | ||
return self.ws_name.replace('__MSL', '').replace('_HIDDEN', '') | ||
|
||
def hideMslInAds(self) -> str: | ||
return self.add_prefix('__MSL') | ||
|
||
def isMslHiddenInAds(self) -> bool: | ||
return '__MSL' in self.ws_name | ||
|
||
def hideTmpMslInAds(self) -> str: | ||
return self.add_prefix('__MSLTMP') | ||
|
||
def hideInAds(self) -> str: | ||
return self.add_prefix('__') | ||
|
||
def isHiddenInAds(self) -> bool: | ||
return self.ws_name.startswith('__') | ||
|
||
def makeVisibleInAds(self) -> str: | ||
return self.ws_name.lstrip('__') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised there are so many options! I don't think it's ideal to have a separate function for each combination of functions. It's plausible in the future we have to add more, and therefore the number of combination functions will increase exponentially.
I wonder if it's a good idea to instead have a
WorkspaceNameOptions
class, that has a constructor that default sets everything to false via named arguments.We could then do a combination of functions by doing:
WorkspaceNameHandler.set_workspace_options(workspace.name, WorkSpaceOptions(hidden_from_mslice=True, hidden_from_ADS=True))
You would then only need individual functions in the
WorkspaceNameHandler
class, and these would not have to be exposed.Perhaps when checking we could then do:
WorkspaceNameHandler.assert_workspace_options(workspace, WorkspaceOptions(hidden_from_mslice=True, hidden_from_ADS=True)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now implemented these suggestions, but instead of creating and entirely separate
WorkspaceOptions
class, I preferred to opt for two methodsget_name
andassert_name
that mimicks this. So in this case one would doWorkspaceNameHandler(workspace.name).get_name(hidden_from_mslice=True, hidden_from_ADS=True
andWorkspaceNameHandler(workspace.name).assert_name(hidden_from_mslice=True, hiddden_from_ADS=True)
.