Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*resolution* is chosen automatically if None (default), otherwise it should be one of:
+-----+-------------------------+---------+
| 'f' | Full resolution | 0.04 km |
| 'h' | High resolution | 0.2 km |
| 'i' | Intermediate resolution | 1.0 km |
| 'l' | Low resolution | 5.0 km |
| 'c' | Crude resolution | 25 km |
+-----+-------------------------+---------+
"""
img = self.pil_image()
import ConfigParser
conf = ConfigParser.ConfigParser()
conf.read(os.path.join(CONFIG_PATH, "satpy.cfg"))
coast_dir = conf.get('shapes', 'dir')
logger.debug("Getting area for overlay: " + str(self.area))
if self.area is None:
raise ValueError("Area of image is None, can't add overlay.")
from satpy.projector import get_area_def
if isinstance(self.area, str):
self.area = get_area_def(self.area)
logger.info("Add coastlines and political borders to image.")
logger.debug("Area = " + str(self.area))
if resolution is None:
def read_raw(filename):
"""Read *filename* without scaling it afterwards."""
form = XMLFormat(os.path.join(CONFIG_PATH, "eps_avhrrl1b_6.5.xml"))
grh_dtype = np.dtype([("record_class", "|i1"),
("INSTRUMENT_GROUP", "|i1"),
("RECORD_SUBCLASS", "|i1"),
("RECORD_SUBCLASS_VERSION", "|i1"),
("RECORD_SIZE", ">u4"),
("RECORD_START_TIME", "S6"),
("RECORD_STOP_TIME", "S6")])
dtypes = []
cnt = 0
with open(filename, "rb") as fdes:
while True:
grh = np.fromfile(fdes, grh_dtype, 1)
if not grh:
break
def read_raw(filename):
"""Read *filename* without scaling it afterwards.
"""
form = XMLFormat(os.path.join(CONFIG_PATH, "eps_avhrrl1b_6.5.xml"))
grh_dtype = np.dtype([("record_class", "|i1"),
("INSTRUMENT_GROUP", "|i1"),
("RECORD_SUBCLASS", "|i1"),
("RECORD_SUBCLASS_VERSION", "|i1"),
("RECORD_SIZE", ">u4"),
("RECORD_START_TIME", "S6"),
("RECORD_STOP_TIME", "S6")])
record_class = ["Reserved", "mphr", "sphr",
"ipr", "geadr", "giadr",
"veadr", "viadr", "mdr"]
records = []
with open(filename, "rb") as fdes:
for filename in filenames:
new_name, ext = os.path.splitext(os.path.basename(filename))
del ext
new_name = os.path.join(WORKING_DIR, new_name)
cmd = (cat_cmd + " " +
filename + " > " +
new_name)
LOG.debug("running " + cmd)
proc = subprocess.Popen(cmd, shell=True)
proc.communicate()
new_names.append(new_name)
conffile = os.path.join(CONFIG_PATH, granules[0].fullname + ".cfg")
conf = ConfigParser()
conf.read(os.path.join(CONFIG_PATH, conffile))
directory = conf.get('avhrr-level1','dir')
filename = conf.get('avhrr-level1','filename')
filename = granules[0].time_slot.strftime(filename)
output_name = os.path.join(directory, filename)
arg_string = " ".join(new_names)
cmd = "$KAI/kai -i " + arg_string + " -o " + output_name
proc = subprocess.Popen(cmd, shell=True)
(out, err) = proc.communicate()
if out:
LOG.debug(out)
if err:
LOG.error(err)
zipfile = bz2.BZ2File(filename)
newname = os.path.join("/tmp", os.path.basename(pathname))
if not os.path.exists(newname):
with open(newname, "wb") as fp_:
fp_.write(zipfile.read())
zipfile.close()
files_to_load.append(newname)
files_to_delete.append(newname)
else:
files_to_load.append(filename)
else:
time_start, time_end = kwargs.get("time_interval",
(satscene.time_slot, None))
conf = ConfigParser()
conf.read(os.path.join(CONFIG_PATH, satscene.fullname + ".cfg"))
options = {}
for option, value in conf.items(satscene.instrument_name + "-level2",
raw=True):
options[option] = value
template = os.path.join(options["dir"], options["filename"])
second = timedelta(seconds=1)
files_to_load = []
if time_end is not None:
time = time_start - second * 85
files_to_load = []
while time <= time_end:
fname = time.strftime(template)
flist = glob.glob(fname)
def load(satscene):
"""Read data from file and load it into *satscene*.
"""
conf = ConfigParser()
conf.read(os.path.join(CONFIG_PATH, satscene.fullname + ".cfg"))
options = {}
for option, value in conf.items(satscene.instrument_name + "-level2",
raw=True):
options[option] = value
LOAD_CASES[satscene.instrument_name](satscene, options)
raise IOError("No l1b file matching!: %s", filename)
else:
filename = file_list[0]
LOGGER.debug("Loading from %s", filename)
scene = AAPP1b(filename)
try:
scene.read()
except ValueError:
LOGGER.info("Can't read %s, exiting.", filename)
return
if options["use_extern_calib"]:
import h5py
LOGGER.info("Reading external calibration coefficients.")
fid = h5py.File(os.path.join(CONFIG_PATH,
satscene.satname + '_calibration_data.h5'))
calib_coeffs = {}
for key in fid.keys():
date_diffs = []
for dat in fid[key]['datetime']:
date_diffs.append(np.abs(satscene.time_slot - \
datetime.datetime(dat[0],
dat[1],
dat[2])))
idx = date_diffs.index(min(date_diffs))
date_diff = satscene.time_slot - \
datetime.datetime(fid[key]['datetime'][idx][0],
fid[key]['datetime'][idx][1],
fid[key]['datetime'][idx][2])
if date_diff.days > 0:
older_or_newer = "newer"
def load(satscene, *args, **kwargs):
"""Read data from file and load it into *satscene*.
"""
del args, kwargs
conf = ConfigParser()
conf.read(os.path.join(CONFIG_PATH, satscene.fullname + ".cfg"))
options = {}
for option, value in conf.items(satscene.instrument_name + "-level2",
raw=True):
options[option] = value
CASES[satscene.instrument_name](satscene, options)
def load(satscene, *args, **kwargs):
"""Read data from file and load it into *satscene*.
A possible *calibrate* keyword argument is passed to the AAPP reader.
Should be 0 for off (counts), 1 for default (brightness temperatures and
reflectances), and 2 for radiances only.
If *use_extern_calib* keyword argument is set True, use external
calibration data.
"""
del args
conf = ConfigParser()
conf.read(os.path.join(CONFIG_PATH, satscene.fullname + ".cfg"))
options = {}
for option, value in conf.items(satscene.instrument_name + "-level2",
raw=True):
options[option] = value
if kwargs.get("filename") is not None:
options["full_filename"] = kwargs["filename"]
options["calibrate"] = kwargs.get("calibrate", True)
options["pre_launch_coeffs"] = kwargs.get("pre_launch_coeffs", False)
options["use_extern_calib"] = kwargs.get("use_extern_calib", False)
LOGGER.info("Loading instrument '%s'", satscene.instrument_name)
try:
CASES[satscene.instrument_name](satscene, options)
products.append("PC")
if "CPP" in scene.channels_to_load:
products.append("CPP")
if len(products) == 0:
return
try:
area_name = scene.area_id or scene.area.area_id
except AttributeError:
area_name = "satproj_?????_?????"
conf = ConfigParser.ConfigParser()
conf.read(os.path.join(CONFIG_PATH, scene.fullname+".cfg"))
directory = conf.get(scene.instrument_name+"-level3", "dir")
try:
geodir = conf.get(scene.instrument_name+"-level3", "geodir")
except NoOptionError:
LOG.warning("No option 'geodir' in level3 section")
geodir = None
filename = conf.get(scene.instrument_name+"-level3", "filename",
raw=True)
pathname_tmpl = os.path.join(directory, filename)
if not geofilename and geodir:
# Load geo file from config file:
try:
if not scene.orbit:
orbit = ""