def test_gamma_version_var(): gamma_version = '20200131' os.environ['GAMMA_VERSION'] = gamma_version result = system.gamma_version() os.environ.pop('GAMMA_VERSION') assert gamma_version == result
def test_bad_gamma_version_var(caplog): with caplog.at_level(logging.WARNING): gamma_version = '20202233' os.environ['GAMMA_VERSION'] = gamma_version _ = system.gamma_version() os.environ.pop('GAMMA_VERSION') assert 'does not conform to the expected YYYYMMDD format' in caplog.text
def test_asf_gamma_version(tmp_path): os.environ.pop('GAMMA_VERSION', None) os.environ['GAMMA_HOME'] = str(tmp_path.resolve()) gamma_version = '20170707' asf = tmp_path / 'ASF_Gamma_version.txt' asf.write_text(gamma_version) result = system.gamma_version() os.environ.pop('GAMMA_HOME') assert gamma_version == result
def test_bad_asf_gamma_version(caplog, tmp_path): with caplog.at_level(logging.WARNING): os.environ.pop('GAMMA_VERSION', None) os.environ['GAMMA_HOME'] = str(tmp_path.resolve()) gamma_version = '20170732' asf = tmp_path / 'ASF_Gamma_version.txt' asf.write_text(gamma_version) _ = system.gamma_version() os.environ.pop('GAMMA_HOME') assert 'does not conform to the expected YYYYMMDD format' in caplog.text
def test_bad_gamma_direcory_parse(caplog, tmp_path): with caplog.at_level(logging.WARNING): os.environ.pop('GAMMA_VERSION', None) gamma_version = '20170732' gamma_home = tmp_path / f'GAMMA_SOFTWARE-{gamma_version}' gamma_home.mkdir() os.environ['GAMMA_HOME'] = str(gamma_home.resolve()) _ = system.gamma_version() os.environ.pop('GAMMA_HOME') assert 'No GAMMA_VERSION environment variable or ASF_Gamma_version.txt ' in caplog.text assert 'does not conform to the expected YYYYMMDD format' in caplog.text
def test_gamma_direcory_parse(caplog, tmp_path): with caplog.at_level(logging.WARNING): os.environ.pop('GAMMA_VERSION', None) gamma_version = '20170707' gamma_home = tmp_path / f'GAMMA_SOFTWARE-{gamma_version}' gamma_home.mkdir() os.environ['GAMMA_HOME'] = str(gamma_home.resolve()) result = system.gamma_version() os.environ.pop('GAMMA_HOME') assert 'No GAMMA_VERSION environment variable or ASF_Gamma_version.txt ' in caplog.text assert gamma_version == result
def create_readme_file(refFile, secFile, outfile, pixelSize, demType): looks = pixelSize / 20 txtlooks = "{}x{}".format(looks * 5, looks) etcdir = os.path.abspath(os.path.dirname(hyp3_insar_gamma.etc.__file__)) now = datetime.datetime.now() date = now.strftime("%Y%m%d") time = now.strftime("%H%M%S") year = now.year basename = os.path.basename(refFile) refname = os.path.splitext(basename)[0] basename = os.path.basename(secFile) secname = os.path.splitext(basename)[0] gamma_ver = gamma_version() if "NED" in demType: if "13" in demType: resa = "1/3" resm = 10 elif "1" in demType: resa = 1 resm = 30 else: resa = 2 resm = 60 elif "SRTMGL" in demType: if "1" in demType: resa = 1 resm = 30 else: resa = 3 resm = 90 elif "EU_DEM" in demType: resa = 1 resm = 30 elif "GIMP" in demType: resa = 1 resm = 30 elif "REMA" in demType: resa = 1 resm = 30 else: log.error("Unrecognized DEM type: {}".format(demType)) sys.exit(1) with open(outfile, "w") as g: with open("{}/README_InSAR_GAMMA.txt".format(etcdir)) as f: for line in f: line = line.replace("[DATE]", date) line = line.replace("[TIME]", "{}00".format(time)) line = line.replace("[REF_NAME]", refname) line = line.replace("[SEC_NAME]", secname) line = line.replace("[YEARPROCESSED]", "{}".format(year)) line = line.replace("[YEARACQUIRED]", refname[17:21]) line = line.replace("[LOOKS]", "{}".format(txtlooks)) line = line.replace("[SPACING]", "{}".format(pixelSize)) line = line.replace("[DEM]", "{}".format(demType)) line = line.replace("[RESA]", "{}".format(resa)) line = line.replace("[RESM]", "{}".format(resm)) line = line.replace("[HYP3_VER]", "{}".format(__version__)) line = line.replace("[GAMMA_VER]", "{}".format(gamma_ver)) g.write("{}".format(line))
def test_no_gamma_home_var(): with pytest.raises(KeyError): os.environ.pop('GAMMA_VERSION', None) os.environ.pop('GAMMA_HOME', None) _ = system.gamma_version()
def rtc_sentinel_gamma(in_file, out_name=None, res=None, dem=None, roi=None, shape=None, match_flag=False, dead_flag=True, gamma_flag=True, lo_flag=True, pwr_flag=True, filter_flag=False, looks=None, terms=1, par=None, no_cross_pol=False, smooth=False, area=False): log_file = configure_log_file() logging.info("===================================================================") logging.info(" Sentinel RTC Program - Starting") logging.info("===================================================================") if res is None: res = 10 if lo_flag: res = 30 browse_res = 30 if res > browse_res: browse_res = res if looks is None: if res == 30: if "GRD" in in_file: looks = 6 else: looks = 3 else: looks = int(res / 10 + 0.5) in_file = in_file.rstrip('/') if not os.path.exists(in_file): logging.error("ERROR: Input file {} does not exist".format(in_file)) sys.exit(1) if in_file.endswith('.zip'): logging.info(f'Unzipping {in_file}') with zipfile.ZipFile(in_file, 'r') as z: z.extractall() in_file = in_file.replace('.zip', '.SAFE') input_type = in_file[7:10] orbit_file = fetch_orbit_file(in_file) if out_name is None: out_name = get_product_name(in_file, orbit_file, res, gamma_flag, pwr_flag, filter_flag, match_flag) report_kwargs(in_file, out_name, res, dem, roi, shape, match_flag, dead_flag, gamma_flag, lo_flag, pwr_flag, filter_flag, looks, terms, par, no_cross_pol, smooth, area, orbit_file) orbit_file = os.path.abspath(orbit_file) # ingest_S1_granule requires absolute path if dem is None: logging.info("Getting DEM file covering this SAR image") tifdem = "tmp_{}_dem.tif".format(os.getpid()) if shape is not None: min_x, min_y, max_x, max_y = get_bb_from_shape(shape) logging.info(f'bounding box: {min_x}, {min_y}, {max_x}, {max_y}') roi = [min_x, min_y, max_x, max_y] if roi is not None: dem_type = get_dem(roi[0], roi[1], roi[2], roi[3], tifdem, post=30) else: demfile, dem_type = getDemFile(in_file, tifdem, post=30) if 'REMA' in dem_type and smooth: logging.info("Preparing to smooth DEM tiles") dem, parfile = smooth_dem_tiles("DEM", build=True) else: dem = "area.dem" parfile = "area.dem.par" if "GIMP" in dem_type or "REMA" in dem_type: ps2dem(tifdem, dem, parfile) else: utm2dem(tifdem, dem, parfile) os.remove(tifdem) elif ".tif" in dem: tiff_dem = dem dem = "area.dem" parfile = "area.dem.par" utm2dem(tiff_dem, dem, parfile) dem_type = "Unknown" elif os.path.isfile("{}.par".format(dem)): dem_type = "Unknown" else: logging.error("ERROR: Unrecognized DEM: {}".format(dem)) sys.exit(1) vvlist = glob.glob("{}/*/*vv*.tiff".format(in_file)) vhlist = glob.glob("{}/*/*vh*.tiff".format(in_file)) hhlist = glob.glob("{}/*/*hh*.tiff".format(in_file)) hvlist = glob.glob("{}/*/*hv*.tiff".format(in_file)) cpol = None pol = None if vvlist: logging.info("Found VV polarization - processing") pol = "VV" rtc_name = out_name + "_" + pol + ".tif" process_pol(in_file, rtc_name, out_name, pol, res, looks, match_flag, dead_flag, gamma_flag, filter_flag, pwr_flag, browse_res, dem, terms, par=par, area=area, orbit_file=orbit_file) if vhlist and not no_cross_pol: cpol = "VH" rtc_name = out_name + "_" + cpol + ".tif" logging.info("Found VH polarization - processing") process_2nd_pol(in_file, rtc_name, cpol, res, looks, gamma_flag, filter_flag, pwr_flag, browse_res, out_name, dem, terms, par=par, area=area, orbit_file=orbit_file) if hhlist: logging.info("Found HH polarization - processing") pol = "HH" rtc_name = out_name + "_" + pol + ".tif" process_pol(in_file, rtc_name, out_name, pol, res, looks, match_flag, dead_flag, gamma_flag, filter_flag, pwr_flag, browse_res, dem, terms, par=par, area=area, orbit_file=orbit_file) if hvlist and not no_cross_pol: cpol = "HV" logging.info("Found HV polarization - processing") rtc_name = out_name + "_" + cpol + ".tif" process_2nd_pol(in_file, rtc_name, cpol, res, looks, gamma_flag, filter_flag, pwr_flag, browse_res, out_name, dem, terms, par=par, area=area, orbit_file=orbit_file) if hhlist is None and vvlist is None: logging.error(f"ERROR: Can not find VV or HH polarization in {in_file}") sys.exit(1) fix_geotiff_locations() reproject_dir(dem_type, res, prod_dir="PRODUCT") reproject_dir(dem_type, res, prod_dir="geo_{}".format(pol)) if cpol: reproject_dir(dem_type, res, prod_dir="geo_{}".format(cpol)) create_browse_images(out_name, pol, cpol, browse_res) rtc_name = out_name + "_" + pol + ".tif" gamma_ver = gamma_version() create_iso_xml(rtc_name, out_name, pol, cpol, in_file, dem_type, log_file, gamma_ver) create_arc_xml(in_file, out_name, input_type, gamma_flag, pwr_flag, filter_flag, looks, pol, cpol, dem_type, res, hyp3_rtc_gamma.__version__, gamma_ver, rtc_name) cogify_dir(directory='PRODUCT') clean_prod_dir() perform_sanity_checks() logging.info("===================================================================") logging.info(" Sentinel RTC Program - Completed") logging.info("===================================================================") create_consolidated_log(out_name, lo_flag, dead_flag, match_flag, gamma_flag, roi, shape, pwr_flag, filter_flag, pol, looks, log_file, smooth, terms, no_cross_pol, par) return 'PRODUCT', out_name