|
1186 | 1186 | "metadata": {},
|
1187 | 1187 | "outputs": [],
|
1188 | 1188 | "source": [
|
1189 |
| - "def load_aus2200_variable(vnames, t1, t2, exp_id, lon_slice, lat_slice, freq, hgt_slice=None, chunks=\"auto\"):\n", |
| 1189 | + "def load_aus2200_variable(vnames, start_time, end_time, exp_id, lon_slice, lat_slice, freq, hgt_slice=None, chunks=\"auto\"):\n", |
1190 | 1190 | "\n",
|
1191 | 1191 | " '''\n",
|
1192 | 1192 | " Load variables from the mjo-enso AUS2200 experiment, stored on the ua8 project\n",
|
|
1195 | 1195 | "\n",
|
1196 | 1196 | " * vnames: list of names of aus2200 variables\n",
|
1197 | 1197 | "\n",
|
1198 |
| - " * t1: start time in %Y-%m-%d %H:%M\"\n", |
| 1198 | + " * start_time: start time in %Y-%m-%d %H:%M\"\n", |
1199 | 1199 | "\n",
|
1200 |
| - " * t2: start time in %Y-%m-%d %H:%M\"\n", |
| 1200 | + " * end_time: end time in %Y-%m-%d %H:%M\"\n", |
1201 | 1201 | " \n",
|
1202 | 1202 | " * exp_id: string describing the experiment. either 'mjo-elnino', 'mjo-lanina' or 'mjo-neutral'\n",
|
1203 | 1203 | "\n",
|
|
1219 | 1219 | " #We are loading a list of files from disk using xr.open_mfdataset. This preprocessing \n",
|
1220 | 1220 | " # just slices the lats, lons and levels we are interested in for each file, which is more efficient\n",
|
1221 | 1221 | " def _preprocess(ds):\n",
|
1222 |
| - " ds = ds.sel(lat=lat_slice,lon=lon_slice)\n", |
| 1222 | + " ds = ds.sel(lat=lat_slice, lon=lon_slice)\n", |
1223 | 1223 | " return ds\n",
|
1224 | 1224 | " def _preprocess_hgt(ds):\n",
|
1225 |
| - " ds = ds.sel(lat=lat_slice,lon=lon_slice,lev=hgt_slice)\n", |
| 1225 | + " ds = ds.sel(lat=lat_slice, lon=lon_slice, lev=hgt_slice)\n", |
1226 | 1226 | " return ds \n",
|
1227 | 1227 | " \n",
|
1228 | 1228 | " out = []\n",
|
|
1233 | 1233 | " chunks=chunks, \n",
|
1234 | 1234 | " parallel=True, \n",
|
1235 | 1235 | " preprocess=_preprocess_hgt, \n",
|
1236 |
| - " engine=\"h5netcdf\").sel(time=slice(t1,t2))\n", |
| 1236 | + " engine=\"h5netcdf\").sel(time=slice(start_time, end_time))\n", |
1237 | 1237 | " else:\n",
|
1238 | 1238 | " ds = xr.open_mfdataset(fnames,\n",
|
1239 | 1239 | " chunks=chunks,\n",
|
1240 | 1240 | " parallel=True,\n",
|
1241 | 1241 | " preprocess=_preprocess,\n",
|
1242 |
| - " engine=\"h5netcdf\").sel(time=slice(t1,t2))\n", |
| 1242 | + " engine=\"h5netcdf\").sel(time=slice(start_time, end_time))\n", |
1243 | 1243 | " out.append(ds[vname])\n",
|
1244 | 1244 | " \n",
|
1245 | 1245 | " return out\n",
|
1246 | 1246 | "\n",
|
1247 | 1247 | "#Define lat lon slices, equivalent to almost the entire AUS2200 domain\n",
|
1248 |
| - "lon_slice = slice(108,159)\n", |
1249 |
| - "lat_slice = slice(-45.7,-6.831799) \n", |
| 1248 | + "lon_slice = slice(108, 159)\n", |
| 1249 | + "lat_slice = slice(-45.7, -6.831799) \n", |
1250 | 1250 | "\n",
|
1251 | 1251 | "#Define times to slice\n",
|
1252 |
| - "t1=\"2016-01-01 00:00\"\n", |
1253 |
| - "t2=\"2016-02-01 00:00\"\n", |
| 1252 | + "start_time=\"2016-01-01 00:00\"\n", |
| 1253 | + "end_time=\"2016-02-01 00:00\"\n", |
1254 | 1254 | "\n",
|
1255 | 1255 | "#Load air temperature for a single model level (111.7 m)\n",
|
1256 | 1256 | "aus2200_ta = load_aus2200_variable([\"ta\"],\n",
|
1257 |
| - " t1,t2,\n", |
| 1257 | + " start_time,\n", |
| 1258 | + " end_time,\n", |
1258 | 1259 | " \"mjo-elnino\",\n",
|
1259 |
| - " lon_slice,lat_slice,\n", |
| 1260 | + " lon_slice,\n", |
| 1261 | + " lat_slice,\n", |
1260 | 1262 | " \"1hr\",\n",
|
1261 |
| - " hgt_slice=slice(100,120),\n", |
1262 |
| - " chunks=({\"time\":6,\"lat\":-1,\"lon\":-1}) \n", |
| 1263 | + " hgt_slice=slice(100, 120),\n", |
| 1264 | + " chunks=({\"time\":6, \"lat\":-1, \"lon\":-1}) \n", |
1263 | 1265 | " )[0]\n"
|
1264 | 1266 | ]
|
1265 | 1267 | },
|
|
0 commit comments