Skip to content

Commit bb2c369

Browse files
committed
Updating modsim.py
1 parent 22cd619 commit bb2c369

1 file changed

Lines changed: 50 additions & 30 deletions

File tree

code/modsim.py

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,47 @@
66
License: https://creativecommons.org/licenses/by/4.0)
77
"""
88

9-
from __future__ import print_function, division
9+
#TODO: check that we have at least version 3.6
10+
11+
import inspect
1012

1113
import logging
1214
logger = logging.getLogger(name='modsim.py')
1315

14-
1516
import matplotlib.pyplot as plt
1617
import numpy as np
1718
import pandas as pd
1819

1920
import seaborn as sns
2021
sns.set(style='white', font_scale=1.5)
2122

22-
from scipy.integrate import odeint
2323
import scipy
2424
import sympy
25-
2625
import pint
2726
UNITS = pint.UnitRegistry()
2827
Quantity = UNITS.Quantity
2928

30-
from numpy import sqrt, array, linspace, pi
31-
29+
from copy import copy
30+
from numpy import sqrt, log, exp, pi
3231
from pandas import DataFrame, Series
33-
34-
35-
import inspect
36-
from inspect import getsource
32+
from time import sleep
3733

3834
from scipy.interpolate import interp1d
3935
from scipy.integrate import odeint
4036
from scipy.optimize import leastsq
4137
from scipy.optimize import minimize_scalar
4238

43-
from time import sleep
4439

4540

4641
def linspace(start, stop, num=50, **kwargs):
47-
"""Returns num evenly spaced samples over the interval [start, stop].
42+
"""Returns an array of evenly-spaced values in the interval [start, stop].
4843
49-
start: number or Quantity
50-
stop: number or Quantity
51-
num: integer
44+
start: first value
45+
stop: last value
46+
num: number of values
47+
48+
Also accepts the same keyword arguments as np.linspace. See
49+
https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html
5250
5351
returns: array or Quantity
5452
"""
@@ -65,19 +63,31 @@ def linspace(start, stop, num=50, **kwargs):
6563

6664

6765
def linrange(start=0, stop=None, step=1, **kwargs):
68-
"""Returns evenly spaced samples over the interval [start, stop].
66+
"""Returns an array of evenly-spaced values in the interval [start, stop].
6967
70-
start: number or Quantity
71-
stop: number or Quantity
72-
step: number or Quantity
68+
This function works best if the space between start and stop
69+
is divisible by step; otherwise the results might be surprising.
70+
71+
By default, the last value in the array is `stop` (at least approximately).
72+
If you provide the keyword argument `endpoint=False`, the last value
73+
in the array is `stop-step`.
74+
75+
start: first value
76+
stop: last value
77+
step: space between values
78+
79+
Also accepts the same keyword arguments as np.linspace. See
80+
https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html
7381
7482
returns: array or Quantity
7583
"""
7684
if stop is None:
7785
stop = start
7886
start = 0
7987

80-
underride(kwargs, endpoint=True, dtype=np.float64)
88+
# TODO: what breaks if we don't make the dtype float?
89+
#underride(kwargs, endpoint=True, dtype=np.float64)
90+
underride(kwargs, endpoint=True)
8191

8292
# see if any of the arguments has units
8393
units = getattr(start, 'units', None)
@@ -608,10 +618,10 @@ def subplots(*args, **kwargs):
608618

609619

610620
def subplot(nrows, ncols, plot_number, **kwargs):
611-
figsize = {(2, 1): (6, 6)}
612-
figsize = {(3, 1): (6, 9)}
621+
figsize = {(2, 1): (8, 8),
622+
(3, 1): (8, 10)}
613623
key = nrows, ncols
614-
default = 8, 5.5
624+
default = (8, 5.5)
615625
width, height = figsize.get(key, default)
616626

617627
plt.subplot(nrows, ncols, plot_number, **kwargs)
@@ -648,10 +658,21 @@ def remove_from_legend(bad_labels):
648658
def decorate(**kwargs):
649659
"""Decorate the current axes.
650660
651-
kwargs: can be any axis property
661+
Call decorate with keyword arguments like
662+
663+
decorate(title='Title',
664+
xlabel='x',
665+
ylabel='y')
666+
667+
The keyword arguments can be any of the axis properties
668+
defined by Matplotlib. To see the list, run plt.getp(plt.gca())
652669
653-
To see the list, run plt.getp(plt.gca())
670+
In addition, you can use `legend=False` to suppress the legend.
671+
672+
And you can use `loc` to indicate the location of the legend
673+
(the default value is 'best')
654674
"""
675+
#
655676
if kwargs.pop('legend', True):
656677
loc = kwargs.pop('loc', 'best')
657678
legend(loc=loc)
@@ -673,6 +694,7 @@ def __init__(self, *args, **kwargs):
673694
See: https://github.com/pandas-dev/pandas/issues/16737
674695
"""
675696
if args or kwargs:
697+
#underride(kwargs, dtype=np.float64)
676698
super().__init__(*args, **kwargs)
677699
else:
678700
super().__init__([], dtype=np.float64)
@@ -693,12 +715,10 @@ def set(self, **kwargs):
693715
for name, value in kwargs.items():
694716
self[name] = value
695717

696-
@property
697-
def _constructor(self):
698-
return self.__class__
699718

700-
701-
class Sweep(MySeries):
719+
class SweepSeries(MySeries):
720+
"""Represents a mapping from parameter values to metrics.
721+
"""
702722
pass
703723

704724

0 commit comments

Comments
 (0)