def concatenate(granules, channels=None): """Concatenate hrpt files. """ filenames = [os.path.join(granule.directory, granule.file_name) for granule in granules] arg_string = " ".join(filenames) if filenames[0].endswith(".bz2"): cat_cmd = "bzcat" else: cat_cmd = "cat" conffile = os.path.join(CONFIG_PATH, granules[0].fullname + ".cfg") conf = ConfigParser() conf.read(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) cmd = cat_cmd + " " + arg_string + " > " + output_name LOG.debug(cmd) proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = proc.communicate() if out: LOG.debug(out) if err: LOG.error(err) LOG.debug("Done concatenating level0 files.") new_dir = conf.get(granules[0].instrument_name + "-level2", "dir") new_name = conf.get(granules[0].instrument_name + "-level2", "filename") pathname = os.path.join(new_dir, granules[0].time_slot.strftime(new_name)) shortname = conf.get('avhrr-level1','shortname') convert_to_1b(output_name, pathname, granules[0].time_slot, granules[-1].time_slot + granules[-1].granularity, shortname, get_orbit(granules[0].time_slot, shortname)) os.remove(output_name) scene = PolarFactory.create_scene(granules[0].satname, granules[0].number, granules[0].instrument_name, granules[0].time_slot, get_orbit(granules[0].time_slot, shortname), variant=granules[0].variant) scene.load(channels) os.remove(pathname) return scene
def test_case_1(): tle1 = "1 26536U 00055A 13076.42963155 .00000201 00000-0 13237-3 0 1369" tle2 = "2 26536 99.0540 128.2392 0010826 39.9070 85.2960 14.12848373643614" scanline_nb = 5680 scan_points = np.arange(24, 2048, 40) #t = datetime(2013, 3, 18, 8, 15, 21, 186000) t = datetime(2013, 3, 18, 8, 15, 22, 352000) #t = datetime(2013, 3, 18, 8, 15, 23, 186000) sgeom = avhrr(scanline_nb, scan_points, 55.25) rpy = [ np.deg2rad(-37.0 / 1000), np.deg2rad(-11.0 / 1000), np.deg2rad(146.0 / 1000) ] #rpy = [0, 0, 0] s_times = sgeom.times(t) print "s_times", s_times.dtype print(s_times[25::51]) pixels_pos = compute_pixels((tle1, tle2), sgeom, s_times, rpy) pos_time = get_lonlatalt(pixels_pos, s_times) # return pixels_pos g = PolarFactory.create_scene("noaa", "16", "avhrr", t, orbit="64374") lons, lats = cached_lonlats(g) # print lats.shape, pos_time[0].shape # print np.sqrt(np.max(lons - pos_time[0].reshape(lons.shape)) ** 2 + np.max(lats - pos_time[1].reshape(lats.shape)) ** 2) # print "max", np.max(abs(lons - pos_time[0].reshape(lons.shape))) # print "max", np.max(abs(lats - pos_time[1].reshape(lats.shape))) print lons.shape plot(pos_time[0], pos_time[1], lons, lats)
def loadGranules(path, band): # A better way to do this might be glob the directory, and create a union of all the # unique combos of _t and _d components files = [] band_prefix = "SV" for file in os.listdir(path): if fnmatch.fnmatch( file, "{band_prefix}{band}*".format(band_prefix=band_prefix, band=band)): files.append(file) #Iterate through the files, generating a datetime object and creating # a PolarFactory object for it. Append to the granules array granules = [] for file in files: parts = file.split('_') year = int(parts[2][1:5]) month = int(parts[2][5:7]) day = int(parts[2][7:9]) hour = int(parts[3][1:3]) minute = int(parts[3][3:5]) orbit = parts[5][1:6] ts = datetime.datetime(year, month, day, hour, minute) #Create the granule, and if it's ok (not a tiny file, not from 1958) # load the requested bands and append it to the scene granule = PolarFactory.create_scene("npp", "1", "viirs", ts, orbit) # if isvalidgranule(granule, bands, path): granule.load([band], dir=path) granules.append(granule) # else: # break print "Found %d granules" % len(granules) return granules
def test_case_5(): tle1 = "1 28654U 05018A 08167.42204778 -.00000193 00000-0 -82304-4 0 4671" tle2 = "2 28654 98.8667 108.3736 0013786 323.0689 36.9527 14.11168946158226" scanline_nb = 5121 scan_points = np.arange(24, 2048, 40) t = datetime(2008, 6, 16, 11, 48, 48, 616000) sgeom = avhrr(scanline_nb, scan_points) # 171, 105, 32 #rpy = [np.deg2rad(-37.0/1000), np.deg2rad(-11.0/1000), np.deg2rad(146.0/1000)] rpy = [0, 0, 0] rpy = [ np.deg2rad(171.0 / 1000), np.deg2rad(105.0 / 1000), np.deg2rad(32.0 / 1000) ] s_times = sgeom.times(t) pixels_pos = compute_pixels((tle1, tle2), sgeom, s_times, rpy) pos_time = get_lonlatalt(pixels_pos, s_times) g = PolarFactory.create_scene("noaa", "18", "avhrr", t, orbit="15838") lons, lats = cached_lonlats(g) print np.sqrt( np.max(lons - pos_time[0].reshape(lons.shape))**2 + np.max(lats - pos_time[1].reshape(lats.shape))**2) print "max", np.max(abs(lons - pos_time[0].reshape(lons.shape))) print "max", np.max(abs(lats - pos_time[1].reshape(lats.shape))) plot(pos_time[0], pos_time[1], lons, lats)
def test_case_3(): tle1 = "1 33591U 09005A 12345.45213434 .00000391 00000-0 24004-3 0 6113" tle2 = "2 33591 098.8821 283.2036 0013384 242.4835 117.4960 14.11432063197875" scanline_nb = 351 scan_points = np.arange(24, 2048, 40) t = datetime(2012, 12, 12, 4, 17, 1, 575000) sgeom = avhrr(scanline_nb, scan_points) rpy = (0, 0, 0) s_times = sgeom.times(t) pixels_pos = compute_pixels((tle1, tle2), sgeom, s_times, rpy) pos_time = get_lonlatalt(pixels_pos, s_times) g = PolarFactory.create_scene("noaa", "19", "avhrr", t, orbit="19812") lons, lats = cached_lonlats(g) print np.sqrt( np.max(lons - pos_time[0].reshape(lons.shape))**2 + np.max(lats - pos_time[1].reshape(lats.shape))**2) print "max", np.max(abs(lons - pos_time[0].reshape(lons.shape))) print "max", np.max(abs(lats - pos_time[1].reshape(lats.shape))) plot(pos_time[0], pos_time[1], lons, lats)
def test_case_4(): tle1 = "1 26536U 00055A 12312.31001555 .00000182 00000-0 12271-3 0 9594" tle2 = "2 26536 99.0767 356.5209 0011007 44.1314 316.0725 14.12803055625240" scanline_nb = 5428 scan_points = np.arange(24, 2048, 40) t = datetime(2012, 11, 7, 9, 33, 46, 526000) sgeom = avhrr(scanline_nb, scan_points, 55.25) rpy = [ np.deg2rad(-9.0 / 1000), np.deg2rad(-199.0 / 1000), np.deg2rad(-11.0 / 1000) ] s_times = sgeom.times(t) pixels_pos = compute_pixels((tle1, tle2), sgeom, s_times, rpy) pos_time = get_lonlatalt(pixels_pos, s_times) g = PolarFactory.create_scene("noaa", "16", "avhrr", t, orbit="62526") lons, lats = cached_lonlats(g) print np.sqrt( np.max(lons - pos_time[0].reshape(lons.shape))**2 + np.max(lats - pos_time[1].reshape(lats.shape))**2) print "max", np.max(abs(lons - pos_time[0].reshape(lons.shape))) print "max", np.max(abs(lats - pos_time[1].reshape(lats.shape))) plot(pos_time[0], pos_time[1], lons, lats)
def loadGranules(path, bands): # A better way to do this might be glob the directory, and create a union of all the # unique combos of _t and _d components files = [] for file in os.listdir(path): if fnmatch.fnmatch(file,"GMODO*"): files.append(file) #Iterate through the files, generating a datetime object and creating # a PolarFactory object for it. Append to the granules array granules = [] for file in files: parts = file.split('_') year = int(parts[2][1:5]) month = int(parts[2][5:7]) day = int(parts[2][7:9]) hour = int(parts[3][1:3]) minute = int(parts[3][3:5]) orbit = parts[5][1:6] ts = datetime.datetime(year, month, day, hour, minute) #Create the granule, and if it's ok (not a tiny file, not from 1958) # load the requested bands and append it to the scene granule = PolarFactory.create_scene("npp","1","viirs", ts, orbit) if isvalidgranule(granule, bands, path): granule.load(bands, dir=path) granule.area = granule[iter(bands).next()].area granules.append(granule) else: break print "Found %d granules" % len(granules) return granules
def concatenate(granules, channels=None): """Concatenate hrpt files. """ filenames = [ os.path.join(granule.directory, granule.file_name) for granule in granules ] arg_string = " ".join(filenames) if filenames[0].endswith(".bz2"): cat_cmd = "bzcat" else: cat_cmd = "cat" conffile = os.path.join(CONFIG_PATH, granules[0].fullname + ".cfg") conf = ConfigParser() conf.read(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) cmd = cat_cmd + " " + arg_string + " > " + output_name LOG.debug(cmd) proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = proc.communicate() if out: LOG.debug(out) if err: LOG.error(err) LOG.debug("Done concatenating level0 files.") new_dir = conf.get(granules[0].instrument_name + "-level2", "dir") new_name = conf.get(granules[0].instrument_name + "-level2", "filename") pathname = os.path.join(new_dir, granules[0].time_slot.strftime(new_name)) shortname = conf.get('avhrr-level1', 'shortname') convert_to_1b(output_name, pathname, granules[0].time_slot, granules[-1].time_slot + granules[-1].granularity, shortname, get_orbit(granules[0].time_slot, shortname)) os.remove(output_name) scene = PolarFactory.create_scene(granules[0].satname, granules[0].number, granules[0].instrument_name, granules[0].time_slot, get_orbit(granules[0].time_slot, shortname), variant=granules[0].variant) scene.load(channels) os.remove(pathname) return scene
def invoke(self, context): """...""" try: orbit = context["global_config"]["orbit"] ts = context["global_config"]["time_slot"] time_slot = datetime(ts[0], ts[1], ts[2], ts[3], ts[4]) global_data = PolarFactory.create_scene("noaa", "19", "avhrr", time_slot, orbit) global_data.load([10.8]) context[self.slots[0]]["content"] = global_data[10.8].data except Exception, e: raise e
def main(): g = PolarFactory.create_scene("npp", "", "viirs", t_start, orbit="07108") #g.load(g.image.green_snow.prerequisites | g.image.hr_overview.prerequisites # | g.image.dnb.prerequisites | g.image.truecolor.prerequisites, time_interval=(t_start, t_end)) g.load(["I01"]) gc.collect() #l = g.project("worldeqc30km") l = g.project("scan") gc.collect() #l["I01"].show() #l.image.truecolor().show() return # l.image.green_snow().save("/tmp/gs_world.png") # l.image.hr_overview().save("/tmp/ov_world.png") # l.image.dnb().save("/tmp/dnb_world.png") # del l # gc.collect() # l = g.project("euron1") # gc.collect() # l.image.green_snow().save("/tmp/gs_euron1.png") # l.image.hr_overview().save("/tmp/ov_euron1.png") # l.image.dnb().save("/tmp/dnb_euron1.png") # del l gc.collect() l = g.project("scan") gc.collect() l.image.green_snow().save("/tmp/gs_scan.png") l.image.hr_overview().save("/tmp/ov_scan.png") l.image.dnb().save("/tmp/dnb_scan.png") del l gc.collect() l = g.project("ssea250") gc.collect() l.image.green_snow().save("/tmp/gs_ssea250.png") l.image.hr_overview().save("/tmp/ov_ssea250.png") l.image.dnb().save("/tmp/dnb_ssea250.png")
""" return datetime(*time.strptime(string, fmt)[:6]) else: strptime = datetime.strptime if __name__ == '__main__': if len(sys.argv) < 3: print "Usage: " + sys.argv[0] + " time_string orbit" sys.exit() time_string = sys.argv[1] orbit = sys.argv[2] time_slot = strptime(time_string, "%Y%m%d%H%M") global_data = PolarFactory.create_scene("noaa", "19", "avhrr", time_slot, orbit) global_data.load() areas = ["euro4", "scan2"] for area in areas: local_data = global_data.project(area) img = local_data.image.overview() img.save("overview_" + area + "_" + time_string + ".png") img = local_data.image.cloudtop() img.save("cloudtop_" + area + "_" + time_string + ".png")
times = [] granules = [] #Iterate through the files, generating a datetime object and creating # a PolarFactory object for it. Append to the granules array for file in files: parts = file.split('_') year = int(parts[2][1:5]) month = int(parts[2][5:7]) day = int(parts[2][7:9]) hour = int(parts[3][1:3]) minute = int(parts[3][3:5]) orbit = parts[5][1:6] ts = datetime.datetime(year, month, day, hour, minute) granule = PolarFactory.create_scene("npp", "1", "viirs", ts, orbit) bands = set([ "I01", "M02", "M04", "M05", "I04", "M14", "M15", "M16", "I05" ]) if isvalidgranule(granule, bands, path): granule.load(bands, dir=path) granule.area = granule[iter(bands).next()].area granules.append(granule) #Load the necessary bands for truecolor for all the granules # Temporary workaround: copy the area of a band into the granule # This allows us to reproject it. This is a temporary fix until # MPOP is patched to do this automatically #bands = granules[0].image.truecolor.prerequisites #print "I have %d granules" % len(granules) #for granule in granules:
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """Code example with OSISAF SST with mpop """ from mpop.satellites import PolarFactory from mpop.imageo import geo_image, palettes import numpy as np from datetime import datetime glbd = PolarFactory.create_scene("Suomi-NPP", "", "viirs", datetime(2016, 9, 8, 13, 0), "") glbd.load(['SST']) areaid = 'euro4' localdata = glbd.project(areaid) sstdata = localdata["SST"].sst.data palette = palettes.sstlut_osisaf_metno() x = np.ma.where(np.less_equal(sstdata, 0), 0, sstdata - 273.15) # Convert sst to numbers between 0 and 28, corresponding to the lut: data = np.ma.where(np.less(x, 0), 28, 28.0 - x) data = np.ma.where(np.greater(x, 23.0), 4, data) # And we want discrete values: data = data.round().astype('uint8')
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """Code example with OSISAF SST with mpop """ from mpop.satellites import PolarFactory from mpop.imageo import geo_image, palettes import numpy as np from datetime import datetime glbd = PolarFactory.create_scene("Suomi-NPP", "", "viirs", datetime(2016, 9, 8, 13, 0), "") glbd.load(['SST']) areaid = 'euro4' localdata = glbd.project(areaid) sstdata = localdata["SST"].sst.data palette = palettes.sstlut_osisaf_metno() x = np.ma.where(np.less_equal(sstdata, 0), 0, sstdata - 273.15) # Convert sst to numbers between 0 and 28, corresponding to the lut: data = np.ma.where(np.less(x, 0), 28, 28.0 - x) data = np.ma.where(np.greater(x, 23.0), 4, data) # And we want discrete values: data = data.round().astype('uint8')
"modis": load_modis } LAT_LON_CASES = { "modis": get_lat_lon_modis } if __name__ == "__main__": filenames = [u'/data/prod/satellit/modis/lvl1/thin_MYD021KM.A2015287.0255.005.2015287051016.NRT.hdf', u'/data/prod/satellit/modis/lvl1/thin_MYD021KM.A2015287.0300.005.2015287050819.NRT.hdf', u'/data/prod/satellit/modis/lvl1/thin_MYD021KM.A2015287.0305.005.2015287050825.NRT.hdf'] from mpop.utils import debug_on debug_on() from mpop.satellites import PolarFactory from datetime import datetime time_slot = datetime(2015, 10, 14, 2, 55) orbit = "18181" global_data = PolarFactory.create_scene( "EARSEOS-Aqua", "", "modis", time_slot, orbit) global_data.load([3.75, 0.555, 0.551, 7.3, 1.63, 10.8, 0.488, 12.0, 0.85, 0.469, 0.748, 0.443, 0.645, 6.7, 0.635, 8.7, 0.412], filename=filenames) #global_data.channels_to_load = set(['31']) #reader = ModisReader(global_data) #reader.load(global_data, filename=filenames) print global_data # global_data[10.8].show()
"modis": load_modis } LAT_LON_CASES = { "modis": get_lat_lon_modis } if __name__ == "__main__": filenames = [u'/data/prod/satellit/modis/lvl1/thin_MYD021KM.A2015287.0255.005.2015287051016.NRT.hdf', u'/data/prod/satellit/modis/lvl1/thin_MYD021KM.A2015287.0300.005.2015287050819.NRT.hdf', u'/data/prod/satellit/modis/lvl1/thin_MYD021KM.A2015287.0305.005.2015287050825.NRT.hdf'] from mpop.utils import debug_on debug_on() from mpop.satellites import PolarFactory from datetime import datetime time_slot = datetime(2015, 10, 14, 2, 55) orbit = "18181" global_data = PolarFactory.create_scene("EARSEOS-Aqua", "", "modis", time_slot, orbit) global_data.load([3.75, 0.555, 0.551, 7.3, 1.63, 10.8, 0.488, 12.0, 0.85, 0.469, 0.748, 0.443, 0.645, 6.7, 0.635, 8.7, 0.412], filename=filenames) #global_data.channels_to_load = set(['31']) #reader = ModisReader(global_data) #reader.load(global_data, filename=filenames) print global_data #global_data[10.8].show()
# Collect general data from the name of the input files year = np.int((geofile.split(os.sep)[-1]).split('_')[3][1:5]) month = np.int((geofile.split(os.sep)[-1]).split('_')[3][5:7]) day = np.int((geofile.split(os.sep)[-1]).split('_')[3][7:9]) hour = np.int((geofile.split(os.sep)[-1]).split('_')[4][1:3]) minute = np.int((geofile.split(os.sep)[-1]).split('_')[4][3:5]) orbit = (geofile.split(os.sep)[-1]).split('_')[6][1:6] endHour = np.int((geofile.split(os.sep)[-1]).split('_')[5][1:3]) endMinute = np.int((geofile.split(os.sep)[-1]).split('_')[5][3:5]) start = datetime(year, month, day, hour, minute) end = datetime(year, month, day, endHour, endMinute) #geofile is just your GITCO* file time_slot = datetime(year, month, day, hour, minute) global_data = PolarFactory.create_scene("npp", "", "viirs", time_slot, orbit) ''' import utils import osr import pyproj srs = osr.SpatialReference() srs.ImportFromEPSG(3857) wgs84 = osr.SpatialReference() wgs84.ImportFromEPSG(4326) proj4_args =srs.ExportToProj4() proj4_args = '%s %s %s %s %s %s %s %s %s' % (proj4_args.split( ' ')[0][1:], \ proj4_args.split( ' ')[1][1:], proj4_args.split( ' ')[2][1:], proj4_args.split( ' ')[3][1:] \ , proj4_args.split( ' ')[4][1:], proj4_args.split( ' ')[5][1:], proj4_args.split( ' ')[6][1:] \ , proj4_args.split( ' ')[7][1:], proj4_args.split( ' ')[8][1:])
times = [] granules = [] #Iterate through the files, generating a datetime object and creating # a PolarFactory object for it. Append to the granules array for file in files: parts = file.split('_') year = int(parts[2][1:5]) month = int(parts[2][5:7]) day = int(parts[2][7:9]) hour = int(parts[3][1:3]) minute = int(parts[3][3:5]) orbit = parts[5][1:6] ts = datetime.datetime(year, month, day, hour, minute) granule = PolarFactory.create_scene("npp","1","viirs", ts, orbit) bands = set(["I01","M02","M04","M05","I04","M14","M15","M16","I05"]) if isvalidgranule(granule, bands, path): granule.load(bands, dir=path) granule.area = granule[iter(bands).next()].area granules.append(granule) #Load the necessary bands for truecolor for all the granules # Temporary workaround: copy the area of a band into the granule # This allows us to reproject it. This is a temporary fix until # MPOP is patched to do this automatically #bands = granules[0].image.truecolor.prerequisites #print "I have %d granules" % len(granules) #for granule in granules: #if isvalidgranule(granule, bands,path): #granule.load(bands, dir=path)
def concatenate(granules, channels=None): """Concatenate eps1a granules. """ if granules[0].file_type.startswith("bzipped"): cat_cmd = "bzcat" else: cat_cmd = "cat" new_names = [] filenames = [os.path.join(granule.directory, granule.file_name) for granule in granules] 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) #clean up for new_name in new_names: os.remove(new_name) new_dir = conf.get(granules[0].instrument_name + "-level2", "dir") new_name = conf.get(granules[0].instrument_name + "-level2", "filename") pathname = os.path.join(new_dir, granules[0].time_slot.strftime(new_name)) shortname = conf.get('avhrr-level1','shortname') orbit = get_orbit(granules[0].time_slot, shortname) convert_to_1b(output_name, pathname, granules[0].time_slot, shortname) os.remove(output_name) scene = PolarFactory.create_scene(granules[0].satname, granules[0].number, granules[0].instrument_name, granules[0].time_slot, orbit, variant=granules[0].variant) scene.load(channels) os.remove(pathname) return scene
def start_sst_processing(sst_file, message, **kwargs): """From a posttroll/trallstalker message start the osisaf sst post- processing""" LOG.info("") LOG.info("sst-file dict: " + str(sst_file)) LOG.info("\tMessage:") LOG.info(message) urlobj = urlparse(message.data['uri']) if 'start_time' in message.data and 'start_date' in message.data: dtdate = message.data['start_date'] dttime = message.data['start_time'] start_time = datetime(dtdate.year, dtdate.month, dtdate.day, dttime.hour, dttime.minute) scene_id = start_time.strftime('%Y%m%d%H%M') else: LOG.warning("No start time in message!") start_time = None return sst_file if 'end_time' in message.data and 'end_date' in message.data: dtdate = message.data['end_date'] dttime = message.data['end_time'] end_time = datetime(dtdate.year, dtdate.month, dtdate.day, dttime.hour, dttime.minute) else: LOG.warning("No end time in message!") end_time = None if (message.data['platform_name'] in ['Suomi-NPP', ] and message.data['instruments'] == 'viirs'): path, fname = os.path.split(urlobj.path) LOG.debug("path " + str(path) + " filename = " + str(fname)) instrument = str(message.data['instruments']) platform_name = message.data['platform_name'] sst_file[scene_id] = os.path.join(path, fname) elif message.data['instruments'] == 'avhrr/3': # if message.data['platform_name'] not in METOP_NAMES and path, fname = os.path.split(urlobj.path) LOG.debug("path " + str(path) + " filename = " + str(fname)) instrument = str(message.data['instruments']) if 'metop_letter' in message.data: platform_name = str("Metop-" + str(message.data['metop_letter'])) else: LOG.warning("Don't know which Metop satellite this is. " + "Set it to Metop-B") platform_name = 'Metop-B' sst_file[scene_id] = os.path.join(path, fname) else: LOG.debug("Scene is not supported") LOG.debug("platform and instrument: " + str(message.data['platform_name']) + " " + str(message.data['instruments'])) return sst_file # Check that the input file really exists: if not os.path.exists(sst_file[scene_id]): LOG.error("File %s does not exist. Don't do anything...", str(sst_file)) return sst_file LOG.info("Sat and Instrument: " + platform_name + " " + instrument) areaid = 'euron1' prfx = platform_name.lower() + start_time.strftime("_%Y%m%d_%H") + \ '_' + str(areaid) outname = os.path.join(SST_OUTPUT_DIR, 'osisaf_sst_float_%s.tif' % prfx) LOG.info("Output file name: " + str(outname)) if os.path.exists(outname): LOG.warning("File " + str(outname) + " already there. Continue...") return sst_file orbit = "00000" endtime = start_time + timedelta(seconds=60 * 12) tslot = start_time glbd = PolarFactory.create_scene( platform_name, "", INSTRUMENT_NAME.get(instrument, instrument), tslot, orbit, variant="DR") LOG.debug("Load sst data...") glbd.load(['SST'], time_interval=(start_time, endtime)) LOG.debug("Project data...") localdata = glbd.project(areaid) img = localdata.image.sst_float() img.save(outname, floating_point=True) LOG.debug("SST Tiff file stored on area %s", str(areaid)) # Store some other products for Diana and other users: # We should rather use producer.py and the XML product list! # FIXME! # if SST_OLD_OUTPUT_DIR: # prfx = start_time.strftime("%Y%m%d%H%M") # outname = os.path.join( # SST_OLD_OUTPUT_DIR, 'noaa_osisaf_sstbaltic_%s.png' % prfx) # LOG.info("Output file name: " + str(outname)) # img = localdata.image.sst_with_landseamask() # img.save(outname) # LOG.debug("SST PNG file stored on area %s", str(areaid)) if SST_SIR_LOCALDIR and SST_SIR_DIR: img = localdata.image.sst_with_landseamask() areaid_str = '{s:{c}<{n}}'.format(s=areaid, n=8, c='_') local_filename = os.path.join(SST_SIR_LOCALDIR, "osafsst_%s%s.png" % (areaid_str, start_time.strftime('%y%m%d%H%M'))) img.save(local_filename) sir_filename = os.path.join(SST_SIR_DIR, "osafsst_%s%s.png_original" % (areaid_str, start_time.strftime('%y%m%d%H%M'))) shutil.copy(local_filename, sir_filename) prfx = platform_name.lower() + start_time.strftime("_%Y%m%d_%H") + \ '_' + str(areaid) outname = os.path.join(SST_OUTPUT_DIR, 'osisaf_sst_%s.tif' % prfx) LOG.info("Output file name: " + str(outname)) LOG.debug("Project data...") localdata = glbd.project(areaid) img = localdata.image.sst() img.save(outname) LOG.debug("SST Tiff file stored on area %s!", str(areaid)) if SST_SIR_LOCALDIR and SST_SIR_DIR: areaid = 'baws' localdata = glbd.project(areaid) img = localdata.image.sst_with_landseamask() areaid_str = '{s:{c}<{n}}'.format(s=areaid, n=8, c='_') local_filename = os.path.join(SST_SIR_LOCALDIR, "osafsst_%s%s.png" % (areaid_str, start_time.strftime('%y%m%d%H%M'))) img.save(local_filename) sir_filename = os.path.join(SST_SIR_DIR, "osafsst_%s%s.png_original" % (areaid_str, start_time.strftime('%y%m%d%H%M'))) shutil.copy(local_filename, sir_filename) return sst_file
#datetime(2013, 3, 12, 10, 43), #datetime(2013, 3, 12, 10, 44), #datetime(2013, 3, 12, 10, 45), #datetime(2013, 3, 12, 10, 47), #datetime(2013, 3, 12, 10, 48) ] # import mpop.utils # mpop.utils.debug_on() # gs = [] for t in tslots: g = PolarFactory.create_scene("npp", "", "viirs", t, orbit="07108") g.load(g.image.green_snow.prerequisites | g.image.hr_overview.prerequisites | g.image.dnb.prerequisites) # for t in tslots[5:6]: # g = PolarFactory.create_scene("npp", "", "viirs", t, orbit="07108") # g.load(g.image.green_snow.prerequisites | g.image.hr_overview.prerequisites # | g.image.dnb.prerequisites) # gs.append(g) """ l = g.project("worldeqc30km")
datetime(2013, 3, 12, 10, 44), datetime(2013, 3, 12, 10, 45), datetime(2013, 3, 12, 10, 47), datetime(2013, 3, 12, 10, 48) ] time_interval = [datetime(2013, 3, 12, 10, 30), datetime(2013, 3, 12, 10, 55)] import mpop.utils mpop.utils.debug_on() gs = [] g = PolarFactory.create_scene("npp", "", "viirs", datetime(2013, 3, 12, 10, 43), orbit="07108") g.load(g.image.green_snow.prerequisites | g.image.hr_overview.prerequisites | g.image.dnb.prerequisites, time_interval=time_interval) """ l = g.project("worldeqc30km") l.image.green_snow().save("/tmp/gs_world.png") l.image.hr_overview().save("/tmp/ov_world.png") l.image.dnb().save("/tmp/dnb_world.png") l = g.project("euron1")
def start_sst_processing(sst_file, message, **kwargs): """From a posttroll/trallstalker message start the osisaf sst post- processing""" LOG.info("") LOG.info("sst-file dict: " + str(sst_file)) LOG.info("\tMessage:") LOG.info(message) urlobj = urlparse(message.data['uri']) if 'start_time' in message.data and 'start_date' in message.data: dtdate = message.data['start_date'] dttime = message.data['start_time'] start_time = datetime(dtdate.year, dtdate.month, dtdate.day, dttime.hour, dttime.minute) scene_id = start_time.strftime('%Y%m%d%H%M') else: LOG.warning("No start time in message!") start_time = None return sst_file if 'end_time' in message.data and 'end_date' in message.data: dtdate = message.data['end_date'] dttime = message.data['end_time'] end_time = datetime(dtdate.year, dtdate.month, dtdate.day, dttime.hour, dttime.minute) else: LOG.warning("No end time in message!") end_time = None if (message.data['platform_name'] in ['Suomi-NPP', ] and message.data['instruments'] == 'viirs'): path, fname = os.path.split(urlobj.path) LOG.debug("path " + str(path) + " filename = " + str(fname)) instrument = str(message.data['instruments']) platform_name = message.data['platform_name'] sst_file[scene_id] = os.path.join(path, fname) elif (message.data['satellite'] in METOP_NAMES and message.data['instruments'] == 'avhrr/3'): path, fname = os.path.split(urlobj.path) LOG.debug("path " + str(path) + " filename = " + str(fname)) instrument = str(message.data['instruments']) platform_name = str("Metop-" + str(message.data['metop_letter'])) sst_file[scene_id] = os.path.join(path, fname) else: LOG.debug("Scene is not supported") LOG.debug("platform and instrument: " + str(message.data['platform_name']) + " " + str(message.data['instruments'])) return sst_file # Check that the input file really exists: if not os.path.exists(sst_file[scene_id]): LOG.error("File %s does not exist. Don't do anything...", str(sst_file)) return sst_file LOG.info("Sat and Instrument: " + platform_name + " " + instrument) areaid = 'euron1' prfx = platform_name.lower() + start_time.strftime("_%Y%m%d_%H") + \ '_' + str(areaid) outname = os.path.join(SST_OUTPUT_DIR, 'osisaf_sst_float_%s.tif' % prfx) LOG.info("Output file name: " + str(outname)) if os.path.exists(outname): LOG.warning("File " + str(outname) + " already there. Continue...") return sst_file orbit = "00000" endtime = start_time + timedelta(seconds=60 * 12) tslot = start_time glbd = PolarFactory.create_scene( platform_name, "", INSTRUMENT_NAME.get(instrument, instrument), tslot, orbit, variant="DR") LOG.debug("Load sst data...") glbd.load(['SST'], time_interval=(start_time, endtime)) LOG.debug("Project data...") localdata = glbd.project(areaid) img = localdata.image.sst_float() img.save(outname, floating_point=True) LOG.debug("SST Tiff file stored on area %s", str(areaid)) # Store some other products for Diana and other users: # We should rather use producer.py and the XML product list! # FIXME! # if SST_OLD_OUTPUT_DIR: # prfx = start_time.strftime("%Y%m%d%H%M") # outname = os.path.join( # SST_OLD_OUTPUT_DIR, 'noaa_osisaf_sstbaltic_%s.png' % prfx) # LOG.info("Output file name: " + str(outname)) # img = localdata.image.sst_with_landseamask() # img.save(outname) # LOG.debug("SST PNG file stored on area %s", str(areaid)) if SST_SIR_LOCALDIR and SST_SIR_DIR: img = localdata.image.sst_with_landseamask() areaid_str = '{s:{c}<{n}}'.format(s=areaid, n=8, c='_') local_filename = os.path.join(SST_SIR_LOCALDIR, "osafsst_%s%s.png" % (areaid_str, start_time.strftime('%y%m%d%H%M'))) img.save(local_filename) sir_filename = os.path.join(SST_SIR_DIR, "osafsst_%s%s.png_original" % (areaid_str, start_time.strftime('%y%m%d%H%M'))) shutil.copy(local_filename, sir_filename) prfx = platform_name.lower() + start_time.strftime("_%Y%m%d_%H") + \ '_' + str(areaid) outname = os.path.join(SST_OUTPUT_DIR, 'osisaf_sst_%s.tif' % prfx) LOG.info("Output file name: " + str(outname)) LOG.debug("Project data...") localdata = glbd.project(areaid) img = localdata.image.sst() img.save(outname) LOG.debug("SST Tiff file stored on area %s!", str(areaid)) if SST_SIR_LOCALDIR and SST_SIR_DIR: areaid = 'baws' localdata = glbd.project(areaid) img = localdata.image.sst_with_landseamask() areaid_str = '{s:{c}<{n}}'.format(s=areaid, n=8, c='_') local_filename = os.path.join(SST_SIR_LOCALDIR, "osafsst_%s%s.png" % (areaid_str, start_time.strftime('%y%m%d%H%M'))) img.save(local_filename) sir_filename = os.path.join(SST_SIR_DIR, "osafsst_%s%s.png_original" % (areaid_str, start_time.strftime('%y%m%d%H%M'))) shutil.copy(local_filename, sir_filename) return sst_file