{ "cells": [ { "cell_type": "markdown", "id": "b0077bd1", "metadata": {}, "source": [ "## 1. Load segment data. Refine segment as needed." ] }, { "cell_type": "markdown", "id": "1a7bfa27", "metadata": {}, "source": [ "Import packages" ] }, { "cell_type": "code", "execution_count": null, "id": "0efb11a1", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:26:43.622776Z", "start_time": "2022-06-02T15:26:40.468961Z" } }, "outputs": [], "source": [ "import csv\n", "import metview as mv" ] }, { "cell_type": "markdown", "id": "0340ecfd", "metadata": {}, "source": [ "Load segment file (csv)" ] }, { "cell_type": "code", "execution_count": null, "id": "f11f47af", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:27:23.538064Z", "start_time": "2022-06-02T15:27:23.533323Z" } }, "outputs": [], "source": [ "# Read the CSV file containing segments\n", "csv_name = \"segments_mc.csv\"\n", "patho_csv = \"/bog/amuttaqin/Datasets/\"\n", "\n", "with open(patho_csv+csv_name, \"r\") as file:\n", " csvreader = csv.reader(file)\n", " segments_whead = list(csvreader)\n", " segments = segments_whead[1:]\n", " [j.pop(0) for j in segments]\n", " \n", "segments = [[float(y) for y in x] for x in segments]" ] }, { "cell_type": "markdown", "id": "ac7811fc", "metadata": {}, "source": [ "Find the intended segment. Will start with segments over Malay Peninsula" ] }, { "cell_type": "code", "execution_count": null, "id": "07ff6ccc", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T17:07:00.796314Z", "start_time": "2022-06-02T17:07:00.792183Z" } }, "outputs": [], "source": [ "# Manual by looking into the segment names and coordinates\n", "# Automatic by finding lat1,lat2,lon1,lon2 with certain range\n", "\n", "segments[23]\n", "s = 23\n", "\n", "lat1 = segments[s][0]\n", "lon1 = segments[s][1]\n", "lat2 = segments[s][2]\n", "lon2 = segments[s][3]\n", "line_segment = [lat1, lon1, lat2, lon2]\n", "\n", "print(segments[s])\n", "print(line_segment)" ] }, { "cell_type": "markdown", "id": "9185cb0d", "metadata": {}, "source": [ "Display segment on map" ] }, { "cell_type": "code", "execution_count": null, "id": "dba8bce3", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T17:11:16.930558Z", "start_time": "2022-06-02T17:11:16.653947Z" } }, "outputs": [], "source": [ "mv.setoutput(\"jupyter\", plot_widget=False, output_width=1200)\n", "my_view = mv.geoview(\n", " map_area_definition=\"corners\", \n", " area = [0, 95, 15, 110],\n", " subpage_y_position=25)\n", "my_coast = mv.mcoast(\n", " map_coastline_colour=\"charcoal\",\n", " map_coastline_resolution=\"medium\",\n", " map_coastline_thickness=5,\n", " map_grid_line_style=\"solid\",\n", " map_grid_latitude_increment=5.,\n", " map_grid_longitude_increment=5.,\n", " map_label=\"on\",\n", " map_label_latitude_frequency=1,\n", " map_label_longitude_frequency=1,\n", " map_label_height=0.5)\n", "geolines = mv.mvl_geoline(*line_segment,1)\n", "line_graph_segments = mv.mgraph(\n", " graph_line_colour = \"red\",\n", " graph_line_thickness = 5.0,\n", " graph_line_style = \"solid\")\n", "title = mv.mtext(\n", " text_font_size=1.0,\n", " text_lines=[\"Segments\"])\n", "#mv.plot(my_view, my_coast, geolines, line_graph_segments, title)\n", "mv.plot(my_view, my_coast, line_graph_segments)" ] }, { "cell_type": "markdown", "id": "81c81d57", "metadata": {}, "source": [ "Refine segment coordinates if needed" ] }, { "cell_type": "code", "execution_count": null, "id": "b1018833", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:02:11.301102Z", "start_time": "2022-06-02T16:02:11.298758Z" } }, "outputs": [], "source": [ "# new_lat1 =\n", "# new_lon1 = \n", "# new_lat2 = \n", "# new_lon2 = \n", "# refined_segment = [new_lat1, new_lon1, new_lat2, new_lon2]" ] }, { "cell_type": "markdown", "id": "afc4a919", "metadata": {}, "source": [ "Display refined segment on a map" ] }, { "cell_type": "code", "execution_count": null, "id": "b1e85554", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:02:15.037736Z", "start_time": "2022-06-02T16:02:15.035121Z" } }, "outputs": [], "source": [ "# area_segments = [0, 90, 15, 110]\n", "\n", "# mv.setoutput(\"jupyter\", plot_widget=False, output_width=1800)\n", "# #mv.setoutput(mv.pdf_output(output_name='/bog/amuttaqin/Figures/segments'))\n", "\n", "# my_view = mv.geoview(\n", "# map_area_definition=\"corners\", \n", "# area=area_segments,\n", "# subpage_y_position=25)\n", "# my_coast = mv.mcoast(\n", "# map_coastline_colour=\"charcoal\",\n", "# map_coastline_resolution=\"medium\",\n", "# map_coastline_land_shade=\"off\",\n", "# map_coastline_sea_shade=\"off\",\n", "# map_coastline_thickness=2,\n", "# map_grid_line_style=\"solid\",\n", "# map_grid_latitude_increment=10,\n", "# map_grid_longitude_increment=10,\n", "# map_label=\"on\",\n", "# map_label_latitude_frequency=5,\n", "# map_label_longitude_frequency=5,\n", "# map_label_height=0.5)\n", "# geolines = mv.mvl_geoline(*refined_segment,1)\n", "# line_graph_segments = mv.mgraph(\n", "# graph_line_colour = \"red\",\n", "# graph_line_thickness = 8.,\n", "# graph_line_style = \"chain_dash\")\n", "# title = mv.mtext(\n", "# text_font_size=1.0,\n", "# text_lines=[\"Segments\"])\n", "# mv.plot(my_view,my_coast, \n", "# geolines, line_graph_segments, title)" ] }, { "cell_type": "markdown", "id": "e9f11b67", "metadata": {}, "source": [ "## 2. Convert segment into transects" ] }, { "cell_type": "markdown", "id": "74dee6fd", "metadata": {}, "source": [ "Import packages" ] }, { "cell_type": "code", "execution_count": null, "id": "a6f0b671", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:12:52.828796Z", "start_time": "2022-06-02T16:12:52.826655Z" } }, "outputs": [], "source": [ "from shapely.geometry import LineString\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "7b4a7469", "metadata": {}, "source": [ "Convert segment into transects" ] }, { "cell_type": "code", "execution_count": null, "id": "c55c7191", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:31:21.504979Z", "start_time": "2022-06-02T16:31:21.496449Z" } }, "outputs": [], "source": [ "lat1 = segments[s][0]\n", "lon1 = segments[s][1]\n", "lat2 = segments[s][2]\n", "lon2 = segments[s][3]\n", "\n", "dist2coast = 0.3 \n", "dist2trnsc = 0.5\n", "\n", "# Create a line aligned with coastline. Let's call it \"segment\"\n", "segment = LineString([(lat1, lon1), (lat2, lon2)])\n", "\n", "# How many possible transects on this segment?\n", "n_trnsc = np.floor(segment.length/dist2trnsc)\n", "\n", "# Create two parallel lines on the left and right side of the segment. \n", "# One will be over landmass, the other will be over ocean\n", "segpl = segment.parallel_offset(dist2coast, 'left')\n", "segpr = segment.parallel_offset(dist2coast, 'right')\n", "\n", "# Split segement at a specified distance\n", "excess = segpl.length - (dist2trnsc*(n_trnsc-1))\n", "start_dist = excess/2\n", "distances = np.arange(start_dist, segpl.length, dist2trnsc)\n", "\n", "ptsl = [segpl.interpolate(distance) for distance in distances]\n", "ptsr = [segpr.interpolate(distance) for distance in distances]\n", "\n", "list_ptsr = []\n", "list_ptsl = []\n", "for pr,pl in zip(ptsr,ptsl):\n", " list_ptsr.append([round(pr.x,4), round(pr.y,4)])\n", " list_ptsl.append([round(pl.x,4), round(pl.y,4)])\n", " list_ptsr.sort()\n", " list_ptsl.sort() \n", "\n", "trnscx = []\n", "list_trnsc = [] \n", "for i in range(int(n_trnsc)):\n", " trnscx.append([list_ptsl[i], list_ptsr[i]])\n", " list_trnsc.append([item for sublist in trnscx[i] for item in sublist])" ] }, { "cell_type": "code", "execution_count": null, "id": "169f2f9c", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:31:22.261681Z", "start_time": "2022-06-02T16:31:22.258805Z" } }, "outputs": [], "source": [ "print(np.shape(list_trnsc))\n", "print(list_trnsc)" ] }, { "cell_type": "markdown", "id": "9473caaf", "metadata": {}, "source": [ "Display transects" ] }, { "cell_type": "code", "execution_count": null, "id": "d0624baa", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:31:25.455041Z", "start_time": "2022-06-02T16:31:24.959001Z" } }, "outputs": [], "source": [ "mv.setoutput(\"jupyter\", plot_widget=False, output_width=1200)\n", "my_view = mv.geoview(\n", " map_area_definition=\"corners\", \n", " area=[0, 90, 15, 110],\n", " subpage_y_position=25)\n", "geolines = []\n", "for i in range(len(list_trnsc)):\n", " lns = mv.mvl_geoline(*list_trnsc[i],1)\n", " geolines.append(lns)\n", "line_graph_transects = mv.mgraph(\n", " graph_line_colour = \"blue\",\n", " graph_line_thickness = 3.,\n", " graph_line_style = \"solid\")\n", "title = mv.mtext(\n", " text_font_size=1.0,\n", " text_lines=[\"Transects\"])\n", "mv.plot(my_view, my_coast, \n", " geolines, line_graph_transects, title)" ] }, { "cell_type": "markdown", "id": "9b1d1dde", "metadata": {}, "source": [ "### 2.1. Determine transect over land vs ocean" ] }, { "cell_type": "markdown", "id": "9cd596d0", "metadata": {}, "source": [ "Load land-sea mask data" ] }, { "cell_type": "code", "execution_count": null, "id": "70256bcc", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:02:50.001979Z", "start_time": "2022-06-02T16:02:49.931907Z" } }, "outputs": [], "source": [ "lsmfname = \"/bog/amuttaqin/Datasets/ERA5-Land/land-sea-mask/lsm_1279l4_0.1x0.1.grb\"\n", "lsm = mv.read(lsmfname)\n", "lsm.describe('lsm')" ] }, { "cell_type": "markdown", "id": "84c02f05", "metadata": {}, "source": [ "Determine transect: over ocean vs land" ] }, { "cell_type": "code", "execution_count": null, "id": "8953e755", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:31:32.128323Z", "start_time": "2022-06-02T16:31:31.914473Z" } }, "outputs": [], "source": [ "trnsc_land = []\n", "trnsc_ocean = []\n", "for i in range(len(list_trnsc)):\n", " loc1 = [list_trnsc[i][0], list_trnsc[i][1]]\n", " loc2 = [list_trnsc[i][2], list_trnsc[i][3]]\n", " \n", " loc1_val = mv.nearest_gridpoint(lsm, loc1)\n", " loc2_val = mv.nearest_gridpoint(lsm, loc2)\n", " \n", " if (loc1_val > 0.5):\n", " trnsc_land.append([loc1[0], loc1[1]]) #trnsc_land.append([loc1_val, loc1[0], loc1[1]])\n", " else:\n", " trnsc_ocean.append([loc1[0], loc1[1]]) #trnsc_ocean.append([loc1_val, loc1[0], loc1[1]])\n", " \n", " if (loc2_val > 0.5):\n", " trnsc_land.append([loc2[0], loc2[1]]) #trnsc_land.append([loc2_val, loc2[0], loc2[1]])\n", " else:\n", " trnsc_ocean.append([loc2[0], loc2[1]]) #trnsc_ocean.append([loc2_val, loc2[0], loc2[1]])" ] }, { "cell_type": "code", "execution_count": null, "id": "c2abdc91", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:31:33.614069Z", "start_time": "2022-06-02T16:31:33.610722Z" } }, "outputs": [], "source": [ "trnsc_ocean" ] }, { "cell_type": "code", "execution_count": null, "id": "ac73471d", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:31:35.522305Z", "start_time": "2022-06-02T16:31:35.519409Z" } }, "outputs": [], "source": [ "trnsc_land" ] }, { "cell_type": "markdown", "id": "cb298615", "metadata": {}, "source": [ "NEXT. Write transect into a file. Add transect ID, region (R1, R2, R3, R4), mainland (Malay_Peninsula, Sumatra, Java, Borneo, Philippines, Sulawesi, Papua, Australia, Others). Also add coast coordinate." ] }, { "cell_type": "code", "execution_count": null, "id": "bc66e42a", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:29:43.906222Z", "start_time": "2022-06-02T15:29:43.904395Z" } }, "outputs": [], "source": [ "# with open(\"/home/amuttaqin/Datasets/transects_mc.csv\", \"a\", newline='') as csvfile:\n", "# coordwriter = csv.writer(csvfile, delimiter=',', quotechar=\" \", quoting=csv.QUOTE_MINIMAL)\n", "# coordwriter.writerow(list_trnsc[i])" ] }, { "cell_type": "markdown", "id": "e599abfa", "metadata": {}, "source": [ "## 3. Analysis" ] }, { "cell_type": "markdown", "id": "813d96f8", "metadata": {}, "source": [ "### 3.1. Skin temperature difference (point)" ] }, { "cell_type": "markdown", "id": "4e196098", "metadata": {}, "source": [ "Import packages" ] }, { "cell_type": "code", "execution_count": null, "id": "42fb4e83", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:29:47.947669Z", "start_time": "2022-06-02T15:29:45.782792Z" } }, "outputs": [], "source": [ "import xarray as xr\n", "from cdo import Cdo\n", "cdo = Cdo()\n", "%matplotlib inline\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "id": "b19348eb", "metadata": {}, "source": [ "Define bounding box for memory-efficient data loading based on transects' coordinates" ] }, { "cell_type": "code", "execution_count": null, "id": "ed17307d", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:29:55.226884Z", "start_time": "2022-06-02T15:29:55.223932Z" } }, "outputs": [], "source": [ "# For Malay Peninsula region, specifically for segement #1\n", "box_lat1 = 0\n", "box_lat2 = 15\n", "box_lon1 = 95\n", "box_lon2 = 110" ] }, { "cell_type": "markdown", "id": "40d75767", "metadata": {}, "source": [ "Area-subset dataset into a temporary file. Remember to delete this file at the end of the script." ] }, { "cell_type": "code", "execution_count": null, "id": "dad90730", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:30:16.276614Z", "start_time": "2022-06-02T15:30:16.273729Z" } }, "outputs": [], "source": [ "#fin1 = \"/bog/amuttaqin/Datasets/ERA5/skto/skto.grib\" # Data size: 20.5 GB\n", "#fin2 = \"/bog/amuttaqin/Datasets/ERA5-Land/skt/skt.grib\" # Data size: 24.7 GB\n", "\n", "ftmp1 = \"/bog/amuttaqin/Datasets/Temporary/tmp1.grib\" # 1.98 GB; subset of 15 x 15 deg longitude by latitude \n", "ftmp2 = \"/bog/amuttaqin/Datasets/Temporary/tmp2.grib\" # 4.91 GB; subset of 15 x 15 deg longitude by latitude\n", "\n", "#cdo.sellonlatbox(box_lon1,box_lon2,box_lat1,box_lat2, input=fin1, output=ftmp1)\n", "#cdo.sellonlatbox(box_lon1,box_lon2,box_lat1,box_lat2, input=fin2, output=ftmp2)\n", "\n", "# execution time: 5m 52s\n", "# latest execution time: 2m 45s" ] }, { "cell_type": "code", "execution_count": null, "id": "16206f8c", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:30:19.989065Z", "start_time": "2022-06-02T15:30:18.570427Z" } }, "outputs": [], "source": [ "cdo.sinfo(input=ftmp1)" ] }, { "cell_type": "code", "execution_count": null, "id": "5d51186f", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:30:24.180877Z", "start_time": "2022-06-02T15:30:22.627811Z" } }, "outputs": [], "source": [ "cdo.sinfo(input=ftmp2)" ] }, { "cell_type": "markdown", "id": "957f57f8", "metadata": {}, "source": [ "Regrid skin temperature of land 0.1 by 0.1 to 0.25 by 0.25 as over ocean" ] }, { "cell_type": "code", "execution_count": null, "id": "24a816e3", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:30:32.909942Z", "start_time": "2022-06-02T15:30:32.907058Z" } }, "outputs": [], "source": [ "ftmp3 = \"/bog/amuttaqin/Datasets/Temporary/tmp3.grib\"\n", "#cdo.remapnn(ftmp1, input=ftmp2, REMAP_EXTRAPOLATE='off', output=ftmp3)\n", "# execution time 27.7s\n", "# latest execution time 26.5s" ] }, { "cell_type": "code", "execution_count": null, "id": "0306b899", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:30:35.645828Z", "start_time": "2022-06-02T15:30:34.856719Z" } }, "outputs": [], "source": [ "cdo.sinfo(input=ftmp3)" ] }, { "cell_type": "code", "execution_count": null, "id": "ccd02afa", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:30:40.538895Z", "start_time": "2022-06-02T15:30:40.536538Z" } }, "outputs": [], "source": [ "#cdo.griddes(input=ftmp1)" ] }, { "cell_type": "code", "execution_count": null, "id": "b4bed474", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:30:45.383638Z", "start_time": "2022-06-02T15:30:45.381241Z" } }, "outputs": [], "source": [ "#cdo.griddes(input=ftmp3)" ] }, { "cell_type": "markdown", "id": "b04721b4", "metadata": {}, "source": [ "Convert grib to netcdf" ] }, { "cell_type": "code", "execution_count": null, "id": "49b59c24", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:30:51.242628Z", "start_time": "2022-06-02T15:30:51.240090Z" } }, "outputs": [], "source": [ "nc1 = \"/bog/amuttaqin/Datasets/Temporary/tmp1.nc\"\n", "nc3 = \"/bog/amuttaqin/Datasets/Temporary/tmp3.nc\"\n", "\n", "#cdo.copy(input=ftmp1, options='-f nc', output=nc1)\n", "#cdo.copy(input=ftmp3, options='-f nc', output=nc3)\n", "\n", "# execution time: 18.8s" ] }, { "cell_type": "markdown", "id": "ea846c95", "metadata": {}, "source": [ "Load area-subset data. Assign land skin temperature and ocean skin temperature into variables (time, lat, lon)" ] }, { "cell_type": "code", "execution_count": null, "id": "b16a4b54", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:31:01.845306Z", "start_time": "2022-06-02T15:30:59.175226Z" } }, "outputs": [], "source": [ "ds1 = xr.open_dataset(nc1, chunks={'latitude':5, 'longitude':5, 'time': 24*365})\n", "ds2 = xr.open_dataset(nc3, chunks={'latitude':5, 'longitude':5, 'time': 24*365})\n", "\n", "# execution time: 1.29s" ] }, { "cell_type": "code", "execution_count": null, "id": "bc2ad68a", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:31:08.717423Z", "start_time": "2022-06-02T15:31:08.689677Z" } }, "outputs": [], "source": [ "ds1" ] }, { "cell_type": "code", "execution_count": null, "id": "83538bad", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T15:31:24.903397Z", "start_time": "2022-06-02T15:31:24.885673Z" } }, "outputs": [], "source": [ "ds2['var235']" ] }, { "cell_type": "markdown", "id": "436c99cc", "metadata": {}, "source": [ "Extract land skin temperatuer and ocean skin temperature at each transect's tip (time)" ] }, { "cell_type": "code", "execution_count": null, "id": "09123330", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:32:16.479119Z", "start_time": "2022-06-02T16:31:46.988848Z" } }, "outputs": [], "source": [ "dtmp_mean_temp = []\n", "dtmp_stdv_temp = []\n", "\n", "for t in range(len(list_trnsc)):\n", " ## Extract land skin temperature and ocean skin tempearture at each transect\n", " ts1 = ds1.sel(lat=trnsc_ocean[t][0], lon=trnsc_ocean[t][1], method='nearest')\n", " ts2 = ds1.sel(lat=trnsc_land[t][0], lon=trnsc_land[t][1], method='nearest')\n", " # ts1 is time series of skin temperature at the tip of each transect over ocean\n", " # ts2 is time series of skin temperature at the tip of each transect over land\n", " # execution time: 8ms\n", " \n", " ## Subtract land and ocean skin temperature at each transect\n", " ts3 = ts2['var235']-ts1['var235'] # land - ocean \n", " # ts3 is time series of skin temperature difference between land and ocean at each transect\n", " \n", " ## Groupby time.hour and calculate hourly mean and standard deviation for the whole period (30 years)\n", " ts4 = ts3.groupby('time.hour').mean(dim='time')\n", " ts5 = ts3.groupby('time.hour').std(dim='time')\n", " # ts4 is the hourly mean of skin temperature difference over the whole period\n", " # ts5 is the hourly std of skin temperature difference over the whole period\n", " \n", " dtmp_mean_temp.append(ts4.compute())\n", " dtmp_stdv_temp.append(ts5.compute())\n", " # execution time: 5.23s\n", " \n", " ## For loop execution time: 22.3s\n", "\n", "dtmp_mean = xr.concat(dtmp_mean_temp, \"transect\")\n", "dtmp_stdv = xr.concat(dtmp_stdv_temp, \"transect\")" ] }, { "cell_type": "code", "execution_count": null, "id": "a8301e41", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:32:19.859696Z", "start_time": "2022-06-02T16:32:19.848597Z" } }, "outputs": [], "source": [ "dtmp_mean.mean(dim='transect')" ] }, { "cell_type": "markdown", "id": "df78ae52", "metadata": {}, "source": [ "Plot hourly mean of skin temp difference with standard deviation shading (whole period)" ] }, { "cell_type": "code", "execution_count": null, "id": "521106b7", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:32:24.609318Z", "start_time": "2022-06-02T16:32:24.511954Z" } }, "outputs": [], "source": [ "x = dtmp_mean.coords['hour'].values\n", "y = dtmp_mean.mean(dim='transect').values\n", "y_err = dtmp_stdv.mean(dim='transect').values\n", "\n", "fig,ax = plt.subplots(figsize=(8,5))\n", "ax.plot(x, y, '-')\n", "ax.fill_between(x, y - y_err, y + y_err, alpha=0.2)\n", "ax.plot(x, y, 'o', color='tab:brown')\n", "ax.set_xlim([-1,24])\n", "ax.set_ylim([-12,8])\n", "ax.set_xticks([0,3,6,9,12,15,18,21])\n", "ax.set_yticks([-12,-8,-4,0,4,8])\n", "ax.set_xlabel('hour (UTC)', fontsize=15)\n", "ax.set_ylabel('Skin temperature diff. (deg C)', fontsize=15)\n", "ax.set_title('Skin Temperature Difference: Land-Ocean', fontsize=15)\n", "ax.tick_params(axis='both', which='major', labelsize=15)" ] }, { "cell_type": "code", "execution_count": null, "id": "3f895c19", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T16:32:31.760468Z", "start_time": "2022-06-02T16:32:31.168878Z" } }, "outputs": [], "source": [ "fig.savefig('/bog/amuttaqin/Figures/segment-5_d2c-0.4.png', format='png', dpi=500)" ] }, { "cell_type": "markdown", "id": "8557ca56", "metadata": {}, "source": [ "Groupby time hour at each season (DJF, MAM, JJA, SON) and calculate mean and standard deviation" ] }, { "cell_type": "code", "execution_count": null, "id": "1100a01a", "metadata": {}, "outputs": [], "source": [ "# ts3_djf = ts3.sel(time=ts3['time.season']=='DJF')\n", "# ts3_mam = ts3.sel(time=ts3['time.season']=='MAM')\n", "# ts3_jja = ts3.sel(time=ts3['time.season']=='JJA')\n", "# ts3_son = ts3.sel(time=ts3['time.season']=='SON')\n", "\n", "# ts3_djf_mean = ts3_djf.groupby('time.hour').mean(dim='time')\n", "# ts3_djf_std = ts3_djf.groupby('time.hour').std(dim='time')\n", "\n", "# ts3_mam_mean = ts3_mam.groupby('time.hour').mean(dim='time')\n", "# ts3_mam_std = ts3_mam.groupby('time.hour').std(dim='time')\n", "\n", "# ts3_jja_mean = ts3_jja.groupby('time.hour').mean(dim='time')\n", "# ts3_jja_std = ts3_jja.groupby('time.hour').mean(dim='time')\n", "\n", "# ts3_son_mean = ts3_son.groupby('time.hour').mean(dim='time')\n", "# ts3_son_std = ts3_son.groupby('time.hour').mean(dim='time')" ] }, { "cell_type": "markdown", "id": "5b124413", "metadata": {}, "source": [ "Plot hourly mean of skin temp difference with standard deviation (DJF, MAM, JJA, SON)" ] }, { "cell_type": "code", "execution_count": null, "id": "bb142edb", "metadata": {}, "outputs": [], "source": [ "# x = ts4.coords['hour'].values\n", "# y = ts4.values\n", "# y_err = ts5.values\n", "\n", "# fig,ax = plt.subplots(figsize=(8,5))\n", "# ax.plot(x, y, '-')\n", "# ax.fill_between(x, y - y_err, y + y_err, alpha=0.2)\n", "# ax.plot(x, y, 'o', color='tab:brown')" ] }, { "cell_type": "markdown", "id": "82da84b8", "metadata": {}, "source": [ "Append output at each transect (whole period + each season)" ] }, { "cell_type": "code", "execution_count": null, "id": "79f4b6f7", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T01:08:17.941308Z", "start_time": "2022-06-02T01:08:17.939510Z" } }, "outputs": [], "source": [ "da_whole = da1, da2, da3, da4, dan" ] }, { "cell_type": "markdown", "id": "6b43035f", "metadata": {}, "source": [ "Transect-composite of hourly mean (whole period)" ] }, { "cell_type": "code", "execution_count": null, "id": "6f726b7d", "metadata": {}, "outputs": [], "source": [ "# xarray.concatenate or merge\n", "# da_composite = da_whole.mean()" ] }, { "cell_type": "markdown", "id": "13178326", "metadata": {}, "source": [ "Transect-composite of hourly mean (DJF, MAM, JJA, SON)" ] }, { "cell_type": "code", "execution_count": null, "id": "796d362a", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T01:14:37.730215Z", "start_time": "2022-06-02T01:14:37.728311Z" } }, "outputs": [], "source": [ "# xarray.concatenate or merge" ] }, { "cell_type": "markdown", "id": "ca3c080a", "metadata": {}, "source": [ "Plot the transect-composite of hourly mean (whole period)" ] }, { "cell_type": "code", "execution_count": null, "id": "04fba839", "metadata": {}, "outputs": [], "source": [ "# x = ts4.coords['hour'].values\n", "# y = ts4.values\n", "# y_err = ts5.values\n", "\n", "# fig,ax = plt.subplots(figsize=(8,5))\n", "# ax.plot(x, y, '-')\n", "# ax.fill_between(x, y - y_err, y + y_err, alpha=0.2)\n", "# ax.plot(x, y, 'o', color='tab:brown')" ] }, { "cell_type": "markdown", "id": "aa464673", "metadata": {}, "source": [ "Plot the transect-composite (DJF, MAM, JJA, SON)" ] }, { "cell_type": "code", "execution_count": null, "id": "38ef56fd", "metadata": {}, "outputs": [], "source": [ "# x = ts4.coords['hour'].values\n", "# y = ts4.values\n", "# y_err = ts5.values\n", "\n", "# fig,ax = plt.subplots(figsize=(8,5))\n", "# ax.plot(x, y, '-')\n", "# ax.fill_between(x, y - y_err, y + y_err, alpha=0.2)\n", "# ax.plot(x, y, 'o', color='tab:brown')" ] }, { "cell_type": "markdown", "id": "caeb0807", "metadata": {}, "source": [ "### 3.2. Sea breeze intensity (point, line-transect, line-segment)" ] }, { "cell_type": "markdown", "id": "ff7d53bc", "metadata": {}, "source": [ "Import packages" ] }, { "cell_type": "code", "execution_count": null, "id": "0f08bd8a", "metadata": {}, "outputs": [], "source": [ "# metview\n", "# cdo" ] }, { "cell_type": "markdown", "id": "a7c5bba0", "metadata": {}, "source": [ "Use the bounding box info from previous analysis." ] }, { "cell_type": "code", "execution_count": null, "id": "c0ea245e", "metadata": {}, "outputs": [], "source": [ "# For Malay Peninsula region:\n", "# lat1 = 0\n", "# lat2 = 15\n", "# lon1 = 90\n", "# lon2 = 110 " ] }, { "cell_type": "markdown", "id": "df7dead9", "metadata": {}, "source": [ "Area-subset dataset into a temporary file. Remember to delete this file at the end of the script." ] }, { "cell_type": "code", "execution_count": null, "id": "ad5fddae", "metadata": {}, "outputs": [], "source": [ "# temp data = CDO sellonlatbox\n", "# Limited area (20 degree longitude by 15 degree latitude) of 30-year hourly data" ] }, { "cell_type": "markdown", "id": "0d613868", "metadata": {}, "source": [ "Load area-subset data. Assign horizontal winds into variables (time, lat, lon)" ] }, { "cell_type": "code", "execution_count": null, "id": "eb25f285", "metadata": {}, "outputs": [], "source": [ "# Xarray.open_dataset(temp_data)" ] }, { "cell_type": "markdown", "id": "ee7d59b1", "metadata": {}, "source": [ "Groupby time.hour and mean and std over time dimension. CDO dhourmean and dhourstd over whole period (30 years) with a file output" ] }, { "cell_type": "code", "execution_count": null, "id": "6fd6678e", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T01:17:58.541130Z", "start_time": "2022-06-02T01:17:58.539297Z" } }, "outputs": [], "source": [ "# cdo dhourmean dhourstat" ] }, { "cell_type": "markdown", "id": "a7d19daf", "metadata": {}, "source": [ "Load cdo dhourmean and dhourstd" ] }, { "cell_type": "code", "execution_count": null, "id": "aa1bba2b", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T01:18:20.855846Z", "start_time": "2022-06-02T01:18:20.853994Z" } }, "outputs": [], "source": [ "# mv.read(ftemp)" ] }, { "cell_type": "markdown", "id": "6e8a6e6c", "metadata": {}, "source": [ "Extract projected wind intensity/values at each transect (cross section), wind_parallel=on" ] }, { "cell_type": "code", "execution_count": null, "id": "2c2dffa7", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T01:18:50.433401Z", "start_time": "2022-06-02T01:18:50.431620Z" } }, "outputs": [], "source": [ "# line = [lat1, lon1, lat2, lon2]\n", "\n", "# xs = mv.mcross_sect(line=line, data=f, wind_parallel='on')" ] }, { "cell_type": "markdown", "id": "2565099a", "metadata": {}, "source": [ "Convert cross section data into xarray DataArray" ] }, { "cell_type": "code", "execution_count": null, "id": "9575d1ad", "metadata": {}, "outputs": [], "source": [ "# xsa = xs.to_dataset()\n", "# xsa" ] }, { "cell_type": "markdown", "id": "c9f7ba20", "metadata": {}, "source": [ "Plot projected wind, x-axis as longitude/latitude, y-axis as wind intensity/values" ] }, { "cell_type": "code", "execution_count": null, "id": "71c4a380", "metadata": {}, "outputs": [], "source": [ "# x = uv_land.coords['hour'].values\n", "# y = uv_land['u'].values\n", "\n", "# fig,ax = plt.subplots(figsize=(8,5))\n", "# ax.plot(x, y, marker='o')" ] }, { "cell_type": "markdown", "id": "49528351", "metadata": {}, "source": [ "Average over land, hourly" ] }, { "cell_type": "code", "execution_count": null, "id": "9fb361d9", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T01:22:54.068823Z", "start_time": "2022-06-02T01:22:54.067035Z" } }, "outputs": [], "source": [ "# split array in the middle \n", "# avearge on one half that over land" ] }, { "cell_type": "markdown", "id": "8d0cac21", "metadata": {}, "source": [ "Plot projected wind, x-axis as time 24 hour, y-axis as wind intensity averaged along transect over land each hour" ] }, { "cell_type": "code", "execution_count": null, "id": "0a5ef621", "metadata": { "ExecuteTime": { "end_time": "2022-06-02T01:22:57.167840Z", "start_time": "2022-06-02T01:22:57.166057Z" } }, "outputs": [], "source": [ "# x = uv_land.coords['hour'].values\n", "# y = uv_land['u'].values\n", "\n", "# fig,ax = plt.subplots(figsize=(8,5))\n", "# ax.plot(x, y, marker='o')" ] }, { "cell_type": "markdown", "id": "13c4c94f", "metadata": {}, "source": [ "### 3.3 Combination between temperature difference and wind breeze intensity" ] }, { "cell_type": "markdown", "id": "9e2375a1", "metadata": {}, "source": [ "Scatter plot, x-axis is the temperature difference range, y-axis is the wind intensity range, each point on the scatter plot represent transect at certain hour?" ] }, { "cell_type": "code", "execution_count": null, "id": "a6096a83", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "d41419f5", "metadata": {}, "source": [ "### NEXT 3.4. Precipitation (point)" ] }, { "cell_type": "code", "execution_count": null, "id": "5131105d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "17c10546", "metadata": {}, "source": [ "### NEXT 3.5. Surface fluxes (point)" ] }, { "cell_type": "code", "execution_count": null, "id": "1f55da37", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "8f9f9e6d", "metadata": {}, "source": [ "## NEXT 4. Append analyses outputs to a dataset for each transect" ] }, { "cell_type": "markdown", "id": "5767b440", "metadata": {}, "source": [ "Append to file" ] }, { "cell_type": "code", "execution_count": null, "id": "46ad6b71", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "c08e6537", "metadata": {}, "source": [ "Delete temporary files" ] }, { "cell_type": "code", "execution_count": null, "id": "2958228f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.12" } }, "nbformat": 4, "nbformat_minor": 5 }