Example - Pad Box

[1]:
import rioxarray # for the extension to load
import xarray

%matplotlib inline

Load in xarray dataset

[2]:
xds = xarray.open_dataarray("../../test/test_data/input/MODIS_ARRAY.nc")
[3]:
xds
[3]:
Show/Hide data repr Show/Hide attributes
xarray.DataArray
  • y: 200
  • x: 200
  • nan nan nan nan 687.0 687.0 ... 491.0 504.0 504.0 515.0 469.0 485.0
    array([[ nan,  nan,  nan, ..., 656., 656., 554.],
           [ nan,  nan,  nan, ..., 694., 694., 642.],
           [ nan,  nan,  nan, ..., 456., 575., 642.],
           ...,
           [993., 817., 817., ..., 471., 479., 498.],
           [893., 893., 816., ..., 479., 479., 469.],
           [816., 816., 832., ..., 515., 469., 485.]], dtype=float32)
    • y
      (y)
      float64
      5.05e+06 5.05e+06 ... 5.004e+06
      array([5049992.781974, 5049761.125615, 5049529.469257, 5049297.812899,
             5049066.156541, 5048834.500182, 5048602.843824, 5048371.187466,
             5048139.531108, 5047907.874749, 5047676.218391, 5047444.562033,
             5047212.905674, 5046981.249316, 5046749.592958, 5046517.9366  ,
             5046286.280241, 5046054.623883, 5045822.967525, 5045591.311167,
             5045359.654808, 5045127.99845 , 5044896.342092, 5044664.685734,
             5044433.029375, 5044201.373017, 5043969.716659, 5043738.0603  ,
             5043506.403942, 5043274.747584, 5043043.091226, 5042811.434867,
             5042579.778509, 5042348.122151, 5042116.465793, 5041884.809434,
             5041653.153076, 5041421.496718, 5041189.84036 , 5040958.184001,
             5040726.527643, 5040494.871285, 5040263.214927, 5040031.558568,
             5039799.90221 , 5039568.245852, 5039336.589493, 5039104.933135,
             5038873.276777, 5038641.620419, 5038409.96406 , 5038178.307702,
             5037946.651344, 5037714.994986, 5037483.338627, 5037251.682269,
             5037020.025911, 5036788.369553, 5036556.713194, 5036325.056836,
             5036093.400478, 5035861.74412 , 5035630.087761, 5035398.431403,
             5035166.775045, 5034935.118686, 5034703.462328, 5034471.80597 ,
             5034240.149612, 5034008.493253, 5033776.836895, 5033545.180537,
             5033313.524179, 5033081.86782 , 5032850.211462, 5032618.555104,
             5032386.898746, 5032155.242387, 5031923.586029, 5031691.929671,
             5031460.273313, 5031228.616954, 5030996.960596, 5030765.304238,
             5030533.647879, 5030301.991521, 5030070.335163, 5029838.678805,
             5029607.022446, 5029375.366088, 5029143.70973 , 5028912.053372,
             5028680.397013, 5028448.740655, 5028217.084297, 5027985.427939,
             5027753.77158 , 5027522.115222, 5027290.458864, 5027058.802506,
             5026827.146147, 5026595.489789, 5026363.833431, 5026132.177072,
             5025900.520714, 5025668.864356, 5025437.207998, 5025205.551639,
             5024973.895281, 5024742.238923, 5024510.582565, 5024278.926206,
             5024047.269848, 5023815.61349 , 5023583.957132, 5023352.300773,
             5023120.644415, 5022888.988057, 5022657.331698, 5022425.67534 ,
             5022194.018982, 5021962.362624, 5021730.706265, 5021499.049907,
             5021267.393549, 5021035.737191, 5020804.080832, 5020572.424474,
             5020340.768116, 5020109.111758, 5019877.455399, 5019645.799041,
             5019414.142683, 5019182.486325, 5018950.829966, 5018719.173608,
             5018487.51725 , 5018255.860891, 5018024.204533, 5017792.548175,
             5017560.891817, 5017329.235458, 5017097.5791  , 5016865.922742,
             5016634.266384, 5016402.610025, 5016170.953667, 5015939.297309,
             5015707.640951, 5015475.984592, 5015244.328234, 5015012.671876,
             5014781.015518, 5014549.359159, 5014317.702801, 5014086.046443,
             5013854.390084, 5013622.733726, 5013391.077368, 5013159.42101 ,
             5012927.764651, 5012696.108293, 5012464.451935, 5012232.795577,
             5012001.139218, 5011769.48286 , 5011537.826502, 5011306.170144,
             5011074.513785, 5010842.857427, 5010611.201069, 5010379.544711,
             5010147.888352, 5009916.231994, 5009684.575636, 5009452.919277,
             5009221.262919, 5008989.606561, 5008757.950203, 5008526.293844,
             5008294.637486, 5008062.981128, 5007831.32477 , 5007599.668411,
             5007368.012053, 5007136.355695, 5006904.699337, 5006673.042978,
             5006441.38662 , 5006209.730262, 5005978.073904, 5005746.417545,
             5005514.761187, 5005283.104829, 5005051.44847 , 5004819.792112,
             5004588.135754, 5004356.479396, 5004124.823037, 5003893.166679])
    • x
      (x)
      float64
      -7.274e+06 ... -7.228e+06
      array([-7273893.821307, -7273662.164949, -7273430.508591, -7273198.852232,
             -7272967.195874, -7272735.539516, -7272503.883158, -7272272.226799,
             -7272040.570441, -7271808.914083, -7271577.257725, -7271345.601366,
             -7271113.945008, -7270882.28865 , -7270650.632291, -7270418.975933,
             -7270187.319575, -7269955.663217, -7269724.006858, -7269492.3505  ,
             -7269260.694142, -7269029.037784, -7268797.381425, -7268565.725067,
             -7268334.068709, -7268102.412351, -7267870.755992, -7267639.099634,
             -7267407.443276, -7267175.786918, -7266944.130559, -7266712.474201,
             -7266480.817843, -7266249.161484, -7266017.505126, -7265785.848768,
             -7265554.19241 , -7265322.536051, -7265090.879693, -7264859.223335,
             -7264627.566977, -7264395.910618, -7264164.25426 , -7263932.597902,
             -7263700.941544, -7263469.285185, -7263237.628827, -7263005.972469,
             -7262774.31611 , -7262542.659752, -7262311.003394, -7262079.347036,
             -7261847.690677, -7261616.034319, -7261384.377961, -7261152.721603,
             -7260921.065244, -7260689.408886, -7260457.752528, -7260226.09617 ,
             -7259994.439811, -7259762.783453, -7259531.127095, -7259299.470737,
             -7259067.814378, -7258836.15802 , -7258604.501662, -7258372.845303,
             -7258141.188945, -7257909.532587, -7257677.876229, -7257446.21987 ,
             -7257214.563512, -7256982.907154, -7256751.250796, -7256519.594437,
             -7256287.938079, -7256056.281721, -7255824.625363, -7255592.969004,
             -7255361.312646, -7255129.656288, -7254897.99993 , -7254666.343571,
             -7254434.687213, -7254203.030855, -7253971.374496, -7253739.718138,
             -7253508.06178 , -7253276.405422, -7253044.749063, -7252813.092705,
             -7252581.436347, -7252349.779989, -7252118.12363 , -7251886.467272,
             -7251654.810914, -7251423.154556, -7251191.498197, -7250959.841839,
             -7250728.185481, -7250496.529122, -7250264.872764, -7250033.216406,
             -7249801.560048, -7249569.903689, -7249338.247331, -7249106.590973,
             -7248874.934615, -7248643.278256, -7248411.621898, -7248179.96554 ,
             -7247948.309182, -7247716.652823, -7247484.996465, -7247253.340107,
             -7247021.683749, -7246790.02739 , -7246558.371032, -7246326.714674,
             -7246095.058315, -7245863.401957, -7245631.745599, -7245400.089241,
             -7245168.432882, -7244936.776524, -7244705.120166, -7244473.463808,
             -7244241.807449, -7244010.151091, -7243778.494733, -7243546.838375,
             -7243315.182016, -7243083.525658, -7242851.8693  , -7242620.212942,
             -7242388.556583, -7242156.900225, -7241925.243867, -7241693.587508,
             -7241461.93115 , -7241230.274792, -7240998.618434, -7240766.962075,
             -7240535.305717, -7240303.649359, -7240071.993001, -7239840.336642,
             -7239608.680284, -7239377.023926, -7239145.367568, -7238913.711209,
             -7238682.054851, -7238450.398493, -7238218.742135, -7237987.085776,
             -7237755.429418, -7237523.77306 , -7237292.116701, -7237060.460343,
             -7236828.803985, -7236597.147627, -7236365.491268, -7236133.83491 ,
             -7235902.178552, -7235670.522194, -7235438.865835, -7235207.209477,
             -7234975.553119, -7234743.896761, -7234512.240402, -7234280.584044,
             -7234048.927686, -7233817.271327, -7233585.614969, -7233353.958611,
             -7233122.302253, -7232890.645894, -7232658.989536, -7232427.333178,
             -7232195.67682 , -7231964.020461, -7231732.364103, -7231500.707745,
             -7231269.051387, -7231037.395028, -7230805.73867 , -7230574.082312,
             -7230342.425954, -7230110.769595, -7229879.113237, -7229647.456879,
             -7229415.80052 , -7229184.144162, -7228952.487804, -7228720.831446,
             -7228489.175087, -7228257.518729, -7228025.862371, -7227794.206013])
  • crs :
    +a=6371007.181 +b=6371007.181 +lon_0=0 +no_defs +proj=sinu +units=m +x_0=0 +y_0=0
    res :
    [231.65635826 231.65635826]
    is_tiled :
    0
    nodata :
    -28672.0
    transform :
    [ 2.31656358e+02 0.00000000e+00 -7.27400965e+06 0.00000000e+00 -2.31656358e+02 5.05010861e+06 0.00000000e+00 0.00000000e+00 1.00000000e+00]
[5]:
xds.plot()
[5]:
<matplotlib.collections.QuadMesh at 0x7fcb90621438>
../_images/examples_pad_box_5_1.png

Pad using a bounding box

See docs for rio.pad_box:

[6]:
xdsc = xds.rio.pad_box(
    minx=-7.3e+06,
    miny=4.99e+06,
    maxx=-7.2e+06,
    maxy=5.06e+06,
)
[9]:
xdsc.values[0, 0]
[9]:
nan
[8]:
xdsc.plot()
[8]:
<matplotlib.collections.QuadMesh at 0x7fcb8ed54ba8>
../_images/examples_pad_box_9_1.png