Simply read a single PixC netcdf¶
[1]:
from pixcdust.readers.netcdf import NcSimpleReader
import glob
[2]:
swot_nc_files = glob.glob('/tmp/pixc'+'/*/*nc')
[3]:
path = swot_nc_files[0]
# You can specify conditions on variables to filter data
conditions= {"sig0":{'operator': "gt", 'threshold': 20}, # sig0 > 20
"classification":{'operator': "ge", 'threshold': 3}, # classification >= 3
}
ncsimple = NcSimpleReader(path, variables=['height', 'sig0', 'classification'], conditions=conditions)
[4]:
ncsimple.read()
ncsimple.data
[4]:
<xarray.Dataset> Size: 4MB
Dimensions: (points: 109059)
Coordinates:
latitude (points) float64 872kB 43.77 43.77 43.86 ... 43.27 43.28
longitude (points) float64 872kB 0.7553 0.7639 1.23 ... 1.243 1.346
* points (points) object 872kB POINT (0.7552957317809046 43.770648...
Data variables:
height (points) float32 436kB 237.4 238.4 156.3 ... 362.6 259.3
sig0 (points) float32 436kB 71.78 503.4 56.08 ... 21.96 34.85
classification (points) float32 436kB 3.0 6.0 3.0 3.0 ... 6.0 6.0 6.0 3.0
Indexes:
points GeometryIndex (crs=EPSG:4326)
Attributes:
description: cloud of geolocated interferogram pixels
interferogram_size_azimuth: 3244
interferogram_size_range: 4856
looks_to_efflooks: 1.5337356015127774
num_azimuth_looks: 7.0
azimuth_offset: 6[5]:
# show some information
str_time_start, dt_time_start, cycle_number, pass_number, tile_number, swath_size = (
ncsimple.extract_info_from_nc_attrs(path)
)
print(dt_time_start, cycle_number, pass_number, tile_number)
2023-04-07 09:36:56 483 16 78
use data with xarray¶
[6]:
ncsimple.to_xarray() # same thing as ncsimple.data
[6]:
<xarray.Dataset> Size: 4MB
Dimensions: (points: 109059)
Coordinates:
latitude (points) float64 872kB 43.77 43.77 43.86 ... 43.27 43.28
longitude (points) float64 872kB 0.7553 0.7639 1.23 ... 1.243 1.346
* points (points) object 872kB POINT (0.7552957317809046 43.770648...
Data variables:
height (points) float32 436kB 237.4 238.4 156.3 ... 362.6 259.3
sig0 (points) float32 436kB 71.78 503.4 56.08 ... 21.96 34.85
classification (points) float32 436kB 3.0 6.0 3.0 3.0 ... 6.0 6.0 6.0 3.0
Indexes:
points GeometryIndex (crs=EPSG:4326)
Attributes:
description: cloud of geolocated interferogram pixels
interferogram_size_azimuth: 3244
interferogram_size_range: 4856
looks_to_efflooks: 1.5337356015127774
num_azimuth_looks: 7.0
azimuth_offset: 6use data with pandas.dataframe¶
[7]:
ncsimple.to_dataframe()
[7]:
| height | sig0 | classification | latitude | longitude | |
|---|---|---|---|---|---|
| points | |||||
| POINT (0.7552957317809046 43.77064850723897) | 237.401733 | 71.784943 | 3.0 | 43.770649 | 0.755296 |
| POINT (0.7639131748832142 43.772247691826806) | 238.399231 | 503.380829 | 6.0 | 43.772248 | 0.763913 |
| POINT (1.2295628619697254 43.85757065547359) | 156.332687 | 56.083870 | 3.0 | 43.857571 | 1.229563 |
| POINT (1.2415500542200562 43.85973888474052) | 138.921036 | 63.636265 | 3.0 | 43.859739 | 1.241550 |
| POINT (1.2417066520121693 43.85976720035634) | 138.882965 | 108.496094 | 4.0 | 43.859767 | 1.241707 |
| ... | ... | ... | ... | ... | ... |
| POINT (1.1943494760700446 43.257191227213) | 265.892639 | 120.980354 | 3.0 | 43.257191 | 1.194349 |
| POINT (1.2433065548072477 43.26610576917034) | 366.280731 | 26.830383 | 6.0 | 43.266106 | 1.243307 |
| POINT (1.2425256128721571 43.26596377126247) | 362.552002 | 83.249802 | 6.0 | 43.265964 | 1.242526 |
| POINT (1.2428212090849797 43.26601752324333) | 362.644897 | 21.960453 | 6.0 | 43.266018 | 1.242821 |
| POINT (1.3463796618983679 43.28480090306965) | 259.349945 | 34.848278 | 3.0 | 43.284801 | 1.346380 |
109059 rows × 5 columns
use data with geopandas.geodataframe¶
[8]:
gdf = ncsimple.to_geodataframe()
gdf
[8]:
| points | height | sig0 | classification | latitude | longitude | |
|---|---|---|---|---|---|---|
| 0 | POINT (0.75530 43.77065) | 237.401733 | 71.784943 | 3.0 | 43.770649 | 0.755296 |
| 1 | POINT (0.76391 43.77225) | 238.399231 | 503.380829 | 6.0 | 43.772248 | 0.763913 |
| 2 | POINT (1.22956 43.85757) | 156.332687 | 56.083870 | 3.0 | 43.857571 | 1.229563 |
| 3 | POINT (1.24155 43.85974) | 138.921036 | 63.636265 | 3.0 | 43.859739 | 1.241550 |
| 4 | POINT (1.24171 43.85977) | 138.882965 | 108.496094 | 4.0 | 43.859767 | 1.241707 |
| ... | ... | ... | ... | ... | ... | ... |
| 109054 | POINT (1.19435 43.25719) | 265.892639 | 120.980354 | 3.0 | 43.257191 | 1.194349 |
| 109055 | POINT (1.24331 43.26611) | 366.280731 | 26.830383 | 6.0 | 43.266106 | 1.243307 |
| 109056 | POINT (1.24253 43.26596) | 362.552002 | 83.249802 | 6.0 | 43.265964 | 1.242526 |
| 109057 | POINT (1.24282 43.26602) | 362.644897 | 21.960453 | 6.0 | 43.266018 | 1.242821 |
| 109058 | POINT (1.34638 43.28480) | 259.349945 | 34.848278 | 3.0 | 43.284801 | 1.346380 |
109059 rows × 6 columns