Skip to content

Commit

Permalink
fix satellite radiation
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Jul 12, 2024
1 parent 4f1db87 commit 2596914
Showing 1 changed file with 78 additions and 50 deletions.
128 changes: 78 additions & 50 deletions notebooks/wp5/satellite_outgoing_radiation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,63 +77,96 @@
"collection_id = \"satellite-earth-radiation-budget\"\n",
"chunks = {\"year\": 1}\n",
"varnames = (\n",
" {\"olr\", \"toa_lw_all_mon\"} if variable == \"longwave\" else {\"rsf\", \"toa_sw_all_mon\"}\n",
" {\"olr\", \"toa_lw_all_mon\", \"LW_flux\"}\n",
" if variable == \"longwave\"\n",
" else {\"rsf\", \"toa_sw_all_mon\", \"SW_flux\"}\n",
")\n",
"\n",
"request_dict = {\n",
" \"CERES\": {\n",
" \"start\": \"2000-03\",\n",
" \"stop\": \"2022-03\",\n",
" \"stop\": \"2024-02\",\n",
" \"product_family\": \"ceres_ebaf\",\n",
" \"climate_data_record_type\": \"thematic_climate_data_record\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"nasa_ceres_ebaf\",\n",
" \"origin\": \"nasa\",\n",
" \"variable\": f\"outgoing_{variable}_radiation\",\n",
" },\n",
" \"Sentinel 3A\": {\n",
" \"start\": \"2017-01\",\n",
" \"stop\": \"2021-12\",\n",
" \"stop\": \"2022-06\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"c3s_cci\",\n",
" \"sensor\": \"slstr_on_sentinel_3a\",\n",
" \"variable\": \"all_available_variables\",\n",
" \"origin\": \"c3s\",\n",
" \"sensor_on_satellite\": \"slstr_on_sentinel_3a\",\n",
" \"variable\": \"all_variables\",\n",
" \"product_family\": \"cci\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"climate_data_record_type\": \"interim_climate_data_record\",\n",
" },\n",
" \"Sentinel 3B\": {\n",
" \"start\": \"2018-10\",\n",
" \"stop\": \"2021-12\",\n",
" \"stop\": \"2022-06\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"c3s_cci\",\n",
" \"sensor\": \"slstr_on_sentinel_3b\",\n",
" \"variable\": \"all_available_variables\",\n",
" \"origin\": \"c3s\",\n",
" \"sensor_on_satellite\": \"slstr_on_sentinel_3b\",\n",
" \"variable\": \"all_variables\",\n",
" \"product_family\": \"cci\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"climate_data_record_type\": \"interim_climate_data_record\",\n",
" },\n",
" \"Sentinel 3A_3B\": {\n",
" \"start\": \"2018-10\",\n",
" \"stop\": \"2022-06\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"c3s\",\n",
" \"sensor_on_satellite\": \"slstr_on_sentinel_3a_3b\",\n",
" \"variable\": \"all_variables\",\n",
" \"product_family\": \"cci\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"climate_data_record_type\": \"interim_climate_data_record\",\n",
" },\n",
" \"ESA ENVISAT\": {\n",
" \"start\": \"2002-05\",\n",
" \"stop\": \"2012-04\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"esa_cloud_cci\",\n",
" \"sensor\": \"aatsr\",\n",
" \"variable\": \"all_available_variables\",\n",
" \"origin\": \"esa\",\n",
" \"product_family\": \"cci\",\n",
" \"climate_data_record_type\": \"thematic_climate_data_record\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"sensor_on_satellite\": \"aatsr\",\n",
" \"variable\": \"all_variables\",\n",
" },\n",
" \"ESA ERS2a\": {\n",
" \"ESA ERS2\": {\n",
" \"start\": \"1995-06\",\n",
" \"stop\": \"1995-12\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"esa_cloud_cci\",\n",
" \"sensor\": \"atsr2\",\n",
" \"variable\": \"all_available_variables\",\n",
" },\n",
" \"ESA ERS2b\": {\n",
" \"start\": \"1996-07\",\n",
" \"stop\": \"2002-12\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"esa_cloud_cci\",\n",
" \"sensor\": \"atsr2\",\n",
" \"variable\": \"all_available_variables\",\n",
" \"origin\": \"esa\",\n",
" \"product_family\": \"cci\",\n",
" \"climate_data_record_type\": \"thematic_climate_data_record\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"sensor_on_satellite\": \"atsr2\",\n",
" \"variable\": \"all_variables\",\n",
" },\n",
" \"HIRS\": {\n",
" \"start\": \"1979-01\",\n",
" \"stop\": \"2023-03\",\n",
" \"stop\": \"2024-04\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"noaa_ncei_hirs\",\n",
" \"origin\": \"noaa_ncei\",\n",
" \"product_family\": \"hirs\",\n",
" \"climate_data_record_type\": \"thematic_climate_data_record\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"version\": \"2_7_reprocessed\",\n",
" \"variable\": f\"outgoing_{variable}_radiation\",\n",
" },\n",
" \"CLARA_A3\": {\n",
" \"start\": \"1979-01\",\n",
" \"stop\": \"2020-12\",\n",
" \"product_family\": \"clara_a3\",\n",
" \"origin\": \"eumetsat\",\n",
" \"variable\": f\"outgoing_{variable}_radiation\",\n",
" \"climate_data_record_type\": \"thematic_climate_data_record\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" },\n",
"}"
]
Expand All @@ -153,29 +186,19 @@
"metadata": {},
"outputs": [],
"source": [
"def convert_source_to_time(ds):\n",
" if \"source\" in ds.dims:\n",
" ds[\"time\"] = (\n",
" \"source\",\n",
" pd.to_datetime(\n",
" [source.split(\"_\")[-2] + \"15\" for source in ds[\"source\"].values],\n",
" format=\"%Y%m%d\",\n",
" ),\n",
" )\n",
" ds[\"time\"].attrs[\"standard_name\"] = \"time\"\n",
" ds = ds.swap_dims(source=\"time\").drop(\"source\")\n",
"def preprocess_time(ds):\n",
" if \"time\" in ds and \"units\" in ds[\"time\"].attrs:\n",
" # Could not decode\n",
" ds = ds.squeeze(\"time\", drop=True)\n",
" if \"time\" not in ds:\n",
" time = pd.to_datetime(ds.attrs[\"time_coverage_start\"])\n",
" ds = ds.assign_coords(time=time)\n",
" return ds\n",
"\n",
"\n",
"def spatial_weighted_mean(ds, lon_slice, lat_slice):\n",
" ds = convert_source_to_time(ds)\n",
" ds = utils.regionalise(ds, lon_slice=lon_slice, lat_slice=lat_slice)\n",
" return diagnostics.spatial_weighted_mean(ds)\n",
"\n",
"\n",
"def time_weighted_mean(ds):\n",
" ds = convert_source_to_time(ds)\n",
" return diagnostics.time_weighted_mean(ds)"
" return diagnostics.spatial_weighted_mean(ds)"
]
},
{
Expand All @@ -193,6 +216,11 @@
"metadata": {},
"outputs": [],
"source": [
"xarray_kwargs = {\n",
" \"drop_variables\": [\"time_bounds\", \"record_status\"],\n",
" \"preprocess\": preprocess_time,\n",
"}\n",
"\n",
"da_maps = {}\n",
"da_timeseries = {}\n",
"for product, request in request_dict.items():\n",
Expand All @@ -210,10 +238,10 @@
" ds = download.download_and_transform(\n",
" collection_id,\n",
" requests,\n",
" transform_func=time_weighted_mean,\n",
" transform_func=diagnostics.time_weighted_mean,\n",
" chunks=chunks,\n",
" transform_chunks=False,\n",
" drop_variables=\"time_bounds\",\n",
" **xarray_kwargs,\n",
" )\n",
" (varname,) = set(ds.data_vars) & varnames\n",
" da = ds[varname]\n",
Expand All @@ -228,7 +256,7 @@
" transform_func=spatial_weighted_mean,\n",
" transform_func_kwargs=slices,\n",
" chunks=chunks,\n",
" drop_variables=\"time_bounds\",\n",
" **xarray_kwargs,\n",
" )\n",
" dataarrays.append(ds[varname].expand_dims(region=[region]))\n",
" da = xr.concat(dataarrays, \"region\")\n",
Expand Down Expand Up @@ -325,7 +353,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 2596914

Please sign in to comment.