Ejemplo n.º 1
0
def _extract_NetCDF_datatype(netcdf,
                             layer_indexs,
                             outdir,
                             datatype,
                             force_custom=False,
                             nodata_value=None):
    """
    This function wraps "_extract_NetCDF_layer_data" and "_gdal_dataset_to_tif".
    It only works for datatypes listed in the datatype_library.csv

    :param netcdf:          a single netcdf filepath
    :param layer_indexs:    list of int index values of layers to extract
    :param outdir:          filepath to output directory to place tifs
    :param datatype:        a dnppy.convert.datatype object created from an
                            entry in the datatype_library.csv
    :param force_custom:    if True, this will force the data to take on the
                            projection and geotransform attributes from
                            the datatype object, even if valid projection
                            and geotransform info can be pulled from the gdal
                            dataset. Should almost never be True.
    :param nodata_value:    the value to set to Nodata

    :return:                list of filepaths to output files
    """

    output_filelist = []

    data = _extract_NetCDF_layer_data(netcdf, layer_indexs)

    for layer_index in layer_indexs:

        dataset = data[layer_index]
        outpath = core.create_outname(outdir, netcdf, str(layer_index), "tif")

        print("creating dataset at {0}".format(outpath))

        _gdal_dataset_to_tif(dataset,
                             outpath,
                             cust_projection=datatype.projectionTXT,
                             cust_geotransform=datatype.geotransform,
                             force_custom=force_custom,
                             nodata_value=nodata_value)

        output_filelist.append(outpath)

    return output_filelist
def _extract_NetCDF_datatype(netcdf, layer_indexs, outdir, datatype, force_custom=False, nodata_value=None):
    """
    This function wraps "_extract_NetCDF_layer_data" and "_gdal_dataset_to_tif".
    It only works for datatypes listed in the datatype_library.csv

    :param netcdf:          a single netcdf filepath
    :param layer_indexs:    list of int index values of layers to extract
    :param outdir:          filepath to output directory to place tifs
    :param datatype:        a dnppy.convert.datatype object created from an
                            entry in the datatype_library.csv
    :param force_custom:    if True, this will force the data to take on the
                            projection and geotransform attributes from
                            the datatype object, even if valid projection
                            and geotransform info can be pulled from the gdal
                            dataset. Should almost never be True.
    :param nodata_value:    the value to set to Nodata

    :return:                list of filepaths to output files
    """

    output_filelist = []

    data = _extract_NetCDF_layer_data(netcdf, layer_indexs)

    for layer_index in layer_indexs:

        dataset = data[layer_index]
        outpath = core.create_outname(outdir, netcdf, str(layer_index), "tif")

        print("creating dataset at {0}".format(outpath))

        _gdal_dataset_to_tif(
            dataset,
            outpath,
            cust_projection=datatype.projectionTXT,
            cust_geotransform=datatype.geotransform,
            force_custom=force_custom,
            nodata_value=nodata_value,
        )

        output_filelist.append(outpath)

    return output_filelist
Ejemplo n.º 3
0
def extract_MPE_NetCDF(netcdf_list, layer_indexs, outdir, area):
    """
    extracts SMOS data from its native NetCDF format.

    :param netcdf_list:     list of hdf files or directory with netcdfs
    :param layer_indexs:    list of integer layer indices
    :param outdir:          directory to place outputs
    :param area:            presently only supports "CONUS"

    :return:                A list of all files created as output
    """

    netcdf_list = core.enf_filelist(netcdf_list)
    output_filelist = []

    # load the GPM datatype from the library
    dtype = datatype_library()["MPE_HRAP_{0}".format(area)]

    # for every hdf file in the input list
    for netcdf in netcdf_list:
        data = _extract_NetCDF_layer_data(netcdf, layer_indexs)

        for layer_index in layer_indexs:

            dataset = data[layer_index]
            outpath = core.create_outname(outdir, netcdf, str(layer_index),
                                          "tif")

            print("creating dataset at {0}".format(outpath))

            _gdal_dataset_to_tif(dataset,
                                 outpath,
                                 cust_projection=dtype.projectionTXT,
                                 cust_geotransform=dtype.geotransform,
                                 force_custom=False,
                                 nodata_value=-1)

            output_filelist.append(outpath)

    return output_filelist
Ejemplo n.º 4
0
def extract_MPE_NetCDF(netcdf_list, layer_indexs, outdir, area):
    """
    extracts SMOS data from its native NetCDF format.

    :param netcdf_list:     list of hdf files or directory with netcdfs
    :param layer_indexs:    list of integer layer indices
    :param outdir:          directory to place outputs
    :param area:            presently only supports "CONUS"

    :return:                A list of all files created as output
    """

    netcdf_list = core.enf_filelist(netcdf_list)
    output_filelist = []

    # load the GPM datatype from the library
    dtype = datatype_library()["MPE_HRAP_{0}".format(area)]

    # for every hdf file in the input list
    for netcdf in netcdf_list:
        data = _extract_NetCDF_layer_data(netcdf, layer_indexs)

        for layer_index in layer_indexs:

            dataset = data[layer_index]
            outpath = core.create_outname(outdir, netcdf, str(layer_index), "tif")

            print("creating dataset at {0}".format(outpath))

            _gdal_dataset_to_tif(dataset, outpath,
                                cust_projection = dtype.projectionTXT,
                                cust_geotransform = dtype.geotransform,
                                force_custom = False,
                                nodata_value = -1)

            output_filelist.append(outpath)

    return output_filelist