From 7499490b16934633e0cb06d2088f1b4f5727387b Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Thu, 5 Dec 2024 14:55:22 +0000 Subject: [PATCH] fix: remove kernel cwd workaround --- .../02_Working_with_Raster_Data.md | 3 +-- .../03_Working_with_Vector_Data.md | 1 - .../01_Loading_Raster_Data_from_GeoTIFF_Files.md | 5 ++--- .../02_Array_Manipulation_with_Xarray.md | 3 +-- .../03_Data_Visualization_with_GeoViews_HvPlot.md | 5 ++--- .../04_Constructing_Advanced_Visualizations.md | 1 - .../01_Using_OPERA_DIST_Products.md | 7 +++---- .../02_Using_OPERA_DSWx_Products.md | 3 +-- 8 files changed, 10 insertions(+), 18 deletions(-) diff --git a/book/01_Geospatial_Background/02_Working_with_Raster_Data.md b/book/01_Geospatial_Background/02_Working_with_Raster_Data.md index e7d7a9b..00c7e46 100644 --- a/book/01_Geospatial_Background/02_Working_with_Raster_Data.md +++ b/book/01_Geospatial_Background/02_Working_with_Raster_Data.md @@ -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 diff --git a/book/01_Geospatial_Background/03_Working_with_Vector_Data.md b/book/01_Geospatial_Background/03_Working_with_Vector_Data.md index f412218..b45367a 100644 --- a/book/01_Geospatial_Background/03_Working_with_Vector_Data.md +++ b/book/01_Geospatial_Background/03_Working_with_Vector_Data.md @@ -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) ``` diff --git a/book/02_Software_Tools_Techniques/01_Loading_Raster_Data_from_GeoTIFF_Files.md b/book/02_Software_Tools_Techniques/01_Loading_Raster_Data_from_GeoTIFF_Files.md index 7d60eac..1627851 100644 --- a/book/02_Software_Tools_Techniques/01_Loading_Raster_Data_from_GeoTIFF_Files.md +++ b/book/02_Software_Tools_Techniques/01_Loading_Raster_Data_from_GeoTIFF_Files.md @@ -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' ``` *** @@ -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) ``` @@ -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) ``` diff --git a/book/02_Software_Tools_Techniques/02_Array_Manipulation_with_Xarray.md b/book/02_Software_Tools_Techniques/02_Array_Manipulation_with_Xarray.md index 78c368d..6d5ae61 100644 --- a/book/02_Software_Tools_Techniques/02_Array_Manipulation_with_Xarray.md +++ b/book/02_Software_Tools_Techniques/02_Array_Manipulation_with_Xarray.md @@ -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' ``` *** @@ -39,7 +38,7 @@ Let's load an example `xarray.DataArray` data structure from a file whose locati ```{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) ``` diff --git a/book/02_Software_Tools_Techniques/03_Data_Visualization_with_GeoViews_HvPlot.md b/book/02_Software_Tools_Techniques/03_Data_Visualization_with_GeoViews_HvPlot.md index 26565c1..0b7d165 100644 --- a/book/02_Software_Tools_Techniques/03_Data_Visualization_with_GeoViews_HvPlot.md +++ b/book/02_Software_Tools_Techniques/03_Data_Visualization_with_GeoViews_HvPlot.md @@ -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' ``` *** @@ -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} @@ -281,7 +280,7 @@ To start, load a local GeoTIFF file using `rioxarray` into an Zarray `DataArray` ```{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} diff --git a/book/02_Software_Tools_Techniques/04_Constructing_Advanced_Visualizations.md b/book/02_Software_Tools_Techniques/04_Constructing_Advanced_Visualizations.md index b271ae9..0f78225 100644 --- a/book/02_Software_Tools_Techniques/04_Constructing_Advanced_Visualizations.md +++ b/book/02_Software_Tools_Techniques/04_Constructing_Advanced_Visualizations.md @@ -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')) diff --git a/book/03_Using_NASA_EarthData/01_Using_OPERA_DIST_Products.md b/book/03_Using_NASA_EarthData/01_Using_OPERA_DIST_Products.md index bb5f79c..e610de0 100644 --- a/book/03_Using_NASA_EarthData/01_Using_OPERA_DIST_Products.md +++ b/book/03_Using_NASA_EarthData/01_Using_OPERA_DIST_Products.md @@ -74,7 +74,6 @@ gv.extension('bokeh') import hvplot.xarray from bokeh.models import FixedTicker -FILE_STEM = Path.cwd().parent if 'book' == Path.cwd().parent.stem else 'book' ``` @@ -82,7 +81,7 @@ We'll read the data from a local file `'OPERA_L3_DIST-ALERT-HLS_T10TEM_20220815T ```{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) ``` @@ -197,7 +196,7 @@ We'll load and relabel the `DataArray` as before. ```{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() ``` @@ -266,7 +265,7 @@ Notice the use of the `FixedTicker` in defining a colorbar better suited for a d ```{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() ``` diff --git a/book/03_Using_NASA_EarthData/02_Using_OPERA_DSWx_Products.md b/book/03_Using_NASA_EarthData/02_Using_OPERA_DSWx_Products.md index b1f19c9..3ca6ed2 100644 --- a/book/03_Using_NASA_EarthData/02_Using_OPERA_DSWx_Products.md +++ b/book/03_Using_NASA_EarthData/02_Using_OPERA_DSWx_Products.md @@ -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() ```