def calc_solid_earth_tides_timeseries(ts_file, geom_file, set_file, date_wise_acq_time=False, update_mode=True, verbose=False): """Calculate the time-series of solid Earth tides (SET) in LOS direction. Parameters: ts_file - str, path of the time-series HDF5 file geom_file - str, path of the geometry HDF5 file set_file - str, output SET time-sereis file date_wise_acq_time - bool, use the exact date-wise acquisition time Returns: set_file - str, output SET time-sereis file """ if update_mode and os.path.isfile(set_file): print('update mode: ON') print('skip re-calculating and use existing file: {}'.format(set_file)) return set_file # prepare LOS geometry: geocoding if in radar-coordinates inc_angle, head_angle, atr_geo = prepare_los_geometry(geom_file) # get LOS unit vector with warnings.catch_warnings(): warnings.simplefilter("ignore", category=RuntimeWarning) unit_vec = [ np.sin(inc_angle) * np.cos(head_angle) * -1, np.sin(inc_angle) * np.sin(head_angle), np.cos(inc_angle), ] # prepare datetime dt_objs = get_datetime_list(ts_file, date_wise_acq_time=date_wise_acq_time) # initiate data matrix num_date = len(dt_objs) length = int(atr_geo['LENGTH']) width = int(atr_geo['WIDTH']) ts_tide = np.zeros((num_date, length, width), dtype=np.float32) # loop for calc print('\n' + '-' * 50) print( 'calculating solid Earth tides using solid.for (D. Milbert, 2018) ...') prog_bar = ptime.progressBar(maxValue=num_date, print_msg=not verbose) for i, dt_obj in enumerate(dt_objs): # calculate tide in ENU direction (tide_e, tide_n, tide_u) = pysolid.calc_solid_earth_tides_grid(dt_obj, atr_geo, display=False, verbose=verbose) # convert ENU to LOS direction # sign convention: positive for motion towards satellite ts_tide[i, :, :] = (tide_e * unit_vec[0] + tide_n * unit_vec[1] + tide_u * unit_vec[2]) prog_bar.update(i + 1, suffix='{} ({}/{})'.format(dt_obj.isoformat(), i + 1, num_date)) prog_bar.close() # radar-coding if input in radar-coordinates atr = readfile.read_attribute(geom_file) if 'Y_FIRST' not in atr.keys(): print('radar-coding the LOS tides time-series ...') res_obj = resample(lut_file=geom_file) res_obj.open() res_obj.src_meta = atr_geo res_obj.prepare() # resample data box = res_obj.src_box_list[0] ts_tide = res_obj.run_resample(src_data=ts_tide[:, box[1]:box[3], box[0]:box[2]]) ## output # attribute atr['FILE_TYPE'] = 'timeseries' atr['UNIT'] = 'm' for key in ['REF_Y', 'REF_X', 'REF_DATE']: if key in atr.keys(): atr.pop(key) # write ds_dict = {} ds_dict['timeseries'] = ts_tide ds_dict['sensingMid'] = np.array( [i.strftime('%Y%m%dT%H%M%S') for i in dt_objs], dtype=np.string_) writefile.write(ds_dict, out_file=set_file, metadata=atr, ref_file=ts_file) return set_file
print(os.path.abspath(__file__)) # prepare inputs dt_obj = dt.datetime(2020, 12, 25, 14, 7, 44) atr = { 'LENGTH': 400, 'WIDTH': 500, 'X_FIRST': -118.2, 'Y_FIRST': 33.8, 'X_STEP': 0.000833333, 'Y_STEP': -0.000833333, } # calculate (tide_e, tide_n, tide_u) = pysolid.calc_solid_earth_tides_grid(dt_obj, atr, verbose=True) # plot out_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'pic')) os.makedirs(out_dir, exist_ok=True) out_fig = os.path.join(out_dir, 'grid.png') pysolid.plot_solid_earth_tides_grid(tide_e, tide_n, tide_u, dt_obj, out_fig=out_fig, display=False) # open the plotted figures if sys.platform in ['linux']: