コード例 #1
0
def in_dir(dir_name, recursive=False):
    """ lists all the rasters in an input directory """

    rast_list = core.list_files(recursive, dir_name)
    rast_list = enf_rastlist(rast_list)

    print("Found {0} file with valid raster format".format(len(rast_list)))

    return rast_list
コード例 #2
0
ファイル: in_dir.py プロジェクト: tklug26/dnppy
def in_dir(dir_name, recursive = False):
    """ lists all the rasters in an input directory """

    rast_list = core.list_files(recursive, dir_name)
    rast_list = enf_rastlist(rast_list)

    print("Found {0} file with valid raster format".format(len(rast_list)))

    return rast_list
コード例 #3
0
ファイル: rast_series.py プロジェクト: tklug26/dnppy
    def from_directory(self, directory, fmt, fmt_unmask = None):
        """
        creates a list of all rasters in a directory, then
        passes this list to self.from_rastlist
        """

        filepaths = core.list_files(False, directory, ".tif")
        filepaths = raster.enf_rastlist(filepaths)
        
        self.from_rastlist(filepaths, fmt, fmt_unmask)
        return
コード例 #4
0
    def from_directory(self, directory, fmt, fmt_unmask=None):
        """
        creates a list of all rasters in a directory, then
        passes this list to self.from_rastlist
        """

        filepaths = core.list_files(False, directory, ".tif")
        filepaths = raster.enf_rastlist(filepaths)

        self.from_rastlist(filepaths, fmt, fmt_unmask)
        return
コード例 #5
0
ファイル: rename.py プロジェクト: lmakely/CN_Tools
def NewFileName (recursive, workspace, installation):
    files = core.list_files(recursive, workspace)
    i = 100
    head, tail = os.path.split(files[0])
    util = tail[0:4]
    newname = installation + "-" + util + "-000"
    
    for items in files:
        print items
        original = items[:-4]
        new= newname + str(i)
        print "Renaming " + original + " to " + new
        core.rename(items, original, workspace + "\\" + new)
        i = i +1
コード例 #6
0
ファイル: Move_and_Name.py プロジェクト: lmakely/CN_Tools
def NewFileName (recursive, workspace, installation):
    #finds files to name
    files = core.list_files(recursive, workspace)
    i = 100
        
    for items in files:
        head, util = os.path.split(os.path.dirname(items))
        
        print items
        original = items[:-4]
        newname = "{0}-{1}-{2}".format(installation, util, str(i).zfill(6))
        print "Renaming " + original + " to " + newname
        core.rename(items, original, workspace + "\\" + newname)
        i = i +1
コード例 #7
0
ファイル: clip.py プロジェクト: lmakely/CN_Tools
def batch_clip(workspace,outspace, clipto, tolerance):
    from dnppy import core
    import arcpy
    import os
    arcpy.env.workspace = workspace

    clipfiles = core.list_files(False, works, ".shp",[".prj", ".clf", '.dbf', '.sbx', '.sbn', '.shx', '.xml'])
    for i in clipfiles:
        head, tail = os.path.split(i)
        clipfile = works + "\\" + clipto
        outs = outspace + "\\" + tail[:-4] + "_Clip.shp"
        cluster_tolerance= tolerance
        print "Currently clipping " + tail
        arcpy.Clip_analysis(i,clipto,outs,cluster_tolerance)
        print tail + " clipped!"
コード例 #8
0
ファイル: in_dir.py プロジェクト: henrykironde/dnppy
def in_dir(dir_name, recursive = False):
    """
    Lists all the rasters in an input directory. finds all formats
    supported by ``raster.enf_rastlist()``.

    :param dir_name:    directory to search rasters for
    :param recursive:   Set to "True" to search within subfolders of input
                        directory "dir_name"
    """

    rast_list = core.list_files(recursive, dir_name)
    rast_list = enf_rastlist(rast_list)

    print("Found {0} file with valid raster format".format(len(rast_list)))

    return rast_list
コード例 #9
0
ファイル: in_dir.py プロジェクト: waynechao128/dnppy
def in_dir(dir_name, recursive=False):
    """
    Lists all the rasters in an input directory. finds all formats
    supported by ``raster.enf_rastlist()``.

    :param dir_name:    directory to search rasters for
    :param recursive:   Set to "True" to search within subfolders of input
                        directory "dir_name"
    """

    rast_list = core.list_files(recursive, dir_name)
    rast_list = enf_rastlist(rast_list)

    print("Found {0} file with valid raster format".format(len(rast_list)))

    return rast_list
