{ "info": { "author": "Daniel Baumann", "author_email": "baumann-dan@outlook.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7" ], "description": "\ufeff# SPTEMP\r\n\r\nA Python package for the representation, processing and analysis of spatio-temporal vector data.\r\n\r\nThe documentation for this package can be found at:\r\nhttps://baumanndaniel.github.io/sptemp/\r\n\r\nThe source code of the package can be found at:\r\nhttps://github.com/BaumannDaniel/sptemp\r\n\r\nThis package was created by Daniel Baumann, baumann-dan@outlook.com\r\n\r\n## Prerequisites\r\n\r\nThe package can be installed without any dependencies, however to use the full functionality of the package, four third party packages are required.\r\n\r\n - [dateutil](https://dateutil.readthedocs.io/en/stable/) : needed for the Time_Period.from_iso() method\r\n - [shapely](https://shapely.readthedocs.io/en/stable/index.html) : needed for the interpolation, moving_geometry and analysis modules\r\n - [pyproj](https://pypi.org/project/pyproj/) : needed if coordinate reference systems are used\r\n - [pandas](https://pandas.pydata.org/) : needed for the analysis module\r\n\r\n## Getting Started\r\n\r\nThe package provides classes to represent timestamped data, as well as discretely and continuesly changing values.\r\n\r\n### Create a moving real number\r\n\r\nIn the following example a moving real number is created from timestamped floats. Such data could for example represent a temperature timeseries or stock prices.\r\n\r\n```python\r\nimport datetime as dt\r\n\r\nfrom sptemp import zeit\r\nfrom sptemp.interpolation import ICollection as IC\r\n\r\ntso1 = zeit.TS_Object(1.5, dt.datetime(2019, 7, 4, 14, 15, 10))\r\ntso2 = zeit.TS_Object(5.2, dt.datetime(2019, 7, 4, 14, 15, 20))\r\ntso3 = zeit.TS_Object(2.4, dt.datetime(2019, 7, 4, 14, 15, 35))\r\ntso4 = zeit.TS_Object(8.9, dt.datetime(2019, 7, 4, 14, 15, 50))\r\n\r\ntsu1 = zeit.TS_Unit(IC.linear, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 10), dt.datetime(2019, 7, 4, 14, 15, 50)))\r\nip1 = zeit.Interpolator([tsu1])\r\n\r\nmvr = zeit.Moving_Object([tso1, tso2, tso3, tso4], ip1)\r\nprint mvr.interpolate(dt.datetime(2019, 7, 4, 14, 15, 17)).value # == 4.09\r\n```\r\n\r\n\r\n\r\n\r\n### Create a moving point geometry\r\n\r\nIn this example a moving point is created from timestamped shapely point geometries.\r\n\r\n```python\r\nimport datetime as dt\r\n\r\nimport shapely.geometry as sg\r\nimport sptemp.moving_geometry as mg\r\nfrom sptemp import zeit\r\nfrom sptemp.interpolation import ICollection as IC\r\nfrom sptemp.interpolation import IPoint\r\n\r\ntsp1 = mg.TS_Point(sg.Point(1,1), dt.datetime(2019, 7, 4, 14, 15, 10))\r\ntsp2 = mg.TS_Point(sg.Point(2,3), dt.datetime(2019, 7, 4, 14, 15, 15))\r\ntsp3 = mg.TS_Point(sg.Point(5,4), dt.datetime(2019, 7, 4, 14, 15, 20))\r\ntsp4 = mg.TS_Point(sg.Point(6,2), dt.datetime(2019, 7, 4, 14, 15, 26))\r\ntsp5 = mg.TS_Point(sg.Point(7,2), dt.datetime(2019, 7, 4, 14, 15, 30))\r\n\r\ntsu1 = zeit.TS_Unit(IPoint.linear_point, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 10), dt.datetime(2019, 7, 4, 14, 15, 21)))\r\ntsu2 = zeit.TS_Unit(IC.constant, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 21), dt.datetime(2019, 7, 4, 14, 15, 24)))\r\ntsu3 = zeit.TS_Unit(IPoint.linear_point, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 24), dt.datetime(2019, 7, 4, 14, 15, 30)))\r\nip1 = zeit.Interpolator([tsu1, tsu2, tsu3])\r\n\r\nmvp = mg.Moving_Point([tsp1, tsp2, tsp3, tsp4, tsp5], ip1)\r\nprint mvp.interpolate(dt.datetime(2019, 7, 4, 14, 15, 17)).value # == sg.Point(3.2,3.4)\r\n```\r\n\r\n\r\n\r\n\r\n### Create a moving point geometry follwing the course defined by a LineString\r\n\r\nIn this example the moving point follows the course defined by a shapely LineString geometry.\r\n\r\n```python\r\nimport datetime as dt\r\n\r\nimport shapely.geometry as sg\r\nimport sptemp.moving_geometry as mg\r\nfrom sptemp import zeit\r\nfrom sptemp.interpolation import IPoint\r\n\r\ntsp1 = mg.TS_Point(sg.Point(1,1), dt.datetime(2019, 7, 4, 14, 15, 10))\r\ntsp2 = mg.TS_Point(sg.Point(7,2), dt.datetime(2019, 7, 4, 14, 15, 30))\r\n\r\ntsu1 = zeit.TS_Unit(IPoint.curve_point, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 10), dt.datetime(2019, 7, 4, 14, 15, 30)))\r\nip1 = zeit.Interpolator([tsu1])\r\n\r\nmvp2 = mg.Moving_Point([tsp1, tsp2], ip1)\r\n\r\nlr = sg.LineString([(1,1),(2,3),(5,4),(6,2),(7,2)])\r\nprint mvp2.interpolate(dt.datetime(2019, 7, 4, 14, 15, 17), lr).value # = sg.Point(2.74564305 3.24854768)\r\n```\r\n\r\n\r\n\r\n\r\n### Create a moving linestring geometry\r\n\r\nIn this example a continuesly moving linestring geometry is created.\r\n\r\n```python\r\nimport datetime as dt\r\n\r\nimport shapely.geometry as sg\r\nimport sptemp.moving_geometry as mg\r\nfrom sptemp import zeit\r\nfrom sptemp.interpolation import ICurve\r\n\r\ntsl1 = mg.TS_LineString(sg.LineString([(1,2),(3,1),(7,4)]), dt.datetime(2019, 7, 4, 14, 15, 10))\r\ntsl2 = mg.TS_LineString(sg.LineString([(1,1),(2,0.5),(3,1),(5,1),(6,2),(7,3)]),\r\n zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 18), dt.datetime(2019, 7, 4, 14, 15, 22)))\r\ntsl3 = mg.TS_LineString(sg.LineString([(1,1),(3,1.5),(5,3),(7,4)]), dt.datetime(2019, 7, 4, 14, 15, 30))\r\n\r\ntsu1 = zeit.TS_Unit(ICurve.basic_linear, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 10), dt.datetime(2019, 7, 4, 14, 15, 30)))\r\nip1 = zeit.Interpolator([tsu1])\r\n\r\nmvl = mg.Moving_LineString([tsl1, tsl2, tsl3], ip1)\r\n\r\nprint mvl.interpolate(dt.datetime(2019, 7, 4, 14, 15, 15)).value.coords[:]\r\n# = [(1.0, 1.375), (2.375, 0.6875), (3.2820250483634053, 1.211518786272554),\r\n# (5.036526791961998, 1.589895093971498), (6.018263395980998, 2.4824475469857488), (7.0, 3.375)]\r\n```\r\n\r\n\r\n\r\n\r\n### Create a moving linear ring geometry\r\n\r\nIn this example a continuesly moving linear ring geometry is created.\r\n\r\n```python\r\nimport datetime as dt\r\n\r\nimport shapely.geometry as sg\r\nimport sptemp.moving_geometry as mg\r\nfrom sptemp import zeit\r\nfrom sptemp.interpolation import IRing\r\n\r\ntslr1 = mg.TS_LinearRing(sg.LinearRing([(1,1),(7,1.5),(6,4),(3,3),(1,1)]), dt.datetime(2019, 7, 4, 14, 15, 10))\r\ntslr2 = mg.TS_LinearRing(sg.LinearRing([(2,1),(4,0.5),(6.5,2),(6,4),(4,4),(4,2),(2,2),(2,1)]), dt.datetime(2019, 7, 4, 14, 15, 18))\r\ntslr3 = mg.TS_LinearRing(sg.LinearRing([(3,2),(6,2),(5.5,3.5),(3,3),(3,2)]), dt.datetime(2019, 7, 4, 14, 15, 30))\r\n\r\ntsu1 = zeit.TS_Unit(IRing.basic_linear, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 10), dt.datetime(2019, 7, 4, 14, 15, 30)))\r\nip1 = zeit.Interpolator([tsu1])\r\n\r\nmvlr = mg.Moving_LinearRing([tslr1, tslr2, tslr3], ip1)\r\n\r\nprint mvlr.interpolate(dt.datetime(2019, 7, 4, 14, 15, 15)).value.coords[:]\r\n# = [(3.625, 3.625), (3.25, 2.0), (1.625, 1.625), (3.875, 1.1875), (4.969669914110089, 1.2633252147247767),\r\n# (6.3125, 2.75), (5.428975315279473, 3.809658438426491), (3.625, 3.625)]\r\n```\r\n\r\n\r\n\r\n### Implement your own interpolation function\r\n\r\nThe users of the sptemp package can provide their own interpolation functions for moving objects.\r\nThese functions must take a minimum of three arguments:\r\n\r\n - **start_ts** (TS_Object): An instance of the sptemp.zeit.TS_Object class or one of its subclasses.\r\n - **end_ts** (TS_Object): An instance of the sptemp.zeit.TS_Object class or one of its subclasses, that lays after start_ts on the time axis.\r\n - **time** (datetime.datetime): datetime object specifying the time for which the function interpolates the value.\r\n\r\nThe function then can define an arbitrary number of additional arguments, that are then passed by the user to the Moving_Object.interpolate() method.\r\nThe function must return a TS_Object instance or an instance of a subclass of the TS_Object class. Alternatively the function can also return None.\r\n\r\nIn the following example an interpolation function \"decelerate\" is defined, which provides interpolation functionality for moving points.\r\n\r\n```python\r\nimport datetime as dt\r\n\r\nimport shapely.geometry as sg\r\nimport sptemp.moving_geometry as mg\r\nfrom sptemp import zeit\r\n\r\ndef decelerate(start_ts, end_ts, time):\r\n decelerate_factor = 1 + ((end_ts.start_time() - time).total_seconds()/(end_ts.start_time() - start_ts.end_time()).total_seconds())\r\n\t if time < end_ts.start_time() else 1.0\r\n t = (time - start_ts.end_time()).total_seconds() * decelerate_factor/(end_ts.start_time() - start_ts.end_time()).total_seconds()\r\n\r\n t_x = (1 - t)*start_ts.value.x + t*end_ts.value.x\r\n t_y = (1 - t)*start_ts.value.y + t*end_ts.value.y\r\n\r\n if start_ts.has_z and end_ts.has_z:\r\n t_z = (1 - t)*start_ts.value.z + t*end_ts.value.z\r\n return mg.TS_Point(sg.Point(t_x, t_y, t_z), time)\r\n else:\r\n return mg.TS_Point(sg.Point(t_x, t_y), time)\r\n\r\ntsp1 = mg.TS_Point(sg.Point(1,1), dt.datetime(2019, 7, 4, 14, 15, 10))\r\ntsp2 = mg.TS_Point(sg.Point(2,3), dt.datetime(2019, 7, 4, 14, 15, 15))\r\ntsp3 = mg.TS_Point(sg.Point(5,4), dt.datetime(2019, 7, 4, 14, 15, 20))\r\ntsp4 = mg.TS_Point(sg.Point(6,2), dt.datetime(2019, 7, 4, 14, 15, 26))\r\ntsp5 = mg.TS_Point(sg.Point(7,2), dt.datetime(2019, 7, 4, 14, 15, 30))\r\n\r\ntsu1 = zeit.TS_Unit(decelerate, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 10), dt.datetime(2019, 7, 4, 14, 15, 30)))\r\nip1 = zeit.Interpolator([tsu1])\r\n\r\nmvp3 = mg.Moving_Point([tsp1, tsp2, tsp3, tsp4, tsp5], ip1)\r\n\r\nprint mvp3.interpolate(dt.datetime(2019, 7, 4, 14, 15, 20)).value # == sg.Point(5,4)\r\n```\r\n\r\n\r\n\r\n\r\n### Create a SPT_DataFrame object\r\n\r\nThe analysis module of the 'sptemp' package provides the class 'SPT_DataFrame', with which spatio-temporal vector data can be represented with a\r\nrelational data structure.\r\n\r\nIn the following example the data of two buoys floating in the water and recording the air- and water temperature, is represented with\r\na SPT_DataFrame.\r\n\r\n```python\r\nimport datetime as dt\r\n\r\nimport pyproj\r\nimport pandas\r\nimport shapely.geometry as sg\r\nimport sptemp.moving_geometry as mg\r\nfrom sptemp import zeit\r\nfrom sptemp.analysis import SPT_DataFrame\r\nfrom sptemp.interpolation import ICollection as IC\r\nfrom sptemp.interpolation import IPoint\r\n\r\nutm32n = pyproj.Proj(init=\"epsg:32632\")\r\n\r\nip = zeit.Interpolator([zeit.TS_Unit(IC.linear, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 0), dt.datetime(2019, 7, 4, 15, 0, 0)))])\r\nip2 = zeit.Interpolator([zeit.TS_Unit(IPoint.linear_point, zeit.Time_Period(dt.datetime(2019, 7, 4, 14, 15, 0), dt.datetime(2019, 7, 4, 15, 0, 0)))])\r\n\r\nair_temp1 = zeit.Moving_Object([zeit.TS_Object(22.4, dt.datetime(2019, 7, 4, 14, 15, 10)),\r\n zeit.TS_Object(22.7, dt.datetime(2019, 7, 4, 14, 28, 45)),\r\n zeit.TS_Object(21.9, dt.datetime(2019, 7, 4, 14, 47, 22))],ip)\r\n\r\nair_temp2 = zeit.Moving_Object([zeit.TS_Object(21.4, dt.datetime(2019, 7, 4, 14, 17, 30)),\r\n zeit.TS_Object(21.7, dt.datetime(2019, 7, 4, 14, 42, 32))],ip) \r\n\r\nwater_temp1 = zeit.Moving_Object([zeit.TS_Object(19.3, dt.datetime(2019, 7, 4, 14, 15, 20)),\r\n zeit.TS_Object(19.1, dt.datetime(2019, 7, 4, 14, 28, 45))],ip)\r\n\r\nwater_temp2 = zeit.Moving_Object([zeit.TS_Object(18.8, dt.datetime(2019, 7, 4, 14, 17, 30)),\r\n zeit.TS_Object(19.2, dt.datetime(2019, 7, 4, 14, 42, 45))],ip)\r\n\r\n\r\nmvp1 = mg.Moving_Point([mg.TS_Point(sg.Point(473925.42, 6354541.11), dt.datetime(2019, 7, 4, 14, 15, 10), utm32n),\r\n mg.TS_Point(sg.Point(473953.76, 6354877.23), dt.datetime(2019, 7, 4, 14, 30, 0), utm32n),\r\n mg.TS_Point(sg.Point(473967.12, 6354854.73), dt.datetime(2019, 7, 4, 14, 50, 0), utm32n)], ip2)\r\n\r\nmvp2 = mg.Moving_Point([mg.TS_Point(sg.Point(474176.89, 6354701.98), dt.datetime(2019, 7, 4, 14, 17, 20), utm32n),\r\n mg.TS_Point(sg.Point(474533.54, 6354770.11), dt.datetime(2019, 7, 4, 14, 50, 0), utm32n)], ip2)\r\n\r\nid = [\"a\", \"b\"]\r\nair_temp = [air_temp1, air_temp2]\r\nwater_temp = [water_temp1, water_temp2]\r\ngeometry = [mvp1, mvp2]\r\n\r\ndf = pandas.DataFrame({\"id\" : id, \"air_temp\" : air_temp, \"water_temp\" : water_temp, \"geometry\" : geometry})\r\nspt_df = SPT_DataFrame(df)\r\n\r\nprint spt_df.interpolate(dt.datetime(2019, 7, 4, 14, 30, 0)).dataframe\r\n```\r\n\r\n| id | water_temp | air_temp | geometry |\r\n| -- | ----------:| --------:| -----------------------------------------------:|\r\n| a | None | 22.6363 | sg.Point(473953.76, 6354877.23) |\r\n| b | 18.998 | 21.5498 | sg.Point(474315.1828571429, 6354728.397755102) |\r\n\r\n\r\n\r\n\r\n\r\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/BaumannDaniel/sptemp", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "sptemp", "package_url": "https://pypi.org/project/sptemp/", "platform": "", "project_url": "https://pypi.org/project/sptemp/", "project_urls": { "Homepage": "https://github.com/BaumannDaniel/sptemp" }, "release_url": "https://pypi.org/project/sptemp/1.1.0/", "requires_dist": null, "requires_python": "", "summary": "package for spatio-temporal vector data processing and analysis.", "version": "1.1.0" }, "last_serial": 5495717, "releases": { "1.1.0": [ { "comment_text": "", "digests": { "md5": "921cff1800227e484bdbbe62e2b2753f", "sha256": "f2265d4e0355f9c367236c832a15decdd3673bfd857ac128cc873ec962b21985" }, "downloads": -1, "filename": "sptemp-1.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "921cff1800227e484bdbbe62e2b2753f", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 50307, "upload_time": "2019-07-06T21:50:56", "url": "https://files.pythonhosted.org/packages/c8/82/dcac1edb3e20a63b966aae1617963573abb88f185261aa02af0b78d98fbd/sptemp-1.1.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f4316628220477eddb359368c8bffab0", "sha256": "7b7706ce4f73ce2e67a5f5e98762358879fed0e292aff6decf0fc646466e627e" }, "downloads": -1, "filename": "sptemp-1.1.0.tar.gz", "has_sig": false, "md5_digest": "f4316628220477eddb359368c8bffab0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 49255, "upload_time": "2019-07-06T21:50:59", "url": "https://files.pythonhosted.org/packages/d1/90/c2fbeb1676bb97f6158008a551689de1aaa61ab4782b2436032b1d38b702/sptemp-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "921cff1800227e484bdbbe62e2b2753f", "sha256": "f2265d4e0355f9c367236c832a15decdd3673bfd857ac128cc873ec962b21985" }, "downloads": -1, "filename": "sptemp-1.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "921cff1800227e484bdbbe62e2b2753f", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 50307, "upload_time": "2019-07-06T21:50:56", "url": "https://files.pythonhosted.org/packages/c8/82/dcac1edb3e20a63b966aae1617963573abb88f185261aa02af0b78d98fbd/sptemp-1.1.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f4316628220477eddb359368c8bffab0", "sha256": "7b7706ce4f73ce2e67a5f5e98762358879fed0e292aff6decf0fc646466e627e" }, "downloads": -1, "filename": "sptemp-1.1.0.tar.gz", "has_sig": false, "md5_digest": "f4316628220477eddb359368c8bffab0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 49255, "upload_time": "2019-07-06T21:50:59", "url": "https://files.pythonhosted.org/packages/d1/90/c2fbeb1676bb97f6158008a551689de1aaa61ab4782b2436032b1d38b702/sptemp-1.1.0.tar.gz" } ] }