Skip to content

Commit

Permalink
Avoid error for refarea in bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
yumorishita committed Sep 10, 2021
1 parent 6a90b48 commit 7637465
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
28 changes: 16 additions & 12 deletions bin/LiCSBAS_cum2flt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
v1.2.1 20210107 Yu Morishita, GSI
v1.2.2 20210910 Yu Morishita, GSI
========
Overview
Expand All @@ -11,7 +11,7 @@
Usage
=====
LiCSBAS_cum2flt.py -d yyyymmdd [-i infile] [-o outfile] [-m yyyymmdd] [-r x1:x2/y1:y2]
[--ref_geo lon1/lon2/lat1/lat2] [--mask maskfile] [--png]
[--ref_geo lon1/lon2/lat1/lat2] [--mask maskfile] [--png]
-d Date to be output
-i Path to input cum file (Default: cum_filt.h5)
Expand All @@ -27,6 +27,8 @@
"""
#%% Change log
'''
v1.2.2 20210910 Yu Morishita, GSI
- Avoid error for refarea in bytes
v1.2.1 20210107 Yu Morishita, GSI
- Replace jet with SCM.roma_r
v1.2 20200703 Yu Morishita, GSI
Expand Down Expand Up @@ -58,13 +60,13 @@ def __init__(self, msg):

#%% Main
def main(argv=None):

#%% Check argv
if argv == None:
argv = sys.argv

start = time.time()
ver="1.2.1"; date=20210107; author="Y. Morishita"
ver="1.2.2"; date=20210910; author="Y. Morishita"
print("\n{} ver{} {} {}".format(os.path.basename(argv[0]), ver, date, author), flush=True)
print("{} {}".format(os.path.basename(argv[0]), ' '.join(argv[1:])), flush=True)

Expand Down Expand Up @@ -146,19 +148,21 @@ def main(argv=None):
refx1, refx2, refy1, refy2 = tools_lib.read_range_geo(refarea_geo, width, length, lat1, dlat, lon1, dlon)
else:
refarea = cumh5['refarea'][()]
if type(refarea) is bytes:
refarea = refarea.decode('utf-8')
refx1, refx2, refy1, refy2 = [int(s) for s in re.split('[:/]', refarea)]

### Master (reference) date
if not imd_m:
imd_m = imdates[0]

### mask
if maskfile:
mask = io_lib.read_img(maskfile, length, width)
mask[mask==0] = np.nan
else:
mask = np.ones((length, width), dtype=np.float32)

### Check date
if not imd_s in imdates:
print('\nERROR: No date of {} exist in {}!'.format(imd_s, cumfile), file=sys.stderr)
Expand All @@ -169,7 +173,7 @@ def main(argv=None):

ix_s = imdates.index(imd_s)
ix_m = imdates.index(imd_m)

### Outfile
if not outfile:
outfile = '{}_{}.cum'.format(imd_m, imd_s)
Expand All @@ -182,16 +186,16 @@ def main(argv=None):
cum_dif = cum_s-cum_m
cum_dif = cum_dif-np.nanmean(cum_dif[refy1:refy2, refx1:refx2])
cum_dif = cum_dif*mask

cum_dif.tofile(outfile)


#%% Make png if specified
if pngflag:
pngfile = outfile+'.png'
title = '{} (Ref X/Y {}:{}/{}:{})'.format(outfile, refx1, refx2, refy1, refy2)
plot_lib.make_im_png(cum_dif, pngfile, cmap, title)


#%% Finish
elapsed_time = time.time()-start
Expand Down
22 changes: 13 additions & 9 deletions bin/LiCSBAS_cum2tstxt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
v1.2 20200703 Yu Morishita, GSI
v1.2.1 20210910 Yu Morishita, GSI
========
Overview
Expand Down Expand Up @@ -28,6 +28,8 @@
"""
#%% Change log
'''
v1.2.1 20210910 Yu Morishita, GSI
- Avoid error for refarea in bytes
v1.2 20200703 Yu Morishita, Uni of Leeds and GSI
- Add --ref_geo option
v1.1 20200227 Yu Morishita, Uni of Leeds and GSI
Expand Down Expand Up @@ -55,13 +57,13 @@ def __init__(self, msg):

#%% Main
def main(argv=None):

#%% Check argv
if argv == None:
argv = sys.argv

start = time.time()
ver=1.2; date=20200703; author="Y. Morishita"
ver="1.2.1"; date=20210910; author="Y. Morishita"
print("\n{} ver{} {} {}".format(os.path.basename(argv[0]), ver, date, author), flush=True)
print("{} {}".format(os.path.basename(argv[0]), ' '.join(argv[1:])), flush=True)

Expand Down Expand Up @@ -129,7 +131,7 @@ def main(argv=None):
dlon = float(cumh5['post_lon'][()])
else:
geocod_flag = False

if 'deramp_flag' in list(cumh5.keys()):
deramp_flag = cumh5['deramp_flag'][()]
else:
Expand Down Expand Up @@ -167,6 +169,8 @@ def main(argv=None):
refx1, refx2, refy1, refy2 = tools_lib.read_range_geo(refarea_geo, width, length, lat1, dlat, lon1, dlon)
else:
refarea = cumh5['refarea'][()]
if type(refarea) is bytes:
refarea = refarea.decode('utf-8')
refx1, refx2, refy1, refy2 = [int(s) for s in re.split('[:/]', refarea)]

if geocod_flag:
Expand All @@ -189,7 +193,7 @@ def main(argv=None):
lat, lon = tools_lib.xy2bl(x, y, lat1, dlat, lon1, dlon)
else:
lat = lon = None

else: ## -g option
if not geocod_flag:
print('\nERROR: not geocoded, -g option unavailable\n', file=sys.stderr)
Expand All @@ -204,7 +208,7 @@ def main(argv=None):
elif not lat2 <= lat <= lat1:
print("\nERROR: {} is out of range ({}-{})".format(lat, lat2, lat1), file=sys.stderr)
return 2

x, y = tools_lib.bl2xy(lon, lat, width, length, lat1, dlat, lon1, dlon)
## update latlon
lat, lon = tools_lib.xy2bl(x, y, lat1, dlat, lon1, dlon)
Expand All @@ -230,12 +234,12 @@ def main(argv=None):
if np.all(np.isnan(ts)):
print('\nERROR: All cum data are Nan at {}/{}!\n'.format(x, y), file=sys.stderr)
return 2

ts_ref = np.nanmean(cum[:, refy1:refy2, refx1:refx2]*mask[refy1:refy2, refx1:refx2], axis=(1, 2))
if np.all(np.isnan(ts_ref)):
print('\nERROR: Ref area has only NaN value!\n', file=sys.stderr)
return 2

ts_dif = ts-ts_ref
ts_dif = ts_dif-ts_dif[0] ## Make first date zero

Expand Down
8 changes: 6 additions & 2 deletions bin/LiCSBAS_cum2vel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
v1.3.2 20210125 Yu Morishita, GSI
v1.3.3 20210910 Yu Morishita, GSI
========
Overview
Expand Down Expand Up @@ -30,6 +30,8 @@
"""
#%% Change log
'''
v1.3.3 20210910 Yu Morishita, GSI
- Avoid error for refarea in bytes
v1.3.2 20210125 Yu Morishita, GSI
- Change cmap for vstd, amp, dt
v1.3.1 20210107 Yu Morishita, GSI
Expand Down Expand Up @@ -73,7 +75,7 @@ def main(argv=None):
argv = sys.argv

