Package: python-sensors
PySensorsis a Scikit-learn style Python package for the sparse placement of sensors, either for reconstruction or classification tasks.Table of contentsSparse sensor placementReconstructionClassificationBasesInstallationDependenciesInstalling with pipInstalling from sourceFeaturesDocumentationCommunity guidelinesGetting supportContributing examplesContributing codeReporting issues or bugsCiting PySensorsReferencesSparse sensor placementSparse sensor placement concerns the problem of selecting a small subset
of sensor or measurement locations in a way that allows one to perform
some task nearly as well as if one had access to measurements ateverylocation.PySensors provides objects designed for the tasks ofreconstructionandclassification. See Manohar et al. (2018) for more information about
the PySensors approach to reconstruction problems and Brunton et al.
(2016) for classification. de Silva et al. (2021) contains a full
literature review along with examples and additional tips for
using PySensors effectively.ReconstructionReconstruction deals with predicting the values of a quantity of interest at different locations other than those where sensors are located.
For example, one might predict the temperature at a point in the middle of a lake based on temperature readings taken at various other positions in the lake.PySensors provides theSSPOR(Sparse Sensor Placement Optimization for Reconstruction) class to aid in the solution of reconstruction problems.Take representative examples of the types of data to be reconstructed (in this case polynomials)x=numpy.linspace(0,1,1001)data=numpy.vander(x,11).T# Create an array whose rows are powers of xfeed them to aSSPORinstance with 10 sensors, andmodel=pysensors.reconstruction.SSPOR(n_sensors=10)model.fit(data)Use thepredictmethod to reconstruct a new function sampled at the chosen sensor locations:f=numpy.abs(x[model.selected_sensors]**2-0.5)f_pred=model.predict(f)ClassificationClassification is the problem of predicting which category an example belongs to, given a set of training data (e.g. determining whether digital photos are of dogs or cats).
TheSSPOC(Sparse Sensor Placement Optimization for Classification) class is used to solve classification problems.
Users familiar with Scikit-learn will find it intuitive:model=pysensors.classification.SSPOC()model.fit(x,y)# Learn sensor locations and fit a linear classifiery_pred=model.predict(x_test[:,model.selected_sensors])#  Get predictionsSee our set ofclassification examplesfor more information.BasesThe basis in which measurement data are represented can have a dramatic
effect on performance. PySensors implements the three bases most commonly
used for sparse sensor placement: raw measurements, SVD/POD/PCA modes, and random projections. Bases can be easily incorporated intoSSPORandSSPOCclasses:basis=pysensors.basis.SVD(n_basis_modes=20)recon_model=pysensors.reconstruction.SSPOR(basis=basis)class_model=pysensors.classification.SSPOC(basis=basis)Seethis examplefor further discussion of these options.InstallationDependenciesThe high-level dependencies for PySensors are Linux or macOS and Python 3.6-3.8.pipis also recommended as is makes managing PySensors’ other dependencies much easier. You can install it by following the instructionshere.PySensors has not been tested on Windows.Installing with pipIf you are using Linux or macOS you can install PySensors with pip from the command line/terminal:pipinstallpython-sensorsNote:the name you type in hereispython-sensorsand isnotpysensors.Once you have run the line above, you are ready to get started with PySensors. Have a look at the examples in ourdocumentationto see what PySensors can do.Installing from sourceFirst clone this repository:gitclonehttps://github.com/dynamicslab/pysensors.gitThen, to install the package, runcdpysensorspipinstall.If you do not have pip you can instead usepythonsetup.pyinstallIf you do not have root access, you should add the--useroption to theinstallcommands above.FeaturesThe primary PySensors objects are theSSPORandSSPOCclasses, which are used to choose sensor locations optimized for reconstruction and classification tasks, respectively. Other implemented objects includebasis- submodule implementing different bases in which to represent dataIdentity- use raw measurement dataSVD- efficiently compute first k left singular vectorsRandomProjection- Gaussian random projections of measurementsConvenience functions to aid in the analysis of error as number of sensors or basis modes are variedDocumentationPySensors has adocumentation sitehosted by readthedocs.
Examples are availableonline, as staticJupyter notebooksand asinteractive notebooks. To run the example notebooks locally you should install the dependencies inrequirements-examples.txt:pipinstall-rrequirements-examples.txtCommunity guidelinesGetting supportYou may create an issue for any questions that aren’t answered by thedocumentationorexamples.Contributing examplesIf you have used PySensors to solve an interesting problem, please consider submitting an example Jupyter notebook showcasing
your work!Contributing codeWe welcome contributions to PySensors. To contribute a new feature please submit a pull request. To get started we recommend installing the packages inrequirements-dev.txtviapipinstall-rrequirements-dev.txtThis will allow you to run unit tests and automatically format your code. To be accepted your code should conform to PEP8 and pass all unit tests. Code can be tested by invokingpytestWe recommend usingpre-committo format your code. Once you have staged changes to commitgitaddpath/to/changed/file.pyyou can run the following to automatically reformat your staged codepre-commitNote that you will then need to re-stage any changespre-commitmade to your code.Reporting issues or bugsIf you find a bug in the code or want to request a new feature, please open an issue.Citing PySensorsWe have published a short paper in the Journal of Open Source Software (JOSS). You can find the paperhere.If you use PySensors in your work, please consider citing it using:de Silva et al., (2021). PySensors: A Python package for sparse sensor placement. Journal of Open Source Software, 6(58), 2828, https://doi.org/10.21105/joss.02828``Bibtex:@article{de Silva2021,
  doi = {10.21105/joss.02828},
  url = {https://doi.org/10.21105/joss.02828},
  year = {2021},
  publisher = {The Open Journal},
  volume = {6},
  number = {58},
  pages = {2828},
  author = {Brian M. de Silva and Krithika Manohar and Emily Clark and Bingni W. Brunton and J. Nathan Kutz and Steven L. Brunton},
  title = {PySensors: A Python package for sparse sensor placement},
  journal = {Journal of Open Source Software}
}Referencesde Silva, Brian M., Krithika Manohar, Emily Clark, Bingni W. Brunton,
Steven L. Brunton, J. Nathan Kutz.
“PySensors: A Python package for sparse sensor placement.”
arXiv preprint arXiv:2102.13476 (2021).[arXiv]Manohar, Krithika, Bingni W. Brunton, J. Nathan Kutz, and Steven L. Brunton.
“Data-driven sparse sensor placement for reconstruction: Demonstrating the
benefits of exploiting known patterns.”
IEEE Control Systems Magazine 38, no. 3 (2018): 63-86.[DOI]Brunton, Bingni W., Steven L. Brunton, Joshua L. Proctor, and J Nathan Kutz.
“Sparse sensor placement optimization for classification.”
SIAM Journal on Applied Mathematics 76.5 (2016): 2099-2122.[DOI]Clark, Emily, Travis Askham, Steven L. Brunton, and J. Nathan Kutz.
“Greedy sensor placement with cost constraints.” IEEE Sensors Journal 19, no. 7
(2018): 2642-2656.[DOI]