def find_parse_metadata(path): """Find and parse a metadata file in a folder, TAR or MTD file path""" if os.path.isdir(path): xmlfile = find_metafile_in_folder(path) else: xmlfile = path return parse_metadata(xmlfile)
def get_geometry(mtdFile): copy_keys = ['sun_azimuth', 'sensor_azimuth', 'sensor_zenith'] metadata = plparser.parse_metadata(mtdFile) gdict = {key: metadata['angles'][key] for key in copy_keys} gdict['sun_zenith'] = 90.0 - metadata['angles']['sun_elevation'] gdict['month'] = metadata['sensing_time'].month gdict['day'] = metadata['sensing_time'].day return gdict
def test_parse_metadata_str(): with open(DIM_XML, 'rb') as fin: mstr = fin.read() try: mstr = mstr.decode('utf-8') except AttributeError: pass metadata = parser.parse_metadata(mstr) assert isinstance(metadata, dict)
def dn_to_radiance(dndata, mtdFile, band_ids): """Apply radiometric correction to Pleadis image""" metadata = plparser.parse_metadata(mtdFile) gain_bias = metadata['calibration_values'] gain, bias = (np.array(gain_bias[key])[band_ids] for key in ['gain', 'bias']) radata = np.zeros(dndata.shape, dtype='float32') with np.errstate(invalid='ignore'): for i in range(radata.shape[0]): radata[i, ...] = dndata[i] / gain[i] + bias[i] radata[radata < 0] = 0 return radata
def get_date(mtdFile): metadata = plparser.parse_metadata(mtdFile) return metadata['sensing_time']
def test_parse_metadata(): metadata = parser.parse_metadata(DIM_XML) assert isinstance(metadata, dict)
def test_footprint(): metadata = parser.parse_metadata(DIM_XML) assert metadata['footprint'].is_valid
def test_common_keys(): metadata = parser.parse_metadata(DIM_XML) missing = (set(COMMON_KEYS) - set(metadata)) assert not missing