start = time.time()
ver="1.3.2"; date=20210125; author="Y. Morishita"
ver="1.3.3"; date=20210910; author="Y. Morishita"
print("\n{} ver{} {} {}".format(os.path.basename(argv[0]), ver, date, author), flush=True)
print("{} {}".format(os.path.basename(argv[0]), ' '.join(argv[1:])), flush=True)

Expand Down Expand Up @@ -160,6 +162,8 @@ def main(argv=None):
refx1, refx2, refy1, refy2 = tools_lib.read_range_geo(refarea_geo, width, length, lat1, dlat, lon1, dlon)
else:
refarea = cumh5['refarea'][()]
if type(refarea) is bytes:
refarea = refarea.decode('utf-8')
refx1, refx2, refy1, refy2 = [int(s) for s in re.split('[:/]', refarea)]


Expand Down
8 changes: 6 additions & 2 deletions bin/LiCSBAS_plot_ts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
v1.13.3 20210205 Yu Morishita, GSI
v1.13.4 20210910 Yu Morishita, GSI
========
Overview
Expand Down Expand Up @@ -53,6 +53,8 @@
"""
#%% Change log
'''
v1.13.4 20210910 Yu Morishita, GSI
- Avoid error for refarea in bytes
v1.13.3 20210205 Yu Morishita, GSI
- More cmap available
v1.13.2 20210126 Yu Morishita, GSI
Expand Down Expand Up @@ -170,7 +172,7 @@ def calc_model(dph, imdates_ordinal, xvalues, model):
if __name__ == "__main__":
argv = sys.argv

ver="1.13.3"; date=20210205; author="Y. Morishita"
ver="1.13.4"; date=20210910; author="Y. Morishita"
print("\n{} ver{} {} {}".format(os.path.basename(argv[0]), ver, date, author), flush=True)
print("{} {}".format(os.path.basename(argv[0]), ' '.join(argv[1:])), flush=True)

Expand Down Expand Up @@ -358,6 +360,8 @@ def calc_model(dph, imdates_ordinal, xvalues, model):
refx1, refx2, refy1, refy2 = tools_lib.read_range_geo(refarea_geo, width, length, lat1, dlat, lon1, dlon)
else:
refarea = cumh5['refarea'][()]
if type(refarea) is bytes:
refarea = refarea.decode('utf-8')
refx1, refx2, refy1, refy2 = [int(s) for s in re.split('[:/]', refarea)]


Expand Down

0 comments on commit 7637465

Please sign in to comment.