{"id":19267036,"url":"https://github.com/mljs/spectra-fitting","last_synced_at":"2025-04-21T19:32:37.389Z","repository":{"id":40506764,"uuid":"41679873","full_name":"mljs/spectra-fitting","owner":"mljs","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-26T12:55:05.000Z","size":1739,"stargazers_count":4,"open_issues_count":5,"forks_count":3,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-10-13T23:47:14.472Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"http://mljs.github.io/spectra-fitting/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mljs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-31T14:26:01.000Z","updated_at":"2024-09-29T01:46:00.000Z","dependencies_parsed_at":"2024-03-07T15:35:25.354Z","dependency_job_id":null,"html_url":"https://github.com/mljs/spectra-fitting","commit_stats":{"total_commits":167,"total_committers":11,"mean_commits":"15.181818181818182","dds":0.7065868263473054,"last_synced_commit":"c7e141ab1cd36d9a9e14b06b9cd5eb986523c3f1"},"previous_names":["mljs/optimize-lorentzian"],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fspectra-fitting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fspectra-fitting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fspectra-fitting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fspectra-fitting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/spectra-fitting/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223876400,"owners_count":17218387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-11-09T20:09:36.306Z","updated_at":"2025-04-21T19:32:37.377Z","avatar_url":"https://github.com/mljs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ml-spectra-fitting\n\n[![NPM version][npm-image]][npm-url]\n[![build status][ci-image]][ci-url]\n[![npm download][download-image]][download-url]\n\nThis is a spectra fitting package to optimize the position (x), max intensity (y), full width at half maximum (FWHM = width) and the ratio of gaussian contribution (mu) if it's required. It supports three kind of shapes:\n\n| Name         |                                                                                                                            Equation                                                                                                                             |\n| ------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |\n| Gaussian     |                                                                 \u003cimg src=\"https://tex.cheminfo.org/?tex=y%20%5Ccdot%20exp%20%5Cleft%5B%5Cfrac%7B%5Cdelta%7D%7B2%20%5Csigma%5E2%7D%5Cright%5D\"/\u003e                                                                 |\n| Lorentzian   |                                                                             \u003cimg src=\"https://tex.cheminfo.org/?tex=y%5Ccdot%5Cfrac%7B%5Cgamma%7D%7B%5Cdelta%20%2B%20%5Cgamma%7D\"/\u003e                                                                             |\n| Pseudo Voigt | \u003cimg src=\"https://tex.cheminfo.org/?tex=y%20*%20%5Cleft%5B%5Cmu%20%5Ccdot%20exp%20%5Cleft%5B%5Cfrac%7B%5Cdelta%7D%7B2%20%5Csigma%5E2%7D%5Cright%5D%20%2B%20(1%20-%20%5Cmu)%20%5Ccdot%20%5Cfrac%7B%5Cgamma%7D%7B%5Cdelta%20%2B%20%5Cgamma%7D%20%5Cright%5D%0A\"/\u003e |\n\nwhere\n\n| \u003cimg src=\"https://tex.cheminfo.org/?tex=%5Cdelta%20%3D%20%5Cleft(t%20-%20x%5Cright)%5E2%0A\"/\u003e | \u003cimg src=\"https://tex.cheminfo.org/?tex=%5Csigma%20%3D%20%5Cfrac%7BFWHM%7D%7B2%5Csqrt%7B2%20%5Ccdot%20Ln(2)%7D%7D\"/\u003e | \u003cimg src=\"https://tex.cheminfo.org/?tex=%5Cgamma%3D%5Cleft(FWHM%5Cright)%5E2\"/\u003e |\n| --------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------ |\n\nIt is a wrapper of [ml-levenberg-marquardt](https://github.com/mljs/levenberg-marquardt)\n\n## [API Documentation](https://mljs.github.io/spectra-fitting/)\n\n## Installation\n\n`$ npm install ml-spectra-fitting`\n\n## Example\n\n```js\nimport { optimize } from 'ml-spectra-fitting';\nimport { SpectrumGenerator } from 'spectrum-generator';\n\nconst generator = new SpectrumGenerator({\n  nbPoints: 101,\n  from: -1,\n  to: 1,\n});\n\n// by default the kind of shape is gaussian;\ngenerator.addPeak({ x: 0.5, y: 0.2 }, { fwhm: 0.2 });\ngenerator.addPeak(\n  { x: -0.5, y: 0.2 },\n  {\n    shape: {\n      kind: 'lorentzian',\n      fwhm: 0.1,\n    },\n  },\n);\n\n//points to fit {x, y};\nlet data = generator.getSpectrum();\nconsole.log(JSON.stringify({ x: Array.from(data.x), y: Array.from(data.y) }));\n//the approximate values to be optimized, It could coming from a peak picking with ml-gsd\nlet peaks = [\n  {\n    x: -0.5,\n    y: 0.22,\n    shape: {\n      kind: 'gaussian',\n      fwhm: 0.25,\n    },\n  },\n  {\n    x: 0.52,\n    y: 0.18,\n    shape: {\n      kind: 'gaussian',\n      fwhm: 0.18,\n    },\n  },\n];\n\n// the function receive an array of peak with {x, y, fwhm} as a guess\n// and return a list of objects\nlet fittedParams = optimize(data, peaks, { shape: { kind: 'pseudoVoigt' } });\n\nconsole.log(fittedParams);\nconst result = {\n  error: 0.12361588652854476,\n  iterations: 100,\n  peaks: [\n    {\n      x: -0.5000014532421942,\n      y: 0.19995307937326137,\n      shape: {\n        kind: 'pseudoVoigt',\n        fwhm: 0.10007670374735196,\n        mu: 0.004731136777288483,\n      },\n    },\n    {\n      x: 0.5001051783652894,\n      y: 0.19960010175400406,\n      shape: {\n        kind: 'pseudoVoigt',\n        fwhm: 0.19935932346969124,\n        mu: 1,\n      },\n    },\n  ],\n};\n```\n\nFor data with and combination of signals with shapes between gaussian and lorentzians, we could use the kind pseudovoigt to fit the data.\n\n```js\nimport { optimize } from 'ml-spectra-fitting';\nimport { SpectrumGenerator } from 'spectrum-generator';\n\nconst generator = new SpectrumGenerator({\n  nbPoints: 101,\n  from: -1,\n  to: 1,\n});\n\n// by default the kind of shape is gaussian;\ngenerator.addPeak({ x: 0.5, y: 0.2 }, { fwhm: 0.2 });\ngenerator.addPeak(\n  { x: -0.5, y: 0.2 },\n  {\n    shape: {\n      kind: 'lorentzian',\n      fwhm: 0.1,\n    },\n  },\n);\n\n//points to fit {x, y};\nlet data = generator.getSpectrum();\nconsole.log(JSON.stringify({ x: Array.from(data.x), y: Array.from(data.y) }));\n//the approximate values to be optimized, It could coming from a peak picking with ml-gsd\nlet peaks = [\n  {\n    x: -0.5,\n    y: 0.22,\n    shape: {\n      kind: 'gaussian',\n      fwhm: 0.25,\n    },\n  },\n  {\n    x: 0.52,\n    y: 0.18,\n    shape: {\n      kind: 'gaussian',\n      fwhm: 0.18,\n    },\n  },\n];\n\n// the function receive an array of peak with {x, y, fwhm} as a guess\n// and return a list of objects\nlet fittedParams = optimize(data, peaks, { shape: { kind: 'pseudoVoigt' } });\n\nconsole.log(fittedParams);\nconst result = {\n  error: 0.12361588652854476,\n  iterations: 100,\n  peaks: [\n    {\n      x: -0.5000014532421942,\n      y: 0.19995307937326137,\n      shape: {\n        kind: 'pseudoVoigt',\n        fwhm: 0.10007670374735196,\n        mu: 0.004731136777288483,\n      },\n    },\n    {\n      x: 0.5001051783652894,\n      y: 0.19960010175400406,\n      shape: {\n        kind: 'pseudoVoigt',\n        fwhm: 0.19935932346969124,\n        mu: 1,\n      },\n    },\n  ],\n};\n```\n\n## License\n\n[MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/ml-spectra-fitting.svg\n[npm-url]: https://npmjs.org/package/ml-spectra-fitting\n[ci-image]: https://github.com/mljs/spectra-fitting/workflows/Node.js%20CI/badge.svg?branch=main\n[ci-url]: https://github.com/mljs/spectra-fitting/actions?query=workflow%3A%22Node.js+CI%22\n[download-image]: https://img.shields.io/npm/dm/ml-spectra-fitting.svg\n[download-url]: https://npmjs.org/package/ml-spectra-fitting\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fspectra-fitting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Fspectra-fitting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fspectra-fitting/lists"}