API reference
Math and array tools
Quiz: how do you return the indices of a vector v = np.random.rand(100) that are greater than 0.4 but less than 0.6? If you answered ((v>0.4)*(v<0.6)).nonzero()[0], you’re right! But with Sciris, you can also just do sc.findinds(v>0.4, v<0.6), which is a little easier.
| sc_math | Extensions to Numpy, including finding array elements and smoothing data. |
| sc_asd | Adaptive stochastic descent optimization algorithm, building on scipy.optimize. |
Containers
Dictionaries are great, right? sc.odict() is a drop-in replacement for a dictionary that has lots of extra features (such as retrieving items by index). Pandas DataFrames are great, right? sc.dataframe() is a drop-in replacement for a DataFrame that has some additional features for ease of use (such as being able to concatenate in place).
| sc_odict | The “odict” class, combining features from an OrderedDict and a list/array. |
| sc_dataframe | Extension of the pandas dataframe to be more flexible, especially with filtering |
Files and versioning
Saving and loading data can be a pain. Sciris tries to make it easier with the should-just-work functions sc.save() and sc.load(). But Sciris also makes it easier if you have a particular format in mind, such as sc.savejson(), or if you want to store metadata along with your results to improve reproducibility (sc.savewithmetadata()).
| sc_fileio | Functions for reading/writing to files, including pickles, JSONs, and Excel. |
| sc_versioning | Functions for checking and saving versioning information, such as Python package |
Printing and plotting
Do you ever do print(obj) and get some unhelpful result like <object at 0x7f4d0b1ea190>? sc.pr(obj) will tell you exactly what’s in the object, including attributes (including their values), properties, and methods. Have you ever wanted to plot something in 3D but given up because it seems like it would take too long? With Sciris, it will work out of the box: try sc.surf3d(np.random.randn(10,10)). We’ll wait.
| sc_printing | Printing/notification functions. |
| sc_plotting | Extensions to Matplotlib, including 3D plotting and plot customization. |
| sc_colors | Handle colors and colormaps. |
Parallelization and profiling
Scientific computing workflows are often embarrassingly parallel, and yet it can be hard to do in practice. With Sciris, you can do sc.parallelize(my_func, 10) to run your function 10 times. It’s also often hard to know where your code is being slow: you can use sc.profile(my_func) for a quick glance, which is often all you need.
| sc_parallel | Functions to allow parallelization to be performed easily. |
| sc_profiling | Profiling and CPU/memory management functions. |
Utilities
The string d = '2022-02-02' looks like a date, right? Without googling, do you know how to convert it to an actual date object? With Sciris, it’s sc.date(d). Without Sciris, it’s datetime.datetime.strptime(d, '%Y-%m-%d').date(). Also, if you need help with anything in Sciris, you can do sc.help(): it doesn’t use ChatGPT, but will do a full text search through the source code.
| sc_utils | Miscellaneous utilities for type checking, printing, dates and times, etc. |
| sc_datetime | Time/date utilities. |
| sc_nested | Functions for working on nested (multi-level) dictionaries and objects. |
| sc_settings | Define options for Sciris, mostly plotting options. |