コード例 #10
0
ファイル: Move_and_Name.py プロジェクト: lmakely/CN_Tools
def sort(filelist):
    # moves files to a folder named after them
    # must decide which part of the filename you want
    # Script will ask you for a project number in order to format the
    #   the name of the folder correctly
    # If another project has a specific naming convention you would like to add just let me know!

    # determines the project naming convention
    project = input("Which project number are you working on?")

    # finds all the files in the workspace folder provided
    # if you are only looking for a certain type of file extension,
    # replace the 2nd False with strings (ex: ".shp") or a list of
    # strings (ex: [".shp", ".xml"]
    # The same can be done with the last False to exclude file types
    files = core.list_files(False, filelist, False, False)
    
    for filename in files:
       head,tail = os.path.split(filename) #identifies the name of the file
    
       if project == 5646:
           tail_list = tail[0:4] #finds the utility type
           print "Beginning to move " + tail #moves to corresponding folder
           move_dir = os.path.join(head, tail_list)

           if not os.path.exists(move_dir):
               os.makedirs(move_dir) # if the folder doesn't already exist in workspace, its now created

           print tail + " moved to folder"
           shutil.move(filename, os.path.join(move_dir, tail))

       elif project ==  5088:
           delim = "_"
           tail_list = tail.split(delim) #finds the utility type
                              
           print "Moving " + tail #moves to corresponding folder
           move_dir = os.path.join(head, tail_list[0])

           if not os.path.exists(move_dir):
               os.makedirs(move_dir)  # if the folder doesn't already exist in workspace, its now created

           shutil.move(filename, os.path.join(move_dir, "_".join(tail_list[1:])))
           print("Moved file '{0}' ".format(filename))
           
    print("Moved all files!")
    return
コード例 #11
0
ファイル: LaST_MoV.py プロジェクト: yantongw/LaSTMoV
        except IndexError:
            pass
    # joins columns and saves output
    f = numpy.column_stack((stn_id, dattim, air_temp))
    g = []
    name = date + '_KPHX' + '.csv'
    api_outname = os.path.join(mwdir, name)
    head = 'stn_id, dattim, air_temp'
    with open(api_outname, 'wb+') as api_work:
        for line in f:
            g.append(line)
        numpy.savetxt(api_work, g, fmt='%s', delimiter=',', header=head)
print 'Data downloaded from mesowest API!'

# Locate days where high air temperature is above 104 Fahrenheit from csv files of weather station data.
stations = core.list_files(False, mwdir, 'KPHX.csv', 'days.csv')
for year in stations:
    with open(year) as annum:
        path, filename = os.path.split(year)
        year_name = filename[0:4]
        print year_name
        temp = csv.reader(annum)
        data = [row for row in temp]
        begin = 0
        highT = []
        high2 = []
        high_spot = []
        output = []
        # create highT
        for h in range(len(data)):
            try:
コード例 #12
0
ファイル: sort.py プロジェクト: henrykironde/dnppy
    use a custom delimiter by setting "delim", and set "recursive" to True
    if you need to do many directories deep and do not mind renaming files
    """

    for filename in filelist:
        head,tail = os.path.split(filename)

        tail_list = tail.split(delim)
        move_dir = os.path.join(head, tail_list[0])

        if not os.path.exists(move_dir):
            os.makedirs(move_dir)

        if recursive:
            shutil.move(filename, os.path.join(move_dir, "_".join(tail_list[1:])))
        else:
            shutil.move(filename, os.path.join(move_dir, "_".join(tail_list)))
        print("Moved file '{0}' ".format(filename))

    print("Moved all files!")
    return


if __name__ == "__main__":
    
    filelist = core.list_files(False, r"C:\Users\jwely\Desktop\troubleshooting\lauren_organize")
    sort(filelist)
    
    
        
コード例 #13
0
ファイル: sort.py プロジェクト: waynechao128/dnppy
    use a custom delimiter by setting "delim", and set "recursive" to True
    if you need to do many directories deep and do not mind renaming files
    """

    for filename in filelist:
        head, tail = os.path.split(filename)

        tail_list = tail.split(delim)
        move_dir = os.path.join(head, tail_list[0])

        if not os.path.exists(move_dir):
            os.makedirs(move_dir)

        if recursive:
            shutil.move(filename,
                        os.path.join(move_dir, "_".join(tail_list[1:])))
        else:
            shutil.move(filename, os.path.join(move_dir, "_".join(tail_list)))
        print("Moved file '{0}' ".format(filename))

    print("Moved all files!")
    return


if __name__ == "__main__":

    filelist = core.list_files(
        False, r"C:\Users\jwely\Desktop\troubleshooting\lauren_organize")
    sort(filelist)
