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

Add example with Behresp parameters #37

Merged
merged 6 commits into from Mar 7, 2019

Conversation

Projects
None yet
2 participants
@hdoupe
Copy link
Collaborator

commented Mar 6, 2019

This PR adds example parameters for the Behavior-Responses package per @martinholmer's suggestion in #34. I also made a couple minor changes to clean things up while I was testing out this example.

(paramtools-dev) henrydoupe@henry-mac:~/Documents/ParamTools$ cd paramtools/examples/behresp/
(paramtools-dev) henrydoupe@henry-mac:~/Documents/ParamTools/paramtools/examples/behresp$ ipython
Python 3.7.2 (default, Dec 29 2018, 06:19:36) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from paramtools import Parameters 
   ...:  
   ...: class BehrespParams(Parameters): 
   ...:     schema = "schema.json" 
   ...:     defaults = "defaults.json" 
   ...:     array_first = True 
   ...:                                                                                                  

In [2]: params = BehrespParams()                                                                         

In [3]: params.BE_sub                                                                                    
Out[3]: array(0.)

In [4]: params.from_array("BE_sub")                                                                      
Out[4]: [{'value': 0.0}]

In [5]: params.adjust({"BE_sub": [{"value": 0.4}]})                                                      

In [6]: params.BE_sub                                                                                    
Out[6]: array(0.4)

In [7]: params.adjust({"BE_sub": [{"value": -0.4}]})                                                     
---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
<ipython-input-7-46d26022a0da> in <module>
----> 1 params.adjust({"BE_sub": [{"value": -0.4}]})

~/Documents/ParamTools/paramtools/parameters.py in adjust(self, params_or_path, raise_errors)
    119 
    120         if raise_errors and self._errors:
--> 121             raise self.validation_error
    122 
    123         # Update attrs.

ValidationError: {'BE_sub': ['BE_sub -0.4 must be greater than 0.0']}

In [8]: params.BE_sub                                                                                    
Out[8]: array(0.4)

In [9]: params.adjust({"BE_sub": [{"value": "elasticity"}]})                                             
---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
<ipython-input-9-25ba7962e1aa> in <module>
----> 1 params.adjust({"BE_sub": [{"value": "elasticity"}]})

~/Documents/ParamTools/paramtools/parameters.py in adjust(self, params_or_path, raise_errors)
    119 
    120         if raise_errors and self._errors:
--> 121             raise self.validation_error
    122 
    123         # Update attrs.

ValidationError: {'BE_sub': ['Not a valid number: elasticity.']}

In [10]:                                                                                                 
@hdoupe

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 6, 2019

@martinholmer The behresp example config files were added in this commit: 0f4754d. If you have any feedback on the files or the example above, I'd love to hear it.

@martinholmer

This comment has been minimized.

Copy link

commented Mar 6, 2019

@hdoupe, thanks for the example.

@hdoupe hdoupe merged commit d1a0774 into master Mar 7, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@hdoupe hdoupe deleted the behresp-ex branch Mar 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.