示例#1
0
文件: utils.py 项目: jlaura/themis_ra
def extract_band(job, image, band_num):
    """
    Extract the temperature data from the processed ISIS cube.

    Parameters
    ----------
    job : dict
               Job specification dictionary

    image : str
               PATH to an ISIS cube to extract bands from

    band_num : int
               Band number that needs to be extracted

    Returns
    ----------
    : ndarray
               Array representation of the extracted band
    """
    header = pvl.load(job['images'])
    bands = find_in_dict(header, 'BAND_BIN_BAND_NUMBER')

    for i, band in enumerate(bands):
        if band_num == band:
            geo_image = io_gdal.GeoDataset(image)
            return geo_image.read_array(band=i + 1)
示例#2
0
 def test_with_projection(self):
     wktsrs = """PROJCS["Moon2000_Mercator180",
         GEOGCS["GCS_Moon_2000",
             DATUM["Moon_2000",
                 SPHEROID["Moon_2000_IAU_IAG",1737400.0,0.0]],
             PRIMEM["Reference_Meridian",0.0],
             UNIT["Degree",0.017453292519943295]],
         PROJECTION["Mercator_1SP"],
         PARAMETER["False_Easting",0.0],
         PARAMETER["False_Northing",0.0],
         PARAMETER["Central_Meridian",180.0],
         PARAMETER["latitude_of_origin",0.0],
         UNIT["Meter",1.0]]"""
     io_gdal.array_to_raster(self.arr, 'test.tif', projection=wktsrs)
     expected_srs = """PROJCS["Moon2000_Mercator180",
         GEOGCS["GCS_Moon_2000",
             DATUM["Moon_2000",
                 SPHEROID["Moon_2000_IAU_IAG",1737400,0]],
             PRIMEM["Reference_Meridian",0],
             UNIT["Degree",0.017453292519943295]],
         PROJECTION["Mercator_2SP"],
         PARAMETER["central_meridian",180],
         PARAMETER["false_easting",0],
         PARAMETER["false_northing",0],
         PARAMETER["standard_parallel_1",0],
         UNIT["Meter",1]]"""
     dataset = io_gdal.GeoDataset('test.tif')
     test_srs = dataset.spatial_reference.__str__()
     self.assertEqual(test_srs.split(), expected_srs.split())
 def setUpClass(cls):
     cls.dataset = io_gdal.GeoDataset(get_path('AS15-M-0295_SML.png'))
     cls.data_array = cls.dataset.read_array(dtype='uint8')
     cls.parameters = {
         "nfeatures": 10,
         "nOctaveLayers": 3,
         "contrastThreshold": 0.02,
         "edgeThreshold": 10,
         "sigma": 1.6
     }
示例#4
0
文件: utils.py 项目: jlaura/themis_ra
def extract_temperature(isiscube, reference_dataset=None):
    """
    Extract the temperature data from the processed ISIS cube.

    Parameters
    ----------
    isiscube : str
               PATH to an ISIS cube to extract
    """
    temperature = io_gdal.GeoDataset(isiscube)
    processing_resolution = temperature.pixel_width
    tempshape = list(temperature.raster_size)[::-1]
    logger.info('Themis temperature data has {} lines and {} samples'.format(
        tempshape[0], tempshape[1]))
    srs = temperature.spatial_reference.ExportToWkt()
    logger.info('The input temperature image projection is: {}'.format(srs))
    return temperature
示例#5
0
文件: utils.py 项目: jlaura/themis_ra
def extract_latlon_transform(isiscube, job):
    """
    Given an ISIS cube, extract the upper left (x, y) coords and the height and width

    Parameters
    ----------
    isiscube : str
               PATH to an ISIS cube to use for latlon to pixel translation

    job : dict
               Job specification dictionary

    Returns
    ----------
    xoff : int
               x coordinate of the upper left pixel

    yoff : int
               y coordinate of the upper left pixel

    width : int
               Width of the new area

    height : int
               Height of the new area
    """
    isiscube_geodata = io_gdal.GeoDataset(isiscube)
    lry, uly = job["lat_extent"]
    ulx, lrx = job["lon_extent"]

    ul_coords = isiscube_geodata.latlon_to_pixel(uly, ulx)
    lr_coords = isiscube_geodata.latlon_to_pixel(lry, lrx)

    xoff = ul_coords[0]
    yoff = ul_coords[1]

    width = abs(lr_coords[0] - xoff)
    height = abs(lr_coords[1] - yoff)
    return xoff, yoff, width, height
示例#6
0
文件: utils.py 项目: jlaura/themis_ra
def extract_ancillary_data(job, temperature, parameters, workingpath, shape,
                           reference_dataset):
    """
    For all ancillary data sets, extract the requested spatial extent

    Parameters
    ----------
    job : dict
        Job specification dictionary

    temperature : object
                Plio GeoDataset object

    parameters : dict
                of extent and time parameters
    """
    ancillarydata = job['ancillarydata']
    for k, v in ancillarydata.items():
        ancillarydata[k] = v

    # Flag to punt on the image if some ancillary data load fails.
    ancillary_failure = False

    #Iterate through the ancillary data.  Clip and resample to the input image
    for k, v in ancillarydata.items():
        if isinstance(v, int) or isinstance(v, float):
            #The user wants a constant value to be used
            arr = np.empty(shape, dtype=np.float32)
            logger.debug('{} set to a constant value, {}'.format(k, v))
            del arr
        else:
            basename = os.path.basename(v)
            root, extension = os.path.splitext(basename)
            tif = os.path.join(workingpath, root + '.tif')

            if v == 'montone':  # Custom dust opacity
                startls = parameters['startlsubs'][0]
                startmartianyear = int(parameters['startmartianyear'][0])
                files = glob.glob(
                    '/scratch/jlaura/KRC/basemaps/tau_geotiff/MY{}*'.format(
                        startmartianyear))

                if len(files) == 0:
                    logger.error(
                        'Requested an image with Mars Year {}.  No Montabone data available for that Mars Year'
                        .format(startmartianyear))
                    ancillary_failure = True
                    continue
                ls = {}
                for t, f in enumerate(files):
                    base, ext = os.path.splitext(f)
                    ls[float(base.split('_')[2])] = t
                keys = []
                for key in ls.keys():
                    try:
                        keys.append(float(key))
                    except:
                        pass
                key = min(keys, key=lambda x: abs(x - startls))
                v = files[ls[key]]

            if v == 'tes':
                startls = startlsubs[0]
                files = glob.glob('/scratch/jlaura/KRC/basemaps/tes_opac/*')
                ls = {}
                for t, f in enumerate(files):
                    base, ext = os.path.splitext(f)
                    ls[float(base.split('_')[-1][2:])] = t
                keys = []
                for key in ls.keys():
                    try:
                        keys.append(float(key))
                    except:
                        pass

                key = min(keys, key=lambda x: abs(x - startls))
                v = files[ls[key]]

            #Clip and resample the image to the correct resolution
            v = io_gdal.GeoDataset(v)
            io_gdal.match_rasters(reference_dataset, v, tif)

            #Read the resampled tif and extract the array
            ancillarydata[k] = io_gdal.GeoDataset(tif)
            logger.debug('Dataset {} extract.'.format(v))

    if ancillary_failure:
        print('FAILED TO EXTRACT ANCILLARY DATA')
        MPI.COMM_WORLD.Abort(1)
        sys.exit()

    return ancillarydata
示例#7
0
 def test_with_no_data_value(self):
     no_data_value = 0.0
     io_gdal.array_to_raster(self.arr, 'test.tif', ndv=no_data_value)
     dataset = io_gdal.GeoDataset('test.tif')
     self.assertEqual(dataset.no_data_value, no_data_value)
示例#8
0
 def test_with_geotrasform(self):
     gt = (-464400.0, 3870.0, 0.0, -506970.0, 0.0, -3870.0)
     io_gdal.array_to_raster(self.arr, 'test.tif', geotransform=gt)
     dataset = io_gdal.GeoDataset('test.tif')
     self.assertEqual(gt, dataset.geotransform)
示例#9
0
 def setUp(self):
     self.dataset = io_gdal.GeoDataset(
         get_path('Mars_MGS_MOLA_ClrShade_MAP2_90.0N0.0_POLA.tif'))
示例#10
0
 def setUp(self):
     self.dataset = io_gdal.GeoDataset(
         get_path('Lunar_LRO_LOLA_Shade_MAP2_90.0N20.0_LAMB.tif'))
示例#11
0
 def test_without_gdal(self):
     io_gdal.has_gdal = False
     with self.assertRaises(ImportError):
         io_gdal.GeoDataset('foo')