Skip to content

Commit

Permalink
fix satellite
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Jul 9, 2024
1 parent b4d6b19 commit 4f1db87
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions notebooks/wp5/satellite_surface_radiation_budget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
" \"climate_data_record_type\": \"thematic_climate_data_record\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"c3s\",\n",
" \"product_family\": \"clara\",\n",
" \"sensor_on_satellite\": \"avhrr_on_multiple_satellites\",\n",
" \"product_family\": \"clara_a2\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"variable\": \"surface_upwelling_shortwave_flux\",\n",
" \"version\": \"v2_0_1\",\n",
Expand All @@ -87,8 +86,7 @@
" \"climate_data_record_type\": \"thematic_climate_data_record\",\n",
" \"format\": \"zip\",\n",
" \"origin\": \"eumetsat\",\n",
" \"product_family\": \"clara\",\n",
" \"sensor_on_satellite\": \"avhrr_on_multiple_satellites\",\n",
" \"product_family\": \"clara_a2\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"variable\": [\n",
" \"surface_downwelling_longwave_flux\",\n",
Expand Down Expand Up @@ -126,7 +124,7 @@
" \"format\": \"zip\",\n",
" \"origin\": \"c3s\",\n",
" \"product_family\": \"cci\",\n",
" \"sensor_on_satellite\": \"slstr_on_sentinel_3a_is_under_investigation\",\n",
" \"sensor_on_satellite\": \"slstr_on_sentinel_3a\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"variable\": \"all_variables\",\n",
" },\n",
Expand All @@ -137,7 +135,7 @@
" \"format\": \"zip\",\n",
" \"origin\": \"c3s\",\n",
" \"product_family\": \"cci\",\n",
" \"sensor_on_satellite\": \"slstr_on_sentinel_3b_is_under_investigation\",\n",
" \"sensor_on_satellite\": \"slstr_on_sentinel_3b\",\n",
" \"time_aggregation\": \"monthly_mean\",\n",
" \"variable\": \"all_variables\",\n",
" },\n",
Expand All @@ -159,29 +157,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 @@ -199,6 +187,8 @@
"metadata": {},
"outputs": [],
"source": [
"xarray_kwargs = {\"drop_variables\": \"time_bounds\", \"preprocess\": preprocess_time}\n",
"\n",
"ds_maps = {}\n",
"ds_timeseries = {}\n",
"for product, request in request_dict.items():\n",
Expand All @@ -213,10 +203,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",
" ds.attrs.update({\"start\": start, \"stop\": stop})\n",
" ds_maps[product] = ds.rename({var: var.lower() for var in ds.data_vars})\n",
Expand All @@ -231,7 +221,7 @@
" \"lat_slice\": slice(-90, 90),\n",
" },\n",
" chunks=chunks,\n",
" drop_variables=\"time_bounds\",\n",
" **xarray_kwargs,\n",
" )\n",
" ds_timeseries[product] = ds.rename({var: var.lower() for var in ds.data_vars})"
]
Expand Down Expand Up @@ -337,7 +327,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 4f1db87

Please sign in to comment.