|
24 | 24 | "metadata": {},
|
25 | 25 | "source": [
|
26 | 26 | "## Functions covered\n",
|
27 |
| - "- [area_poly_sphere](https://www.ncl.ucar.edu/Document/Functions/Built-in/area_poly_sphere.shtml)" |
| 27 | + "- [area_poly_sphere](https://www.ncl.ucar.edu/Document/Functions/Built-in/area_poly_sphere.shtml)\n", |
| 28 | + "- [css2c](https://www.ncl.ucar.edu/Document/Functions/Built-in/css2c.shtml)" |
28 | 29 | ]
|
29 | 30 | },
|
30 | 31 | {
|
|
53 | 54 | "## Python Functionality"
|
54 | 55 | ]
|
55 | 56 | },
|
| 57 | + { |
| 58 | + "cell_type": "markdown", |
| 59 | + "id": "6dc1d6c4-ac26-4346-9aa3-2c73182a7511", |
| 60 | + "metadata": {}, |
| 61 | + "source": [ |
| 62 | + "### area_poly_sphere" |
| 63 | + ] |
| 64 | + }, |
56 | 65 | {
|
57 | 66 | "cell_type": "code",
|
58 | 67 | "execution_count": null,
|
59 |
| - "id": "95225429-62d5-4d38-b170-850526c28107", |
| 68 | + "id": "2ba99b37-a743-4776-bc7b-d5a08b977642", |
60 | 69 | "metadata": {},
|
61 | 70 | "outputs": [],
|
62 | 71 | "source": [
|
|
73 | 82 | " \"Half of the World\",\n",
|
74 | 83 | " \"Single Point -> Invalid NCL\",\n",
|
75 | 84 | " \"Single Degree\",\n",
|
76 |
| - "]" |
77 |
| - ] |
78 |
| - }, |
79 |
| - { |
80 |
| - "cell_type": "markdown", |
81 |
| - "id": "6dc1d6c4-ac26-4346-9aa3-2c73182a7511", |
82 |
| - "metadata": {}, |
83 |
| - "source": [ |
84 |
| - "### area_poly_sphere" |
85 |
| - ] |
86 |
| - }, |
87 |
| - { |
88 |
| - "cell_type": "code", |
89 |
| - "execution_count": null, |
90 |
| - "id": "2ba99b37-a743-4776-bc7b-d5a08b977642", |
91 |
| - "metadata": {}, |
92 |
| - "outputs": [], |
93 |
| - "source": [ |
| 85 | + "]\n", |
| 86 | + "\n", |
94 | 87 | "ncl_lat = [\n",
|
95 | 88 | " [40.0150, 42.3601, 29.5518],\n",
|
96 | 89 | " [41.00488, 41.00203, 37.00540, 37.00051],\n",
|
|
118 | 111 | "ncl_results[poly_name[4]] = 54450.39\n",
|
119 | 112 | "ncl_results[poly_name[5]] = 255032000\n",
|
120 | 113 | "ncl_results[poly_name[6]] = -127516000\n",
|
121 |
| - "ncl_results[poly_name[7]] = 9401.705" |
| 114 | + "ncl_results[poly_name[7]] = 9401.705\n", |
| 115 | + "\n", |
| 116 | + "from pyproj import Geod\n", |
| 117 | + "\n", |
| 118 | + "python_results = {}\n", |
| 119 | + "geod = Geod(ellps=\"sphere\") # radius = 6370997 m\n", |
| 120 | + "for i in range(len(poly_name)):\n", |
| 121 | + " poly_area_m, _ = geod.polygon_area_perimeter(ncl_lon[i], ncl_lat[i])\n", |
| 122 | + " poly_area_km2 = abs(poly_area_m) * 1e-6\n", |
| 123 | + " python_results[poly_name[i]] = poly_area_km2" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "markdown", |
| 128 | + "id": "c0e65c3e-2377-47ec-b94c-e7eb753966d9", |
| 129 | + "metadata": {}, |
| 130 | + "source": [ |
| 131 | + "### css2c" |
122 | 132 | ]
|
123 | 133 | },
|
124 | 134 | {
|
125 | 135 | "cell_type": "code",
|
126 | 136 | "execution_count": null,
|
127 |
| - "id": "35803c5d-bf83-4a35-b61c-50466d9d5095", |
| 137 | + "id": "35abde81-5843-4504-8e32-a137ee1aa094", |
128 | 138 | "metadata": {},
|
129 | 139 | "outputs": [],
|
130 | 140 | "source": [
|
131 |
| - "from pyproj import Geod\n", |
| 141 | + "import geocat.datafiles as gdf\n", |
| 142 | + "import numpy as np\n", |
| 143 | + "from astropy.coordinates.representation import UnitSphericalRepresentation\n", |
| 144 | + "from astropy import units\n", |
132 | 145 | "\n",
|
133 |
| - "python_results = {}\n", |
134 |
| - "geod = Geod(ellps=\"sphere\") # radius = 6370997 m\n", |
135 |
| - "for i in range(len(poly_name)):\n", |
136 |
| - " poly_area_m, _ = geod.polygon_area_perimeter(ncl_lon[i], ncl_lat[i])\n", |
137 |
| - " poly_area_km2 = abs(poly_area_m) * 1e-6\n", |
138 |
| - " python_results[poly_name[i]] = poly_area_km2" |
| 146 | + "css2c_data = gdf.get('applications_files/ncl_outputs/css2c_output.txt')\n", |
| 147 | + "css2c_data = np.loadtxt(css2c_data, delimiter=',', skiprows=6)\n", |
| 148 | + "\n", |
| 149 | + "lat_lon = tuple(map(tuple, (css2c_data[::, 0:2])))\n", |
| 150 | + "cart_values = css2c_data[::, 2:]\n", |
| 151 | + "ncl_css2c = dict(zip(lat_lon, cart_values))" |
| 152 | + ] |
| 153 | + }, |
| 154 | + { |
| 155 | + "cell_type": "code", |
| 156 | + "execution_count": null, |
| 157 | + "id": "ee104ea1-e287-4635-b404-5b06ccfb6949", |
| 158 | + "metadata": {}, |
| 159 | + "outputs": [], |
| 160 | + "source": [ |
| 161 | + "## Collect Latitude and Longtiude Pairs\n", |
| 162 | + "lat_lon = []\n", |
| 163 | + "for lat in range(-90, 90 + 1):\n", |
| 164 | + " for lon in range(-180, 180 + 1):\n", |
| 165 | + " lat_lon.append((lat, lon))\n", |
| 166 | + "\n", |
| 167 | + "## Calculate Cartesian coordinates\n", |
| 168 | + "astropy_css2c = {}\n", |
| 169 | + "for i, pair in enumerate(lat_lon):\n", |
| 170 | + " lat, lon = pair\n", |
| 171 | + " spherical_coords = UnitSphericalRepresentation(\n", |
| 172 | + " lat=lat * units.deg, lon=lon * units.deg\n", |
| 173 | + " )\n", |
| 174 | + " cart_coords = spherical_coords.to_cartesian()\n", |
| 175 | + " astropy_css2c[pair] = cart_coords.xyz.value" |
139 | 176 | ]
|
140 | 177 | },
|
141 | 178 | {
|
|
146 | 183 | "## Comparison"
|
147 | 184 | ]
|
148 | 185 | },
|
| 186 | + { |
| 187 | + "cell_type": "markdown", |
| 188 | + "id": "384790de-53f9-45d7-8bc1-fef86df21b57", |
| 189 | + "metadata": {}, |
| 190 | + "source": [ |
| 191 | + "### area_poly_sphere" |
| 192 | + ] |
| 193 | + }, |
149 | 194 | {
|
150 | 195 | "cell_type": "markdown",
|
151 | 196 | "id": "cb61d4f0-bd10-4034-bfe8-b0c6e9137ec3",
|
|
180 | 225 | " if key != \"Single Point -> Invalid NCL\":\n",
|
181 | 226 | " assert False"
|
182 | 227 | ]
|
| 228 | + }, |
| 229 | + { |
| 230 | + "cell_type": "markdown", |
| 231 | + "id": "57251c09-ef8c-438f-b3cf-cf798e7f4028", |
| 232 | + "metadata": {}, |
| 233 | + "source": [ |
| 234 | + "### css2c" |
| 235 | + ] |
| 236 | + }, |
| 237 | + { |
| 238 | + "cell_type": "code", |
| 239 | + "execution_count": null, |
| 240 | + "id": "d5738d2d-5abe-4ed4-8e90-c42881c2bfb0", |
| 241 | + "metadata": {}, |
| 242 | + "outputs": [], |
| 243 | + "source": [ |
| 244 | + "for key in ncl_css2c.keys():\n", |
| 245 | + " if key in astropy_css2c.keys():\n", |
| 246 | + " assert abs(ncl_css2c[key][0] - astropy_css2c[key][0]) < 0.000005\n", |
| 247 | + " assert abs(ncl_css2c[key][1] - astropy_css2c[key][1]) < 0.000005\n", |
| 248 | + " assert abs(ncl_css2c[key][2] - astropy_css2c[key][2]) < 0.000005" |
| 249 | + ] |
183 | 250 | }
|
184 | 251 | ],
|
185 | 252 | "metadata": {
|
|
0 commit comments