{"id":17190905,"url":"https://github.com/dfm/untrendy","last_synced_at":"2025-04-13T19:42:45.281Z","repository":{"id":7931761,"uuid":"9321081","full_name":"dfm/untrendy","owner":"dfm","description":"De-trending Kepler light curves in style","archived":false,"fork":false,"pushed_at":"2020-06-12T18:26:40.000Z","size":645,"stargazers_count":3,"open_issues_count":5,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-27T10:21:33.826Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/dfm.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.rst","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-09T12:50:55.000Z","updated_at":"2020-06-12T18:26:44.000Z","dependencies_parsed_at":"2022-09-25T05:11:11.267Z","dependency_job_id":null,"html_url":"https://github.com/dfm/untrendy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfm%2Funtrendy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfm%2Funtrendy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfm%2Funtrendy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfm%2Funtrendy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfm","download_url":"https://codeload.github.com/dfm/untrendy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248462194,"owners_count":21107817,"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":[],"created_at":"2024-10-15T01:24:21.816Z","updated_at":"2025-04-13T19:42:45.258Z","avatar_url":"https://github.com/dfm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Untrendy\n========\n\nIn an age where studying exoplanets is just the hippest thing ever, sometimes\nit's good to step out of line and be a little untrendy! This library is a set\nof hacks that can robustly remove the out-of-transit trends in light curve\ndata.\n\nInstallation\n------------\n\n**Untrendy** depends on ``numpy`` and ``scipy`` so make sure that you install\nthose first. Then, you can install using ``pip``:\n\n::\n\n    pip install untrendy\n\nUsage\n-----\n\n**Untrendy** is really complicated. It has approximately *one* function and\nabout *200 lines of code (including documentation)*. It mostly runs on love\nand magic (more complete details are given below if you want).\n\nLet's say that you have a light curve with time samples ``t``, flux\nmeasurements ``f`` and uncertainties ``sigma``. You can simply run:\n\n.. code-block:: python\n\n    import untrendy\n    f_detrend, sigma_detrend = untrendy.untrend(t, f, sigma)\n\nto find a robust estimate of the global trends of the time series and remove\nit. The default settings are tuned to work well for finding the\n\"out-of-transit\" trends in Kepler data but a detailed description of the\noptions is listed below. You can also just fit for the trends and get a\ncallable representation of the trend:\n\n.. code-block:: python\n\n    trend = untrendy.fit_trend(t, f, ferr)\n\nIn this case, you can find the background level at some time ``t0`` by calling\nthe function:\n\n.. code-block:: python\n\n    bkg = trend(t0)\n\nNotes\n-----\n\n1. The spline sometimes goes to hell in regions where you don't have any\n   samples so be careful with that.\n2. This whole procedure introduces correlated errors. You've been warned.\n\nCommand Line Untrending\n-----------------------\n\nThere is also the option of using **Untrendy** from the command line if you\ndon't want to bother with all the Python stuff. If you have a whitespace\nseparated ASCII file containing your light curve, you can de-trend it by\nrunning:\n\n::\n\n    untrend /path/to/data.txt\n\nThe code will assume that your file has 2 or 3 columns with time, flux and\n(optionally) uncertainties for each observation. Then, the de-trended light\ncurve will be written to standard out in the same format. Alternatively, the\nsame program can read the data right from standard in:\n\n::\n\n    cat /path/to/data.txt | untrend\n\nThis gives you the option of doing something crazy and then piping it all\nUNIX-like. Personally, I would just use Python.\n\nAPI\n---\n\nFit the trend\n+++++++++++++\n\n*untrendy.*\\ **fit_trend** (``x``, ``y``, ``yerr=None``, ``Q=12``, ``dt=3.0``,\n``tol=0.00125``, ``maxiter=15``, ``fill_times=None``, ``maxditer=4``,\n``nfill=4``)\n\nUse iteratively re-weighted least squares to fit a spline to the\nout-of-transit trends in a time series. The input data should be \"clean\".\nIn other words, bad data should be masked and it often helps to normalize\nthe fluxes (by the median or something).\n\n**Parameters**\n\n:``x``:          The sampled times.\n:``y``:          The fluxes corresponding to the times in ``x``.\n:``yerr``:       (optional) The 1-sigma error bars on ``y``.\n:``Q``:          (optional) The parameter controlling the severity of the\n                 re-weighting.\n:``dt``:         (optional) The initial spacing between time control\n                 points.\n:``tol``:        (optional) The convergence criterion.\n:``maxiter``:    (optional) The maximum number of re-weighting iterations\n                 to run.\n:``fill_times``: (optional) If provided, this number sets the minimum time\n                 spacing between adjacent samples that is acceptable. If\n                 the spacing is larger, knots will be added to fill in\n                 the gap.\n:``maxditer``:   (optional) The maximum number of discontinuity search\n                 iterations to run.\n:``nfill``:      (optional) The number of knots to use to fill in the\n                 gaps.\n\n**Returns**\n\n:``trend``:      A callable representation of the trend.\n\nRemove the trend\n++++++++++++++++\n\n*untrendy.*\\ **untrend** (``x``, ``y``, ``yerr=None``, ``**kwargs``)\n\nUse iteratively re-weighted least squares to remove the out-of-transit\ntrends in a light curve. Unlike ``fit_trend``, this function masks bad\ndata (``NaN``) and normalizes the data before fitting.\n\n**Parameters**\n\n:``x``:          The sampled times.\n:``y``:          The fluxes corresponding to the times in ``x``.\n:``yerr``:       (optional) The 1-sigma error bars on ``y``.\n:``**kwargs``:   (optional) Other arguments passed to the ``fit_trend``\n                 function.\n\n**Returns**\n\n:``flux``:       The de-trended relative fluxes.\n:``ferr``:       The de-trended uncertainties on ``flux``.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfm%2Funtrendy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfm%2Funtrendy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfm%2Funtrendy/lists"}