Spatialtemporal Smoothing of Data
There are options in NASAPrecipitation.jl to spatialtemporally smooth data.
smoothing(
<NASAPrecipitation Dataset>,
<GeoRegion>,
<smoothing options> ...,
)
It is important to see the documentation and see which options are available for each type of dataset, but we summarize it in the table below:
Type | Spatial | Temporal |
---|---|---|
IMERGHalfHourly | Yes | Yes (specify hours) |
IMERGDaily | Yes | Yes (specify days) |
IMERGMonthly | Yes | No |
TRMM3Hourly | Yes | Yes (specify hours) |
TRMMDaily | Yes | Yes (specify days) |
TRMMMonthly | Yes | No |
Setup
using NASAPrecipitation
using CairoMakie
using DelimitedFiles
download("https://raw.githubusercontent.com/natgeo-wong/GeoPlottingData/main/coastline_resl.txt","coast.cst")
coast = readdlm("coast.cst",comments=true)
clon = coast[:,1]
clat = coast[:,2]
nothing
Spatial Smoothing Example
Let's define a rectangular domain in Southeast Asia and download some NASAPrecipitation data for this region:
npd = IMERGMonthly(start=Date(2015),stop=Date(2015,3))
geo = RectRegion("TMP","GLB","Southeast Asia",[15,-15,125,95],savegeo=false)
download(npd,geo)
lsd = getLandSea(npd,geo)
The Land-Sea Dataset (no Topography) has the following properties:
Longitude Points (lon) : Float32[95.05, 95.15, 95.25, 95.35, 95.45, 95.55, 95.65, 95.75, 95.85, 95.95 … 124.05, 124.15, 124.25, 124.35, 124.45, 124.55, 124.65, 124.75, 124.85, 124.95]
Latitude Points (lat) : Float32[-14.95, -14.85, -14.75, -14.65, -14.55, -14.45, -14.35, -14.25, -14.15, -14.05 … 14.05, 14.15, 14.25, 14.35, 14.45, 14.55, 14.65, 14.75, 14.85, 14.95]
Region Size (nlon * nlat) : 300 lon points x 300 lat points
We then proceed to perform a spatial smoothing (1.0º longitude, 0.2º latitude) of the data.
npd_smth = IMERGMonthly(start=Date(2015,2),stop=Date(2015,2))
smoothing(npd_smth,geo,smoothlon=1,smoothlat=0.2)
[ Info: 2024-02-17T00:57:27.353 - NASAPrecipitation.jl - Setting up data structure containing information on IMERG Monthly data to be downloaded
[ Info: 2024-02-17T00:57:28.532 - NASAPrecipitation.jl - Checking to see if the specified GeoRegion "TMP" is within the "IMERG" GeoRegion
[ Info: 2024-02-17T00:57:28.533 - GeoRegions.jl - Retrieving information for the GeoRegion defined by the ID IMERG
[ Info: 2024-02-17T00:57:28.534 - GeoRegions.jl - Performing a check to determine if the Southeast Asia GeoRegion (TMP) is inside the Global IMERG Dataset GeoRegion (IMERG)
[ Info: 2024-02-17T00:57:28.534 - GeoRegions.jl - The GeoRegion TMP (Southeast Asia) is indeed a subset of the GeoRegion IMERG (Global IMERG Dataset)
[ Info: 2024-02-17T00:57:28.536 - NASAPrecipitation.jl - Retrieving the regional IMERG Land-Sea mask for the "TMP" GeoRegion ...
[ Info: 2024-02-17T00:57:28.536 - NASAPrecipitation.jl - Preallocating data arrays for the analysis of data in the Southeast Asia Region ...
[ Info: 2024-02-17T00:57:28.583 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 January ...
[ Info: 2024-02-17T00:57:29.430 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-01-01
[ Info: 2024-02-17T00:57:29.431 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:29.437 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-01-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:29.440 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 February ...
[ Info: 2024-02-17T00:57:30.318 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-02-01
[ Info: 2024-02-17T00:57:30.318 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:30.319 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:30.325 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-02-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:30.328 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 March ...
[ Info: 2024-02-17T00:57:31.179 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-03-01
[ Info: 2024-02-17T00:57:31.179 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:31.180 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:31.186 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-03-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:31.189 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 April ...
[ Info: 2024-02-17T00:57:32.056 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-04-01
[ Info: 2024-02-17T00:57:32.056 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:32.057 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:32.063 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-04-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:32.066 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 May ...
[ Info: 2024-02-17T00:57:32.951 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-05-01
[ Info: 2024-02-17T00:57:32.951 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:32.952 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:32.958 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-05-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:32.961 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 June ...
[ Info: 2024-02-17T00:57:33.812 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-06-01
[ Info: 2024-02-17T00:57:33.812 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:33.813 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:33.819 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-06-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:33.822 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 July ...
[ Info: 2024-02-17T00:57:34.688 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-07-01
[ Info: 2024-02-17T00:57:34.689 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:34.690 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:34.695 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-07-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:34.698 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 August ...
[ Info: 2024-02-17T00:57:35.566 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-08-01
[ Info: 2024-02-17T00:57:35.566 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:35.567 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:35.574 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-08-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:35.577 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 September ...
[ Info: 2024-02-17T00:57:36.437 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-09-01
[ Info: 2024-02-17T00:57:36.437 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:36.438 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:36.444 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-09-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:36.446 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 October ...
[ Info: 2024-02-17T00:57:37.304 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-10-01
[ Info: 2024-02-17T00:57:37.304 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:37.305 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:37.311 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-10-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:37.314 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 November ...
[ Info: 2024-02-17T00:57:38.183 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-11-01
[ Info: 2024-02-17T00:57:38.183 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:38.184 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:38.190 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-11-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
[ Info: 2024-02-17T00:57:38.192 - NASAPrecipitation.jl - Performing spatial smoothing (1.00x0.20) on IMERGv7 Monthly Precipitation Rate data in Southeast Asia during 2015 December ...
[ Info: 2024-02-17T00:57:39.051 - NASAPrecipitation.jl - Saving IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-12-01
[ Info: 2024-02-17T00:57:39.051 - NASAPrecipitation.jl - Overwrite stale NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:39.052 - NASAPrecipitation.jl - Creating NetCDF file /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc ...
[ Info: 2024-02-17T00:57:39.058 - NASAPrecipitation.jl - IMERGv7 Monthly data in the Southeast Asia GeoRegion for 2015-12-01 has been saved into /home/runner/imergv7monthly/TMP/imergv7monthly-TMP-smooth_1.00x0.20_00steps-2015.nc
Now let us compare the difference between the raw and smoothed data.
ds_raw = read(npd_smth,geo,Date(2015))
ds_smth = read(npd_smth,geo,Date(2015),smooth=true,smoothlon=1,smoothlat=0.2)
prcp_raw = ds_raw["precipitation"][:,:,11] * 86400
prcp_smth = ds_smth["precipitation"][:,:,11] * 86400
close(ds_raw)
close(ds_smth)
fig = Figure()
aspect = (maximum(lsd.lon)-minimum(lsd.lon)+2)/(maximum(lsd.lat)-minimum(lsd.lat)+2)
ax1 = Axis(
fig[1,1],width=350,height=350/aspect,
title="November 2015 (Raw)",xlabel="Longitude / º",ylabel="Latitude / º",
limits=(minimum(lsd.lon)-1,maximum(lsd.lon)+1,minimum(lsd.lat)-1,maximum(lsd.lat)+1)
)
ax2 = Axis(
fig[1,2],width=350,height=350/aspect,
title="November 2015 (Smoothed 1.0ºx0.2º)",xlabel="Longitude / º",
limits=(minimum(lsd.lon)-1,maximum(lsd.lon)+1,minimum(lsd.lat)-1,maximum(lsd.lat)+1)
)
contourf!(
ax1,lsd.lon,lsd.lat,prcp_raw,colormap=:Blues,
levels=range(0,20,length=11),extendlow=:auto,extendhigh=:auto
)
contourf!(
ax2,lsd.lon,lsd.lat,prcp_smth,colormap=:Blues,
levels=range(0,20,length=11),extendlow=:auto,extendhigh=:auto
)
lines!(ax1,clon,clat,color=:black)
lines!(ax2,clon,clat,color=:black)
resize_to_layout!(fig)
fig
And we see that the data is smoothed in the longitude-direction. Because they are not smoothed equally in both longitude and latitude, the fields look stretched in the longitude direction.
API
NASAPrecipitation.smoothing
— Functionsmoothing(;
npd :: Union{IMERGHalfHourly},
geo :: GeoRegion = GeoRegion("GLB");
spatial :: Bool = false,
temporal :: Bool = false,
hours :: Real = 0,
smoothlon :: Real = 0,
smoothlat :: Real = 0,
verbose :: Bool = false
)
Perform spatialtemporal smoothing of the NASAPrecipitation dataset over the dates specified in the npd
NASAPrecipitationDataset and geo
GeoRegion.
Keyword arguments
spatial
: Iftrue
, perform spatial smoothingtemporal
: Iftrue
, perform temporal smoothinghours
: The number of hours that temporal smoothing is performed over. Must be an integer multiple of the timestep.smoothlon
: The number of longitude degrees to smooth over. Must be an integer multiple of thenpd
dataset resolution.smoothlat
: The number of latitude degrees to smooth over. Must be an integer multiple of thenpd
dataset resolution.verbose
: Iftrue
, then do extra logging
smoothing(;
npd :: Union{IMERGDaily,TRMMDaily},
geo :: GeoRegion;
spatial :: Bool = false,
temporal :: Bool = false,
days :: Int = 0,
smoothlon :: Real = 0,
smoothlat :: Real = 0,
verbose :: Bool = false
)
Perform spatialtemporal smoothing of a daily NASAPrecipitation dataset over the dates specified in the npd
NASAPrecipitationDataset and geo
GeoRegion.
Keyword arguments
spatial
: Iftrue
, perform spatial smoothingtemporal
: Iftrue
, perform temporal smoothingdays
: The number of days that temporal smoothing is performed over. Must be an integer.smoothlon
: The number of longitude degrees to smooth over. Must be an integer multiple of thenpd
dataset resolution.smoothlat
: The number of latitude degrees to smooth over. Must be an integer multiple of thenpd
dataset resolution.verbose
: Iftrue
, then do extra logging
smoothing(;
npd :: Union{IMERGMonthly,TRMMMonthly},
geo :: GeoRegion;
smoothlon :: Real = 0,
smoothlat :: Real = 0,
verbose :: Bool = false
)
Perform spatial smoothing of the **Monthly* NASAPrecipitation dataset over the dates specified in the npd
NASAPrecipitationDataset and geo
GeoRegion.
Temporal smoothing cannot be performed on IMERGMonthly and TRMMMonthly datasets. They can only be spatially smoothed.
Keyword arguments
smoothlon
: The number of longitude degrees to smooth over. Must be an integer multiple of thenpd
dataset resolution.smoothlat
: The number of latitude degrees to smooth over. Must be an integer multiple of thenpd
dataset resolution.verbose
: Iftrue
, then do extra logging