Skip to content

Commit

Permalink
fix: remove kernel cwd workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Dec 5, 2024
1 parent 90bf902 commit 7499490
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 18 deletions.
3 changes: 1 addition & 2 deletions book/01_Geospatial_Background/02_Working_with_Raster_Data.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ As an example, let's load data from a local GeoTIFF file using the Python `rioxa
from pathlib import Path
import rioxarray as rio
FILE_STEM = Path.cwd().parent if 'book' == Path.cwd().parent.stem else 'book'
LOCAL_PATH = Path(FILE_STEM, 'assets/OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif'
```

```{code-cell} python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ Let's see how to parse and plot GeoJSON files using [GeoPandas](https://geopanda
import geopandas as gpd
from pathlib import Path
FILE_STEM = Path.cwd().parent if 'book' == Path.cwd().parent.stem else 'book'
GEOJSON = Path(FILE_STEM, 'assets/cables.geojson')
print(GEOJSON)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import rasterio
import rioxarray as rio
from pathlib import Path
FILE_STEM = Path.cwd().parent if 'book' == Path.cwd().parent.stem else 'book'
```

***
Expand All @@ -48,7 +47,7 @@ Observe first that `open_rasterio` works on local file paths and remote URLs.

```{code-cell} python jupyter={"source_hidden": false}
%%time
LOCAL_PATH = Path(FILE_STEM, 'assets/OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif'
data = rio.open_rasterio(LOCAL_PATH)
```

Expand Down Expand Up @@ -90,7 +89,7 @@ From the [Rasterio documentation](https://rasterio.readthedocs.io/en/stable):

```{code-cell} python jupyter={"source_hidden": false}
# Show rasterio.open works using context manager
LOCAL_PATH = Path(FILE_STEM, 'assets/OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif'
print(LOCAL_PATH)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ from pathlib import Path
import numpy as np, pandas as pd, xarray as xr
import rioxarray as rio
FILE_STEM = Path.cwd().parent if 'book' == Path.cwd().parent.stem else 'book'
```

***
Expand All @@ -39,7 +38,7 @@ Let's load an example `xarray.DataArray` data structure from a file whose locati
<!-- #endregion -->

```{code-cell} python jupyter={"source_hidden": false}
LOCAL_PATH = Path(FILE_STEM, 'assets/OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif'
data = rio.open_rasterio(LOCAL_PATH)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import geoviews as gv
gv.extension('bokeh')
from geoviews import opts
FILE_STEM = Path.cwd().parent if 'book' == Path.cwd().parent.stem else 'book'
```

***
Expand Down Expand Up @@ -200,7 +199,7 @@ The code below loads a Pandas DataFrame of temperature data.
```{code-cell} python jupyter={"source_hidden": false}
import pandas as pd, numpy as np
from pathlib import Path
LOCAL_PATH = Path(FILE_STEM, 'assets/temperature.csv')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'temperature.csv'
```

```{code-cell} python jupyter={"source_hidden": false}
Expand Down Expand Up @@ -281,7 +280,7 @@ To start, load a local GeoTIFF file using `rioxarray` into an Zarray `DataArray`
<!-- #endregion -->

```{code-cell} python jupyter={"source_hidden": false}
LOCAL_PATH = Path(FILE_STEM, 'assets/OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif'
```

```{code-cell} python jupyter={"source_hidden": false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ gv.extension('bokeh')
```

```{code-cell} python jupyter={"source_hidden": false}
FILE_STEM = Path.cwd().parent if 'book' == Path.cwd().parent.stem else 'book'
ASSET_PATH = Path(FILE_STEM, 'assets')
SHAPE_FILE = ASSET_PATH / 'shapefiles' / 'mckinney' / 'McKinney_NIFC.shp'
RASTER_FILES = list(ASSET_PATH.glob('OPERA*VEG*.tif'))
Expand Down
7 changes: 3 additions & 4 deletions book/03_Using_NASA_EarthData/01_Using_OPERA_DIST_Products.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ gv.extension('bokeh')
import hvplot.xarray
from bokeh.models import FixedTicker
FILE_STEM = Path.cwd().parent if 'book' == Path.cwd().parent.stem else 'book'
```

<!-- #region jupyter={"source_hidden": false} -->
We'll read the data from a local file `'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif'`. Before loading the data, let's examine the metadata embedded in the filename.
<!-- #endregion -->

```{code-cell} python jupyter={"source_hidden": false}
LOCAL_PATH = Path(FILE_STEM, 'assets/OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-ANOM-MAX.tif'
filename = LOCAL_PATH.name
print(filename)
```
Expand Down Expand Up @@ -197,7 +196,7 @@ We'll load and relabel the `DataArray` as before.
<!-- #endregion -->

```{code-cell} python jupyter={"source_hidden": false}
LOCAL_PATH = Path(FILE_STEM, 'assets/OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-DIST-DATE.tif')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-DIST-DATE.tif'
data = rio.open_rasterio(LOCAL_PATH)
data = data.rename({'x':'longitude', 'y':'latitude', 'band':'band'}).squeeze()
```
Expand Down Expand Up @@ -266,7 +265,7 @@ Notice the use of the `FixedTicker` in defining a colorbar better suited for a d
<!-- #endregion -->

```{code-cell} python jupyter={"source_hidden": false}
LOCAL_PATH = Path(FILE_STEM, 'assets/OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-DIST-STATUS.tif')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T185931Z_20220817T153514Z_S2A_30_v0.1_VEG-DIST-STATUS.tif'
data = rio.open_rasterio(LOCAL_PATH)
data = data.rename({'x':'longitude', 'y':'latitude', 'band':'band'}).squeeze()
```
Expand Down
3 changes: 1 addition & 2 deletions book/03_Using_NASA_EarthData/02_Using_OPERA_DSWx_Products.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ from bokeh.models import FixedTicker
```

```{code-cell} python
FILE_STEM = Path.cwd().parent if 'book' == Path.cwd().parent.stem else 'book'
LOCAL_PATH = Path(FILE_STEM, 'assets/OPERA_L3_DSWx-HLS_T12SVG_20230411T180222Z_20230414T030945Z_L8_30_v1.0_B01_WTR.tif')
LOCAL_PATH = Path.cwd().parent / 'assets' / 'OPERA_L3_DSWx-HLS_T12SVG_20230411T180222Z_20230414T030945Z_L8_30_v1.0_B01_WTR.tif'
b01_wtr = rio.open_rasterio(LOCAL_PATH).rename({'x':'longitude', 'y':'latitude'}).squeeze()
```

Expand Down

0 comments on commit 7499490

Please sign in to comment.