Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 jwl pentmonsoon #563

Merged
merged 150 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
04248b7
place holder
lee1043 Jul 11, 2018
fa6dbe7
renamed
lee1043 Jul 11, 2018
e548ecc
place holder
lee1043 Jul 11, 2018
f2e4896
renamed
lee1043 Jul 11, 2018
019d0a1
extracting time series for each year
lee1043 Jul 12, 2018
cb8b36d
add getting precip ave from pentad chunk
lee1043 Jul 12, 2018
65bf49c
pentad chunk added
lee1043 Jul 12, 2018
b2806a0
clean up conflicts
lee1043 Jul 12, 2018
01a95ad
add testing plot
lee1043 Jul 12, 2018
c6de19d
minor bug fix for plot file name
lee1043 Jul 12, 2018
bd93183
add for testing purpose archive
lee1043 Jul 12, 2018
da1a923
rename plot file
lee1043 Jul 12, 2018
f502064
rename plot file saving
lee1043 Jul 12, 2018
56560ce
minor change for test plot name
lee1043 Jul 12, 2018
09e5d98
add composite of year by year pentad time sereies
lee1043 Jul 12, 2018
d528937
minor clean up
lee1043 Jul 12, 2018
118bef6
debug test plot for multiple lines
lee1043 Jul 12, 2018
be0d3bd
Delete cmip5_CNRM-CM5_historical_r9i1p1_ASM_1850.png
lee1043 Jul 12, 2018
be5b5d1
add sample nc output for develop process
lee1043 Jul 12, 2018
0b80d2d
clarify variable name for monsoon regions
lee1043 Jul 12, 2018
ab5562c
minor fix
lee1043 Jul 12, 2018
fe68029
use one testing plot for multiple monsoon regions
lee1043 Jul 12, 2018
c2c2ec4
unify coordinate axis between individual year and composite time series
lee1043 Jul 12, 2018
1cc0d9b
minor fix
lee1043 Jul 12, 2018
b83c2f6
test with multiple models
lee1043 Jul 12, 2018
574369c
fix for testing plot when analyzing multiple model
lee1043 Jul 12, 2018
84f82a0
minor fix for plot legend
lee1043 Jul 12, 2018
e4b9b58
minor: fix legend box location to lower right
lee1043 Jul 12, 2018
437584a
add result example for develop process
lee1043 Jul 12, 2018
235188d
start merging pmpparser capability
lee1043 Jul 15, 2018
d3ee524
download complete for CPC daily ref dataset
lee1043 Jul 15, 2018
f15024b
issue list added in classical way
lee1043 Jul 15, 2018
0382cbb
add comment for issue list note
lee1043 Jul 15, 2018
0b1f251
add comment on issue note
lee1043 Jul 15, 2018
b4697c7
minor revise for comment
lee1043 Jul 15, 2018
ea624c1
comment adding for issue list note
lee1043 Jul 15, 2018
7c14810
land only (mask out ocean area)
lee1043 Jul 15, 2018
8d7e2d7
d.unit to d.units
lee1043 Jul 15, 2018
849372c
reduce redundancy of type conversion to MV2.array for pentad_time_series
lee1043 Jul 15, 2018
94fa66e
reduce hardcorded part
lee1043 Jul 16, 2018
cf7f984
merge debugging part to shorten code
lee1043 Jul 16, 2018
024ef10
add issue list
lee1043 Jul 16, 2018
b0a53b8
rename testing output dir
lee1043 Jul 16, 2018
38c1d1d
working on leap year issue
lee1043 Jul 16, 2018
5837482
add Sperber monsoon domains
lee1043 Jul 16, 2018
016f50d
move divide chunk to lib and draft leap year handling
lee1043 Jul 16, 2018
8370fb1
advance chunk dividing, but still need to correct
lee1043 Jul 17, 2018
cc046a9
bug fix for leap year chunk getting
lee1043 Jul 18, 2018
7235af6
bug fix for leap year chunk getting
lee1043 Jul 18, 2018
4982515
clean up
lee1043 Jul 18, 2018
63a37e8
remove redundant debug print
lee1043 Jul 18, 2018
9d0ff81
mark completed task in issue list
lee1043 Jul 18, 2018
f50ddb5
minor: plot legend location change
lee1043 Jul 18, 2018
4982441
test modpath, update issue list
lee1043 Jul 18, 2018
82942b4
reduce debug print
lee1043 Jul 18, 2018
a4d5030
update model list as available
lee1043 Jul 18, 2018
5eecd12
Get modnames from myParam.py
lee1043 Jul 18, 2018
cce7333
test with multi runs
lee1043 Jul 18, 2018
625ad83
add numpy cumsum for cumulative pentad time series
lee1043 Jul 18, 2018
6255402
clean up
lee1043 Jul 18, 2018
f08dd5b
check with r1i1p1 when testing
lee1043 Jul 18, 2018
9cccab0
add JSON and fractional accumulation for metrics calculation
lee1043 Jul 18, 2018
8ce6a62
add metrics calc
lee1043 Jul 18, 2018
dcfca35
minor grammer fix
lee1043 Jul 18, 2018
8915a6f
add copyfile import
lee1043 Jul 18, 2018
11cfb79
add json import
lee1043 Jul 18, 2018
6faa930
add description at top
lee1043 Jul 18, 2018
871473a
advance json structure
lee1043 Jul 18, 2018
a5cebb3
disable try statement when debugging
lee1043 Jul 18, 2018
37c392b
minor fix for chunk average
lee1043 Jul 18, 2018
57b709f
test run
lee1043 Jul 19, 2018
2fa2f58
test run
lee1043 Jul 19, 2018
88acb79
plot option from myParam.py applied for plotting part
lee1043 Jul 19, 2018
3592f0b
test with multiple regions
lee1043 Jul 19, 2018
b34ebf0
advance print statements
lee1043 Jul 19, 2018
6a7a9d3
clean up
lee1043 Jul 19, 2018
04a7ef0
clean up
lee1043 Jul 19, 2018
4b04ee2
code clean up
lee1043 Jul 19, 2018
06f3ff6
add map to visualize geographical location of monsoon domains
lee1043 Jul 19, 2018
2741292
show plot legend for only one panel
lee1043 Jul 19, 2018
cb2205d
GoG domain monsoon decay at 60%
lee1043 Jul 19, 2018
72667d9
start pendtad ts from 7/1 for SH monsoon domains
lee1043 Jul 19, 2018
5362c6e
shorten code
lee1043 Jul 19, 2018
c8f3784
advance
lee1043 Jul 19, 2018
e7ccd0d
add check time spend for each run
lee1043 Jul 20, 2018
f7ff1dc
add check time spend for each run (typo fix)
lee1043 Jul 20, 2018
b7d8e83
advance code efficiency (load lf once per model, close xml files afte…
lee1043 Jul 20, 2018
c808309
minor fix
lee1043 Jul 20, 2018
7cc39c4
bug fix for plotting
lee1043 Jul 20, 2018
531b81c
simplify plot and code for it
lee1043 Jul 20, 2018
d07eda0
BNU-ESM returned axis no match error: make sure array to have consist…
lee1043 Jul 20, 2018
7315338
plot label fix
lee1043 Jul 20, 2018
c10f4d0
code clean up
lee1043 Jul 21, 2018
7436a95
put place holder for 72 to 73 interpolation for 360 day/year model (e…
lee1043 Jul 21, 2018
9f60290
add 360 day calendar handling: 1d interpolation
lee1043 Jul 23, 2018
569dd53
minor bug fix for string joining
lee1043 Jul 23, 2018
84e6ecc
adjust 1d interp process
lee1043 Jul 23, 2018
cbff793
minor fix
lee1043 Jul 23, 2018
2ecb7a6
minor fix 2
lee1043 Jul 23, 2018
1135fb5
update issue list
lee1043 Jul 23, 2018
752a1b9
merged master in
doutriaux1 Aug 1, 2018
66af4b3
tweaks to cleanup PR before going to master
doutriaux1 Aug 8, 2018
d97a85f
partial fixes to @lee1043 PR
doutriaux1 Aug 9, 2018
d2240ad
merged master in
doutriaux1 Aug 10, 2018
68f467c
example of string contructor template as argument
doutriaux1 Aug 10, 2018
e3f4e2f
move domain check plotting files to doc directory
lee1043 Aug 20, 2018
4372431
Delete monsoon_domain_map.png
lee1043 Aug 20, 2018
809e9fe
Delete plot_monsoon_domain.py
lee1043 Aug 20, 2018
4799a5d
remove test output files
lee1043 Aug 28, 2018
0126558
Merge branch '404_jwl_pentmonsoon' of https://github.com/PCMDI/pcmdi_…
lee1043 Aug 28, 2018
58166c7
few changes: add sperber_metrics for importing, replace StringConstru…
lee1043 Aug 28, 2018
2ebfa56
some clean up and add inline document
lee1043 Aug 28, 2018
6a95f25
clean up and typo fix
lee1043 Aug 28, 2018
d3ff74b
Include OBS dataset for metric calculation
lee1043 Aug 28, 2018
f1d45d6
bug fix for when daily file saved as e.g., 1997-1-1 0:0:0.0
lee1043 Aug 28, 2018
66f593c
bug fix for when daily file saved as e.g., 1997-1-1 0:0:0.0 (cont)
lee1043 Aug 28, 2018
4bfb60a
obs capability add bug fix
lee1043 Aug 28, 2018
322422a
to work with obs
lee1043 Aug 29, 2018
af51756
turn off debugging mode
lee1043 Aug 29, 2018
d103b8c
enable option for run across cmip5
lee1043 Aug 29, 2018
f108788
add switch to decide include obs or not
lee1043 Aug 29, 2018
ad47c86
clean up
lee1043 Aug 29, 2018
93f481c
add import sys for case being called
lee1043 Aug 30, 2018
217e168
HadGEM2 model family 360 calendar handling case when bound not proper…
lee1043 Aug 30, 2018
4d7128c
clean up
lee1043 Aug 30, 2018
55dc24e
define modpath_lf for parser
lee1043 Aug 30, 2018
4a866a6
add one more try level for model, not only for realizations, because …
lee1043 Aug 30, 2018
a1f4375
typo fix
lee1043 Aug 30, 2018
860af5c
use relative path for default_regions.py when testing purpose
lee1043 Aug 31, 2018
d7c83fe
add import numpy as np
lee1043 Aug 31, 2018
b7f7911
add debugging message
lee1043 Aug 31, 2018
deb9802
json structure revised
lee1043 Aug 31, 2018
cb7893b
Improve start and end year getting part
lee1043 Sep 4, 2018
e197663
minor: add inline description
lee1043 Sep 4, 2018
877050e
improve inline description
lee1043 Sep 4, 2018
b3ec3fa
minor: remove repeated blank line
lee1043 Sep 4, 2018
44bc3b6
remove importing divide_chunks which no more used
lee1043 Sep 4, 2018
31c53f4
move f_lf close upward
lee1043 Sep 4, 2018
0e96ec1
simplify if statement for plot and nc_out
lee1043 Sep 4, 2018
741f30d
clean up inline description
lee1043 Sep 5, 2018
b93d95e
Merge branch 'master' into 404_jwl_pentmonsoon
doutriaux1 Sep 6, 2018
0acedcf
jiwoo branch ready?
doutriaux1 Sep 7, 2018
82d3af2
mac ffmpeg issue fix
doutriaux1 Sep 10, 2018
233b9b0
travis mac ffmpeg fix
doutriaux1 Sep 10, 2018
eb08631
add debug print
lee1043 Sep 10, 2018
66b8e62
fix little flake8 tweak
doutriaux1 Sep 12, 2018
6846eb7
I had FFMPEG env defined at the wrong place for circleci and not used…
doutriaux1 Sep 12, 2018
19e918c
magic conda pkg combination?
doutriaux1 Sep 12, 2018
4bd26fc
travis needs scipy
doutriaux1 Sep 12, 2018
81097e8
correct bash...
doutriaux1 Sep 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
jiwoo branch ready?
  • Loading branch information
doutriaux1 committed Sep 7, 2018
commit 0acedcf44ed3db870c3c5e80fd26078870753020
3 changes: 2 additions & 1 deletion share/test_data_files.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://cdat.llnl.gov/cdat/pmp
9c55c78adc9cbfba4ad98b1e68c403aa monsoon_sperber_aus.nc
60582c6986451ffd4925a303c4f0040a sample_data_pr_CMCC.nc
37acc58e3ba0acd6b35ad3439ee96453 test_monsoon_sperber_input.nc
3731b19e00226bb6a482c27e19bc1d91 test_monsoon_sperber_input_lf.nc
17 changes: 6 additions & 11 deletions src/python/monsoon_sperber/doc/myParam.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Background Information
# -------------------------------------------------
mip = 'cmip5'
#exp = 'piControl'
exp = 'historical'
frequency = 'da'
realm = 'atm'
Expand All @@ -12,11 +11,11 @@
# Observation
# -------------------------------------------------
reference_data_name = 'GPCP'
reference_data_path = '/p/user_pub/pmp/pmp_results/tree_v0.3/pmp_v1.1.2/data/PMPObs/PMPObs_v1.3/atmos/day/pr/GPCP-1-3/gn/v20180816/pr_day_GPCP-1-3_BE_gn_19961002-20170101.nc'
reference_data_path = '/p/user_pub/pmp/pmp_results/tree_v0.3/pmp_v1.1.2/data/PMPObs/PMPObs_v1.3/atmos/day/pr/GPCP-1-3/gn/v20180816/pr_day_GPCP-1-3_BE_gn_19961002-20170101.nc' # noqa
reference_data_lf_path = '/work/lee1043/DATA/LandSeaMask_1x1_NCL/NCL_LandSeaMask_rewritten.nc'

varOBS = 'pr'
ObsUnitsAdjust = (True, 'multiply', 86400.0) # kg m-2 s-1 to mm day-1
ObsUnitsAdjust = (True, 'multiply', 86400.0) # kg m-2 s-1 to mm day-1

osyear = 1996
oeyear = 2016
Expand All @@ -29,15 +28,12 @@
modpath = '/work/lee1043/ESGF/xmls/cmip5/historical/day/pr/cmip5.%(model).%(exp).%(realization).day.pr.xml'
modpath_lf = '/work/lee1043/ESGF/xmls/cmip5/fx/fx/sftlf/cmip5.%(model).fx.r0i0p0.fx.sftlf.xml'

modnames = ['ACCESS1-0', 'ACCESS1-3', 'BCC-CSM1-1', 'BCC-CSM1-1-M', 'BNU-ESM', 'CanCM4', 'CanESM2', 'CCSM4', 'CESM1-BGC', 'CESM1-CAM5', 'CESM1-FASTCHEM', 'CMCC-CESM', 'CMCC-CM', 'CMCC-CMS', 'CNRM-CM5', 'CSIRO-Mk3-6-0', 'EC-EARTH', 'FGOALS-g2', 'GFDL-CM3', 'GFDL-ESM2G', 'GFDL-ESM2M', 'GISS-E2-H', 'GISS-E2-R', 'HadGEM2-AO', 'HadGEM2-CC', 'HadGEM2-ES', 'INMCM4', 'IPSL-CM5A-LR', 'IPSL-CM5A-MR', 'IPSL-CM5B-LR', 'MIROC-ESM', 'MIROC-ESM-CHEM', 'MIROC4h', 'MIROC5', 'MPI-ESM-MR', 'MPI-ESM-P', 'MRI-CGCM3', 'MRI-ESM1', 'NorESM1-M']
modnames = ['ACCESS1-0', 'ACCESS1-3', 'BCC-CSM1-1', 'BCC-CSM1-1-M', 'BNU-ESM', 'CanCM4', 'CanESM2', 'CCSM4', 'CESM1-BGC', 'CESM1-CAM5', 'CESM1-FASTCHEM', 'CMCC-CESM', 'CMCC-CM', 'CMCC-CMS', 'CNRM-CM5', 'CSIRO-Mk3-6-0', 'EC-EARTH', 'FGOALS-g2', 'GFDL-CM3', 'GFDL-ESM2G', 'GFDL-ESM2M', 'GISS-E2-H', 'GISS-E2-R', 'HadGEM2-AO', 'HadGEM2-CC', 'HadGEM2-ES', 'INMCM4', 'IPSL-CM5A-LR', 'IPSL-CM5A-MR', 'IPSL-CM5B-LR', 'MIROC-ESM', 'MIROC-ESM-CHEM', 'MIROC4h', 'MIROC5', 'MPI-ESM-MR', 'MPI-ESM-P', 'MRI-CGCM3', 'MRI-ESM1', 'NorESM1-M'] # noqa

#modnames = ['CanESM2']

#realization = '*' # realizations
realization = 'r1i1p1'

varModel = 'pr'
ModUnitsAdjust = (True, 'multiply', 86400.0) # kg m-2 s-1 to mm day-1
ModUnitsAdjust = (True, 'multiply', 86400.0) # kg m-2 s-1 to mm day-1
units = 'mm/d'

msyear = 1961
Expand All @@ -53,6 +49,5 @@
# =================================================
# Miscellaneous
# -------------------------------------------------
update_json = True # False
#debug = True # False
debug = False # False
update_json = True
debug = False
41 changes: 22 additions & 19 deletions src/python/monsoon_sperber/doc/plot_monsoon_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,46 @@
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon

def draw_screen_poly( lats, lons, m):
x, y = m( lons, lats )
xy = zip(x,y)
poly = Polygon( xy, facecolor='red', alpha=0.4, edgecolor='red', linewidth=2)

def draw_screen_poly(lats, lons, m):
x, y = m(lons, lats)
xy = zip(x, y)
poly = Polygon(xy, facecolor='red', alpha=0.4,
edgecolor='red', linewidth=2)
plt.gca().add_patch(poly)


lats = {}
lons = {}

lats['AIR'] = [ 7, 25, 25, 7 ]
lons['AIR'] = [ 65, 65, 85, 85 ]
lats['AIR'] = [7, 25, 25, 7]
lons['AIR'] = [65, 65, 85, 85]

lats['AUS'] = [ -20, -10, -10, -20 ]
lons['AUS'] = [ 120, 120, 150, 150 ]
lats['AUS'] = [-20, -10, -10, -20]
lons['AUS'] = [120, 120, 150, 150]

lats['Sahel'] = [ 13, 18, 18, 13 ]
lons['Sahel'] = [ -10, -10, 10, 10 ]
lats['Sahel'] = [13, 18, 18, 13]
lons['Sahel'] = [-10, -10, 10, 10]

lats['GoG'] = [ 0, 5, 5, 0 ]
lons['GoG'] = [ -10, -10, 10, 10 ]
lats['GoG'] = [0, 5, 5, 0]
lons['GoG'] = [-10, -10, 10, 10]

lats['NAM'] = [ 20, 37, 37, 20 ]
lons['NAM'] = [ -112, -112, -103, -103 ]
lats['NAM'] = [20, 37, 37, 20]
lons['NAM'] = [-112, -112, -103, -103]

lats['SAM'] = [ -20, -2.5, -2.5, -20 ]
lons['SAM'] = [ -65, -65, -40, -40 ]
lats['SAM'] = [-20, -2.5, -2.5, -20]
lons['SAM'] = [-65, -65, -40, -40]

regions = lats.keys()

plt.figure(figsize=(12,6))
plt.figure(figsize=(12, 6))

m = Basemap(lon_0=0)
m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='grey',lake_color='aqua')
m.fillcontinents(color='grey', lake_color='aqua')
m.drawcoastlines()

for region in regions:
draw_screen_poly( lats[region], lons[region], m )
draw_screen_poly(lats[region], lons[region], m)

plt.savefig('monsoon_domain_map.png')
2 changes: 1 addition & 1 deletion src/python/monsoon_sperber/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .argparse_functions import AddParserArgument, YearCheck # noqa
from .calc_metrics import sperber_metrics # noqa
from .model_land_only import model_land_only # noqa
from .divide_chunks import divide_chunks, divide_chunks, divide_chunks_advanced, interp1d #noqa
from .divide_chunks import divide_chunks, divide_chunks_advanced, interp1d # noqa
39 changes: 23 additions & 16 deletions src/python/monsoon_sperber/lib/argparse_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,28 @@ def AddParserArgument(P):
P.add_argument("--modpath_lf",
type=str,
help="Path of landsea mask for model data set")
P.add_argument("--varobs", dest="varOBS", type=str, help="Variable name in reference data set")
P.add_argument("--varmod", dest="varMOD", type=str, help="Variable name in model data set")
P.add_argument("--obs_units_adjust", dest="ObsUnitsAdjust", type=tuple,
P.add_argument("--varobs", dest="varOBS", type=str,
help="Variable name in reference data set")
P.add_argument("--varmod", dest="varMOD", type=str,
help="Variable name in model data set")
P.add_argument("--obs_units_adjust", dest="ObsUnitsAdjust", type=tuple,
help="Unit conversion\n"
"- if needed: e.g., (True, 'multiply', 86400.),\n"
"- no needed: (False, 0, 0)")
P.add_argument("--mod_units_adjust", dest="ModUnitsAdjust", type=tuple,
P.add_argument("--mod_units_adjust", dest="ModUnitsAdjust", type=tuple,
help="Unit conversion\n"
"- if needed: e.g., (True, 'multiply', 86400.),\n"
"- no needed: (False, 0, 0)")
P.add_argument("--units", dest="units", type=str, help="Final units for the variable")
P.add_argument("--osyear", dest="osyear", type=int, help="Start year for reference data set")
P.add_argument("--msyear", dest="msyear", type=int, help="Start year for model data set")
P.add_argument("--oeyear", dest="oeyear", type=int, help="End year for reference data set")
P.add_argument("--meyear", dest="meyear", type=int, help="End year for model data set")
P.add_argument("--units", dest="units", type=str,
help="Final units for the variable")
P.add_argument("--osyear", dest="osyear", type=int,
help="Start year for reference data set")
P.add_argument("--msyear", dest="msyear", type=int,
help="Start year for model data set")
P.add_argument("--oeyear", dest="oeyear", type=int,
help="End year for reference data set")
P.add_argument("--meyear", dest="meyear", type=int,
help="End year for model data set")
P.add_argument("--modnames",
type=list,
default=None,
Expand All @@ -48,17 +55,17 @@ def AddParserArgument(P):
type=bool,
default=False,
help="Option for debug: False (defualt) or True")
P.add_argument("--nc_out", dest="nc_out", help="record netcdf output", action="store_true", default=False)
P.add_argument("--plot", dest="plot", help="produce plots", action="store_true", default=False)
P.add_argument("--include_obs", dest="includeOBS", help="include observation", action="store_true", default=False)
P.add_argument("--nc_out", dest="nc_out",
help="record netcdf output", action="store_true", default=False)
P.add_argument("--plot", dest="plot", help="produce plots",
action="store_true", default=False)
P.add_argument("--include_obs", dest="includeOBS",
help="include observation", action="store_true", default=False)
return P


def YearCheck(syear, eyear, P):
if syear >= eyear:
P.error('Given starting year, '
+ str(syear)
+ ', is later than given ending year, '
+ str(eyear))
P.error('Given starting year {} is later than given ending year,\ {}'.format(syear, eyear))
else:
pass
12 changes: 7 additions & 5 deletions src/python/monsoon_sperber/lib/calc_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@

Jiwoo Lee, 2018-07

Note: Code for picking onset/decay index inspired by
Note: Code for picking onset/decay index inspired by
https://stackoverflow.com/questions/2236906/first-python-list-index-greater-than-x
"""

import MV2


def sperber_metrics(d, region, debug=False):
""" d: input, 1d array of cumulative pentad time series """
# Convert accumulation to fractional accumulation; normalize by sum
d_sum = d[-1]
frac_accum = MV2.divide(d, d_sum)
onset_index = next(i for i,v in enumerate(frac_accum) if v >= 0.2)
onset_index = next(i for i, v in enumerate(frac_accum) if v >= 0.2)
if region == 'GoG':
decay_threshold = 0.6
else:
decay_threshold = 0.8
decay_index = next(i for i,v in enumerate(frac_accum) if v >= decay_threshold)
slope = ( frac_accum[decay_index] - frac_accum[onset_index] ) \
/ float(decay_index - onset_index)
decay_index = next(i for i, v in enumerate(
frac_accum) if v >= decay_threshold)
slope = (frac_accum[decay_index] - frac_accum[onset_index]) \
/ float(decay_index - onset_index)
return {'frac_accum': frac_accum,
'onset_index': onset_index,
'decay_index': decay_index,
Expand Down
82 changes: 42 additions & 40 deletions src/python/monsoon_sperber/lib/divide_chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,82 @@
Code taken from https://www.geeksforgeeks.org/break-list-chunks-size-n-python/
"""
# Yield successive n-sized
# chunks from l.
def divide_chunks(l, n):
# looping till length l
for i in range(0, len(l), n):
yield l[i:i+n]
# chunks from data.


def divide_chunks(data, n):
# looping till length data
for i in range(0, len(data), n):
yield data[i:i+n]


""" Above code advanced considering leap year
"""
def divide_chunks_advanced(l, n, debug=False):


def divide_chunks_advanced(data, n, debug=False):
# Double check first date should be Jan 1 (except for SH monsoon)
tim = l.getTime()
tim = data.getTime()
calendar = tim.calendar
month = tim.asComponentTime()[0].month
day = tim.asComponentTime()[0].day
if debug: print('debug: first day of year is '+str(month)+'/'+str(day))
if month not in [1,7] or day != 1:
sys.exit('error: first day of year time series is '+str(month)+'/'+str(day))
if debug:
print('debug: first day of year is '+str(month)+'/'+str(day))
if month not in [1, 7] or day != 1:
sys.exit('error: first day of year time series is ' +
str(month)+'/'+str(day))

# Check number of days in given year
nday = len(l)
nday = len(data)

if nday in [365, 360]:
# looping till length l
for i in range(0, len(l), n):
yield l[i:i+n]
# looping till length data
for i in range(0, nday, n):
yield data[i:i+n]
elif nday == 366:
# until leap year day detected
for i in range(0, len(l), n):
for i in range(0, nday, n):
# Check if leap year date included
leap_detect = False
for ii in range(i, i+n):
date = l.getTime().asComponentTime()[ii]
date = data.getTime().asComponentTime()[ii]
month = date.month
day = date.day
if month == 2 and day > 28:
if debug:
if debug:
print('debug: leap year detected:', month, '/', day)
leap_detect = True
if leap_detect:
yield l[i:i+n+1]
yield data[i:i+n+1]
tmp = i+n+1
break
else:
yield l[i:i+n]
yield data[i:i+n]
# after leap year day passed
if leap_detect:
for i in range(tmp, len(l), n):
yield l[i:i+n]
for i in range(tmp, nday, n):
yield data[i:i+n]
elif nday == 361 and calendar == '360_day':
# Speacial case handling for HadGEM2 family where time bounds was not
# Speacial case handling for HadGEM2 family where time bounds was not
# properly saved, so include next year's first day in time series
if debug:
print('debug: 361 to 360 revise: l.shape, before:', l.shape)
l = l[0:360]
print('debug: 361 to 360 revise: l.shape, before:', data.shape)
data = data[0:360]
if debug:
print('debug: 361 to 360 revise: l.shape, after:', l.shape)
# looping till length l
for i in range(0, len(l), n):
yield l[i:i+n]
#elif nday == 360:
# l2 = interp1d(l, 365, debug=debug)
# # looping till length l
# for i in range(0, len(l2), n):
# yield l2[i:i+n]
print('debug: 361 to 360 revise: l.shape, after:', data.shape)
# looping till length data
for i in range(0, nday, n):
yield data[i:i+n]
else:
sys.exit('error: number of days in year is '+str(nday))


def interp1d(l, ref_length, debug=False):
l = np.array(l)
l_interp = interp.interp1d(np.arange(l.size), l)
l2 = l_interp(np.linspace(0, l.size-1, ref_length))
def interp1d(data, ref_length, debug=False):
data = np.array(data)
data_interp = interp.interp1d(np.arange(data.size), data)
data2 = data_interp(np.linspace(0, data.size-1, ref_length))
if debug:
print('debug: 1d interpolation')
print('debug: length before interp: ', len(l))
print('debug: length after interp: ', len(l2))
return l2
print('debug: length before interp: ', len(data))
print('debug: length after interp: ', len(data2))
return data2
Loading