minseok96 commited on
Commit
3db2eaa
·
verified ·
1 Parent(s): 0651e46

Upload vis_rdr.ipynb

Browse files
Files changed (1) hide show
  1. vis_rdr.ipynb +130 -0
vis_rdr.ipynb ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 19,
6
+ "id": "91dcaf61-f160-4d17-a921-80a5c4ace5e5",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "ename": "FileNotFoundError",
11
+ "evalue": "[Errno 2] No such file or directory: './SAR2RDR-Dataset/RDR/test/RDR_CMP_HSP_PUB_202401211300.npy'",
12
+ "output_type": "error",
13
+ "traceback": [
14
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
15
+ "\u001b[31mFileNotFoundError\u001b[39m Traceback (most recent call last)",
16
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[19]\u001b[39m\u001b[32m, line 32\u001b[39m\n\u001b[32m 30\u001b[39m lat = np.loadtxt(\u001b[33m'\u001b[39m\u001b[33m./lonlat/RDR_lat.txt\u001b[39m\u001b[33m'\u001b[39m, delimiter=\u001b[33m'\u001b[39m\u001b[33m,\u001b[39m\u001b[33m'\u001b[39m).reshape(\u001b[32m2881\u001b[39m, \u001b[32m2305\u001b[39m)[::-\u001b[32m1\u001b[39m]\n\u001b[32m 31\u001b[39m lon = np.loadtxt(\u001b[33m'\u001b[39m\u001b[33m./lonlat/RDR_lon.txt\u001b[39m\u001b[33m'\u001b[39m, delimiter=\u001b[33m'\u001b[39m\u001b[33m,\u001b[39m\u001b[33m'\u001b[39m).reshape(\u001b[32m2881\u001b[39m, \u001b[32m2305\u001b[39m)[::-\u001b[32m1\u001b[39m]\n\u001b[32m---> \u001b[39m\u001b[32m32\u001b[39m rdr = \u001b[43mnp\u001b[49m\u001b[43m.\u001b[49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m./SAR2RDR-Dataset/RDR/test/RDR_CMP_HSP_PUB_202401211300.npy\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 34\u001b[39m y0, y1 = \u001b[32m1200\u001b[39m - \u001b[32m200\u001b[39m, \u001b[32m1200\u001b[39m + \u001b[32m980\u001b[39m \u001b[38;5;66;03m# 1000 : 2180\u001b[39;00m\n\u001b[32m 35\u001b[39m x0, x1 = \u001b[32m1121\u001b[39m - \u001b[32m328\u001b[39m, \u001b[32m1121\u001b[39m + \u001b[32m772\u001b[39m \u001b[38;5;66;03m# 793 : 1893\u001b[39;00m\n",
17
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.11/site-packages/numpy/lib/_npyio_impl.py:451\u001b[39m, in \u001b[36mload\u001b[39m\u001b[34m(file, mmap_mode, allow_pickle, fix_imports, encoding, max_header_size)\u001b[39m\n\u001b[32m 449\u001b[39m own_fid = \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[32m 450\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m451\u001b[39m fid = stack.enter_context(\u001b[38;5;28mopen\u001b[39m(os.fspath(file), \u001b[33m\"\u001b[39m\u001b[33mrb\u001b[39m\u001b[33m\"\u001b[39m))\n\u001b[32m 452\u001b[39m own_fid = \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[32m 454\u001b[39m \u001b[38;5;66;03m# Code to distinguish from NumPy binary files and pickles.\u001b[39;00m\n",
18
+ "\u001b[31mFileNotFoundError\u001b[39m: [Errno 2] No such file or directory: './SAR2RDR-Dataset/RDR/test/RDR_CMP_HSP_PUB_202401211300.npy'"
19
+ ]
20
+ }
21
+ ],
22
+ "source": [
23
+ "import numpy as np\n",
24
+ "import matplotlib.pyplot as plt\n",
25
+ "import matplotlib\n",
26
+ "import cartopy.crs as ccrs\n",
27
+ "import cartopy.feature as cfeature\n",
28
+ "\n",
29
+ "def my_cmap_radar_kma():\n",
30
+ " colors = ['#c3c3c7',\n",
31
+ " '#ffffff', '#009bf5', '#004af5',\n",
32
+ " '#00ff00', '#00be00', '#008c00', '#005a00',\n",
33
+ " '#ffff00', '#ffdc1f', '#f9cd00', '#e0b900', '#ccaa00',\n",
34
+ " '#ff6600', '#ff3200', '#d20000', '#b40000',\n",
35
+ " '#e0a9ff', '#cc6aff', '#b329ff', '#9300e4',\n",
36
+ " '#b3b4de', '#4c4eb1', '#000390', '#000000']\n",
37
+ " bounds_vals = [-1e-5, 0, 0.1, 0.5, 1.0, 2, 3, 4, 5, 6, 7,\n",
38
+ " 8, 9, 10, 15, 20, 25, 30, 40, 50, 60, 70, 90, 110, 150, 200]\n",
39
+ " bounds_labels = ['', 0, 0.1, 0.5, 1, 2, 3, 4, 5, 6, 7,\n",
40
+ " 8, 9, 10, 15, 20, 25, 30, 40, 50, 60, 70, 90, 110, 150, '']\n",
41
+ "\n",
42
+ " cmap = matplotlib.colors.ListedColormap(colors, name=\"kma_radar\").with_extremes(under='#ffffff')\n",
43
+ " norm = matplotlib.colors.BoundaryNorm(bounds_vals, cmap.N)\n",
44
+ " try:\n",
45
+ " matplotlib.colormaps.register(cmap=cmap)\n",
46
+ " except Exception:\n",
47
+ " pass\n",
48
+ " return cmap, bounds_vals, bounds_labels, norm\n",
49
+ "\n",
50
+ "cmap_radar_kma, bounds_vals, bounds_labels, kma_norm = my_cmap_radar_kma()\n",
51
+ "\n",
52
+ "lat = np.loadtxt('./lonlat/RDR_lat.txt', delimiter=',').reshape(2881, 2305)[::-1]\n",
53
+ "lon = np.loadtxt('./lonlat/RDR_lon.txt', delimiter=',').reshape(2881, 2305)[::-1]\n",
54
+ "rdr = np.load(\"./SAR2RDR-Dataset/RDR/test/RDR_CMP_HSP_PUB_202401211300.npy\")\n",
55
+ "\n",
56
+ "y0, y1 = 1200 - 200, 1200 + 980 # 1000 : 2180\n",
57
+ "x0, x1 = 1121 - 328, 1121 + 772 # 793 : 1893\n",
58
+ "\n",
59
+ "projection = ccrs.LambertConformal(\n",
60
+ " central_longitude=float(lon.mean()),\n",
61
+ " central_latitude=float(lat.mean()),\n",
62
+ " standard_parallels=(30, 60),\n",
63
+ ")\n",
64
+ "\n",
65
+ "fig, ax = plt.subplots(figsize=(10, 8), subplot_kw={'projection': projection})\n",
66
+ "ax.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.5)\n",
67
+ "ax.add_feature(cfeature.BORDERS.with_scale('50m'), linewidth=0.5)\n",
68
+ "ax.set_extent([lon.min(), lon.max(), lat.min(), lat.max()], crs=ccrs.PlateCarree())\n",
69
+ "\n",
70
+ "# radar\n",
71
+ "im = ax.pcolormesh(\n",
72
+ " lon, lat, rdr,\n",
73
+ " cmap=cmap_radar_kma, norm=kma_norm,\n",
74
+ " shading='auto', rasterized=True,\n",
75
+ " transform=ccrs.PlateCarree(), alpha=0.9\n",
76
+ ")\n",
77
+ "\n",
78
+ "cbar = plt.colorbar(im, ax=ax, orientation='vertical',\n",
79
+ " boundaries=bounds_vals, ticks=bounds_vals, extend='max')\n",
80
+ "cbar.ax.set_yticklabels([str(x) if x != '' else '' for x in bounds_labels])\n",
81
+ "\n",
82
+ "\n",
83
+ "ax.plot(lon[y0, x0:x1], lat[y0, x0:x1],\n",
84
+ " transform=ccrs.PlateCarree(), color='red', linewidth=1.8)\n",
85
+ "\n",
86
+ "ax.plot(lon[y0:y1, x1-1], lat[y0:y1, x1-1],\n",
87
+ " transform=ccrs.PlateCarree(), color='red', linewidth=1.8)\n",
88
+ "\n",
89
+ "ax.plot(lon[y1-1, x0:x1][::-1], lat[y1-1, x0:x1][::-1],\n",
90
+ " transform=ccrs.PlateCarree(), color='red', linewidth=1.8)\n",
91
+ "\n",
92
+ "ax.plot(lon[y0:y1, x0][::-1], lat[y0:y1, x0][::-1],\n",
93
+ " transform=ccrs.PlateCarree(), color='red', linewidth=1.8)\n",
94
+ "\n",
95
+ "plt.title(\"KMA Radar (LCC Projection) — window outlined\")\n",
96
+ "plt.tight_layout()\n",
97
+ "plt.show()\n"
98
+ ]
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "execution_count": null,
103
+ "id": "a5f5b20c-df64-4873-9fee-854cc2e5a1ad",
104
+ "metadata": {},
105
+ "outputs": [],
106
+ "source": []
107
+ }
108
+ ],
109
+ "metadata": {
110
+ "kernelspec": {
111
+ "display_name": "Python 3 (ipykernel)",
112
+ "language": "python",
113
+ "name": "python3"
114
+ },
115
+ "language_info": {
116
+ "codemirror_mode": {
117
+ "name": "ipython",
118
+ "version": 3
119
+ },
120
+ "file_extension": ".py",
121
+ "mimetype": "text/x-python",
122
+ "name": "python",
123
+ "nbconvert_exporter": "python",
124
+ "pygments_lexer": "ipython3",
125
+ "version": "3.11.12"
126
+ }
127
+ },
128
+ "nbformat": 4,
129
+ "nbformat_minor": 5
130
+ }