|
24 | 24 | "import hyrax\n", |
25 | 25 | "\n", |
26 | 26 | "rng = np.random.default_rng(42)\n", |
27 | | - "output_path = Path('./random_lightcurve.parquet')\n", |
| 27 | + "output_path = Path(\"./random_lightcurve.parquet\")\n", |
28 | 28 | "\n", |
29 | 29 | "n_objects = 10\n", |
30 | 30 | "n_points = 64\n", |
|
39 | 39 | " band = rng.choice([0, 1, 2], size=n_points)\n", |
40 | 40 | " rows.append(\n", |
41 | 41 | " {\n", |
42 | | - " 'object_id': f'obj-{idx:04d}',\n", |
43 | | - " 'lightcurve': {\n", |
44 | | - " 'time': times.tolist(),\n", |
45 | | - " 'flux': flux.tolist(),\n", |
46 | | - " 'flux_err': flux_err.tolist(),\n", |
47 | | - " 'band': band.tolist(),\n", |
| 42 | + " \"object_id\": f\"obj-{idx:04d}\",\n", |
| 43 | + " \"lightcurve\": {\n", |
| 44 | + " \"time\": times.tolist(),\n", |
| 45 | + " \"flux\": flux.tolist(),\n", |
| 46 | + " \"flux_err\": flux_err.tolist(),\n", |
| 47 | + " \"band\": band.tolist(),\n", |
48 | 48 | " },\n", |
49 | 49 | " }\n", |
50 | 50 | " )\n", |
|
53 | 53 | "pq.write_table(table, output_path)\n", |
54 | 54 | "\n", |
55 | 55 | "h = hyrax.Hyrax()\n", |
56 | | - "h.config['data_request'] = {\n", |
57 | | - " 'infer': {\n", |
58 | | - " 'lc': {\n", |
59 | | - " 'dataset_class': 'NestedPandasDataset',\n", |
60 | | - " 'data_location': str(output_path),\n", |
61 | | - " 'primary_id_field': 'object_id',\n", |
| 56 | + "h.config[\"data_request\"] = {\n", |
| 57 | + " \"infer\": {\n", |
| 58 | + " \"lc\": {\n", |
| 59 | + " \"dataset_class\": \"NestedPandasDataset\",\n", |
| 60 | + " \"data_location\": str(output_path),\n", |
| 61 | + " \"primary_id_field\": \"object_id\",\n", |
62 | 62 | " # Request only nested columns using nested-pandas dot-notation.\n", |
63 | | - " 'fields': ['lightcurve.time', 'lightcurve.flux', 'lightcurve.flux_err', 'lightcurve.band'],\n", |
| 63 | + " \"fields\": [\"lightcurve.time\", \"lightcurve.flux\", \"lightcurve.flux_err\", \"lightcurve.band\"],\n", |
64 | 64 | " }\n", |
65 | 65 | " }\n", |
66 | 66 | "}\n", |
67 | 67 | "\n", |
68 | 68 | "prepared = h.prepare()\n", |
69 | | - "print(f'Loaded rows: {len(prepared[\"infer\"])}')" |
| 69 | + "print(f\"Loaded rows: {len(prepared['infer'])}\")" |
70 | 70 | ] |
71 | 71 | }, |
72 | 72 | { |
|
84 | 84 | "metadata": {}, |
85 | 85 | "outputs": [], |
86 | 86 | "source": [ |
87 | | - "prepared['infer'][0]['lc'].keys()" |
| 87 | + "prepared[\"infer\"][0][\"lc\"].keys()" |
88 | 88 | ] |
89 | 89 | }, |
90 | 90 | { |
|
94 | 94 | "metadata": {}, |
95 | 95 | "outputs": [], |
96 | 96 | "source": [ |
97 | | - "prepared['infer'][0]['lc']['lightcurve.time'][:5], prepared['infer'][0]['lc']['lightcurve.flux'][:5]" |
| 97 | + "prepared[\"infer\"][0][\"lc\"][\"lightcurve.time\"][:5], prepared[\"infer\"][0][\"lc\"][\"lightcurve.flux\"][:5]" |
98 | 98 | ] |
99 | 99 | }, |
100 | 100 | { |
|
107 | 107 | "import matplotlib.pyplot as plt\n", |
108 | 108 | "import numpy as np\n", |
109 | 109 | "\n", |
110 | | - "time = np.asarray(prepared['infer'][0]['lc']['lightcurve.time'])\n", |
111 | | - "flux = np.asarray(prepared['infer'][0]['lc']['lightcurve.flux'])\n", |
112 | | - "flux_err = np.asarray(prepared['infer'][0]['lc']['lightcurve.flux_err'])\n", |
113 | | - "band = np.asarray(prepared['infer'][0]['lc']['lightcurve.band'])\n", |
| 110 | + "time = np.asarray(prepared[\"infer\"][0][\"lc\"][\"lightcurve.time\"])\n", |
| 111 | + "flux = np.asarray(prepared[\"infer\"][0][\"lc\"][\"lightcurve.flux\"])\n", |
| 112 | + "flux_err = np.asarray(prepared[\"infer\"][0][\"lc\"][\"lightcurve.flux_err\"])\n", |
| 113 | + "band = np.asarray(prepared[\"infer\"][0][\"lc\"][\"lightcurve.band\"])\n", |
114 | 114 | "\n", |
115 | 115 | "plt.figure(figsize=(10, 5))\n", |
116 | 116 | "for b in np.unique(band):\n", |
117 | 117 | " m = band == b\n", |
118 | | - " plt.errorbar(time[m], flux[m], flux_err[m], fmt='o', label=f'band {b}', alpha=0.8)\n", |
| 118 | + " plt.errorbar(time[m], flux[m], flux_err[m], fmt=\"o\", label=f\"band {b}\", alpha=0.8)\n", |
119 | 119 | "\n", |
120 | | - "plt.xlabel('MJD')\n", |
121 | | - "plt.ylabel('Flux')\n", |
122 | | - "plt.grid(True, which='both', linestyle='--', linewidth=0.5)\n", |
| 120 | + "plt.xlabel(\"MJD\")\n", |
| 121 | + "plt.ylabel(\"Flux\")\n", |
| 122 | + "plt.grid(True, which=\"both\", linestyle=\"--\", linewidth=0.5)\n", |
123 | 123 | "plt.legend()\n", |
124 | 124 | "plt.show()" |
125 | 125 | ] |
|
0 commit comments