Beispiel #1
0
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
Beispiel #2
0
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())))
Beispiel #3
0
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, msg1Src, exeDir, GSHHS_ROOT, tmpDir = 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)
    print("\n.msg1Src directory is set to: %s" % msg1Src)
    print("\n.exeDir directory is set to: %s" % exeDir)
    print("\n.GSHHS directory is set to: %s" % GSHHS_ROOT)
    print("\n.tmpDir directory is set to: %s" % tmpDir)

    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 + '-*'
            # searchStr = msg1Src + 'H-000-MSG1*' + dateSnap + tt + '*'

            files = glob.glob(searchStr)

            # Start reading filename in satpy
            scn = Scene(filenames=files, reader='hrit_msg')

            available_comps = scn.available_composite_names()
            channels_inverted = [s for s in available_comps if "_inv" in s]

            # add the remaining 3 non-inverted channels & 3d channel
            #allChnls = channels_inverted  + ["IR_016", "VIS006", "VIS008", "ir108_3d"]
            allChnls = channels_inverted + ["ir108_3d"]

            # 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('India_SC')

                    # # 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 = tmpDir + 'ind_' + ii + '_' + dateSnap + '_' + tt + '.png'
                    outImgStr3w = 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)

                    #  move the tmp files to proper web area
                    mv2WebCmd = 'mv ' + outImgStr3 + ' ' + outImgStr3w
                    os.system(mv2WebCmd)

                    # 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