{"id":17686922,"url":"https://github.com/yanndebray/eclipse","last_synced_at":"2025-05-13T00:36:05.558Z","repository":{"id":232218086,"uuid":"783771219","full_name":"yanndebray/eclipse","owner":"yanndebray","description":"🌑🌒🌓 Analyze the total solar eclipse with MATLAB + SunPy","archived":false,"fork":false,"pushed_at":"2024-07-17T19:34:34.000Z","size":1042,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T05:11:11.812Z","etag":null,"topics":["matlab","python","sunpy"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yanndebray.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2024-04-08T14:37:31.000Z","updated_at":"2024-07-17T19:34:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"570f1a2c-2a7c-49d2-b724-6cc360ad019b","html_url":"https://github.com/yanndebray/eclipse","commit_stats":null,"previous_names":["yanndebray/eclipse"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanndebray%2Feclipse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanndebray%2Feclipse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanndebray%2Feclipse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanndebray%2Feclipse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanndebray","download_url":"https://codeload.github.com/yanndebray/eclipse/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253850603,"owners_count":21973663,"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":["matlab","python","sunpy"],"created_at":"2024-10-24T10:46:25.065Z","updated_at":"2025-05-13T00:36:05.532Z","avatar_url":"https://github.com/yanndebray.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Eclipse 🌑🌒🌓\n\n[![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=yanndebray/eclipse\u0026file=livescript.mlx)\n\nView Sunpy app in Focus mode:\nhttps://matlab.mathworks.com/open/github/v1?repo=yanndebray/eclipse\u0026file=sunpy.mlapp\u0026focus=true\n\nAnalyze the total solar eclipse\n\n2024\\-04\\-08\n\nhttps://github.com/yanndebray/eclipse/assets/128002745/f4d92364-e9b4-4a92-af09-97cf625087b4\n\n\n\u003ca name=\"beginToc\"\u003e\u003c/a\u003e\n\n## Table of Contents\n[Context](#context)\n \n[Resources](#resources)\n \n[Set up environment](#set-up-environment)\n \n[Import data with Python live task](#import-data-with-python-live-task)\n \n[Transform Pandas Dataframe to MATLAB Table](#transform-pandas-dataframe-to-matlab-table)\n \n[Export to ipynb and md](#export-to-ipynb-and-md)\n \n\u003ca name=\"endToc\"\u003e\u003c/a\u003e\n\n# Context\n\nIn this tutorial, we will show how to use MATLAB with the SunPy community Python library for Solar Physics\n\n\n![image_0.png](README_media/image_0.png)\n\n# Resources\n-  [https://github.com/yanndebray/matlab\\-with\\-python\\-book](https://github.com/yanndebray/matlab-with-python-book) \n-  [https://docs.sunpy.org/en/stable/generated/gallery/showcase/eclipse\\_amount.html](https://docs.sunpy.org/en/stable/generated/gallery/showcase/eclipse_amount.html)  \n\n# Set up environment\n```matlab\nsetup\n```\n\n```matlabTextOutput\nWarning: Name is nonexistent or not a directory: /MATLAB Drive/eclipse/pip\nDefaulting to user installation because normal site-packages is not writeable\nRequirement already satisfied: sunpy in /home/matlab/.local/lib/python3.10/site-packages (5.1.2)\nRequirement already satisfied: jplephem in /home/matlab/.local/lib/python3.10/site-packages (2.21)\nRequirement already satisfied: pandas in /home/matlab/.local/lib/python3.10/site-packages (2.2.1)\nRequirement already satisfied: astropy!=5.1.0,\u003e=5.0.6 in /home/matlab/.local/lib/python3.10/site-packages (from sunpy) (6.0.1)\nRequirement already satisfied: numpy\u003e=1.21.0 in /home/matlab/.local/lib/python3.10/site-packages (from sunpy) (1.26.4)\nRequirement already satisfied: packaging\u003e=19.0 in /home/matlab/.local/lib/python3.10/site-packages (from sunpy) (24.0)\nRequirement already satisfied: parfive\u003e=2.0.0 in /home/matlab/.local/lib/python3.10/site-packages (from parfive[ftp]\u003e=2.0.0-\u003esunpy) (2.1.0)\nRequirement already satisfied: pyerfa in /home/matlab/.local/lib/python3.10/site-packages (from sunpy) (2.0.1.3)\nRequirement already satisfied: python-dateutil\u003e=2.8.2 in /home/matlab/.local/lib/python3.10/site-packages (from pandas) (2.9.0.post0)\nRequirement already satisfied: pytz\u003e=2020.1 in /home/matlab/.local/lib/python3.10/site-packages (from pandas) (2024.1)\nRequirement already satisfied: tzdata\u003e=2022.7 in /home/matlab/.local/lib/python3.10/site-packages (from pandas) (2024.1)\nRequirement already satisfied: astropy-iers-data\u003e=0.2024.2.26.0.28.55 in /home/matlab/.local/lib/python3.10/site-packages (from astropy!=5.1.0,\u003e=5.0.6-\u003esunpy) (0.2024.4.8.0.32.4)\nRequirement already satisfied: PyYAML\u003e=3.13 in /usr/lib/python3/dist-packages (from astropy!=5.1.0,\u003e=5.0.6-\u003esunpy) (5.4.1)\nRequirement already satisfied: tqdm\u003e=4.27.0 in /home/matlab/.local/lib/python3.10/site-packages (from parfive\u003e=2.0.0-\u003eparfive[ftp]\u003e=2.0.0-\u003esunpy) (4.66.2)\nRequirement already satisfied: aiohttp in /home/matlab/.local/lib/python3.10/site-packages (from parfive\u003e=2.0.0-\u003eparfive[ftp]\u003e=2.0.0-\u003esunpy) (3.9.3)\nRequirement already satisfied: aioftp\u003e=0.17.1 in /home/matlab/.local/lib/python3.10/site-packages (from parfive[ftp]\u003e=2.0.0-\u003esunpy) (0.22.3)\nRequirement already satisfied: six\u003e=1.5 in /usr/lib/python3/dist-packages (from python-dateutil\u003e=2.8.2-\u003epandas) (1.16.0)\nRequirement already satisfied: aiosignal\u003e=1.1.2 in /home/matlab/.local/lib/python3.10/site-packages (from aiohttp-\u003eparfive\u003e=2.0.0-\u003eparfive[ftp]\u003e=2.0.0-\u003esunpy) (1.3.1)\nRequirement already satisfied: attrs\u003e=17.3.0 in /home/matlab/.local/lib/python3.10/site-packages (from aiohttp-\u003eparfive\u003e=2.0.0-\u003eparfive[ftp]\u003e=2.0.0-\u003esunpy) (23.2.0)\nRequirement already satisfied: frozenlist\u003e=1.1.1 in /home/matlab/.local/lib/python3.10/site-packages (from aiohttp-\u003eparfive\u003e=2.0.0-\u003eparfive[ftp]\u003e=2.0.0-\u003esunpy) (1.4.1)\nRequirement already satisfied: multidict\u003c7.0,\u003e=4.5 in /home/matlab/.local/lib/python3.10/site-packages (from aiohttp-\u003eparfive\u003e=2.0.0-\u003eparfive[ftp]\u003e=2.0.0-\u003esunpy) (6.0.5)\nRequirement already satisfied: yarl\u003c2.0,\u003e=1.0 in /home/matlab/.local/lib/python3.10/site-packages (from aiohttp-\u003eparfive\u003e=2.0.0-\u003eparfive[ftp]\u003e=2.0.0-\u003esunpy) (1.9.4)\nRequirement already satisfied: async-timeout\u003c5.0,\u003e=4.0 in /home/matlab/.local/lib/python3.10/site-packages (from aiohttp-\u003eparfive\u003e=2.0.0-\u003eparfive[ftp]\u003e=2.0.0-\u003esunpy) (4.0.3)\nRequirement already satisfied: idna\u003e=2.0 in /home/matlab/.local/lib/python3.10/site-packages (from yarl\u003c2.0,\u003e=1.0-\u003eaiohttp-\u003eparfive\u003e=2.0.0-\u003eparfive[ftp]\u003e=2.0.0-\u003esunpy) (3.6)\n```\n\n```matlab\npipshow(\"sunpy\")\n```\n\n```matlabTextOutput\nName: sunpy\nVersion: 5.1.2\nSummary: SunPy core package: Python for Solar Physics\nHome-page: https://sunpy.org\nAuthor: The SunPy Community\nAuthor-email: sunpy@googlegroups.com\nLicense: BSD 2-Clause\nLocation: /home/matlab/.local/lib/python3.10/site-packages\nRequires: astropy, numpy, packaging, parfive, pyerfa\nRequired-by: \n```\n\n# Import data with Python live task\n\n\n![](README_media/pytask.png)\n\n\n```matlab\n% Python code input\npycode4 = [...\n\"import astropy.units as u\",...\n\"from astropy.coordinates import EarthLocation, solar_system_ephemeris\",...\n\"from astropy.time import Time\",...\n\"from sunpy.coordinates import sun\",...\n\"import numpy as np\",...\n\"import pandas as pd\",...\n\"\",...\n\"# Define the geodetic coordinates\",...\n\"latitude = 29.6 * u.deg\",...\n\"longitude = -98.5 * u.deg  # Note that the longitude should come first\",...\n\"\",...\n\"# Create the EarthLocation object\",...\n\"location = EarthLocation.from_geodetic(longitude, latitude)\",...\n\"max2023 = Time('2023-10-14 16:54')\",...\n\"max2024 = Time('2024-04-08 18:35')\",...\n\"\",...\n\"time = max2024\",...\n\"\",...\n\"# Define an array of observation times centered around the time of interest\",...\n\"times = time + np.concatenate([np.arange(-120, -5) * u.min,\",...\n\"                                np.arange(-300, 300) * u.s,\",...\n\"                                np.arange(5, 121) * u.min])\",...\n\"\",...\n\"# Create an observer coordinate for the time array\",...\n\"observer = location.get_itrs(times)\",...\n\"\",...\n\"# Calculate the eclipse amounts using a JPL ephemeris\",...\n\"with solar_system_ephemeris.set('de440s'):\",...\n\"    amount = sun.eclipse_amount(observer)\",...\n\"    amount_minimum = sun.eclipse_amount(observer, moon_radius='minimum')\",...\n\"\",...\n\"# Calculate the start/end points of partial/total solar eclipse\",...\n\"partial = np.flatnonzero(amount \u003e 0)\",...\n\"if len(partial) \u003e 0:\",...\n\"    print(\"\"Eclipse detected:\"\")\",...\n\"    start_partial, end_partial = times[partial[[0, -1]]]\",...\n\"    print(f\"\"  Partial solar eclipse starts at {start_partial} UTC\"\")\",...\n\"\",...\n\"    total = np.flatnonzero(amount_minimum == 1)\",...\n\"    if len(total) \u003e 0:\",...\n\"        start_total, end_total = times[total[[0, -1]]]\",...\n\"        print(f\"\"  Total solar eclipse starts at {start_total} UTC\\n\"\"\",...\n\"                f\"\"  Total solar eclipse ends at {end_total} UTC\"\")\",...\n\"    print(f\"\"  Partial solar eclipse ends at {end_partial} UTC\"\")\",...\n\"\",...\n\"df = pd.DataFrame({'time': times.to_datetime(), 'amount': amount, 'amount_minimum': amount_minimum})\",...\n\"\"...\n];\n\n[latitude, longitude, df] = pyrun(pycode4, ...\n     [ \"latitude\" \"longitude\" \"df\" ])\n```\n\n```matlabTextOutput\nEclipse detected:\n  Partial solar eclipse starts at 2024-04-08 17:15:00.000 UTC\n  Total solar eclipse starts at 2024-04-08 18:33:44.000 UTC\n  Total solar eclipse ends at 2024-04-08 18:35:33.000 UTC\n  Partial solar eclipse ends at 2024-04-08 19:55:00.000 UTC\nlatitude = \n  Python Quantity:\n\n   29.6000\n\n    Use details function to view the properties of the Python object.\n\n    Use double function to convert to a MATLAB array.\n\nlongitude = \n  Python Quantity:\n\n  -98.5000\n\n    Use details function to view the properties of the Python object.\n\n    Use double function to convert to a MATLAB array.\n\ndf = \n  Python DataFrame with properties:\n\n          T: [1x1 py.pandas.core.frame.DataFrame]\n         at: [1x1 py.pandas.core.indexing._AtIndexer]\n      attrs: [1x1 py.dict]\n       axes: [1x2 py.list]\n    columns: [1x1 py.pandas.core.indexes.base.Index]\n     dtypes: [1x1 py.pandas.core.series.Series]\n      empty: 0\n      flags: [1x1 py.pandas.core.flags.Flags]\n        iat: [1x1 py.pandas.core.indexing._iAtIndexer]\n       iloc: [1x1 py.pandas.core.indexing._iLocIndexer]\n      index: [1x1 py.pandas.core.indexes.range.RangeIndex]\n        loc: [1x1 py.pandas.core.indexing._LocIndexer]\n       ndim: [1x1 py.int]\n      shape: [1x2 py.tuple]\n       size: [1x1 py.int]\n     values: [1x1 py.numpy.ndarray]\n\n                       time  amount  amount_minimum\n    0   2024-04-08 16:35:00     0.0             0.0\n    1   2024-04-08 16:36:00     0.0             0.0\n    2   2024-04-08 16:37:00     0.0             0.0\n    3   2024-04-08 16:38:00     0.0             0.0\n    4   2024-04-08 16:39:00     0.0             0.0\n    ..                  ...     ...             ...\n    826 2024-04-08 20:31:00     0.0             0.0\n    827 2024-04-08 20:32:00     0.0             0.0\n    828 2024-04-08 20:33:00     0.0             0.0\n    829 2024-04-08 20:34:00     0.0             0.0\n    830 2024-04-08 20:35:00     0.0             0.0\n    \n    [831 rows x 3 columns]\n\n```\n\n```matlab\n\n% Clean up\nclear pycode4;\n```\n\n# Transform Pandas Dataframe to MATLAB Table\n```matlab\n% T = table(df)\nTT = timetable(df)\n```\n| |time|amount|amount_minimum|\n|:--:|:--:|:--:|:--:|\n|1|08-Apr-2024 16:35:00|0|0|\n|2|08-Apr-2024 16:36:00|0|0|\n|3|08-Apr-2024 16:37:00|0|0|\n|4|08-Apr-2024 16:38:00|0|0|\n|5|08-Apr-2024 16:39:00|0|0|\n|6|08-Apr-2024 16:40:00|0|0|\n|7|08-Apr-2024 16:41:00|0|0|\n|8|08-Apr-2024 16:42:00|0|0|\n|9|08-Apr-2024 16:43:00|0|0|\n|10|08-Apr-2024 16:44:00|0|0|\n|11|08-Apr-2024 16:45:00|0|0|\n|12|08-Apr-2024 16:46:00|0|0|\n|13|08-Apr-2024 16:47:00|0|0|\n|14|08-Apr-2024 16:48:00|0|0|\n\n```matlab\n% stackedplot(TT)\nplot(TT.time,TT.amount)\n```\n\n![figure_0.png](README_media/figure_0.png)\n\n![](README_media/stackedplot.png)\n\n```matlab\n% San Antonio, Texas\nlat = py.numpy.array(latitude); lat = double(lat);\nlon = py.numpy.array(longitude); lon = double(lon);\ngeoscatter(lat,lon, 'filled')\n```\n\n![figure_1.png](README_media/figure_1.png)\n\n# Export to ipynb and md\n```matlab\nexport('livescript.mlx','README.md');\nexport('livescript.mlx','notebook.ipynb');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanndebray%2Feclipse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanndebray%2Feclipse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanndebray%2Feclipse/lists"}