コード例 #14
0
        # only save output if continuous is true or is last raster in series
        if continuous is True or i == (len(rasterlist[1:]) - 1):

            # create output name and save it
            if outdir is None:
                this_outdir = os.path.dirname(araster)
            else:
                this_outdir = outdir

            # update the figure
            rastfig.update_fig(outrast)

            outpath = core.create_outname(this_outdir, araster, "gft", "tif")
            print("Filled gaps in {0}".format(os.path.basename(araster)))
            outrast = outrast.astype(numpy_datatype)
            from_numpy(outrast, new_meta, outpath, NoData_Value)
            output_filelist.append(outpath)

        # prepare for next time step by setting current to old
        old_rast = new_rast

    return output_filelist



if __name__ == "__main__":
    from null_set_range import *
    rastdir = r"C:\Users\jwely\Desktop\troubleshooting\Bender_TX_data\2010-11"
    rastlist = core.list_files(True, rastdir,["LST"], ["gft"])
    outlist = gap_fill_temporal(rastlist, NoData_Value = -1)
コード例 #15
0
ファイル: clip.py プロジェクト: lmakely/CN_Tools
# author: Lauren Makely
# organization: Clark Nexsen
# date: May 19, 2015

from dnppy import core
import arcpy
import os

works = "V:\\Projects\\5646_GAARNG_SUE_Survey_RC\\Development\\Working\\LMM"

arcpy.env.workspace = "V:\\Projects\\5646_GAARNG_SUE_Survey_RC\\Development\\Working\\LMM"

clipfiles = core.list_files(False, works, ".shp",[".prj", ".clf", '.dbf', '.sbx', '.sbn', '.shx', '.xml'])

for i in clipfiles:
    head, tail = os.path.split(i)
    clipto = works + "\\Cedartown_Inst.shp"
    outs = "V:\\Projects\\5646_GAARNG_SUE_Survey_RC\\Development\\Working\\LMM\\Clipped" + "\\" + tail
    cluster_tolerance="#"
    arcpy.Clip_analysis(i,clipto,outs,cluster_tolerance)

    # Help: batch clips features to a defined shape
    #   workspace   folder with data to be clipped
    #   outspace    folder for clipped data to be placed
    #   clipto      file to clip features to with extension
    #   tolerance   cluster tolerance which is optional (use "#") if no input

def batch_clip(workspace,outspace, clipto, tolerance):
    from dnppy import core
    import arcpy
    import os
コード例 #16
0
        # only save output if continuous is true or is last raster in series
        if continuous is True or i == (len(rasterlist[1:]) - 1):

            # create output name and save it
            if outdir is None:
                this_outdir = os.path.dirname(araster)
            else:
                this_outdir = outdir

            # update the figure
            rastfig.update_fig(outrast)

            outpath = core.create_outname(this_outdir, araster, "gft", "tif")
            print("Filled gaps in {0}".format(os.path.basename(araster)))
            outrast = outrast.astype(numpy_datatype)
            from_numpy(outrast, new_meta, outpath, NoData_Value)
            output_filelist.append(outpath)

        # prepare for next time step by setting current to old
        old_rast = new_rast

    return output_filelist


if __name__ == "__main__":

    rastdir = r"C:\Users\jwely\Desktop\troubleshooting\Bender_TX_data\2010-11"
    rastlist = core.list_files(True, rastdir, ["LST"], ["gft"])
    outlist = gap_fill_temporal(rastlist, NoData_Value=-1)
コード例 #17
0
ファイル: LaST_MoV.py プロジェクト: NASA-DEVELOP/LaSTMoV
        except IndexError:
            pass
    # joins columns and saves output
    f = numpy.column_stack((stn_id, dattim, air_temp))
    g = []
    name = date + '_KPHX' + '.csv'
    api_outname = os.path.join(mwdir, name)
    head = 'stn_id, dattim, air_temp'
    with open(api_outname, 'wb+') as api_work:
        for line in f:
            g.append(line)
        numpy.savetxt(api_work, g, fmt='%s', delimiter=',', header=head)
print 'Data downloaded from mesowest API!'

# Locate days where high air temperature is above 104 Fahrenheit from csv files of weather station data.
stations = core.list_files(False, mwdir, 'KPHX.csv', 'days.csv')
for year in stations:
    with open(year) as annum:
        path, filename = os.path.split(year)
        year_name = filename[0:4]
        print year_name
        temp = csv.reader(annum)
        data = [row for row in temp]
        begin = 0
        highT = []
        high2 = []
        high_spot = []
        output = []
        # create highT
        for h in range(len(data)):
            try: