Giter Site home page Giter Site logo

Comments (3)

toliwaga avatar toliwaga commented on May 26, 2024 1

I agree that this would be a handy feature. It probably makes sense to use anchors and tags to implement this feature.

Fortunately you don't have to wait. You can define a join method and register it as a tag handler with yaml globally, and it will be available to you in all your yaml files. Try the following:

Add this to the import section at the top of run_populationsim.py

import yaml

Put the following before any other executable code in run_populationsim.py (i.e. before the handle_standard_args() call) to install the yaml tag handler

## define custom tag handler
def join(loader, node):
    seq = loader.construct_sequence(node)
    return ''.join([str(i) for i in seq])

yaml.add_constructor('!join', join)

Now, in settings.py, you can define an anchor for model_year, and use the !join tag to concatenate it into other strings:

current_model_year: &MODEL_YEAR '2010'

TEST_JOIN:
  - tablename: !join [*MODEL_YEAR, _mazData.csv]
    other_stuff: stuff

You can test this by doing this at somewhere near the beginning of run_populationsim.py

print "TEST_JOIN:", setting('TEST_JOIN')
exit()

And it should print out:

TEST_JOIN: [{'tablename': '2010_mazData.csv', 'other_stuff': 'stuff'}]

You could avoid defining a custom tag by simply doing something like:

current_model_year: &MODEL_YEAR '2010'

TEST_JOIN:
  - tablename: !!python/object/apply:string.join [[*MODEL_YEAR, _mazData], '']
    other_stuff: stuff

but this introduces yet another python3 compatibility issue. Plus it isn't very readable.

from populationsim.

bettinardi avatar bettinardi commented on May 26, 2024 1

Thanks for the quick feedback Jeff.
I also wanted to mention that ODOT will need to think about this question as well. Our next step in the contract is to implement PopulationSim in our Statewide Integrated Model (SWIM) which runs a synthetic population each year for ~30 years (2010-2040) in an automated way into the future. So ODOT could think about this as a a more flexible run structure with the inputs and output folders being specified more flexibility and dynamically.

If we work out a flexible "data" and "outputs" location and naming process. Then one should be able to setup a yaml that works through a series of changing input and output locations with just one config file...

from populationsim.

toliwaga avatar toliwaga commented on May 26, 2024

Yes - the next contract step will be a good opportunity to come up with a standard way of dealing with this common situation.

from populationsim.

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.