def main(): from satpy.utils import debug_on debug_on() p = parse_cmdline() (im, sc) = vis.get_fog_blend_for_sat( "seviri_l1b_hrit" if p.seviri else "abi_l1b", [str(x) for x in (p.seviri or p.abi)], "nwcsaf-geo" if p.nwcsaf else "cmsaf-claas2_l2_nc", [str(x) for x in (p.nwcsaf or p.cmsaf)], p.area, "overview") if p.store_intermediates or p.store_dependencies: p.out.mkdir(exist_ok=True, parents=True) im.save(str(p.out / "fog_blend.tif")) else: im.save(str(p.out)) if p.store_dependencies: sc.save_datasets(filename=str(p.out / "{name:s}.tif"), datasets={ d["name"] for d in sc.keys() if isinstance(sc[d], xarray.DataArray) }) if p.store_intermediates: fogpy.composites.save_extras(sc, p.out / "intermediates.nc")
def test_debug_on(caplog): """Test that debug_on is working as expected.""" from satpy.utils import debug, debug_off, debug_on def depwarn(): logger = logging.getLogger("satpy.silly") logger.debug("But now it's just got SILLY.") warnings.warn("Stop that! It's SILLY.", DeprecationWarning) warnings.filterwarnings("ignore", category=DeprecationWarning) debug_on(False) filts_before = warnings.filters.copy() # test that logging on, but deprecation warnings still off with caplog.at_level(logging.DEBUG): depwarn() assert warnings.filters == filts_before assert "But now it's just got SILLY." in caplog.text debug_on(True) # test that logging on and deprecation warnings on with pytest.warns(DeprecationWarning): depwarn() assert warnings.filters != filts_before debug_off() # other tests assume debugging is off # test that filters were reset assert warnings.filters == filts_before with debug(): assert warnings.filters != filts_before assert warnings.filters == filts_before
def __init__(self, message, product, volcview_band, product_label): debug_on() self.message = message self.product = product self.product_label = product_label self.volcview_band = volcview_band self.data = message.data self.color_bar_font = aggdraw.Font(GOLDENROD, TYPEFACE, size=FONT_SIZE) self.scene = self._create_scene() context = zmq.Context() self.publisher = context.socket(zmq.PUB) self.publisher.connect(SECTOR_PROXY)
def main(): from satpy.utils import debug_on debug_on() p = parse_cmdline() fn = vis.unpack_and_show_testdata( p.path, p.composites, p.channels, p.areas, p.outdir, p.filename_pattern, p.coastline_dir, p.show_only_coastlines) print("Files written:", fn)
def batchSDR2Geotiff(input_dir, output_dir, pattern, areaid, debug): if debug: debug_on() curdir = os.getcwd() os.chdir(input_dir) #OUTPUT_DIR=os.path.join(input_dir,OUTPUT_DIR_RELATIVE) output_dir = os.path.abspath(output_dir) #works for abs and relative paths if not os.path.exists(output_dir): os.makedirs(output_dir) hdf_files = glob.glob(os.path.join(input_dir, pattern)) os.chdir(curdir) for hdf in hdf_files: SDR2Geotiff(hdf, output_dir, areaid, radius=2000)
def batchEDR2Geotiff(input_dir, output_dir,pattern, areaid, debug): # ********* SETTINGS ******************************************* #input_dir='/media/leonidas/Hitachi/daily_viirs/2017_packed/EDR_CLOUD_MASK' #output_dir="geotiffs_greece2" # pattern='GMODO-VICMO_npp_d20170331_t2346150_e2351554_b28114_c20181105104544883294_noac_ops.h5' #'GMODO-VICMO_npp_d201703*.h5' #'GMODO-VICMO_npp_d201703*.h5' #'GMODO-VICMO_npp_d20170328_t0056143_e0101547_b28058_c20181105104553745389_noac_ops.h5'#GMODO-VICMO_npp_d20170328_t0056143_e0101547_b28058_c20181105104553745389_noac_ops.h5'##'GMODO-VICMO_npp_d201703*.h5'#'GMODO-VICMO_npp_d20170328_t0056143_e0101547_b28058_c20181105104553745389_noac_ops.h5'#GMODO-VICMO_npp_d20170313_t0039560_e0045364_b27845_c20181105104612702584_noac_ops.h5 if debug: debug_on() curdir=os.getcwd() os.chdir(input_dir) #OUTPUT_DIR=os.path.join(input_dir,OUTPUT_DIR_RELATIVE) output_dir = os.path.abspath(output_dir) #works for abs and relative paths if not os.path.exists(output_dir): os.makedirs(output_dir) hdf_files = glob.glob(os.path.join(input_dir,pattern)) os.chdir(curdir) for hdf in hdf_files: EDR2Geotiff(hdf, output_dir, areaid,radius=2000)
def main(): """Launch trollflow2.""" args = parse_args() prod_list = args.product_list test_message = args.test_message topics = args.topic nameserver = args.nameserver addresses = args.addresses if args.log_config is not None: with open(args.log_config) as fd: import yaml log_dict = yaml.load(fd.read()) logging.config.dictConfig(log_dict) else: from satpy.utils import debug_on debug_on() run(prod_list, topics=topics, test_message=test_message, nameserver=nameserver, addresses=addresses)
import matplotlib.pyplot as plt import numpy as np import datetime import os, pyresample from pyresample import image, geometry from pyresample.utils import load_area import pkg_resources pkg_resources.require("scipy==0.19.0") import scipy.misc from pycoast import ContourWriterAGG import aggdraw from PIL import Image, ImageFont, ImageDraw from cll_composites import * debug_on() my_example_nc_file = "MSG2_ccs4_201712250900_rad.nc" fname = "MSG2_ccs4_201712250900_rad.png" fh = Dataset(my_example_nc_file, mode='r') z = fh.variables['HRV'][:] z = z.reshape(640,710) fh.close() fig = plt.figure(frameon=False) fig.set_size_inches(7.1,6.4) ax = plt.Axes(fig, [0., 0., 1., 1.]) ax.set_axis_off() fig.add_axes(ax) ax.imshow(z) fig.savefig(fname, dpi=300)
from __future__ import division from __future__ import print_function # Marco Sassi's program # zueub428:/opt/pytroll/nwcsaf/nwcsaf-processing/bin/NWCSAF_processing.py # old version: zueub428:/opt/safnwc/bin/NWCSAF_processing.py # see also https://github.com/pytroll/pytroll-examples/blob/master/satpy/ears-nwc.ipynb from satpy.utils import debug_on debug_on() import nwcsaf import numpy as np from satpy import Scene, find_files_and_readers from datetime import datetime #product = {} #product_list = ['CMA'] #product_list = ['CTTH'] product_list = ['CTTH'] product_list = ['CT'] ## 'ASII-NG' and 'RDT-CW' do not work!! # sam's product_list = ['CMA', 'CT', 'CTTH', 'CMIC', 'PC', 'CRR', 'iSHAI', 'CI', 'RDT-CW', 'ASII-NG'] ## 'ASII-NG' and 'RDT-CW' do not work!! # product_list = ['ASII-NG', 'CI', 'CMA', 'CMIC', 'CRR', 'CRR-Ph', 'CT', 'CTTH', 'HRW', 'iSHAI', 'PC', 'PC-Ph', 'PLAX', 'RDT-CW'] # product.keys() ['ASII-NG', 'CI', 'CMA', 'CMIC', 'CRR', 'CRR-Ph', 'CT', 'CTTH', 'HRW', 'iSHAI', 'PC', 'PC-Ph', 'RDT-CW'] # sam's product_list = ['CMA', 'CT', 'CTTH', 'CMIC', 'PC', 'CRR', 'iSHAI', 'CI', 'RDT-CW', 'ASII-NG'] make_images = True
def before_all(context): if not context.config.log_capture: from satpy.utils import debug_on debug_on()
def before_all(context): """Enable satpy debugging.""" if not context.config.log_capture: from satpy.utils import debug_on debug_on()
def msg1NDVI(dateSnap, avail_times, fldrs): """ What does this function do? This definition/function is meant for computing NDVI from SEVIRI data Ref: https://nbviewer.jupyter.org/github/pytroll/pytroll-examples/blob/master/satpy/hrit_msg_tutorial.ipynb :param dateSnap: :param avail_times: :param fldrs: :return: NDVI """ # Start the logic import os, sys, glob from satpy.utils import debug_on from satpy.scene import Scene from satpy.dataset import combine_metadata from datetime import datetime from myDefinitions import nc_write_sat_level_2, embellish, imResize debug_on() print("\n \t \t \t STARTING THE msg1NDVI run @ time: %s \t \t \t \n \n" % str(datetime.now())) print("\n.Processing Date set is: %s" % dateSnap) # Test whether all data folders are appropriately set or not. basDir, datDir, outDir, logDir, webDir, geoTdir, GSHHS_ROOT = fldrs print("\n.Base directory is set to: %s" % basDir) print("\n.Data directory is set to %s" % datDir) print("\n.NetCDF output directory is set to: %s" % outDir) print("\n.Log directory is set to: %s" % logDir) print("\n.Web directory is set to: %s" % webDir) print("\n.GeoTiff directory is set to: %s" % geoTdir) avail_times = str(avail_times).split() for tt in avail_times: # Start for-loop-1 print("..Started processing for time: %s" % tt) files = glob.glob(datDir + 'H-000-MSG1*' + dateSnap + tt + '-*') print(">>>>>>>>>>> Testing 123: <<<<<<<<<<<<<<<\n") print(files) # Start reading filename in satpy scn = Scene(filenames=files, reader='hrit_msg') # start the NDVI computation scn.load(['VIS006', 0.6]) scn.load(['VIS008', 0.8]) ndvi = (scn[0.8] - scn[0.6]) / (scn[0.8] + scn[0.6]) ndvi.attrs = combine_metadata(scn[0.6], scn[0.8]) scn['ndvi'] = ndvi composite = 'ndvi' prodStr = 'ndvi' capStr = 'NDVI' # resample the data to Indian region indScn = scn.resample('IndiaSC') # save the data # # Save as netCDF data ---- TO BE IMPLEMENTED ---- outImgStr1 = outDir + 'ind_MSG-1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.nc' nc_write_sat_level_2(indScn, outImgStr1, prodStr) # Save as Full Resolution GeoTIFF files outImgStr2 = geoTdir + 'ind_MSG-1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.tiff' indScn.save_dataset(composite, filename = outImgStr2, writer = 'geotiff') # Add graphics # img2 = embellish(basDir, GSHHS_ROOT, outImgStr2, capStr, dateSnap, tt) # img2.save(outImgStr2) # Save the data as resized png files outImgStr3 = webDir + 'ind_MSG1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.png' indScn.save_dataset(composite, filename = outImgStr3, writer = "simple_image") outImgStr3 = imResize(outImgStr3) # Add graphics img3 = embellish(basDir, GSHHS_ROOT, outImgStr3, capStr, dateSnap, tt) img3.save(outImgStr3) print("msg1NDVI() says: Finished with processing of time-slot - %s - at: %s " % (tt, str(datetime.now())))
def msg1RGBProc(dateSnap, avail_times, fldrs): """ What does this definition do? This script processes the raw MSG-1 data into RGB Data Products in netCDF-4, geoTIFF & png file formats :param dateSnap: :param avail_times: A single string NOT an array :param fldrs: :return: """ #-Start coding # start the logic import os, sys, glob from satpy.utils import debug_on from satpy.scene import Scene from datetime import datetime from myDefinitions import nc_write_sat_level_1_5, embellish, imResize # Start the logic debug_on() print("\n \t \t \t STARTING THE msg1RGBProc run @ time: %s \t \t \t \n \n" % str(datetime.now())) print("\n.Processing Date set is: %s" % dateSnap) # Test whether all data folders are appropriately set or not. basDir, datDir, outDir, logDir, webDir, geoTdir, GSHHS_ROOT = fldrs print("\n.Base directory is set to: %s" % basDir) print("\n.Data directory is set to %s" % datDir) print("\n.NetCDF output directory is set to: %s" % outDir) print("\n.Log directory is set to: %s" % logDir) print("\n.Web directory is set to: %s" % webDir) print("\n.GeoTiff directory is set to: %s" % geoTdir) avail_times = str(avail_times).split() for tt in avail_times: # Start for-loop-1 print("..Started processing for time: %s" % tt) files = glob.glob(datDir + 'H-000-MSG1*' + dateSnap + tt + '-*') # Start reading filename in satpy scn = Scene(filenames=files, reader='hrit_msg') # loop into available composites for composite in ['natural', 'ir_overview', 'night_fog', 'convection', 'dust', 'airmass', 'cloud_top_temperature', 'cloud_top_height', 'cloudtype', 'cloud_top_phase', 'cloud_top_pressure', 'cloudmask']: if (composite == 'natural'): prodStr = 'NAT' capStr = 'Quasi True Colour' elif (composite == 'night_fog'): prodStr = 'NFog' capStr = 'Night Fog' elif (composite == 'convection'): prodStr = 'CON' # Problematic capStr = 'Convection Activity' elif (composite == 'cloud_optical_thickness'): prodStr = 'COP' # 2 much Problematic capStr = 'Cloud Optical Thickness' elif (composite == 'realistic_colors'): prodStr = 'REAL' # problematic capStr = 'Realistic RGB Colors' elif (composite == 'ir_overview'): prodStr = 'IR' capStr = 'Infra-Red' elif (composite == 'cloud_top_temperature'): prodStr = 'CTT' # problematic capStr = 'Cloud Top Temperature' elif (composite == 'airmass'): prodStr = 'airM' capStr = 'Air Mass' elif (composite == 'dust'): prodStr = 'dust' capStr = 'DUST' elif (composite == 'cloud_top_height'): prodStr = 'CTH' capStr = 'Cloud Top Height' elif (composite == 'cloudtype'): prodStr = 'CType' capStr = 'Cloud Type' elif (composite == 'cloud_top_pressure'): prodStr = 'CTP' capStr = 'Cloud Top Pressure' elif (composite == 'cloud_top_phase'): prodStr = 'CTPh' capStr = 'Cloud Top Phase' elif (composite == 'cloudmask'): prodStr = 'CMask' capStr = 'Cloud Mask' # end if condition try: # Load the scene scn.load([composite]) # India Specific Scene indScn = scn.resample("IndiaSC") indScn.load([composite]) # # Save as netCDF data ---- TO BE IMPLEMENTED ---- # outImgStr1 = outDir + 'ind_MSG-1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.nc' # # indImg.save_datasets(writer = 'cf', filename = outImgStr1) # nc_write_sat_level_1_5(indScn, outImgStr1, prodStr) # Save as Full Resolution GeoTIFF files outImgStr2 = geoTdir + 'ind_MSG-1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.tiff' indScn.save_dataset(composite, filename = outImgStr2, writer = 'geotiff') # Add graphics # img2 = embellish(basDir, GSHHS_ROOT, outImgStr2, capStr, dateSnap, tt) # img2.save(outImgStr2) # Save the data as resized png files outImgStr3 = webDir + 'ind_MSG1_RGB_' + prodStr + '_' + dateSnap + '_' + tt + '.png' indScn.save_dataset(composite, filename = outImgStr3, writer = "simple_image") outImgStr3 = imResize(outImgStr3) # Add graphics img3 = embellish(basDir, GSHHS_ROOT, outImgStr3, capStr, dateSnap, tt) img3.save(outImgStr3) # unload the read channel data scn.unload([composite]) indScn.unload([composite]) print("Finished processing for RGB Composite: %s " % composite) except: print("Something went wrong with this RGB composite: %s" % composite) continue # end try-except block # end for-loop #Finished time slots finTmStmps = [tt] print("\n.Reading Finished Time slots as: %s" % finTmStmps) finTmsFile = logDir + "finishedTimeSlots_" + dateSnap + ".txt" fp = open(finTmsFile, 'a+') for item in finTmStmps: fp.write("%s \n" % item) # end for loop to write fp.close() # end for-loop # end-for-loop print("msg1RGBProc() says: Finished with processing of time-slot - %s - at: %s " % (tt, str(datetime.now())))
def msg1Proc1_5(dateSnap, avail_times, fldrs): """ What does this definition do? This script processes the raw MSG-1 Level 1.5 data to produces radiance/reflectance image files in netCDF,-4 geoTIFF & png file formats. :param dateSnap: :param avail_times: A single string NOT an array :param fldrs: :return: """ #- Start coding # import necessary modules import os, sys, glob from satpy.utils import debug_on from satpy.scene import Scene from datetime import datetime from myDefinitions import nc_write_sat_level_1_5, embellish, imResize # Start the logic debug_on() print("\n \t \t \t STARTING THE msg1Proc1_5 run @ time: %s \t \t \t \n \n" % str(datetime.now())) print("\n.Processing Date set is: %s" % dateSnap) # Test whether all data folders are appropriately set or not. basDir, datDir, outDir, logDir, webDir, geoTdir, GSHHS_ROOT = fldrs print("\n.Base directory is set to: %s" % basDir) print("\n.Data directory is set to %s" % datDir) print("\n.NetCDF output directory is set to: %s" % outDir) print("\n.Log directory is set to: %s" % logDir) print("\n.Web directory is set to: %s" % webDir) print("\n.GeoTiff directory is set to: %s" % geoTdir) avail_times = str(avail_times).split() for tt in avail_times: try: # Start for-loop-1 print("..Started processing for time: %s" % tt) searchStr = datDir + 'H-000-MSG1*' + dateSnap + tt + '-*' files = glob.glob(searchStr) # for testing print(">>>>>>>>>> For Testing <<<<<<<<<<") print("datDir is set to %s: " % datDir) print("Search string is %s" % searchStr) print(files) # Start reading filename in satpy scn = Scene(filenames=files, reader='hrit_msg') # Get the dataset names in the scene allChnls = scn.all_dataset_names() allChnls.remove('HRV') # due to higher resolution # Save the individual channels (except HRV) as separate gray-scale GeoTIFF files.. for ii in allChnls: try: str(ii).split() print("Working on channel: %s" % ii) scn.load(str(ii).split()) indImg = scn.resample('IndiaSC') # Save as netCDF data outImgStr1 = outDir + 'ind_MSG1-Band_' + ii + '_' + dateSnap + '_' + tt + '.nc' nc_write_sat_level_1_5(indImg, outImgStr1, ii) # Save as Full Resolution GeoTIFF files outImgStr2 = geoTdir + 'ind_' + ii + '_' + dateSnap + '_' + tt + '.tiff' indImg.save_dataset(ii, filename = outImgStr2, writer = 'geotiff') # Add graphics # img2 = embellish(basDir, GSHHS_ROOT, outImgStr2, ii, dateSnap, tt) # img2.save(outImgStr2) # Save the data as resized png files outImgStr3 = webDir + 'ind_' + ii + '_' + dateSnap + '_' + tt + '.png' indImg.save_dataset(ii, filename = outImgStr3, writer = "simple_image") outImgStr3 = imResize(outImgStr3) # Add graphics img3 = embellish(basDir, GSHHS_ROOT, outImgStr3, ii, dateSnap, tt) img3.save(outImgStr3) # unload the read channel data scn.unload(str(ii).split()) print("Finished processing for channel: %s " % ii) except: print("Something went wrong with this Channel: %s" % ii) continue # end try-except block #end for-loop print("Finished processing for time-stamp: %s" % tt) except: print("Something went wrong with this time: %s" % tt) continue
def main(): from satpy.utils import debug_on debug_on() topics = sys.argv[1].split(',') prod_list = sys.argv[2] run(topics, prod_list)