grdwindinversion 0.2.3.post15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- grdwindinversion/.github/ISSUE_TEMPLATE.md +15 -0
- grdwindinversion/.gitignore +106 -0
- grdwindinversion/.travis.yml +28 -0
- grdwindinversion/__init__.py +14 -0
- grdwindinversion/config_prod.yaml +45 -0
- grdwindinversion/config_prod_recal.yaml +45 -0
- grdwindinversion/data_config.yaml +5 -0
- grdwindinversion/inversion.py +1002 -0
- grdwindinversion/load_config.py +24 -0
- grdwindinversion/main.py +59 -0
- grdwindinversion/streaks.py +79 -0
- grdwindinversion/utils.py +42 -0
- grdwindinversion-0.2.3.post15.dist-info/AUTHORS.rst +14 -0
- grdwindinversion-0.2.3.post15.dist-info/LICENSE +22 -0
- grdwindinversion-0.2.3.post15.dist-info/METADATA +80 -0
- grdwindinversion-0.2.3.post15.dist-info/RECORD +19 -0
- grdwindinversion-0.2.3.post15.dist-info/WHEEL +5 -0
- grdwindinversion-0.2.3.post15.dist-info/entry_points.txt +2 -0
- grdwindinversion-0.2.3.post15.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from yaml import load
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import grdwindinversion
|
|
5
|
+
from yaml import CLoader as Loader
|
|
6
|
+
local_config_potential_path = os.path.expanduser(
|
|
7
|
+
'~/.grdwindinversion/data_config.yaml')
|
|
8
|
+
|
|
9
|
+
if os.path.exists(local_config_potential_path):
|
|
10
|
+
config_path = local_config_potential_path
|
|
11
|
+
else:
|
|
12
|
+
config_path = os.path.join(os.path.dirname(
|
|
13
|
+
grdwindinversion.__file__), 'data_config.yaml')
|
|
14
|
+
logging.info('config path: %s', config_path)
|
|
15
|
+
stream = open(config_path, 'r')
|
|
16
|
+
conf = load(stream, Loader=Loader)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def getConf():
|
|
20
|
+
"""
|
|
21
|
+
if local_config_potential_path exists it will superseed config_path
|
|
22
|
+
:return:
|
|
23
|
+
"""
|
|
24
|
+
return conf
|
grdwindinversion/main.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from grdwindinversion.inversion import makeL2
|
|
2
|
+
from grdwindinversion.utils import get_memory_usage
|
|
3
|
+
import grdwindinversion
|
|
4
|
+
import time
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def processor_starting_point():
|
|
9
|
+
import argparse
|
|
10
|
+
|
|
11
|
+
parser = argparse.ArgumentParser(
|
|
12
|
+
description='Perform inversion from S1(L1-GRD) SAFE, L1-RCM, L1-RS2 ; using xsar/xsarsea tools')
|
|
13
|
+
parser.add_argument('--input_file', help='input file path', required=True)
|
|
14
|
+
parser.add_argument('--config_file',
|
|
15
|
+
help='config file path [if not provided will take config file based on input file]', required=True)
|
|
16
|
+
parser.add_argument('--resolution', required=False, default='1000m',
|
|
17
|
+
help='set resolution ["full" | "1000m" | "xXxm"]')
|
|
18
|
+
|
|
19
|
+
parser.add_argument('--outputdir', required=True)
|
|
20
|
+
parser.add_argument('--verbose', action='store_true', default=False)
|
|
21
|
+
parser.add_argument('--overwrite', action='store_true', default=False,
|
|
22
|
+
help='overwrite existing .nc files [default is False]', required=False)
|
|
23
|
+
|
|
24
|
+
parser.add_argument('--no_generate_csv', action='store_false',
|
|
25
|
+
help="En cas d'activation, désactive la génération du .csv")
|
|
26
|
+
|
|
27
|
+
args = parser.parse_args()
|
|
28
|
+
fmt = '%(asctime)s %(levelname)s %(filename)s(%(lineno)d) %(message)s'
|
|
29
|
+
if args.verbose:
|
|
30
|
+
logging.basicConfig(level=logging.DEBUG, format=fmt,
|
|
31
|
+
datefmt='%d/%m/%Y %H:%M:%S', force=True)
|
|
32
|
+
else:
|
|
33
|
+
logging.basicConfig(level=logging.INFO, format=fmt,
|
|
34
|
+
datefmt='%d/%m/%Y %H:%M:%S', force=True)
|
|
35
|
+
t0 = time.time()
|
|
36
|
+
input_file = args.input_file.rstrip('/')
|
|
37
|
+
logging.info('input file: %s', input_file)
|
|
38
|
+
|
|
39
|
+
# if '1SDV' not in input_file and '_VV_VH' not in input_file:
|
|
40
|
+
# raise Exception('this processor only handle dual polarization acquisitions VV+VH for now.')
|
|
41
|
+
# if '1SSH' in input_file or '1SDH' in input_file or '_HH_HV' in input_file:
|
|
42
|
+
# raise Exception('this processor only handle acquisitions with VV or VV+VH polarization for now.')
|
|
43
|
+
|
|
44
|
+
config_file = args.config_file
|
|
45
|
+
out_folder = args.outputdir
|
|
46
|
+
resolution = args.resolution
|
|
47
|
+
if resolution == "full":
|
|
48
|
+
resolution = None
|
|
49
|
+
|
|
50
|
+
out_file, outputds = makeL2(input_file, out_folder, config_file,
|
|
51
|
+
overwrite=args.overwrite, resolution=resolution, generateCSV=args.no_generate_csv)
|
|
52
|
+
|
|
53
|
+
logging.info('out_file: %s', out_file)
|
|
54
|
+
logging.info('current memory usage: %s ', get_memory_usage(var='current'))
|
|
55
|
+
logging.info('done in %1.3f min', (time.time() - t0) / 60.)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == '__main__':
|
|
59
|
+
processor_starting_point()
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import xarray as xr
|
|
2
|
+
import xsarsea.gradients
|
|
3
|
+
import xarray as xr
|
|
4
|
+
from scipy.ndimage import binary_dilation
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_streaks(xr_dataset, xr_dataset_100):
|
|
9
|
+
"""
|
|
10
|
+
Get the streaks from the wind field.
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
xr_dataset : xarray.Dataset
|
|
15
|
+
dataset at user resolution.
|
|
16
|
+
xr_dataset_100 : xarray.Dataset
|
|
17
|
+
dataset at 100m resolution.
|
|
18
|
+
|
|
19
|
+
Returns
|
|
20
|
+
-------
|
|
21
|
+
xarray.Dataset
|
|
22
|
+
Extract wind direction from Koch Method using xsarsea tools.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
# return empy dataArray, waiting for solution
|
|
26
|
+
return xr.DataArray(data=np.nan * np.ones([len(xr_dataset.coords[dim]) for dim in ['line','sample']]),
|
|
27
|
+
dims=['line','sample'],
|
|
28
|
+
coords=[xr_dataset.coords[dim] for dim in ['line','sample']])
|
|
29
|
+
#
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
gradients = xsarsea.gradients.Gradients(xr_dataset_100['sigma0_detrend'], windows_sizes=[
|
|
33
|
+
1600, 3200], downscales_factors=[1, 2], window_step=1)
|
|
34
|
+
|
|
35
|
+
# get gradients histograms as an xarray dataset
|
|
36
|
+
hist = gradients.histogram
|
|
37
|
+
|
|
38
|
+
# get orthogonals gradients
|
|
39
|
+
hist['angles'] = hist['angles'] + np.pi/2
|
|
40
|
+
|
|
41
|
+
# mean
|
|
42
|
+
hist_mean = hist.mean(['downscale_factor', 'window_size', 'pol'])
|
|
43
|
+
|
|
44
|
+
# smooth
|
|
45
|
+
hist_mean_smooth = hist_mean.copy()
|
|
46
|
+
hist_mean_smooth['weight'] = xsarsea.gradients.circ_smooth(
|
|
47
|
+
hist_mean['weight'])
|
|
48
|
+
|
|
49
|
+
# smooth only
|
|
50
|
+
# hist_smooth = hist.copy()
|
|
51
|
+
# hist_smooth['weight'] = xsarsea.gradients.circ_smooth(hist_smooth['weight'])
|
|
52
|
+
|
|
53
|
+
# select histogram peak
|
|
54
|
+
iangle = hist_mean_smooth['weight'].fillna(0).argmax(dim='angles')
|
|
55
|
+
streaks_dir = hist_mean_smooth.angles.isel(angles=iangle)
|
|
56
|
+
streaks_weight = hist_mean_smooth['weight'].isel(angles=iangle)
|
|
57
|
+
streaks = xr.merge(
|
|
58
|
+
[dict(angle=streaks_dir, weight=streaks_weight)]).drop('angles')
|
|
59
|
+
|
|
60
|
+
# streaks are [0, pi]. Remove ambiguity with anciallary wind
|
|
61
|
+
ancillary_wind = xr_dataset_100['ancillary_wind'].sel(line=streaks.line,
|
|
62
|
+
sample=streaks.sample,
|
|
63
|
+
method='nearest').compute()
|
|
64
|
+
streaks_c = streaks['weight'] * np.exp(1j * streaks['angle'])
|
|
65
|
+
diff_angle = xr.apply_ufunc(np.angle, ancillary_wind / streaks_c)
|
|
66
|
+
streaks_c = xr.where(np.abs(diff_angle) > np.pi/2, -streaks_c, streaks_c)
|
|
67
|
+
streaks['weight'] = np.abs(streaks_c)
|
|
68
|
+
streaks['angle'] = xr.apply_ufunc(np.angle, streaks_c)
|
|
69
|
+
|
|
70
|
+
streaks_dir = xr.apply_ufunc(
|
|
71
|
+
np.angle, streaks_c.interp(line=xr_dataset.line, sample=xr_dataset.sample))
|
|
72
|
+
streaks_dir = xr.where(
|
|
73
|
+
xr_dataset['land_mask'], np.nan, streaks_dir)
|
|
74
|
+
streaks_dir.attrs['comment'] = 'angle in radians, anticlockwise, 0=line'
|
|
75
|
+
streaks_dir.attrs['description'] = 'wind direction estimated from local gradient, and direction ambiguity removed with ancillary wind'
|
|
76
|
+
|
|
77
|
+
return streaks_dir
|
|
78
|
+
|
|
79
|
+
"""
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
def get_memory_usage(unit='Go', var='ru_maxrss', force_psutil=False):
|
|
2
|
+
"""
|
|
3
|
+
var str: ru_maxrss or ru_ixrss or ru_idrss or ru_isrss or current
|
|
4
|
+
Returns
|
|
5
|
+
-------
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
if unit == 'Go':
|
|
9
|
+
factor = 1000000.
|
|
10
|
+
elif unit == 'Mo':
|
|
11
|
+
factor = 1000.
|
|
12
|
+
elif unit == 'Ko':
|
|
13
|
+
factor = 1.
|
|
14
|
+
else:
|
|
15
|
+
raise Exception('not handle unit')
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
if force_psutil:
|
|
19
|
+
on_purpose_error
|
|
20
|
+
import resource
|
|
21
|
+
mems = {}
|
|
22
|
+
mems['ru_maxrss'] = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / factor
|
|
23
|
+
mems['ru_ixrss'] = resource.getrusage(resource.RUSAGE_SELF).ru_ixrss / factor
|
|
24
|
+
mems['ru_idrss'] = resource.getrusage(resource.RUSAGE_SELF).ru_idrss / factor
|
|
25
|
+
mems['ru_isrss'] = resource.getrusage(resource.RUSAGE_SELF).ru_isrss / factor
|
|
26
|
+
mems['current'] = getCurrentMemoryUsage() / factor
|
|
27
|
+
# memory_used_go = resource.getrusage(resource.RUSAGE_SELF).get(var) /factor
|
|
28
|
+
memory_used_go = mems[var]
|
|
29
|
+
except: # on windows resource is not usable
|
|
30
|
+
import psutil
|
|
31
|
+
memory_used_go = psutil.virtual_memory().used / factor / 1000.
|
|
32
|
+
str_mem = 'RAM usage: %1.1f %s' % (memory_used_go, unit)
|
|
33
|
+
return str_mem
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def getCurrentMemoryUsage():
|
|
37
|
+
''' Memory usage in kB '''
|
|
38
|
+
|
|
39
|
+
with open('/proc/self/status') as f:
|
|
40
|
+
memusage = f.read().split('VmRSS:')[1].split('\n')[0][:-3]
|
|
41
|
+
|
|
42
|
+
return int(memusage.strip())
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, Antoine Grouazel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: grdwindinversion
|
|
3
|
+
Version: 0.2.3.post15
|
|
4
|
+
Summary: Package to perform Wind inversion from GRD Level-1 SAR images
|
|
5
|
+
License: MIT
|
|
6
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Natural Language :: English
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
License-File: AUTHORS.rst
|
|
21
|
+
Requires-Dist: xsar
|
|
22
|
+
Requires-Dist: xsarsea
|
|
23
|
+
Requires-Dist: xarray
|
|
24
|
+
Requires-Dist: xarray-datatree
|
|
25
|
+
Requires-Dist: pyyaml
|
|
26
|
+
Requires-Dist: numpy
|
|
27
|
+
Requires-Dist: scipy
|
|
28
|
+
Requires-Dist: fsspec
|
|
29
|
+
Requires-Dist: aiohttp
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# grdwindinversion
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
[](https://pypi.org/project/grdwindinversion/)
|
|
37
|
+
[](https://github.com/umr-lops/grdwindinversion/pulls?utf8=%E2%9C%93&q=is%3Apr%20author%3Aapp%2Fdependabot)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Package to perform Wind inversion from GRD Level-1 SAR images
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
* Free software: MIT license
|
|
47
|
+
* Documentation: https://grdwindinversion.readthedocs.io.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
|
|
55
|
+
SAR_L1-to-L2_wind_processor -h
|
|
56
|
+
usage: SAR_L1-to-L2_wind_processor [-h] --input_file INPUT_FILE [--config_file CONFIG_FILE] --outputdir OUTPUTDIR [--verbose] [--overwrite]
|
|
57
|
+
|
|
58
|
+
Perform inversion from S1(L1-GRD) SAFE, L1-RCM, L1-RS2 ; using xsar/xsarsea tools
|
|
59
|
+
|
|
60
|
+
options:
|
|
61
|
+
-h, --help show this help message and exit
|
|
62
|
+
--input_file INPUT_FILE
|
|
63
|
+
input file path
|
|
64
|
+
--config_file CONFIG_FILE
|
|
65
|
+
config file path [if not provided will take config file based on input file]
|
|
66
|
+
--outputdir OUTPUTDIR
|
|
67
|
+
--verbose
|
|
68
|
+
--overwrite overwrite existing .nc files [default is False]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
## Features
|
|
73
|
+
|
|
74
|
+
This Python library (based on `xarray`) allows to perform wind inversion from level-1 GRD (projected magnitude image).
|
|
75
|
+
Mission supported:
|
|
76
|
+
* Sentinel-1
|
|
77
|
+
* RCM
|
|
78
|
+
* RadarSat-2
|
|
79
|
+
|
|
80
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
grdwindinversion/.gitignore,sha256=vmDRHGeESYckUdUztsPr7u6ZNfBYMCVR3GE3AJCBnsY,1204
|
|
2
|
+
grdwindinversion/.travis.yml,sha256=q13Gro7mMK7xN5eDEhyMIgcXIYsgSQfAEzk4dv34ie0,694
|
|
3
|
+
grdwindinversion/__init__.py,sha256=VQc2V_j124NX2Gp06Go1oSZDSF4lBIVPYT-W9ZkNBXE,415
|
|
4
|
+
grdwindinversion/config_prod.yaml,sha256=tIWn83LXNIl9l6w2I4TU-ZIk35EZm44GeIXklgYqFw8,1010
|
|
5
|
+
grdwindinversion/config_prod_recal.yaml,sha256=WzucOsKVCK-lw5kRn-4llONwBxl8TogYrReeLycXC6k,1006
|
|
6
|
+
grdwindinversion/data_config.yaml,sha256=YbbgxqpgasR5RINO29Ep_1cELdZotoylLzn6Qh7f6LM,473
|
|
7
|
+
grdwindinversion/inversion.py,sha256=WoMgi4gRjMU11FHhb0xlZS_Hl7KKY5W_gbvI86cGNh8,43984
|
|
8
|
+
grdwindinversion/load_config.py,sha256=bt7EXTmXfbuK0oNR-qwtijv_iZBQzi5BtY92RGKEo4Y,651
|
|
9
|
+
grdwindinversion/main.py,sha256=l5PEyIkqQ7Vjha0zs9FO3uqTpCVdNdoen5Zu8svJH8g,2651
|
|
10
|
+
grdwindinversion/streaks.py,sha256=SucALdajwAr-tcqwJs6KOj8CQ7qQPp3JUKSh2dHAJTY,2950
|
|
11
|
+
grdwindinversion/utils.py,sha256=nIao7g_lGKgzL5y_ipBsxLoQDetf0OLrPy8FEd4eyWU,1428
|
|
12
|
+
grdwindinversion/.github/ISSUE_TEMPLATE.md,sha256=qiM_a7CCUz3fSrz3Q20Se1nwPNFS8QCc8tkwK_0DSCo,327
|
|
13
|
+
grdwindinversion-0.2.3.post15.dist-info/AUTHORS.rst,sha256=KmhW_5LBKGTIGwWEVkoTm1qx_bvdDR3yYL-1cwbDOFQ,218
|
|
14
|
+
grdwindinversion-0.2.3.post15.dist-info/LICENSE,sha256=-B8mBiTeY3J7OLuayiV1myqmc7yeijBc7s34kc8RTmg,1075
|
|
15
|
+
grdwindinversion-0.2.3.post15.dist-info/METADATA,sha256=-EzqUV0fqvzAXgjgZYEKC5cloJCV0Dh9vahVZINXMbI,2399
|
|
16
|
+
grdwindinversion-0.2.3.post15.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
|
|
17
|
+
grdwindinversion-0.2.3.post15.dist-info/entry_points.txt,sha256=2rjvlVCy0iasRXjOz3kOIGuy2OCGQ-VTNuwuViQ6cMM,95
|
|
18
|
+
grdwindinversion-0.2.3.post15.dist-info/top_level.txt,sha256=z6lPix3QPEYOo37qq8plA2hY7S3C8MQZY81agRlksMI,17
|
|
19
|
+
grdwindinversion-0.2.3.post15.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
grdwindinversion
|