Coder Social home page Coder Social logo

Comments (12)

mattiarighi avatar mattiarighi commented on August 18, 2024

This is now implemented in REFACTORING_backend_developconfig.

@valeriupredoi and @bouweandela: it would be good if you could test it on your machines.

@bouweandela: please have a look at the error messages, I am not sure what is the best practice here.

@axel-lauer: you could try to add CMIP3 as a test, I will send you a config file for our cluster.

Thanks!

from esmvaltool.

valeriupredoi avatar valeriupredoi commented on August 18, 2024

from esmvaltool.

mattiarighi avatar mattiarighi commented on August 18, 2024

Hi Valeriu, I think these fixes do not apply to REFACTORING_backend_developconfig, since the root paths definitions have been moved out of the code.

from esmvaltool.

valeriupredoi avatar valeriupredoi commented on August 18, 2024

from esmvaltool.

bouweandela avatar bouweandela commented on August 18, 2024

Hi Mattia,

Looks good, you manage to do the same thing with 500 lines of code less!

Testing

it works fine with namelist_MyVar.yml, but I had to change config-user.yml a bit to make it work, did you forget to commit the updated config-user.yml file?

Error messages

I think this covers two topics: (1) logging and raising exceptions and (2) how to do string formatting

Logging and raising exceptions

I think we may need to define a few custom exceptions that we can raise if a user does something wrong. As far as I can see there are four places where we depend on user input:

  1. config-user.yml
  2. input data
  3. namelist
  4. diagnostic code

so I think we could add four custom exceptions and for these cases make sure we check the user input and we raise those if the user does something wrong and catch them with nice error message in the log. Probably all of those exceptions would need to inherit from a single ESMValToolError exception.

Apart from that, I think we do not need to raise many exceptions, just log what you are doing and run your code assuming everything is fine. E.g. I think that this style of code:

logger.info("CMIP5: mapping mip %s to realm", mip)
return mipdict[mip]

is preferred to this:

if mip in mipdict:
    return mipdict[mip]

raise KeyError("CMIP5: cannot map mip {} to realm".format(mip))

because it is shorter and therefore much more readable and it is often very difficult to cover all the possible things that can go wrong (and code becomes very difficult to read if you try to do this).

String formatting

  • Best practice is to always use new style string formatting (i.e. using the format method of a string), see https://docs.python.org/3.6/library/string.html#format-examples for examples
  • Except in log messages, there the format string should be specified using old style formatting, but the formatting arguments should be passed as arguments to the logging function. For example:
    yes: logger.info("x has value %s", x)
    no: logger.info("x has value %s" % x)
    no: logger.info("x has value {}".format(x))

from esmvaltool.

valeriupredoi avatar valeriupredoi commented on August 18, 2024

from esmvaltool.

valeriupredoi avatar valeriupredoi commented on August 18, 2024

from esmvaltool.

mattiarighi avatar mattiarighi commented on August 18, 2024

Thanks for testing!
I will take note of your suggestions, but we should merge this now.
We have a working version which is a good basis for starting the integration of the diagnostics.

from esmvaltool.

valeriupredoi avatar valeriupredoi commented on August 18, 2024

from esmvaltool.

mattiarighi avatar mattiarighi commented on August 18, 2024

This is merged now.
Issue closed. :-)

from esmvaltool.

valeriupredoi avatar valeriupredoi commented on August 18, 2024

from esmvaltool.

valeriupredoi avatar valeriupredoi commented on August 18, 2024

from esmvaltool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.