Skip to content

Commit

Permalink
fix ocean color
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed May 17, 2024
1 parent b0d1e66 commit dfce566
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions notebooks/wp5/ocean_color_timeseries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@
"# Variable to analyse\n",
"variables = [\n",
" \"chlor_a\",\n",
" \"Rrs_412\",\n",
" \"Rrs_443\",\n",
" \"Rrs_490\",\n",
" \"Rrs_510\",\n",
" \"Rrs_560\",\n",
" \"Rrs_665\",\n",
"]\n",
"assert set(variables) <= {\"chlor_a\"} | {\n",
" f\"Rrs_{wl}\" for wl in (412, 443, 490, 510, 560, 665)\n",
"}\n",
"\n",
"# Regions to plot\n",
"regions = {\n",
" \"Global\": {\"lon_slice\": slice(-180, 180), \"lat_slice\": slice(90, -90)},\n",
" \"50S-50N\": {\"lon_slice\": slice(-180, 180), \"lat_slice\": slice(50, -50)},\n",
" \"Global Ocean\": {\"lon_slice\": slice(-180, 180), \"lat_slice\": slice(90, -90)},\n",
" \"Latitudes 50$^o$S-50$^o$N\": {\n",
" \"lon_slice\": slice(-180, 180),\n",
" \"lat_slice\": slice(50, -50),\n",
" },\n",
" \"NASTG\": {\"lon_slice\": slice(-80, 0), \"lat_slice\": slice(50, 0)},\n",
" \"SPSTG\": {\"lon_slice\": slice(-120, -110), \"lat_slice\": slice(-20, -30)},\n",
"}\n",
"for region, slices in regions.items():\n",
" # Enforce sorting as original data\n",
Expand Down Expand Up @@ -122,11 +122,15 @@
"def regionalised_spatial_weighted_mean(ds, variable, lon_slice, lat_slice):\n",
" da = ds[variable]\n",
" da = utils.regionalise(da, lon_slice=lon_slice, lat_slice=lat_slice)\n",
" if variable == \"chlor_a\":\n",
" da = da.where((da > 1.0e-2) & (da < 1.0e2))\n",
" with xr.set_options(keep_attrs=True):\n",
" da = 10 ** diagnostics.spatial_weighted_mean(np.log10(da))\n",
" da.attrs[\"long_name\"] = da.attrs[\"long_name\"].replace(\" (not log-transformed)\", \"\")\n",
" if variable == \"chlor_a\":\n",
" da = da.where((da > 0.01) & (da < 1.0e2))\n",
" da = 10 ** diagnostics.spatial_weighted_mean(np.log10(da))\n",
" da.attrs[\"long_name\"] = da.attrs[\"long_name\"].replace(\n",
" \" (not log-transformed)\", \"\"\n",
" )\n",
" else:\n",
" da = diagnostics.spatial_weighted_mean(da)\n",
" return da.to_dataset(name=variable)"
]
},
Expand Down

0 comments on commit dfce566

Please sign in to comment.