-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Problem
As a use of the solvis library I want a simple, intuitive way to change rupture rates of an InversionSolution. Uses cases include:
- Scaling rates of all rutpures. Currently implemented as
InversionSolution.scale_rupture_rates(...)def scale_rupture_rates( - Creating a new solution that has the mean rates of two or more solutions. This requires adding rates from each solution and then scaling by the inverse of the number of input solutions.
Proposal
Follow the Pandas and Numpy convention for arithemetic operations on pandas.DataFrame pandas.Series numpy.ndarray.e.g.
import pandas as pd
>>> ds = pd.Series(data=[1.0 ,2.0])
>>> ds
0 1.0
1 2.0
dtype: float64
>>> ds2 = pd.Series(data=[2.0 ,4.0])
>>> ds2
0 2.0
1 4.0
dtype: float64
>>> ds + 5.5
0 6.5
1 7.5
dtype: float64
>>> ds * 2.0
0 2.0
1 4.0
dtype: float64
>>> ds + ds2
0 3.0
1 6.0
dtype: float64
>>> ds * ds2
0 2.0
1 8.0
dtype: float64
>>> ds / ds2
0 0.5
1 0.5
dtype: float64Having specific methods for every operation requires more documentation, is harder for users to discover, and requires a new version release to implement new operations of this type.
solivs rate operations would then look like:
>>> solution1 = solvis.InversionSolution.from_archive(filename1)
>>> solution2 = solvis.InversionSolution.from_archive(filename2)
>>> solution3 = solution1 + solution2
>>> solution4 = solution3 * 0.5Done Criteria
We would implement the following magic methods on InversionSolution:
-
__add__ -
__sub__ -
__mul__ -
__truediv__
Questions
- what happens if a call with two
InversionSolutionoperands do not have the same number of rutprues? Raise an exception? Union the ruptures? - do we worry about protecting users from combining
InversionSolutionobjects with the same number of ruptures, but those ruptures are not identical? This is unlikely, though technically possible.