Skip to content

#301 List of available config accessible for end-users#327

Merged
Didou09 merged 11 commits intodevelfrom
Issue301_GetListConfigs
Jan 17, 2020
Merged

#301 List of available config accessible for end-users#327
Didou09 merged 11 commits intodevelfrom
Issue301_GetListConfigs

Conversation

@Didou09
Copy link
Copy Markdown
Member

@Didou09 Didou09 commented Jan 13, 2020

Motivations:

As pointed out by issue #301 , in the online tutorial for plotting the gallery of fusion machines, we ask the user to read a hidden variable tf.geom.utils._DCONFIG_TABLE.

This is not good practice, a public method should exist to list all available pre-implemenetd configurations.

Main changes:

Two new methods are created, a hidden and a public:

  • tf.geom.utils._get_listconfig() : a hidden method used to generate the dict of (unique keys, shortcuts) from hidden variables _DCONFIG and _DCONFIG_TABLE and return either a fully formatted str message or the dict itself. It is used to provide the core message of the public method, and also re-used to properly generate the error message when tf.geom.utils.create_Config() is not properly called by the user.
  • tf.geom.utils.get_available_config(): a public method that prints a fully formatted explicit message containing all available keys to pre-implemented config

Example:

In [1]: import tofu as tf

In [2]: tf.geom.utils.get_available_config()
A config is the geometry of a tokamak
You can define your own, see online tutorial at:
    https://tofuproject.github.io/tofu/auto_examples/tutorials/tuto_plot_create_geometry.html
tofu also also provides some pre-defined config ready to load
They are available via their name or via shortcuts

	unique names	shortcuts
	------------ 	-------------------------
	- ITER-V1     	['ITER-V1', 'A2']
	- ITER-V2     	['ITER-V2', 'B4', 'ITER']
	- JET-V0      	['JET-V0', 'JET']
	- NSTX-V0     	['NSTX-V0', 'NSTX']
	- WEST-Sep    	['WEST-Sep', 'A3']
	- WEST-V1     	['WEST-V1', 'A1']
	- WEST-V2     	['WEST-V2', 'B1']
	- WEST-V3     	['WEST-V3', 'B2']
	- WEST-V4     	['WEST-V4', 'B3', 'WEST']

  => to get a pre-defined config, call for example:
	config = tf.geom.utils.create_config('ITER')

Issues:

Fixes, in devel, issue #301

@Didou09 Didou09 self-assigned this Jan 13, 2020
@pep8speaks
Copy link
Copy Markdown

pep8speaks commented Jan 13, 2020

Hello @Didou09! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-01-17 15:45:54 UTC

Comment thread tofu/geom/utils.py Outdated
# Default config
_DEFCONFIG = 'ITER'

def _get_listconfig(dconfig=_DCONFIG, dconfig_table=_DCONFIG_TABLE,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

core hidden method
It is the base that provides either a dict or a str (formatted message) containing the core info

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is great. However, I would suggest adding a short docstring to the new method and its intended use.
In particular, this would allow to describe in words what _DCONFIG and _DCONFIG_TABLE is
(to me, it's not clear what the difference is).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment thread tofu/geom/utils.py Outdated
return msg


def get_available_config(dconfig=_DCONFIG, dconfig_table=_DCONFIG_TABLE,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Public method for end-users

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, a docstring would be nice.

Also, since this is a new public method, it should be added to __all__ no? As far as I can tell this is not the case.

Otherwise the message is nicely written, especially the use of an URL is good I believe.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, thanks :-)

Comment thread tofu/geom/utils.py
+ "\t - unique keys: {}\n".format(list(dconfig.keys()))
+ "\t - shortcuts : {}\n\n".format(list(dconfig_table.keys()))
+ " => you provided: case = {}\n".format(config))
msg = ("\nThe provided config name is not valid.\n"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This error message re-uses the formatted message created by the hidden method

@Didou09 Didou09 changed the title List of available config accessible for end-users #301 List of available config accessible for end-users Jan 13, 2020
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 14, 2020

Codecov Report

❗ No coverage uploaded for pull request base (devel@f7444b9). Click here to learn what that means.
The diff coverage is 0.97%.

Impacted file tree graph

@@           Coverage Diff            @@
##             devel     #327   +/-   ##
========================================
  Coverage         ?   40.04%           
========================================
  Files            ?       79           
  Lines            ?    24111           
  Branches         ?        0           
========================================
  Hits             ?     9656           
  Misses           ?    14455           
  Partials         ?        0
Impacted Files Coverage Δ
tofu/geom/_core.py 63.19% <0%> (ø)
tofu/data/_plot.py 91.2% <0%> (ø)
tofu/imas2tofu/_core.py 0.67% <0%> (ø)
tofu/utils.py 47.93% <0%> (ø)
tofu/data/_core.py 38.97% <0%> (ø)
tofu/data/_comp.py 19.93% <0%> (ø)
tofu/__init__.py 93.93% <100%> (ø)
tofu/version.py 100% <100%> (ø)
tofu/geom/utils.py 42.39% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7444b9...7340194. Read the comment docs.

Copy link
Copy Markdown
Contributor

@flothesof flothesof left a comment

Choose a reason for hiding this comment

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

Good work :)
I've spotted one major thing (all missing) and some minor stuff (docstrings).

Comment thread tofu/geom/utils.py Outdated
# Default config
_DEFCONFIG = 'ITER'

def _get_listconfig(dconfig=_DCONFIG, dconfig_table=_DCONFIG_TABLE,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is great. However, I would suggest adding a short docstring to the new method and its intended use.
In particular, this would allow to describe in words what _DCONFIG and _DCONFIG_TABLE is
(to me, it's not clear what the difference is).

Comment thread tofu/geom/utils.py Outdated
return msg


def get_available_config(dconfig=_DCONFIG, dconfig_table=_DCONFIG_TABLE,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, a docstring would be nice.

Also, since this is a new public method, it should be added to __all__ no? As far as I can tell this is not the case.

Otherwise the message is nicely written, especially the use of an URL is good I believe.

@Didou09 Didou09 requested a review from flothesof January 17, 2020 15:10
Copy link
Copy Markdown
Contributor

@flothesof flothesof left a comment

Choose a reason for hiding this comment

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

One more small issue.

Other than that docstrings look great and thanks for the renaming of vars, I think it improves readability.

Comment thread tofu/geom/utils.py

def get_available_config(dconfig=_DCONFIG,
dconfig_shortcuts=_DCONFIG_SHORTCUTS,
verb=True, returnas=False):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is returnas a bool here? Shouldn't it be str?
Below there's a check if returnas is str...
What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nope, in general in many tofu functions / methods, returnas can be:

  • False => nothing is returned
  • None / True => set to default return format
  • a specific format (here str)

It is because in this function there is only one output possible format, but that may evolve in the future.
The use of True / None is to specify we want output but either the user doesn't know that he has choice between several formats (in that case it is usually set to the most intuitive) or to let the format be decided later by another function.

I agree in this case we just have a choice between False (default) and str, but this way we keep the general workflow / convention

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did not implement True / None because I forgot though,
But in 99 % cases users will not ask for returning anything

@Didou09 Didou09 merged commit 468e68a into devel Jan 17, 2020
@Didou09 Didou09 deleted the Issue301_GetListConfigs branch January 17, 2020 15:54
@Didou09 Didou09 mentioned this pull request Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants