示例#1
0
def show_tile_bounds( location: str, year, time_range, download = True ):
    dat_url = "https://floodmap.modaps.eosdis.nasa.gov/Products"
    dataMgr = MWPDataManager( DATA_DIR, dat_url )
    dataMgr.setDefaults(product="2D2OT", download=download, year=year, start_day=time_range[0], end_day=time_range[1])
    file_paths = dataMgr.get_tile(location)
    data_arrays: List[xr.DataArray ] =  XGeo.loadRasterFiles(file_paths[0:2], band=1 )
    print( f"Reading location: {location}")
    print( TileLocator.get_bounds(data_arrays[0]) )
    print( TileLocator.infer_tiles_xa( data_arrays[0] ) )
示例#2
0
def show_roi( xbounds, ybounds, year, time_range  ):
    dat_url = "https://floodmap.modaps.eosdis.nasa.gov/Products"
    dataMgr = MWPDataManager( DATA_DIR, dat_url )
    dataMgr.setDefaults(product="2D2OT", year=year, start_day=time_range[0], end_day=time_range[1])
    location = TileLocator.get_tile( *xbounds, *ybounds )
    file_paths = dataMgr.get_tile(location)
    roi_bounds = xbounds + ybounds
    time_values = np.array([ get_date_from_filename(os.path.basename(path)) for path in file_paths], dtype='datetime64[ns]')
    cropped_data: xr.DataArray = XRio.load(file_paths, mask=roi_bounds, band=0, index=time_values)
    cropped_data.attrs['cmap'] = dict(colors=colors3)
    animation = SliceAnimation( cropped_data )
    animation.show()
示例#3
0
    def get_mpw_data(self, **kwargs ) -> Tuple[Optional[xr.DataArray],Optional[ np.array]]:
        print( "reading mpw data")
        t0 = time.time()
        results_dir = kwargs.get('results_dir')
        lake_id = kwargs.get('lake_index')
        download = kwargs.get( 'download', True )

        from geoproc.data.mwp import MWPDataManager
        from geoproc.xext.xrio import XRio
        source_spec = kwargs.get('source')
        data_url = source_spec.get('url')
        product = source_spec.get('product')
        locations = source_spec.get( 'location', self.infer_tile_locations() )
        if not locations:
            print( "NO LOCATION DATA.  ABORTING")
            return None, None

        year_range = kwargs.get('year_range')
        day_range = kwargs.get('day_range',[0,365])
        dataMgr = MWPDataManager(results_dir, data_url)

        cropped_tiles: Dict[str,xr.DataArray] = {}
        file_paths = []
        time_values = None
        cropped_data = None
        for location in locations:
            try:
                print( f"Reading Location {location}" )
                dataMgr.setDefaults(product=product, download=download, years=range(int(year_range[0]),int(year_range[1])+1), start_day=int(day_range[0]), end_day=int(day_range[1]))
                file_paths = dataMgr.get_tile(location)
                time_values = np.array([ self.get_date_from_filename(os.path.basename(path)) for path in file_paths], dtype='datetime64[ns]')
                cropped_tiles[location] =  XRio.load( file_paths, mask=self.roi_bounds, band=0, mask_value=self.mask_value, index=time_values )
            except Exception as err:
                print( f"Error reading mpw data for location {location}, first file paths = {file_paths[0:10]} ")
                for file in file_paths:
                    if not os.path.isfile( file ): print( f"   --> File {file} does not exist!")
                exc = traceback.format_exc()
                print( f"Error: {err}: \n{exc}" )
                XRio.print_array_dims( file_paths )
        nTiles = len( cropped_tiles.keys() )
        if nTiles > 0:
            print( f"Merging {nTiles} Tiles ")
            cropped_data = self.merge_tiles( cropped_tiles)
            cropped_data.attrs.update( roi = self.roi_bounds )
            cropped_data = cropped_data.persist()
        print(f"Done reading mpw data for lake {lake_id} in time {time.time()-t0}, nTiles = {nTiles}")
        return cropped_data, time_values
示例#4
0
                data_vars.append(key)
        return data_vars


if __name__ == "__main__":
    from geoproc.util.configuration import Region
    from geoproc.data.mwp import MWPDataManager

    colors = [(0, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0)]
    locations = ["120W050N", "100W040N"]
    products = ["1D1OS", "2D2OT", "3D3OT"]
    DATA_DIR = "/Users/tpmaxwel/Dropbox/Tom/Data/Birkitt"
    location: str = locations[0]
    product = products[0]
    year = 2019
    download = False
    roi = None
    bbox = Region([3000, 3500], 750)
    time_index_range = [0, 365]

    dataMgr = MWPDataManager(
        DATA_DIR, "https://floodmap.modaps.eosdis.nasa.gov/Products")
    dataMgr.setDefaults(product=product,
                        download=download,
                        year=2019,
                        start_day=time_index_range[0],
                        end_day=time_index_range[1])  # , bbox=bbox )
    data_array: xr.DataArray = dataMgr.get_tile_data(location, True)

    data_array.xplot.animate(title='MPW Time Slice Animation', colors=colors)
示例#5
0
                    data_arrays = [xa.open_rasterio(file)[0] for file in files]
                else:
                    data_arrays = [
                        xa.open_rasterio(file)[0,
                                               bbox.origin[0]:bbox.bounds[0],
                                               bbox.origin[1]:bbox.bounds[1]]
                        for file in files
                    ]
            else:
                dset = xa.open_mfdataset(
                    files) if len(files) > 1 else xa.open_dataset(files[0])
                data_arrays = dset.data_vars.values()
            return [array.to_iris() for array in data_arrays]


if __name__ == '__main__':
    DATA_DIR = "/Users/tpmaxwel/Dropbox/Tom/Data/Birkitt"
    location = "120W050N"
    dataMgr = MWPDataManager(
        DATA_DIR, "https://floodmap.modaps.eosdis.nasa.gov/Products")
    dataMgr.setDefaults(product="1D1OS",
                        download=True,
                        year=2019,
                        start_day=1,
                        end_day=365)
    files = dataMgr.get_tile(location, download=False)

    irisDataMgr = IrisDataManager(DATA_DIR)
    cubes = irisDataMgr.get_cube_data(files)
    print(cubes)
示例#6
0
                               dtype='datetime64[ns]')
        water_prob = water_prob.assign_coords(year=time_values).rename(
            year='time')
    return water_prob


lake_mask: gpd.GeoSeries = gpd.read_file(SHAPEFILE)

cropped_data_file = DATA_DIR + f"/SaltLake_cropped_data.nc"
if use_existing_cropped_data:

    cropped_data_dataset: xr.Dataset = xr.open_dataset(cropped_data_file)
    cropped_data: xr.DataArray = cropped_data_dataset.cropped_data
    cropped_data.attrs['cmap'] = dict(colors=colors4)
else:
    dataMgr = MWPDataManager(DATA_DIR, dat_url)
    dataMgr.setDefaults(product=product,
                        download=download,
                        years=range(*year_range),
                        start_day=time_range[0],
                        end_day=time_range[1])
    file_paths = dataMgr.get_tile(location)

    dem_arrays: List[xr.DataArray] = dataMgr.get_array_data(glob(DEMs))
    dem_array: xr.DataArray = dem_arrays[0]
    xc = dem_array.coords['x']
    yc = dem_array.coords['y']

    time_values = np.array([
        get_date_from_filename(os.path.basename(path)) for path in file_paths
    ],
示例#7
0
location: str = locations[0]
product: str = products[0]
year = 2019
download = False
shpManager = ShapefileManager()
locPoint: Point = shpManager.parseLocation(location)
minH20 = 2
threshold = 0.5
binSize = 8
LakeIndex = 6
time_range = [0, 365]  # [200,216] #
#    subset = [500,100]
subset = None
anim_running = True

dataMgr = MWPDataManager(DATA_DIR, dat_url)
dataMgr.setDefaults(product=product,
                    download=download,
                    year=year,
                    start_day=time_range[0],
                    end_day=time_range[1])
file_paths = dataMgr.get_tile(location)

waterMapGenerator = WaterMapGenerator()
data_array: xr.DataArray = waterMapGenerator.createDataset(file_paths,
                                                           subset=subset)
print(
    f" Data Array {data_array.name}: shape = {data_array.shape}, dims = {data_array.dims}"
)

masking_results: xr.Dataset = waterMapGenerator.get_water_masks(
示例#8
0
    import matplotlib.pyplot as plt
    from matplotlib.colors import LinearSegmentedColormap, Normalize

    locations = ["120W050N", "100W040N"]
    products = ["1D1OS", "3D3OT"]
    DATA_DIR = "/Users/tpmaxwel/Dropbox/Tom/Data/Birkitt"
    data_source_url = "https://floodmap.modaps.eosdis.nasa.gov/Products"
    location: str = locations[1]
    product: str = products[0]
    year = 2019
    start_day = 171
    num_days = 4
    download = False
    south = location[-1] == "S"

    dataMgr = MWPDataManager(DATA_DIR, data_source_url)
    dataMgr.setDefaults(product=product,
                        download=download,
                        year=year,
                        start_day=start_day,
                        end_day=start_day + num_days - 1)
    file_paths = dataMgr.get_tile(location)
    arrays: List[xr.DataArray] = dataMgr.get_array_data(file_paths)
    data_array = arrays[0]

    osgeoManager = OsgeoManager(DATA_DIR)
    result: np.ndarray = osgeoManager.reprojectXarray(arrays[0], 250)

    print(result.shape)

    colors = [(0, 0, 0), (0.5, 1, 0.25), (0, 0, 1), (1, 1, 0)]