Sympy derived quantities from string equations #278
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.
This is a test to see if we can/should use
sympy
to parse equations to derive quantities.The idea is the user can put an equation and constituents (already in) in the variable defaults file and sympy will parse the string equation and then xarray will do the calculations.
For quick comparison, here is the current ADF generated RESTOM lat/lon plot:
![RESTOM_ANN_LatLon_Mean_ADF](https://private-user-images.githubusercontent.com/56696811/296070551-4be26db1-8516-4521-86b1-8680d0f52c56.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4OTQ1MTcsIm5iZiI6MTcyMzg5NDIxNywicGF0aCI6Ii81NjY5NjgxMS8yOTYwNzA1NTEtNGJlMjZkYjEtODUxNi00NTIxLTg2YjEtODY4MGQwZjUyYzU2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE3VDExMzAxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJlNWY0NWE4YzhmYTVlODdlMWQxYTA1ZGM3MDk1NzU2ODllMGIzZjk3YTAzNTMxYzUzNjQxM2RmMDJlZDI0ZTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.KfsuRWvWGAw_YXGtyCdNQIo862kpztNSuoO1o9ceoN8)
And Sympy derived:
![RESTOM_ANN_LatLon_Mean_Sympy](https://private-user-images.githubusercontent.com/56696811/296070605-8c088f7e-9d7e-49fe-a00b-b8747f79b5a7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4OTQ1MTcsIm5iZiI6MTcyMzg5NDIxNywicGF0aCI6Ii81NjY5NjgxMS8yOTYwNzA2MDUtOGMwODhmN2UtOWQ3ZS00OWZlLWEwMGItYjg3NDdmNzliNWE3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE3VDExMzAxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk4ZmVkY2M3MGRlOTQwODAyNGU2ZDdhOWU3YjVjZjhjYWIwYzU5ZTU2YTdjNzQ2MGVkMDlkZTA0NGMxMTU5MTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.lk2wqZLwePPk0avrNGllzrkyQYyIlH2ydQcKghj503U)
This is a small test case so far, but it seems pretty flexible in how it parses equations. For example, I created a fake var called MADEUPVAR with a derived equation: PRECC-(0.5*PRECL)+PRECSC and it seemed to handle the parenthesis.
![MADEUPVAR_ANN_LatLon_Mean](https://private-user-images.githubusercontent.com/56696811/296071141-207a3969-1d69-490a-bac2-3a6be22f8180.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4OTQ1MTcsIm5iZiI6MTcyMzg5NDIxNywicGF0aCI6Ii81NjY5NjgxMS8yOTYwNzExNDEtMjA3YTM5NjktMWQ2OS00OTBhLWJhYzItM2E2YmUyMmY4MTgwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE3VDExMzAxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU3MTgxM2VmMGFiN2Y4NzNlZTMzMWRlMjJhNDAwZjkzMTcwMzIxYWM3MTA1OTI1MjBjZDQxNjlhNzYxZTIwZDcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.EHJwfhuIvOlvYvmelUAaxMt7mpVc2fQ5tQkkbT_3WPk)
If it makes sense, we can move this to discussions so we can chat about it. If you want to add some stress testing, checkout my branch and give it a try: https://github.com/justin-richling/ADF/tree/sympy-derived-qunatity-draft
The only python packages sympy would add to the npl environment are: