|
20 | 20 | "metadata": {}, |
21 | 21 | "outputs": [], |
22 | 22 | "source": [ |
23 | | - "import gcsfs\n", |
24 | 23 | "import pandas as pd\n", |
25 | 24 | "import xarray as xr" |
26 | 25 | ] |
|
153 | 152 | "id": "12", |
154 | 153 | "metadata": {}, |
155 | 154 | "source": [ |
156 | | - "In many cases, you'll need to first connect to the cloud provider.\n", |
157 | | - "The CMIP6 dataset allows anonymous access, but for some cases,\n", |
158 | | - "you may need to authenticate." |
| 155 | + "If Zarr-python is version 3 or greater, we can simply pass URIs to Zarr Stores to `xr.open_zarr`. Note that anonymous access is used by default." |
159 | 156 | ] |
160 | 157 | }, |
161 | 158 | { |
|
165 | 162 | "metadata": {}, |
166 | 163 | "outputs": [], |
167 | 164 | "source": [ |
168 | | - "fs = gcsfs.GCSFileSystem(token=\"anon\")" |
169 | | - ] |
170 | | - }, |
171 | | - { |
172 | | - "cell_type": "markdown", |
173 | | - "id": "14", |
174 | | - "metadata": {}, |
175 | | - "source": [ |
176 | | - "Next, we'll need a mapping to the Google Storage object.\n", |
177 | | - "This can be done using `fs.get_mapper`.\n", |
178 | | - "\n", |
179 | | - "A more generic way (for other cloud providers) is to use\n", |
180 | | - "[`fsspec.get_mapper`](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.get_mapper) instead." |
181 | | - ] |
182 | | - }, |
183 | | - { |
184 | | - "cell_type": "code", |
185 | | - "execution_count": null, |
186 | | - "id": "15", |
187 | | - "metadata": {}, |
188 | | - "outputs": [], |
189 | | - "source": [ |
190 | | - "store = fs.get_mapper(\n", |
191 | | - " \"gs://cmip6/CMIP6/ScenarioMIP/NOAA-GFDL/GFDL-ESM4/ssp585/r1i1p1f1/Omon/zos/gn/v20180701/\"\n", |
192 | | - ")" |
193 | | - ] |
194 | | - }, |
195 | | - { |
196 | | - "cell_type": "markdown", |
197 | | - "id": "16", |
198 | | - "metadata": {}, |
199 | | - "source": [ |
200 | | - "With that, we can open the Zarr store like so." |
201 | | - ] |
202 | | - }, |
203 | | - { |
204 | | - "cell_type": "code", |
205 | | - "execution_count": null, |
206 | | - "id": "17", |
207 | | - "metadata": {}, |
208 | | - "outputs": [], |
209 | | - "source": [ |
210 | | - "ds = xr.open_zarr(store=store, consolidated=True)\n", |
| 165 | + "ds = xr.open_zarr(\n", |
| 166 | + " \"gs://cmip6/CMIP6/ScenarioMIP/NOAA-GFDL/GFDL-ESM4/ssp585/r1i1p1f1/Omon/zos/gn/v20180701/\",\n", |
| 167 | + " consolidated=True,\n", |
| 168 | + ")\n", |
211 | 169 | "ds" |
212 | 170 | ] |
213 | 171 | }, |
214 | 172 | { |
215 | 173 | "cell_type": "markdown", |
216 | | - "id": "18", |
| 174 | + "id": "14", |
217 | 175 | "metadata": {}, |
218 | 176 | "source": [ |
219 | 177 | "### Selecting time slices\n", |
|
226 | 184 | { |
227 | 185 | "cell_type": "code", |
228 | 186 | "execution_count": null, |
229 | | - "id": "19", |
| 187 | + "id": "15", |
230 | 188 | "metadata": {}, |
231 | 189 | "outputs": [], |
232 | 190 | "source": [ |
|
236 | 194 | }, |
237 | 195 | { |
238 | 196 | "cell_type": "markdown", |
239 | | - "id": "20", |
| 197 | + "id": "16", |
240 | 198 | "metadata": {}, |
241 | 199 | "source": [ |
242 | 200 | "Sea level change would just be 2100 minus 2015." |
|
245 | 203 | { |
246 | 204 | "cell_type": "code", |
247 | 205 | "execution_count": null, |
248 | | - "id": "21", |
| 206 | + "id": "17", |
249 | 207 | "metadata": {}, |
250 | 208 | "outputs": [], |
251 | 209 | "source": [ |
|
254 | 212 | }, |
255 | 213 | { |
256 | 214 | "cell_type": "markdown", |
257 | | - "id": "22", |
| 215 | + "id": "18", |
258 | 216 | "metadata": {}, |
259 | 217 | "source": [ |
260 | 218 | "Note that up to this point, we have not actually downloaded any\n", |
|
268 | 226 | { |
269 | 227 | "cell_type": "code", |
270 | 228 | "execution_count": null, |
271 | | - "id": "23", |
| 229 | + "id": "19", |
272 | 230 | "metadata": {}, |
273 | 231 | "outputs": [], |
274 | 232 | "source": [ |
|
277 | 235 | }, |
278 | 236 | { |
279 | 237 | "cell_type": "markdown", |
280 | | - "id": "24", |
| 238 | + "id": "20", |
281 | 239 | "metadata": {}, |
282 | 240 | "source": [ |
283 | 241 | "We can do a quick plot to show how Sea Level is predicted to change\n", |
|
287 | 245 | { |
288 | 246 | "cell_type": "code", |
289 | 247 | "execution_count": null, |
290 | | - "id": "25", |
| 248 | + "id": "21", |
291 | 249 | "metadata": {}, |
292 | 250 | "outputs": [], |
293 | 251 | "source": [ |
|
296 | 254 | }, |
297 | 255 | { |
298 | 256 | "cell_type": "markdown", |
299 | | - "id": "26", |
| 257 | + "id": "22", |
300 | 258 | "metadata": {}, |
301 | 259 | "source": [ |
302 | 260 | "Notice the blue parts between -40 and -60 South where sea level has dropped?\n", |
|
307 | 265 | }, |
308 | 266 | { |
309 | 267 | "cell_type": "markdown", |
310 | | - "id": "27", |
| 268 | + "id": "23", |
311 | 269 | "metadata": {}, |
312 | 270 | "source": [ |
313 | 271 | "That's all! Hopefully this will get you started on accessing more cloud-native datasets!" |
|
0 commit comments