科学网

 找回密码
  注册

tag 标签: 元数据

相关帖子

版块 作者 回复/查看 最后发表

没有相关内容

相关日志

python处理Landsat系列影像的一些总结(2)
wenzhaofei 2018-3-23 11:31
3、利用python读取Landsat系列数据的元数据(*MTL.txt文件) 在前几年NASA里的某团对发布了处理Landsat的python(2.7)工具包( dnppy ),但我在电脑上安装了多次都没有成功,于是放弃安装了。根据其官方介绍,该工具包能读元数据(*MTL.txt文件)、能实现反射率定标(包括星上(TOA)反射率和地表(surface)反射率)和辐射定标,感觉很实用。我又不愿意自己去写,于是就在他们给的代码了修改了一下,以为己用。这里直接贴上了。将该代码复制保存为.py文件(如lst_meta.py),然后再import就可以直接调用里面的函数了(import lst_meta) __author__ = 'jwely(modified by wenzhaofei)' # standard imports from datetime import datetime, timedelta from numpy import radians, ndarray, sin, cos, degrees, arctan2, arcsin, tan, arccos import inspect class solar: Object class for handling solar calculations. Many equations are taken from the excel sheet at this url : It requires a physical location on the earth and a datetime object :param lat: decimal degrees latitude (float OR numpy array) :param lon: decimal degrees longitude (float OR numpy array) :param time_zone: float of time shift from GMT (such as -5 for EST) :param date_time_obj: either a timestamp string following fmt or a datetime obj :param fmt: if date_time_obj is a string, fmt is required to interpret it :param slope: slope of land at lat,lon for solar energy calculations :param aspect: aspect of land at lat,lon for solar energy calculations An instance of this class may have the following attributes: =================== =========================================== ======== attribute description type =================== =========================================== ======== lat latitude (array) lon longitude (array) tz time zone (scalar) rdt reference datetime object (date_time_obj) (scalar) slope slope, derivative of DEM (array) aspect aspect (north is 0, south is 180) (array) ajd absolute julian day (scalar) ajc absolute julian century (scalar) geomean_long geometric mean longitude of the sun (scalar) geomean_anom geometric mean longitude anomaly of the sun (scalar) earth_eccent eccentricity of earths orbit (scalar) sun_eq_of_center the suns equation of center (scalar) true_long true longitude of the sun (scalar) true_anom true longitude anomaly of the sun (scalar) app_long the suns apparent longitude (scalar) oblique_mean_elip earth oblique mean ellipse (scalar) oblique_corr correction to earths oblique elipse (scalar) right_ascension suns right ascension angle (scalar) declination solar declination angle (scalar) equation_of_time equation of time (minutes) (scalar) hour_angle_sunrise the hour angle at sunrise (array) solar_noon LST of solar noon (array) sunrise LST of sunrise time (array) sunset LST of sunset time (array) sunlight LST fractional days of sunlight (array) true_solar LST for true solar time (array) hour_angle total hour angle (array) zenith zenith angle (array) elevation elevation angle (array) azimuth azimuthal angle (array) rad_vector radiation vector (distance in AU) (scalar) earth_distance earths distance to sun in meters (scalar) norm_irradiance incident solar energy at earth distance (scalar) =================== =========================================== ======== Units used by this class unless otherwise labeled - angle = degrees - distance = meters - energy = watts or joules - time = mostly in datetime objects. labeled in most cases. Planned improvements 1. DONE. Inputs of numpy arrays for lat and lon needs to be allowed. 2. inputs of a numpy array DEM for slope/aspect effects on incident solar energy Present performance To process about one landsat tile (7300^2 matrix) requires 9GB of memory and takes 45 seconds to process on a single 3.3GHz thread. It would be nice to get the same output to run on ~5GB of memory so a 8GB system could handle it. def __init__(self, lat, lon, date_time_obj, time_zone = 0, fmt = False, slope = None, aspect = None): Initializes critical spatial and temporal information for solar object. # empty list of class attributes self.ajc = None # abs julian century (defined on __init__) self.ajd = None # abs julian day (defined on __init__) self.app_long = None self.atmo_refraction = None self.azimuth = None self.declination = None self.earth_distance = None self.earth_eccent = None self.elevation = None self.elevation_noatmo = None self.equation_of_time = None self.frac_day = None self.geomean_anom = None self.geomean_long = None self.hour_angle = None self.hour_angle_sunrise = None self.lat = lat # lattitude (E positive)- float self.lat_r = radians(lat) # lattitude in radians self.lon = lon # longitude (N positive)- float self.lon_r = radians(lon) # longitude in radians self.norm_irradiance = None self.oblique_corr = None self.oblique_mean_elip = None self.rad_vector = None self.rdt = None # reference datetime (defined on __init__) self.right_ascension = None self.solar_noon = None self.solar_noon_time = None self.sun_eq_of_center = None self.sunlight = None self.sunlight_time = None self.sunrise = None self.sunrise_time = None self.sunset = None self.sunset_time = None self.true_anom = None self.true_long = None self.true_solar = None self.true_solar_time = None self.tz = None # time zone (defined on __init__) self.zenith = None # slope and aspect self.slope = slope self.aspect = aspect # Constants as attributes self.sun_surf_rad = 63156942.6 # radiation at suns surface (W/m^2) self.sun_radius = 695800000. # radius of the sun in meters self.orbital_period = 365.2563630 # num of days it takes earth to revolve self.altitude = -0.01448623 # altitude of center of solar disk # sets up the object with some subfunctions self._set_datetime(date_time_obj, fmt, GMT_hour_offset = time_zone) # specify if attributes are scalar floats or numpy array floats if isinstance(lat, ndarray) and isinstance(lon, ndarray): self.is_numpy = True else: self.is_numpy = False return def _set_datetime(self, date_time_obj, fmt = False, GMT_hour_offset = 0): sets the critical time information including absolute julian day/century. Accepts datetime objects or a datetime string with format :param date_time_obj: datetime object for time of solar calculations. Will also accept string input with matching value for fmt param :param fmt: if date_time_obj is input as a string, fmt allows it to be interpreted :param GMT_hour_offset: Number of hours from GMT for timezone of calculation area. # if input is datetime_obj set it if isinstance(date_time_obj, datetime): self.rdt = date_time_obj self.rdt += timedelta(hours = -GMT_hour_offset) elif isinstance(date_time_obj, str) and isinstance(fmt, str): self.rdt = datetime.strptime(date_time_obj,fmt) self.rdt += timedelta(hours = -GMT_hour_offset) else: raise Exception(bad datetime!) self.tz = GMT_hour_offset # uses the reference day of january 1st 2000 jan_1st_2000_jd = 2451545 jan_1st_2000 = datetime(2000,1,1,12,0,0) time_del = self.rdt - jan_1st_2000 self.ajd = float(jan_1st_2000_jd) + float(time_del.total_seconds())/86400 self.ajc = (self.ajd - 2451545)/36525.0 return def get_geomean_long(self): :return geomean_long: geometric mean longitude of the sun if not self.geomean_long is None: return self.geomean_long self.geomean_long = (280.46646 + self.ajc * (36000.76983 + self.ajc*0.0003032)) % 360 return self.geomean_long def get_geomean_anom(self): calculates the geometric mean anomoly of the sun if not self.geomean_anom is None: return self.geomean_anom self.geomean_anom = (357.52911 + self.ajc * (35999.05029 - 0.0001537 * self.ajc)) return self.geomean_anom def get_earth_eccent(self): :return earth_eccent: precise eccentricity of earths orbit at referece datetime if not self.earth_eccent is None: return self.earth_eccent self.earth_eccent = 0.016708634 - self.ajc * (4.2037e-5 + 1.267e-7 * self.ajc) return self.earth_eccent def get_sun_eq_of_center(self): :return sun_eq_of_center: the suns equation of center if not self.sun_eq_of_center is None: return self.sun_eq_of_center if self.geomean_anom is None: self.get_geomean_anom() ajc = self.ajc gma = radians(self.geomean_anom) self.sun_eq_of_center = sin(gma) * (1.914602 - ajc*(0.004817 + 0.000014 * ajc)) + \\ sin(2*gma) * (0.019993 - 0.000101 * ajc) + \\ sin(3*gma) * 0.000289 return self.sun_eq_of_center def get_true_long(self): :return true_long: the tru longitude of the sun if not self.true_long is None: return self.true_long if self.geomean_long is None: self.get_geomean_long() if self.sun_eq_of_center is None: self.get_sun_eq_of_center() self.true_long = self.geomean_long + self.sun_eq_of_center return self.true_long def get_true_anom(self): :return true_anom: calculates the true anomaly of the sun if not self.true_anom is None: return self.true_anom if self.geomean_long is None: self.get_geomean_long() if self.sun_eq_of_center is None: self.get_sun_eq_of_center() self.true_anom = self.geomean_anom + self.sun_eq_of_center return self.true_anom def get_rad_vector(self): :return rad_vector: incident radiation vector to surface at ref_datetime (AUs) if not self.rad_vector is None: return self.rad_vector if self.earth_eccent is None: self.get_earth_eccent() if self.true_anom is None: self.get_true_anom() ec = self.earth_eccent ta = radians(self.true_anom) self.rad_vector = (1.000001018*(1 - ec**2)) / (1 + ec *cos(ta)) return self.rad_vector def get_app_long(self): :return app_long: calculates apparent longitude of the sun if not self.app_long is None: return self.app_long if self.true_long is None: self.get_true_long() stl = self.true_long ajc = self.ajc self.app_long = stl - 0.00569 - 0.00478 * sin(radians(125.04 - 1934.136 * ajc)) return self.app_long def get_oblique_mean_elip(self): :return oblique_mean_elip: oblique mean elliptic of earth orbit if not self.oblique_mean_elip is None: return self.oblique_mean_elip ajc = self.ajc self.oblique_mean_elip = 23 + (26 + (21.448 - ajc * (46.815 + ajc * (0.00059 - ajc * 0.001813)))/60)/60 return self.oblique_mean_elip def get_oblique_corr(self): :return oblique_corr: the oblique correction if not self.oblique_corr is None: return self.oblique_corr if self.oblique_mean_elip is None: self.get_oblique_mean_elip() ome = self.oblique_mean_elip ajc = self.ajc self.oblique_corr = ome + 0.00256 * cos(radians(125.04 - 1934.136 * ajc)) return self.oblique_corr def get_right_ascension(self): :return right_ascension: the suns right ascension angle if not self.right_ascension is None: return self.right_ascension if self.app_long is None: self.get_app_long() if self.oblique_corr is None: self.get_oblique_corr() sal = radians(self.app_long) oc = radians(self.oblique_corr) self.right_ascension = degrees(arctan2(cos(oc) * sin(sal), cos(sal))) return self.right_ascension def get_declination(self): :return declination: solar declination angle at ref_datetime if not self.declination is None: return self.declination if self.app_long is None: self.get_app_long() if self.oblique_corr is None: self.get_oblique_corr() sal = radians(self.app_long) oc = radians(self.oblique_corr) self.declination = degrees(arcsin((sin(oc) * sin(sal)))) return self.declination def get_equation_of_time(self): :return equation_of_time: the equation of time in minutes if not self.equation_of_time is None: return self.equation_of_time if self.oblique_corr is None: self.get_oblique_corr() if self.geomean_long is None: self.get_geomean_long() if self.geomean_anom is None: self.get_geomean_anom() if self.earth_eccent is None: self.get_earth_eccent() oc = radians(self.oblique_corr) gml = radians(self.geomean_long) gma = radians(self.geomean_anom) ec = self.earth_eccent vary = tan(oc/2)**2 self.equation_of_time = 4 * degrees(vary * sin(2*gml) - 2 * ec * sin(gma) + 4 * ec * vary * sin(gma) * cos(2 * gml) - 0.5 * vary * vary * sin(4 * gml) - 1.25 * ec * ec * sin(2 * gma)) return self.equation_of_time def get_hour_angle_sunrise(self): :return hour_angle_sunrise: the hour angle of sunrise if not self.hour_angle_sunrise is None: return self.hour_angle_sunrise if self.declination is None: self.get_declination() d = radians(self.declination) lat = self.lat_r self.hour_angle_sunrise = degrees(arccos((cos(radians(90.833)) / (cos(lat) * cos(d)) - tan(lat) * tan(d)))) return self.hour_angle_sunrise def get_solar_noon(self): :return solar_noon: solar noon in (local sidereal time LST) if not self.solar_noon is None: return self.solar_noon if self.equation_of_time is None: self.get_equation_of_time() lon = self.lon eot = self.equation_of_time tz = self.tz self.solar_noon = (720 - 4 * lon - eot + tz * 60)/1440 # format this as a time for display purposes (Hours:Minutes:Seconds) if self.is_numpy: self.solar_noon_time = timedelta(days = self.solar_noon.mean()) else: self.solar_noon_time = timedelta(days = self.solar_noon) return self.solar_noon def get_sunrise(self): :return sunrise: returns the time of sunrise if not self.sunrise is None: return self.sunrise if self.solar_noon is None: self.get_solar_noon() if self.hour_angle_sunrise is None: self.get_hour_angle_sunrise() sn = self.solar_noon ha = self.hour_angle_sunrise self.sunrise = (sn * 1440 - ha * 4)/1440 # format this as a time for display purposes (Hours:Minutes:Seconds) if self.is_numpy: self.sunrise_time = timedelta(days = self.sunrise.mean()) else: self.sunrise_time = timedelta(days = self.sunrise) return self.sunrise def get_sunset(self): :return sunset: returns the time of sunset if not self.sunset is None: return self.sunset if self.solar_noon is None: self.get_solar_noon() if self.hour_angle_sunrise is None: self.get_hour_angle_sunrise() sn = self.solar_noon ha = self.hour_angle_sunrise self.sunset = (sn * 1440 + ha * 4)/1440 # format this as a time for display purposes (Hours:Minutes:Seconds) if self.is_numpy: self.sunset_time = timedelta(days = self.sunset.mean()) else: self.sunset_time = timedelta(days = self.sunset) return self.sunset def get_sunlight(self): :return sunlight: amount of daily sunlight in fractional days if not self.sunlight is None: return self.sunlight if self.hour_angle_sunrise is None: self.get_hour_angle_sunrise() self.sunlight = 8 * self.hour_angle_sunrise / (60 * 24) # format this as a time for display purposes (Hours:Minutes:Seconds) if self.is_numpy: self.sunlight_time = timedelta(days = self.sunlight.mean()) else: self.sunlight_time = timedelta(days = self.sunlight) return self.sunlight def get_true_solar(self): :return true_solar: true solar time at ref_datetime if not self.true_solar is None: return self.true_solar if self.equation_of_time is None: self.get_equation_of_time lon = self.lon eot = self.equation_of_time # turn reference datetime into fractional days frac_sec = (self.rdt - datetime(self.rdt.year, self.rdt.month, self.rdt.day)).total_seconds() frac_hr = frac_sec / (60 * 60) + self.tz frac_day = frac_hr / 24 self.frac_day = frac_day # now get true solar time self.true_solar = (frac_day * 1440 + eot + 4 * lon - 60 * self.tz) % 1440 # format this as a time for display purposes (Hours:Minutes:Seconds) if self.is_numpy: self.true_solar_time = timedelta(days = self.true_solar.mean() / (60*24)) else: self.true_solar_time = timedelta(days = self.true_solar / (60*24)) return self.true_solar def get_hour_angle(self): :return hour_angle: returns hour angle at ref_datetime if not self.hour_angle is None: return self.hour_angle if self.true_solar is None: self.get_true_solar() ts = self.true_solar # matrix hour_angle calculations if self.is_numpy: ha = ts ha = ha /4 + 180 ha = ha /4 - 180 self.hour_angle = ha # scalar hour_angle calculations else: if ts = 0: self.hour_angle = ts/4 + 180 else: self.hour_angle = ts/4 - 180 return self.hour_angle def get_zenith(self): :return zenith: returns solar zenith angle at ref_datetime if not self.zenith is None: return self.zenith if self.declination is None: self.get_declination() if self.hour_angle is None: self.get_hour_angle() d = radians(self.declination) ha = radians(self.hour_angle) lat = self.lat_r self.zenith = degrees(arccos(sin(lat) * sin(d) + cos(lat) * cos(d) * cos(ha))) return self.zenith def get_elevation(self): :return elevation: returns solar elevation angle at ref_datetime if not self.elevation is None: return self.elevation if self.zenith is None: self.get_zenith() # perform an approximate atmospheric refraction correction # matrix hour_angle calculations # these equations are hideous, but im not sure how to improve them without # adding computational complexity if self.is_numpy: e = 90 - self.zenith ar = e * 0 ar = 0 ar = 58.1 / tan(radians(e )) - \\ 0.07 / tan(radians(e ))**3 + \\ 0.000086 / tan(radians(e ))**5 ar = 1735 + e * \\ (103.4 + e * (-12.79 + e * 0.711)) ar = -20.772 / tan(radians(e )) # scalar hour_angle calculations else: e = 90 - self.zenith er = radians(e) if e 85: ar = 0 elif e 5: ar = 58.1 / tan(er) - 0.07 / tan(er)**3 + 0.000086 / tan(er)**5 elif e -0.575: ar = 1735 + e * (103.4 + e * ( -12.79 + e * 0.711)) else: ar = -20.772 / tan(er) self.elevation_noatmo = e self.atmo_refraction = ar / 3600 self.elevation = self.elevation_noatmo + self.atmo_refraction return self.elevation def get_azimuth(self): :return azimuth: returns solar azimuth angle at ref_datetime if not self.azimuth is None: return self.azimuth if self.declination is None: self.get_declination() if self.hour_angle is None: self.get_hour_angle() if self.zenith is None: self.get_zenith() lat = self.lat_r d = radians(self.declination) ha = radians(self.hour_angle) z = radians(self.zenith) # matrix azimuth calculations # these equations are hideous monsters, but im not sure how to improve them without # adding computational complexity. if self.is_numpy: az = ha * 0 az = (degrees(arccos(((sin(lat ) * cos(z )) - sin(d)) / (cos(lat ) * sin(z )))) + 180) % 360 az = (540 - degrees(arccos(((sin(lat ) * cos(z )) -sin(d))/ (cos(lat ) * sin(z ))))) % 360 self.azimuth = az else: if ha 0: self.azimuth = (degrees(arccos(((sin(lat) * cos(z)) - sin(d)) / (cos(lat) * sin(z)))) + 180) % 360 else: self.azimuth = (540 - degrees(arccos(((sin(lat) * cos(z)) -sin(d))/ (cos(lat) * sin(z))))) % 360 return self.azimuth def get_earth_distance(self): :return earth_distance: distance between the earth and the sun at ref_datetime if self.rad_vector is None: self.get_rad_vector() # convert rad_vector length from AU to meters self.earth_distance = self.rad_vector * 149597870700 return self.earth_distance def get_norm_irradiance(self): Calculates incoming solar energy in W/m^2 to a surface normal to the sun. inst_irradiance is calculated as = sun_surf_radiance\\*(sun_radius / earth_distance)^2 and is then corrected as a function of solar incidence angle :return norm_irradiance: the normal irradiance in W/m^2 if not self.norm_irradiance is None: return self.norm_irradiance if self.earth_distance is None: self.get_earth_distance() ed = self.earth_distance # calculate irradiance to normal surface at earth distance self.norm_irradiance = self.sun_surf_rad * (self.sun_radius / ed)**2 return self.norm_irradiance def get_inc_irradiance(self): calculates the actual incident solar irradiance at a given lat,lon coordinate with adjustments for slope and aspect if they have been given. Not finished. print(this function is unfinished!) return def summarize(self): prints attribute list and corresponding values for key in sorted(self.__dict__.iterkeys()): print({0} {1}.format(key.ljust(20),sc.__dict__ )) return def compute_all(self): Computes and prints all the attributes of this solar object. Spatial averages are printed for numpy array type attributes. print(=*50) print(Interogation of entire matrix of points.) print(Some values displayed below are spatial averages) print(=*50) if self.is_numpy: # print means of lat/lon arrays print(latitude, longitude \\t{0}, {1}.format(self.lat.mean(), self.lon.mean())) else: print(latitude, longitude \\t{0}, {1}.format(self.lat, self.lon)) print(datetime \\t\\t{0} (GMT).format(self.rdt)) print(time zone \\t\\t{0} (GMT offset).format(self.tz)) print() print(abs julian day \\t\\t{0}\\t (day).format(self.ajd)) print(abs julian century \\t{0}\\t (cen).format(self.ajc)) print(suns geomean long \\t{0}\\t (deg).format(self.get_geomean_long())) print(suns geomean anom \\t{0}\\t (deg).format(self.get_geomean_anom())) print(earth eccentricity \\t{0}.format(self.get_earth_eccent())) print(suns eq of center \\t{0}.format(self.get_sun_eq_of_center())) print(suns true long \\t\\t{0}\\t (deg).format(self.get_true_long())) print(suns true anom \\t\\t{0}\\t (deg).format(self.get_true_anom())) print(suns apparent long \\t{0}\\t (deg).format(self.get_app_long())) print(earth obliq mean elip \\t{0}\\t (deg).format(self.get_oblique_mean_elip())) print(earth obliq correction\\t{0}\\t (deg).format(self.get_oblique_corr())) print(sun right ascension \\t{0}\\t (deg).format(self.get_right_ascension())) print(solar declination angle {0}\\t (deg).format(self.get_declination())) print(equation of time \\t{0}\\t (min).format(self.get_equation_of_time)) if self.is_numpy: # print means of hour angle array print(hour angle sunrise\\t{0}\\t (deg).format(self.get_hour_angle_sunrise().mean())) else: print(hour angle sunrise\\t{0}\\t (deg).format(self.get_hour_angle_sunrise())) print() self.get_solar_noon() print(solar noon \\t\\t{0}\\t (HMS - LST).format(self.solar_noon_time)) self.get_sunrise() print(sunrise \\t\\t{0}\\t (HMS - LST).format(self.sunrise_time)) self.get_sunset() print(sunset \\t\\t{0}\\t (HMS - LST).format(self.sunset_time)) self.get_sunlight() print(sunlight durration \\t{0}\\t (HMS).format(self.sunlight_time)) self.get_true_solar() print(true solar time \\t{0}\\t (HMS - LST).format(self.true_solar_time)) print() if self.is_numpy: # print means of these array objects print(hour angle \\t\\t{0}\\t (deg).format(self.get_hour_angle().mean())) print(solar zenith angle \\t{0}\\t (deg).format(self.get_zenith().mean())) print(solar elevation angle \\t{0}\\t (deg).format(self.get_elevation().mean())) print(solar azimuth angle \\t{0}\\t (deg).format(self.get_azimuth().mean())) else: print(hour angle \\t\\t{0}\\t (deg).format(self.get_hour_angle())) print(solar zenith angle \\t{0}\\t (deg).format(self.get_zenith())) print(solar elevation angle \\t{0}\\t (deg).format(self.get_elevation())) print(solar azimuth angle \\t{0}\\t (deg).format(self.get_azimuth())) print() print(radiation vector \\t{0}\\t (AU).format(self.get_rad_vector())) print(earth sun distance \\t{0}(m).format(self.get_earth_distance())) print(norm irradiance \\t{0}\\t (W/m*m).format(self.get_norm_irradiance())) print(=*50) # testing if __name__ == __main__: # use the current time and my time zone my_datestamp = 20150515-120000 # date stamp my_fmt = %Y%m%d-%H%M%S # datestamp format my_tz = -4 # timezone (GMT/UTC) offset my_lat = 37 # lat (N positive) my_lon = -76.4 # lon (E positive) sc = solar(my_lat, my_lon, my_datestamp, my_tz, my_fmt) sc.compute_all() sc.summarize() class landsat_metadata: A landsat metadata object. This class builds is attributes from the names of each tag in the xml formatted .MTL files that come with landsat data. So, any tag that appears in the MTL file will populate as an attribute of landsat_metadata. You can access explore these attributes by using, for example .. code-block:: python from dnppy import landsat meta = landsat.landsat_metadata(my_filepath) # create object from pprint import pprint # import pprint pprint(vars(m)) # pretty print output scene_id = meta.LANDSAT_SCENE_ID # access specific attribute :param filename: the filepath to an MTL file. def __init__(self, filename): There are several critical attributes that keep a common naming convention between all landsat versions, so they are initialized in this class for good record keeping and reference # custom attribute additions self.FILEPATH = filename self.DATETIME_OBJ = None # product metadata attributes self.LANDSAT_SCENE_ID = None self.DATA_TYPE = None self.ELEVATION_SOURCE = None self.OUTPUT_FORMAT = None self.SPACECRAFT_ID = None self.SENSOR_ID = None self.WRS_PATH = None self.WRS_ROW = None self.NADIR_OFFNADIR = None self.TARGET_WRS_PATH = None self.TARGET_WRS_ROW = None self.DATE_ACQUIRED = None self.SCENE_CENTER_TIME = None # image attributes self.CLOUD_COVER = None self.IMAGE_QUALITY_OLI = None self.IMAGE_QUALITY_TIRS = None self.ROLL_ANGLE = None self.SUN_AZIMUTH = None self.SUN_ELEVATION = None self.EARTH_SUN_DISTANCE = None # calculated for Landsats before 8. # read the file and populate the MTL attributes self._read(filename) def _read(self, filename): reads the contents of an MTL file # if the filename input is actually already a metadata class object, return it back. if inspect.isclass(filename): return filename fields = metafile = open(filename, 'r') metadata = metafile.readlines() for line in metadata: # skips lines that contain bad flags denoting useless data AND lines # greater than 1000 characters. 1000 character limit works around an odd LC5 # issue where the metadata has 40,000+ characters of whitespace bad_flags = if not any(x in line for x in bad_flags) and len(line) = 1000: try: line = line.replace( , ) line = line.replace(\\n, ) field_name, field_value = line.split(' = ') fields.append(field_name) values.append(field_value) except: pass for i in range(len(fields)): # format fields without quotes,dates, or times in them as floats if not any( , 'DATE' in fields , 'TIME' in fields ]): setattr(self, fields , float(values )) else: values = values .replace('', '') setattr(self, fields , values ) # create datetime_obj attribute (drop decimal seconds) dto_string = self.DATE_ACQUIRED + self.SCENE_CENTER_TIME self.DATETIME_OBJ = datetime.strptime(dto_string.split(.) , %Y-%m-%d%H:%M:%S) # only landsat 8 includes sun-earth-distance in MTL file, so calculate it # for the Landsats 4,5,7 using solar module. if not self.SPACECRAFT_ID == LANDSAT_8: # use 0s for lat and lon, sun_earth_distance is not a function of any one location on earth. s = solar(0, 0, self.DATETIME_OBJ, 0) self.EARTH_SUN_DISTANCE = s.get_rad_vector() print(Scene {0} center time is {1}.format(self.LANDSAT_SCENE_ID, self.DATETIME_OBJ))
个人分类: 科研笔记|10354 次阅读|0 个评论
[转载]垃圾分类和语义网
timy 2011-11-14 19:57
From: http://blog.baojie.org/2011/11/09/semantic-web-is-a-life-style/ 垃圾分类和语义网 2011/11/09 Jie Bao 发表评论 Go to comments 我搬到加州来后,生活发生了很大的变化,其中之一就是处理垃圾的方式。我现在住的小区垃圾是分类的,很简单,分为可回收垃圾和不可回收垃圾。在纳舒厄(Nashua)住的时候,垃圾是不分类的,我们只有一个垃圾桶,很小的一个。其实我们家是有大号垃圾桶的,但是一直不用。为什么呢?因为大号垃圾桶要好几天甚至一个星期才能填满,里面的东西早臭了。 现在垃圾要分类了,我们家厨房也需要两个垃圾桶。一开始,我觉得这是一个非常挑战我的耐心的繁琐的工作。你想想,我本来生活的好好的,现在非要在扔每一个东西的时候都要想一下,到底是A桶还是B桶,这不是添加了额外的负担?要知道,我从来不是个环保主义者。 出于尽可能偷懒的原则,我和媳妇商量后,决定这样: 大垃圾桶(终于用上了)装可回收垃圾:纸张,玻璃,塑料,金属,木头,等等 小垃圾桶装不可回收垃圾:其他一切 为什么?因为可回收垃圾恰好是那些不会发臭的东西,放久一点也没有关系。小垃圾桶倒得勤一点就是。 在新家住了两个星期,这个原则被很好的执行了,而且成了一种自觉地习惯,因为我们发现这样做有很大的好处!再次重申,我从来不是一个虚伪的环保主义者(如戈尔之流),我确实自私地发现了垃圾分类对我自己带来了立即的好处,甚至后悔为什么以前不这样做。 第一,我倒垃圾的频率降低了。原来我每天要倒一到两次垃圾,现在小垃圾桶大概两天倒一次(还没有变臭),大垃圾桶超过一周才倒一次。 第二,垃圾袋的需要数量下降了。一个大垃圾桶的垃圾袋可以装10倍于小垃圾桶袋子的东西。这样每周购物袋就足够装小垃圾桶,不用再买。 第三,如果扔了不该扔的广告,优惠券,杂志,论文什么的,还可以捡回来,不用担心脏了。 于是,垃圾分类变成了一件很愉快的事,成了我的一个新的生活习惯。 某天,在我考虑尿布算可回收还是不可回收垃圾的时候,我突然联想到,其实语义网的实现,和垃圾分类制度有很多相似之处。 垃圾分类其实就是我给垃圾(“数据”)加元数据的过程。这个过程能够成为我的生活习惯,是因为它满足了如下的特点: 它虽然有点麻烦,但还不是过于麻烦 。试想如果一个垃圾分类制度,要求我区分有机可回收垃圾(纸张,木头等),无机可回收垃圾(玻璃,金属等),有机不可回收垃圾(食物残渣等),无机不可回收垃圾(比如电池),这可能就超过了我的耐心和智力的极限。 它给我带来立即的好处,而不是长期以后的好处 (比如减缓地球变暖)。而且,只要我做了,我就给自己带来好处,不需要等我的邻居都这样做。 它对现有系统的改造要求很小 ,原有的垃圾桶都可以用,只不过组合方式变了一下。厨房放两个垃圾桶还比较容易,如果要更多,那我只好再去买垃圾桶,而且也未必有足够的地方放。(注:分类垃圾处理可能和不分类的有区别——比如原来只要填埋就可以了,现在还要建回收厂;不过这对普通群众是不可见的。而且,原来的填埋机制还继续可用。) 传统的语义网技术之所以到目前应用还很少,不是因为它缺少了上面的特点吗? 麻烦的元数据生成 。要知道,即使是最简单的分类和加标签,对大多数Web用户都是一个智力和耐心的极大挑战。即使是简单的垃圾二分法,也依赖于我多年的生活经验——我们家妞就完全搞不懂。元数据如果来自用户,必须尽可能的不改变他本来的工作/生活方式,尽可能的不要求知识背景。如果能分两类的,就不要分四类。如果能完全不要用户参与分类,那最好——比如我们家妞就完全不用操心,自有别人代劳决定尿布算哪一类。 元数据的发布缺少及时回报效应 。用户为什么懒得提供元数据?无利不起早,没有好处,只有付出的事,谁会做?而且这个回报,还不能是太久以后,最好是立竿见影的。比如一个餐馆老板,你和说Pizza或者Wine本体有什么用,他云里雾里,看不见可行的赚钱门路;你演示给他看,用餐馆本体( schema.org )给他餐馆主页加几个标签,或者上传点菜单到 allmeus.com ,Google搜索立即排名提高,那他就有动力做下去。 修正主义还是革命? 一说语义网应用,上来就说RDF,OWL,SPARQL,Triple Store,Ontology Editor,等等,先不说招一个真懂这些的程序员要多少钱,就说怎么和原有的数据、服务结合,就是一个头疼的问题。有些革命性的前驱,2009年就全用Triple Store搭应用,200万用户就死掉了,关门。即使是现在,依我看,修正主义的态度还是要好一点,对现有系统的改造还是保守一点好。即使你是搭一个新的系统,本体是能简单就简单,推理机甚至Triple Store能不用就不用。你说,这都不用,那还叫什么语义网应用?我反驳说,并不需要在家里装一个垃圾分类机器人才能搞垃圾分类。 长期看,元数据的产生和使用,也就是语义网,是一种生活方式。Web现在就是一种生活方式。我岳父在美国的时候,特别不理解我们为什么一回家就在网上泡着。可是,唔,现在除了上网还能干什么?或者说,什么不是在网上(如下图)?生活方式是很难培养的,但一旦形成也很难改变。又比如说写东西,我再也不会用笔和纸写任何长的文章——因为我已经习惯了电子写作非线性的思维方式。语义网也会改变人的生活甚至思维方式。但在目前,还是应该先做“垃圾分类”这种规模的小事。
个人分类: 信息组织|2725 次阅读|0 个评论
学术报告预报: 作为数字存档基础设施的元数据
热度 3 Wuyishan 2011-10-25 08:06
学术报告预报 题 目: 作为数字存档基础设施的元数据:关于数字资源存档与保存的思考(用英文讲授) 报告人 : 杉本茂雄( SUGIMOTO Shigeo )教授 日本筑波大学 时 间: 2011 年 10 月 27 日(星期四)下午 2:00 地 点: 中国科学技术信息研究所一层第五会议室 ( 196 房间) (北京复兴路 15 号,中央电视台西侧) 杉本茂雄教授简介: 日本筑波大学图书馆、信息和媒体学研究生院教授。他目前担任知识社区研究中心的主任。他于 1977, 1979 和 1985 年在京都大学信息科学系分别获得学士、硕士和博士学位。他于 1983 年进入日本图书情报学大学,该大学于 2002 年被并入筑波大学,并更名为筑波大学图书馆、信息和媒体研究生院。杉本茂雄教授的研究方向为数字图书馆、数字存档和元数据。杉本茂雄教授对信息学院间的国际合作也非常有兴趣,他多次参与重大的国际会议,曾担任 ICADL 2006 和 JCDL 2007 的联合主席。目前,杉本茂雄教授担任 JCDL 和 ICADL 指导委员会委员,以及都柏林核心元数据倡议监督委员会和咨询委员会委员。 内容简介 : 杉本茂雄教授将从个人的角度来谈谈数字存档与保存的问题。首先将阐明一些背景问题,以帮助分享所讨论内容的知识及对它的理解。就背景问题而言,主要涉及术语和基本概念,以及报告人所参与的一些活动,以帮助听众更好地理解本次报告的相关内容。其次,将对数字存档中的相关元数据问题进行探讨,这些问题选自于报告人最近的研究活动,如,作为因特网上元数据共享的基础设施的元数据标准注册系统,用于文件管理和存档的面向任务的元数据模型,以及云计算环境中数字资源的分层元数据等。 欢迎所内外各界人士踊跃参加! 中国科学技术信息研究所 信息资源中心 学术委员会 二○一一年十月十九日
个人分类: 图书情报学研究|4331 次阅读|4 个评论
信息资源整合方式
lengxiaozi 2011-6-15 22:22
按照整合方法的不同可以把资源整合分为数据层的资源整合和虚拟资源整合。所谓数据层的资源整合是将不同的数据资源以某种统一的方式构建成数据仓储库,是一种物理集成方式;虚拟资源整合是在数据资源不变的情况下(分库存在)利用各种技术实现跨库检索,以此达到资源的整合。基于数据层的资源整合能够实现统一检索功能,此外还可以进行一些数据分析、数据挖掘,但是构建数据仓储库是一种费时费力的工程。而且现在各个数据厂商各自为政,数据格式不一,还存在重复数据。这都为数据层的资源整合带来困难,涉及到的技术主要是元数据收割技术和ETL技术。虚拟资源整合主要是利用一些技术手段,如SFX、openurl等实现信息资源的统一检索,不利于以后资源的深度挖掘。因此现在基于元数据仓储的信息资源整合是发展趋势。
个人分类: 工作心得|4431 次阅读|0 个评论
[转载]只有元数据能救数字图书馆----张晓林
wlp8631 2010-4-28 16:20
张晓林:只有元数据能救数字图书馆? 关键词 : 张晓林 数字图书馆 元数据 2004 年 10 月在上海召开的 DC2004 国际元数据会议上,中科院文献情报中心主任张晓林教授作为第一位主题报告的演讲者,作了题为《 Driving Digital Libraries Forward by Metadata Development 》 的主旨发言,发言中系统阐述了他牵头的科技部科技基础条件平台工作重点项目我国数字图书馆标准与规范项目 (Chinese Digital Library Standards ,简称 CDLS) 的背景、意义、作用和预期取得的成果。张晓林教授在图书馆学和情报学领域有着全面的训练和造诣,但是他近年来更多地是以一个技术驱动论者的形象出现,大量丰富的著述和演讲集中在数字图书馆和元数据领域。此次演讲也是他近年来思索的一个集中反映。 在 张晓林 教授看来,数字图书馆存在于分布、异构、动态的网络环境中,必须依据一定的原则进行建设才能确保其可获得、可互操作及可持续发展,这些原则就是模块化、开放集成、开放服务以及可伸缩可扩展。依据这些原则, 张 教授提出一个与 5S 模型完全不同的数字资源生命周期模型(如图三所示),虽然没有在其中明确定义数字图书馆的边界,但对于这样一种开放的认识,所有的相关部分都是数字图书馆的领域范围,而且 张 教授认为,这个模型也提供了数字图书馆标准规范建设的一个框架,基于对这个模型的所有实体及其相互关系的描述而实现的丰富多彩的功能,是驱动数字图书馆建设和发展的核心内容,因此以数字图书馆的标准规范建设(主要是元数据标准规范)来促进数字图书馆的建设和发展是一条必须的和可行的道路。 !-- -- !-- -- 图示:数字资源的生命周期模型 完整全面的标准规范对于数字图书馆建设无疑具有非常重要的意义。然而应该说在目前我国数字图书馆建设所面临的技术、法规和模式三大难题当中,技术因素是比较容易解决和相对次要的。而且仅就技术问题而言,不同的模型所提供的视角不同,所归纳整理的问题也不同,特别对于发展迅速的 IT 应用来说,标准规范实在只是个相对的、应该退居后台的东西。在这里需要说明的是, 张晓林 教授从来没有说过诸如只有元数据能救数字图书馆的话,这个标题,只是对目前国内数字图书馆界重技术而不重应用的一种反思和忧虑。目前国内数字图书馆应用真正需要的,是集成了各类标准规范在内的、直接面向应用的解决方案,就像 DSpace 、 Fedora 、 5S 系列开源软件以及 Greenstone 那种,甚至解决部分问题的 OAI 、 OpenURL 、 LOCKSS 等也可资使用,一些语义 Web 的杀手级应用也可望于近期能够出来。而绝不是那些号称提供数字图书馆解决方案的计算机公司所提供的那些混淆视听的东西。技术问题从来都不应该是图书馆员们操心的内容,但是如果图书馆员不尽早参与,数字图书馆是不会成功的,美国对 DLI 研发历史的反思就说明了这一点。而我们的情况正好相反:只有图书馆员关心数字图书馆。上面列举的一些数字图书馆软件和解决方案可能对我国以图书馆员为主的数字图书馆建设者们来说也还是太复杂了,这就给我们这个行业的一些 Key Player 们(关键人物,如 张晓林 教授等)提出了一个课题,应该由图书馆界来主导数字图书馆发展的潮流,提供需求,参与解决方案的研发,而不是由计算机界或者企业界主导。图书馆界需要数字图书馆标准规范,但是远远不止这些。 !-- -- !-- -- !-- -- 其中文版名为《以元数据的发展促进数字图书馆的前进》,刊登在上海科技文献出版社出版的图书馆杂志《理论学术年刊 2004 》。 注释:此文是张晓林写的论文元数据科研成果。
个人分类: 数字图书馆|103 次阅读|0 个评论
我国政府信息资源元数据核心集CGIMC建议方案
wangfangnk 2009-2-28 06:55
三、我国政府信息资源元数据核心集CGIMC方案 ??对于我国来说,政府信息资源的元数据体系,不仅是电子政务环境下公众和企业迅速定位和检索政府信息资源的重要目录体系,同时也是跨地区、跨部门的政府机构交换、共享信息资源的互操作描述标准。我国政府信息资源元数据体系的建立,应该满足以下几点要求: ??(1)标准化 ??元数据的标准化是政府信息资源共享的重要前提,也是国际信息交换与跨语言检索的重要基穿? ??(2)可扩展 ??政府信息资源内容形式复杂多样,涉及到档案文献、数据库系统、空间地理数据、网页等等,特定的资源对象常常有特定的元数据标准。因此,政府信息资源元数据的核心元素集应该具有充分的可扩展性,以适应描述不同类型的资源对象,同时为不同元数据标准间的互操作提供基穿? ??(3)技术性 ?? 作为分布式的网络系统,电子政务的元数据不仅要能静态地描述信息资源,同时还要能支持网络环境下的互操作与信息共享,因此要求在技术上具有成熟性和可操作性。 ? (4)互操作性 ??由不同组织管理的、采用不同技术、异构的分布式系统所组成的团体被称为联盟,电子政务系统是一个典型的联盟。为了向用户提供一致的服务,需要联盟成员的系统元数据之间具有互操作性。为了实现互操作,需要它们在技术、资源内容和组织管理上达成一致性协议。William Y. Arms?定义了三种层次的互操作:联盟,采集和搜集,这三个层次对成员间联系的紧密程度依次降低。比如Z39.50实现了联盟层次的互操作,OAI(Open Archives Initiative)就是基于元数据采集的思想,而互联网的搜索引擎则属于搜集层次的互操作协议。 ??我国政府信息资源同样具有异构、海量与分布式存储的特征,并且与数字城市系统具有密不可分的关系。因此,我国政府信息资源的元数据体系在描述框架、网络传输、Web服务等方面应充分考虑不同信息资源的的互操作问题,比如空间地理、气象、人口、公文等信息资源的特征,并充分考虑与我国的数字图书馆著录项目CNMARC以及DC之间的映射。考虑到专业元素设置、应用实施的可操作性等问题,根据上文的对比分析,我们建议以GILS为基础,针对我国国情进行适当的调整和修正。 ??具体地,我们结合政府信息资源统一交换目录体系、中国文书分类方法、中国档案分类方法、中国档案排架方法、《国务院公文主题词表》等的基本思想,探索性地将我国政府信息资源的元数据核心元素定义为五大类共23个,如表2所示: 表2 我国政府信息资源元数据核心集建议方案(CGIMC, China Government Information Metadata Core) ?元数据类型元素名称元素描述 ? 资源内容元数据 ?1、题名 ?2、文摘资源主要内容的摘要 ?3、主题词 以我国《国务院公文主题词表》及各部委制定的行业?专门主题词表为依据 ?? 关键词或非受控主题词 ?4、参照参考文献 ?? 相关信息 ?? 网络链接地址 ?5、空间域边界坐标 地理位置 ?6、时期与资源相关的时间,如起始时间 资源责任元数据 ?7、创作者 ?8、其他责任者 ?9、记录来源指明创作或最后修改该记录的机构 ?10、方法 产生资源所使用的特殊方法,以保证资源的真实性与有效性 ?11、出版或发布者 ?12、出版或发布日期 资源表示元数据 ?13、记录语种资源所使用的语种 ?14、记录格式资源的文件格式 ?15、控制识别将此条记录与其他记录区别开来的标志 资源获取元数据 ?16、可获得性(Availability)资源描述:关于资源内容与外部形态的描述    获取或订购途径    获取技术条件    可获得日期    可获得的链接 ?17、记录索取号目录号,或其他索取号如档号、文件分类号 ?18、获取限制一般获取限制,安全级别、或密级以及创作者 关于资源传播与使用限制的声明 ?19、使用限制关于资源使用的法律及技术条件,如资源使用所需的硬件、软件与网络条件 资源管理元数据 ?20、存储信息存储的地点、期限与介质类型 ?21、使用信息使用者、使用时间及目的的相关信息 ?22、维护信息备份、升级或格式转换等信息 ?23、变更信息最后修改日期:记录最后被修改的日期    记录复核日期:记录最后复议审核的日期    删除或终止保存日期 在这个建议方案中,CGIMC借鉴了GILS与DC-government的内容,针对政府信息资源的一些特点,结合我国电子政务正在建设扩充阶段的实际情况,在内容元数据中引进了空间域、时期与参照栏目,在责任元数据中特别突出了证明资源真实有效性的方法一栏。整个元数据体系特别强调了资源获取信息的描述,如资源密级等获取限制,以及相关的使用技术条件。最后考虑到政府信息资源的长期保存与保护问题,引入了资源管理元数据,以保证政府信息资源的变更记录与长期的真实有效性。 ??关于方案中元素的句法结构,需要参照RDF框架,借鉴GILS的做法,进行具体定义。初步看来,此方案考虑不同行业性质的政府信息资源特点,可以与一些专业性质的元数据体系,比如空间地理信息元数据标准集、数字图书馆元数据体系等,做出映射地图。支持MARC格式,不同专业性质的的部门可以根据自身的特点对相关的元素进行增删取舍。关于其扩展性可以通过两种途径:一是通过增加新的元素或者二级元素来实现资源特征描述;二是通过句法结构与修饰语来增加元素的适用范围。关于其互操作以及网络环境下的查询、交换与共享服务,需要遵循下文中的标准与协议。 节选自:王芳.我国电子政务元数据的构建及其基于WEB服务的共享实现.情报学报,2007,1
个人分类: 电子政务|5712 次阅读|0 个评论

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-3 16:45

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部