Skip to content

Commit

Permalink
Merge pull request #118 from umr-lops/pre-release-v0.9
Browse files Browse the repository at this point in the history
release v0.9
  • Loading branch information
agrouaze authored Oct 17, 2022
2 parents 3837840 + 0411b1b commit f64436a
Show file tree
Hide file tree
Showing 15 changed files with 1,070 additions and 592 deletions.
4 changes: 2 additions & 2 deletions docs/examples/mask.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"# get the shapely polygon of the mask (on the footprint, lon/lat)\n",
"land_poly = s1meta.get_mask('ocean')\n",
"\n",
"# convert lon/lat to atrack/xtrack\n",
"# convert lon/lat to line/sample\n",
"land_poly_coords = s1meta.ll2coords(s1meta.get_mask('ocean'))\n",
"\n",
"# plot masked sigma0, with coastline\n",
Expand Down Expand Up @@ -141,7 +141,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
26 changes: 16 additions & 10 deletions docs/examples/projections.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"id": "ab8a4bb1-6523-4d93-b2a8-068355328498",
"metadata": {},
"source": [
"To have it displayed the same way it was aquired, we need to pass `kdims=['xtrack', 'atrack']`.\n",
"To have it displayed the same way it was aquired, we need to pass `kdims=['sample', 'line']`.\n",
"\n",
"We can see here that the orbit pass is **descending**"
]
Expand All @@ -86,7 +86,7 @@
"metadata": {},
"outputs": [],
"source": [
"hv.Image(xsar_obj.dataset.sigma0.sel(pol='VV'), kdims=['xtrack', 'atrack']).opts(alpha=0.7, cmap='gray', clim=(0,0.05))"
"hv.Image(xsar_obj.dataset.sigma0.sel(pol='VV'), kdims=['sample', 'line']).opts(alpha=0.7, cmap='gray', clim=(0,0.05))"
]
},
{
Expand All @@ -111,6 +111,7 @@
"metadata": {},
"outputs": [],
"source": [
"import rasterio\n",
"xsar_obj.recompute_attrs()\n",
"sigma0_proj = xsar_obj.dataset['sigma0'].rio.reproject('epsg:4326',shape=(1000,1000),nodata=np.nan)\n",
"sigma0_proj"
Expand Down Expand Up @@ -198,8 +199,8 @@
"cmap.set_clim(vmin=0, vmax=0.05)\n",
"rgb_sigma0 = xr.DataArray(\n",
" (cmap.to_rgba(xsar_obj.dataset['sigma0'].sel(pol='VV'), bytes=True)), \n",
" dims=['atrack', 'xtrack', 'band']\n",
").transpose('band', 'atrack', 'xtrack')\n",
" dims=['line', 'sample', 'band']\n",
").transpose('band', 'line', 'sample')\n",
"rgb_sigma0\n"
]
},
Expand All @@ -208,7 +209,7 @@
"id": "3570b206-ebac-4bc8-a58a-b3a24b4369a8",
"metadata": {},
"source": [
"`rgb_sigma0` is now an `xarray.DataArray`, with sames spatials dims `['atrack', 'xtrack']`, and an new dim `band` that hold color in R,G,B,A. \n",
"`rgb_sigma0` is now an `xarray.DataArray`, with sames spatials dims `['line', 'sample']`, and an new dim `band` that hold color in R,G,B,A. \n",
"\n",
"This dataarray is currently not georeferenced. To georefence it, we have **to store it into xsar_obj.dataset and call [xsar.Sentinel1Dataset.recompute_attrs()](../basic_api.rst#xsar.Sentinel1Dataset.recompute_attrs)**.\n"
]
Expand All @@ -220,7 +221,9 @@
"metadata": {},
"outputs": [],
"source": [
"xsar_obj.dataset['sigma0_rgba'] = rgb_sigma0 \n",
"#xsar_obj.dataset['sigma0_rgba'] = rgb_sigma0 \n",
"rgb_sigma0.name = 'sigma0_rgba'\n",
"xsar_obj.datatree['measurement'] = xsar_obj.datatree['measurement'].assign(xr.merge([xsar_obj.dataset,rgb_sigma0]))\n",
"xsar_obj.recompute_attrs()\n",
"xsar_obj.dataset['sigma0_rgba'].rio.reproject('epsg:4326',shape=(1000,1000),nodata=0).rio.to_raster('/tmp/sigma0_color.tiff')"
]
Expand Down Expand Up @@ -373,7 +376,10 @@
"metadata": {},
"outputs": [],
"source": [
"xsar_obj.dataset['sigma0_rasterized'] = xsar_obj.map_raster(merged_grid['sigma0'])\n",
"#xsar_obj.dataset['sigma0_rasterized'] = \n",
"tmp_ds = xsar_obj.map_raster(merged_grid['sigma0'])\n",
"tmp_ds.name = 'sigma0_rasterized'\n",
"xsar_obj.datatree['measurement'] = xsar_obj.datatree['measurement'].assign(xr.merge([xsar_obj.dataset,tmp_ds]))\n",
"xsar_obj.recompute_attrs()"
]
},
Expand All @@ -385,8 +391,8 @@
"outputs": [],
"source": [
"(\n",
" hv.Image(xsar_obj.dataset['sigma0_rasterized'], kdims=['xtrack','atrack']).opts(title='from raster') \n",
" + hv.Image(xsar_obj.dataset.sigma0.sel(pol='VV'), kdims=['xtrack','atrack']).opts(title='original') \n",
" hv.Image(xsar_obj.dataset['sigma0_rasterized'], kdims=['sample','line']).opts(title='from raster') \n",
" + hv.Image(xsar_obj.dataset.sigma0.sel(pol='VV'), kdims=['sample','line']).opts(title='original') \n",
").opts(hv.opts.Image(tools=['hover'],cmap='gray', clim=(0,0.05), alpha=0.7))"
]
}
Expand All @@ -407,7 +413,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down
26 changes: 22 additions & 4 deletions docs/examples/xsar.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,43 @@
"filename"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# open the datatree with xarray\n",
"dt_xsar = xsar.open_datatree(filename,resolution='100m')\n",
"dt_xsar"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# open the dataset with xarray\n",
"sar_ds = xsar.open_dataset(filename, resolution='100m')\n",
"sar_ds"
"ds_xsar = xsar.open_dataset(filename, resolution='100m')\n",
"ds_xsar"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# we use here 'rasterize' to display the image, because the full image is really big\n",
"rasterize(hv.Image(sar_ds.sigma0.sel(pol='VH')).opts(cmap='gray',colorbar=True,tools=['hover'],title=\"xsar\",width=800,height=800,clim=(0,0.02)))"
"rasterize(hv.Image(ds_xsar.sigma0.sel(pol='VH')).opts(cmap='gray',colorbar=True,tools=['hover'],title=\"xsar\",width=800,height=800,clim=(0,0.02)))"
]
}
],
Expand All @@ -81,7 +99,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
16 changes: 10 additions & 6 deletions docs/examples/xsar_advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"\n",
"It might be:\n",
"\n",
" * a dict `{'atrack': 20, 'xtrack': 20}`: 20*20 pixels. so if sensor resolution is 10m, the final resolution will be 100m\n",
" * a dict `{'line': 20, 'sample': 20}`: 20*20 pixels. so if sensor resolution is 10m, the final resolution will be 100m\n",
" * a string like `'200m'`: Sensor resolution will be automatically used to compute the window size"
]
},
Expand All @@ -122,8 +122,8 @@
"source": [
"## Extract a sub image of 10*10km around a lon/lat point\n",
"\n",
"### Convert (lon,lat) to (atrack, xtrack)\n",
"we can use [sar_meta.ll2coords](../basic_api.rst#xsar.Sentinel1Meta.ll2coords) to convert (lon,lat) to (atrack, xtrack):"
"### Convert (lon,lat) to (line, sample)\n",
"we can use [sar_meta.ll2coords](../basic_api.rst#xsar.Sentinel1Meta.ll2coords) to convert (lon,lat) to (line, sample):"
]
},
{
Expand All @@ -144,7 +144,7 @@
"source": [
"The result is floating, because it is the position inside the pixel.\n",
"If real indexes from existing dataset is needed, you'll have to use [sar_ds.ll2coords](../basic_api.rst#xsar.Sentinel1Dataset.ll2coords) \n",
"Result will be the nearest (atrack, xtrack) in the dataset"
"Result will be the nearest (line, sample) in the dataset"
]
},
{
Expand All @@ -171,7 +171,7 @@
"outputs": [],
"source": [
"box_size = 10000 # 10km\n",
"dist = {'atrack' : int(np.round(box_size / 2 / sar_meta.pixel_atrack_m)), 'xtrack': int(np.round(box_size / 2 / sar_meta.pixel_xtrack_m))}\n",
"dist = {'line' : int(np.round(box_size / 2 / sar_meta.pixel_line_m)), 'sample': int(np.round(box_size / 2 / sar_meta.pixel_sample_m))}\n",
"dist"
]
},
Expand All @@ -190,7 +190,7 @@
"outputs": [],
"source": [
"# select 10*10 km around point_coords\n",
"sar_ds.dataset = sar_ds.dataset.sel(atrack=slice(point_coords[0] - dist['atrack'], point_coords[0] + dist['atrack']), xtrack=slice(point_coords[1] - dist['xtrack'], point_coords[1] + dist['xtrack']))\n",
"sar_ds.dataset = sar_ds.dataset.sel(line=slice(point_coords[0] - dist['line'], point_coords[0] + dist['line']), sample=slice(point_coords[1] - dist['sample'], point_coords[1] + dist['sample']))\n",
"sar_ds"
]
},
Expand All @@ -205,6 +205,10 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "",
"name": ""
},
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/xsar_batch_datarmor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"outputs": [],
"source": [
"def l1b(safe, outfile):\n",
" ds = xsar.open_dataset(safe, resolution='1000m')\n",
" ds = xsar.open_dataset(safe, resolution='1000m')['measurement'].ds\n",
" # make attributes to be str, so writable to file\n",
" to_str = ['start_date', 'stop_date', 'footprint']\n",
" for attr in to_str:\n",
Expand Down
Loading

0 comments on commit f64436a

Please sign in to comment.