0% found this document useful (0 votes)
11 views6 pages

Matlab1 07042023214637

Uploaded by

foo-hoat Lim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Matlab1 07042023214637

Uploaded by

foo-hoat Lim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
Tython import netcoF4 as nc import numpy as np import pandas as pd from datetime import datetime import matplotlib.pyplot as plt import openpyx1. from matplotlib.ticker import ScalarFormatter # Read a file of CDF format. address = r'F:\Adrian Angkasa 2023\3-9-2023 Dr Lim NetCDF4 Data Analysis\Kedah\KDH-BCSD.pr.day.MIROCS. histrcp85.PM.19702100.nc' data = nc.Dataset(address) # Read the stations’ closest coordinates. address_1 = r'F:\Adrian Angkasa 2023\3-9-2023 Dr Lim NetCDF4 Data Analysis\Kedah NetCDF Files Investigation Python\stations_closest_coordinates.csv' rf_coord = pd.read_csv(address_1) # Determine the variables within the data. # prep - precipitation # lat - latitude # lon - longitude # time - time variables = data.variables prep = variables['pr'][:] lat variables['lat'][:] lon variables['lon'][:] time variables[ ‘time’ ][:] time_units = variables['time'].units time_cal = variables['time'].calendar # Convert the float to datetime format. The data is in year-month-day # hour-minute-second format. # OH M&S date_time date_time Nc.num2date(time,units = time_units,calendar = time_cal) = [dt.strftime('%Y-%m-%d KH:%M:%S") for dt in date time] # Prepare a dataframe for rainfall time series. df = pd.DataFrame({ ‘date’ :date_time, 'dummy" :np.zeros(47482)}) # Select the data based on the closest coordinates. for x in range(len(rf_coord)): lat_close Ff_coord[ Closest latitude" ][x] lon_close rf_coord[ "Closest longitude’ ][x] rf_st_name “f_coord[ RF Station Name" ][x] i np.abs(1on - lon_close).argmin() j np.abs(lat - lat_close).argmin() prep_select prep[:, j,i] precip prep_select.data df [rf_st_name] del df[ ‘dummy"] precip # Plot the dataframe time series. fig,ax = plt.subplots() formatter = ScalarFormatter(useMathText=True) formatter. set_powerlimits((-2, 2)) values = [np.arange(1,27,1), np.arange(28,68,1) ,np.arange(70,86,1)] for i in values: ax.plot(df.iloc[:,i].cumsum(), linestyle = 'solid') ax.set_xlabel('Time (Days)') ax. set_xticks (np. arange(®, 50000, 5000)) ax. set_x1im(@, 48000) ax. set_ylim(@, 400000) ax.set_ylabel (‘Cumulative Rainfall (mm)') ax. set_title('Kedah MIROCS 85% Precipitation’) ax.yaxis.set_major_formatter (formatter) ax.grid(linestyle = ‘dotted",color = ‘lightgrey') plt.show() MATLAB Clear all; close all; filename = dir('./KDH-BCSD.pr.day*.nc'); for k = 1: length( filename ) data{k} = nc_varget( filename(k).name, ‘pr’ ); disp( ["Done loading file ' num2str(k) '/10°] ); end %----compute the accumulation ---- for k = 1: length( filename ) ‘tmp = data{k}(:,:,:)5 for t = 1 : 47482 %--- do until December 2699 only % tmp_acc(t,:,:) = sum( tmp(1:t, :,:), 1); Xsum over First dim. Fondo? (C File * numastr(k) *7205° TIME" numastr( t/47482 ) ] )5 end disp ( [ ‘File * numastr(k) '/10"] ); tmp_acc = cumsum( tmp, 1); data_acc{k} = tmp_acc; clear tmp tmp_ace end %~-~ work on the 3 percentiles values of the accumulated curve at each points location for y= 1: 32 forx= 1:22 for k = 1: length( filename ) ts(k, 1:47482) = squeeze(data_acc{k}(1:47482,y,x)); end p10 = pretile( ts, 10); p50 = pretile( ts, 50); P90 = pretile( ts, 98); data_p10(:,y,x) = p1e'; data_p5@(:,y,x) = p50"; data_p90(:,y,x) = poe"; end end % ~ reconstruct the daily values from the percetiles of the accumulation data pl@_recon(1,:,:) = data_p1@(1,:,:); data_ple_recon(2:47482,:,:) = data p10(2:47482,:,:) - data_p10(1:47482-1, : data_p50_recon(1,:,:) = data p5@(1,:,:)5 data, p50_recon(2:47482,:,:) = data p50(2:47482,:,:) - data p50(1:47482-1,:,: data_p9@_recon(1 data_p90(1,:,:)3 data_p9@_recon(2:47482,:,:) = data_p90(2:47482,:,:) - data_p9@(1:47482-1,:,:)5 (skeq) awit 000Sb 0000b OOOSE DOODE 000SZ 0000Z 000ST 0000T 000s uoneydicerd %S8 SOOUIW YePey cor (ww) j1eyuley eaneinwn5

You might also like