Skip to content

Commit

Permalink
Add option to sum instead of mean for accum variables
Browse files Browse the repository at this point in the history
  • Loading branch information
natgeo-wong committed Sep 24, 2023
1 parent e880ac2 commit cbb784d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
13 changes: 10 additions & 3 deletions src/hour2time/hour2day.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ function hourly2daily(
e5ds :: ERA5Hourly,
evar :: ERA5Variable,
ereg :: ERA5Region;
verbose :: Bool = false
verbose :: Bool = false,
dosum :: Bool = false
)

e5dsdy = ERA5Daily(start=e5ds.start,stop=e5ds.stop,path=dirname(e5ds.path))
Expand All @@ -17,6 +18,8 @@ function hourly2daily(
tmpdata = zeros(nlon,nlat,24)
dydata = zeros(nlon,nlat,ntimesteps(e5dsdy))

if !dosum; fac = 1; else; fac = 24 end

for dt in e5ds.start : Month(1) : e5ds.stop

if verbose
Expand All @@ -32,7 +35,11 @@ function hourly2daily(
close(ds)

if verbose
@info "$(modulelog()) - Performing daily-averaging on $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(dt)) $(monthname(dt)) ..."
if !dosum
@info "$(modulelog()) - Performing daily-averaging on $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(dt)) $(monthname(dt)) ..."
else
@info "$(modulelog()) - Performing daily summation on $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(dt)) $(monthname(dt)) ..."
end
end

for idy = 1 : ndy
Expand All @@ -43,7 +50,7 @@ function hourly2daily(
scale=sc,offset=of,mvalue=mv,fvalue=fv
)
for ilat = 1 : nlat, ilon = 1 : nlon
dydata[ilon,ilat,idy] = mean(view(tmpdata,ilon,ilat,:))
dydata[ilon,ilat,idy] = mean(view(tmpdata,ilon,ilat,:)) * fac
end
end

Expand Down
13 changes: 9 additions & 4 deletions src/hour2time/hour2month.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ function hourly2monthly(
e5ds :: ERA5Hourly,
evar :: ERA5Variable,
ereg :: ERA5Region;
verbose :: Bool = false
verbose :: Bool = false,
dosum :: Bool = false
)

e5dsmo = ERA5Monthly(start=e5ds.start,stop=e5ds.stop,path=dirname(e5ds.path))
Expand All @@ -25,7 +26,7 @@ function hourly2monthly(
if verbose
@info "$(modulelog()) - Loading $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(idt)) $(monthname(idt)) ..."
end
nhr = daysinmonth(idt) * 24
nhr = daysinmonth(idt) * 24; if !dosum; fac = 1; else; fac = nhr end
ds = NCDataset(e5dfnc(e5ds,evar,ereg,idt))
sc = ds[evar.ID].attrib["scale_factor"]
of = ds[evar.ID].attrib["add_offset"]
Expand All @@ -39,10 +40,14 @@ function hourly2monthly(
close(ds)

if verbose
@info "$(modulelog()) - Performing daily-averaging on $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(idt)) $(monthname(idt)) ..."
if !dosum
@info "$(modulelog()) - Performing daily-averaging on $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(idt)) $(monthname(idt)) ..."
else
@info "$(modulelog()) - Performing daily summation on $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(idt)) $(monthname(idt)) ..."
end
end
for ilat = 1 : nlat, ilon = 1 : nlon
modata[ilon,ilat,imo] = mean(view(tmpdata,ilon,ilat,1:nhr))
modata[ilon,ilat,imo] = mean(view(tmpdata,ilon,ilat,1:nhr)) * fac
end

end
Expand Down
14 changes: 10 additions & 4 deletions src/hour2time/hour2monthhour.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ function hourly2monthlyhour(
e5ds :: ERA5Hourly,
evar :: ERA5Variable,
ereg :: ERA5Region;
verbose :: Bool = false
verbose :: Bool = false,
dosum :: Bool = false
)

e5dsmo = ERA5Monthly(start=e5ds.start,stop=e5ds.stop,path=dirname(e5ds.path),hours=true)
Expand All @@ -24,7 +25,7 @@ function hourly2monthlyhour(
if verbose
@info "$(modulelog()) - Loading $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(idt)) $(monthname(idt)) ..."
end
ndy = daysinmonth(idt)
ndy = daysinmonth(idt); if !dosum; fac = 1; else; fac = ndy end
nhr = daysinmonth(idt) * 24
sc = ds[evar.ID].attrib["scale_factor"]
of = ds[evar.ID].attrib["add_offset"]
Expand All @@ -34,7 +35,12 @@ function hourly2monthlyhour(
close(ds)

if verbose
@info "$(modulelog()) - Performing daily-averaging on $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(idt)) $(monthname(idt)) ..."
if !dosum
@info "$(modulelog()) - Performing daily-averaging on $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(idt)) $(monthname(idt)) ..."
else
@info "$(modulelog()) - Performing daily summation on $(e5ds.name) $(evar.name) data in $(ereg.geo.name) (Horizontal Resolution: $(ereg.resolution)) during $(year(idt)) $(monthname(idt)) ..."
end

end

for ihr = 1 : 24
Expand All @@ -44,7 +50,7 @@ function hourly2monthlyhour(
scale=sc,offset=of,mvalue=mv,fvalue=fv
)
for ilat = 1 : nlat, ilon = 1 : nlon
modata[ilon,ilat,it] = mean(view(tmpdata,ilon,ilat,1:ndy))
modata[ilon,ilat,it] = mean(view(tmpdata,ilon,ilat,1:ndy)) * fac
end
end
end
Expand Down

0 comments on commit cbb784d

Please sign in to comment.