grdwindinversion 0.3.3__py3-none-any.whl → 0.3.6__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.
@@ -3,19 +3,22 @@ import logging
3
3
  import os
4
4
  import grdwindinversion
5
5
  from yaml import CLoader as Loader
6
+
6
7
  local_config_potential_path1 = os.path.expanduser(
7
- '~/.grdwindinversion/data_config.yaml')
8
- local_config_potential_path2 = os.path.join(os.path.dirname(
9
- grdwindinversion.__file__), 'local_data_config.yaml')
8
+ "~/.grdwindinversion/data_config.yaml"
9
+ )
10
+ local_config_potential_path2 = os.path.join(
11
+ os.path.dirname(grdwindinversion.__file__), "local_data_config.yaml"
12
+ )
10
13
  if os.path.exists(local_config_potential_path1):
11
14
  config_path = local_config_potential_path1
12
15
  elif os.path.exists(local_config_potential_path2):
13
16
  config_path = local_config_potential_path2
14
17
  else:
15
- config_path = os.path.join(os.path.dirname(
16
- grdwindinversion.__file__), 'data_config.yaml')
17
- logging.info('config path: %s', config_path)
18
- stream = open(config_path, 'r')
18
+ config_path = os.path.join(
19
+ os.path.dirname(grdwindinversion.__file__), "data_config.yaml"
20
+ )
21
+ stream = open(config_path, "r")
19
22
  conf = load(stream, Loader=Loader)
20
23
 
21
24
 
grdwindinversion/main.py CHANGED
@@ -1,40 +1,77 @@
1
- from grdwindinversion.inversion import makeL2
2
- from grdwindinversion.utils_memory import get_memory_usage
3
- import grdwindinversion
4
1
  import time
5
2
  import logging
3
+ import sys
4
+ from importlib.metadata import version
6
5
 
7
6
 
8
7
  def processor_starting_point():
9
8
  import argparse
10
9
 
10
+ pre_parser = argparse.ArgumentParser(add_help=False)
11
+ pre_parser.add_argument(
12
+ "-v", "--version", action="store_true", help="Print version"
13
+ )
14
+ pre_args, remaining_args = pre_parser.parse_known_args()
15
+
16
+ # Handle the version argument right away
17
+ if pre_args.version:
18
+ print(version("grdwindinversion"))
19
+ sys.exit()
20
+
21
+ from grdwindinversion.inversion import makeL2
22
+ from grdwindinversion.utils_memory import get_memory_usage
23
+ from grdwindinversion.load_config import config_path
24
+ import grdwindinversion
25
+
11
26
  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"]')
27
+ description="Perform inversion from S1(L1-GRD) SAFE, L1-RCM, L1-RS2 ; using xsar/xsarsea tools"
28
+ )
29
+ parser.add_argument("--input_file", help="input file path", required=True)
30
+ parser.add_argument(
31
+ "--config_file",
32
+ help="config file path [if not provided will take config file based on input file]",
33
+ required=True,
34
+ )
35
+ parser.add_argument(
36
+ "--resolution",
37
+ required=False,
38
+ default="1000m",
39
+ help='set resolution ["full" | "1000m" | "xXxm"]',
40
+ )
18
41
 
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)
42
+ parser.add_argument("--outputdir", required=True)
43
+ parser.add_argument("--verbose", action="store_true", default=False)
44
+ parser.add_argument(
45
+ "--overwrite",
46
+ action="store_true",
47
+ default=False,
48
+ help="overwrite existing .nc files [default is False]",
49
+ required=False,
50
+ )
23
51
 
24
- parser.add_argument('--no_generate_csv', action='store_false',
25
- help="En cas d'activation, désactive la génération du .csv")
52
+ parser.add_argument(
53
+ "--no_generate_csv",
54
+ action="store_false",
55
+ help="En cas d'activation, désactive la génération du .csv",
56
+ )
26
57
 
27
58
  args = parser.parse_args()
28
- fmt = '%(asctime)s %(levelname)s %(filename)s(%(lineno)d) %(message)s'
59
+
60
+ fmt = "%(asctime)s %(levelname)s %(filename)s(%(lineno)d) %(message)s"
29
61
  if args.verbose:
30
- logging.basicConfig(level=logging.DEBUG, format=fmt,
31
- datefmt='%d/%m/%Y %H:%M:%S', force=True)
62
+ logging.basicConfig(
63
+ level=logging.DEBUG, format=fmt, datefmt="%d/%m/%Y %H:%M:%S", force=True
64
+ )
32
65
  else:
33
- logging.basicConfig(level=logging.INFO, format=fmt,
34
- datefmt='%d/%m/%Y %H:%M:%S', force=True)
66
+ logging.basicConfig(
67
+ level=logging.INFO, format=fmt, datefmt="%d/%m/%Y %H:%M:%S", force=True
68
+ )
35
69
  t0 = time.time()
36
- input_file = args.input_file.rstrip('/')
37
- logging.info('input file: %s', input_file)
70
+
71
+ logging.info("config path: %s", config_path)
72
+
73
+ input_file = args.input_file.rstrip("/")
74
+ logging.info("input file: %s", input_file)
38
75
 
39
76
  # if '1SDV' not in input_file and '_VV_VH' not in input_file:
40
77
  # raise Exception('this processor only handle dual polarization acquisitions VV+VH for now.')
@@ -47,13 +84,19 @@ def processor_starting_point():
47
84
  if resolution == "full":
48
85
  resolution = None
49
86
 
50
- out_file, outputds = makeL2(input_file, out_folder, config_file,
51
- overwrite=args.overwrite, resolution=resolution, generateCSV=args.no_generate_csv)
87
+ out_file, outputds = makeL2(
88
+ input_file,
89
+ out_folder,
90
+ config_file,
91
+ overwrite=args.overwrite,
92
+ resolution=resolution,
93
+ generateCSV=args.no_generate_csv,
94
+ )
52
95
 
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.)
96
+ logging.info("out_file: %s", out_file)
97
+ logging.info("current memory usage: %s ", get_memory_usage(var="current"))
98
+ logging.info("done in %1.3f min", (time.time() - t0) / 60.0)
56
99
 
57
100
 
58
- if __name__ == '__main__':
101
+ if __name__ == "__main__":
59
102
  processor_starting_point()
grdwindinversion/utils.py CHANGED
@@ -4,9 +4,10 @@ import logging
4
4
  import xsarsea
5
5
 
6
6
 
7
- logging.basicConfig(level=logging.INFO,
8
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
9
- logger = logging.getLogger('grdwindinversion')
7
+ logging.basicConfig(
8
+ level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
9
+ )
10
+ logger = logging.getLogger("grdwindinversion")
10
11
 
11
12
 
12
13
  mem_monitor = True
@@ -17,6 +18,31 @@ except ImportError:
17
18
  mem_monitor = False
18
19
 
19
20
 
21
+ def convert_polarization_name(pol):
22
+ """
23
+ Convert polarization name to the format used in the output filename
24
+
25
+ Parameters
26
+ ----------
27
+ pol : str
28
+ polarization name
29
+
30
+ Returns
31
+ -------
32
+ str
33
+ polarization name in the format used in the output filename (dv/dh/sv/sh/xx)
34
+ """
35
+ if pol == "VV_VH":
36
+ return "dv"
37
+ elif pol == "HH_HV":
38
+ return "dh"
39
+ elif pol == "VV":
40
+ return "sv"
41
+ elif pol == "HH":
42
+ return "sh"
43
+ else:
44
+ return "xx"
45
+
20
46
  def check_incidence_range(incidence, models, **kwargs):
21
47
  """
22
48
  Check if the incidence range of the dataset is within the range of the LUT of the model.
@@ -44,17 +70,19 @@ def check_incidence_range(incidence, models, **kwargs):
44
70
  rets = []
45
71
  for model_name in models:
46
72
  lut_range = xsarsea.windspeed.get_model(model_name).inc_range
47
- if 'inc_range' in kwargs:
73
+ if "inc_range" in kwargs:
48
74
  logging.debug(
49
- f"GMF {model_name} inc_range will be changed by kwargs to {kwargs['inc_range']}")
50
- lut_range = kwargs['inc_range']
75
+ f"GMF {model_name} inc_range will be changed by kwargs to {kwargs['inc_range']}"
76
+ )
77
+ lut_range = kwargs["inc_range"]
51
78
 
52
79
  inc_range = [incidence.min(), incidence.max()]
53
- if (inc_range[0] >= lut_range[0] and inc_range[1] <= lut_range[1]):
80
+ if inc_range[0] >= lut_range[0] and inc_range[1] <= lut_range[1]:
54
81
  rets.append(True)
55
82
  else:
56
83
  logging.warn(
57
- f"incidence range {inc_range} is not within the range of the LUT of the model {model_name} {lut_range} : inversion will be approximate using LUT minmium|maximum incidences")
84
+ f"incidence range {inc_range} is not within the range of the LUT of the model {model_name} {lut_range} : inversion will be approximate using LUT minmium|maximum incidences"
85
+ )
58
86
  rets.append(False)
59
87
 
60
88
  return rets
@@ -76,26 +104,28 @@ def get_pol_ratio_name(model_co):
76
104
  """
77
105
 
78
106
  model = xsarsea.windspeed.get_model(model_co)
79
- if model.pol == 'HH':
107
+ if model.pol == "HH":
80
108
  try:
81
109
  import re
82
110
 
83
111
  def check_format(s):
84
- pattern = r'^([a-zA-Z0-9]+)_R(high|low)_hh_([a-zA-Z0-9_]+)$'
112
+ pattern = r"^([a-zA-Z0-9]+)_R(high|low)_hh_([a-zA-Z0-9_]+)$"
85
113
  match = re.match(pattern, s)
86
114
  if match:
87
115
  vvgmf, res, polrationame = match.groups()
88
116
  return polrationame
89
117
  else:
90
118
  logging.warn(
91
- f"String format is not correct for polarization ratio name = {s}\nReturning '/'")
119
+ f"String format is not correct for polarization ratio name = {s}\nReturning '/'"
120
+ )
92
121
  return "/"
122
+
93
123
  get_pol_ratio_name = check_format(model_co)
94
124
  return get_pol_ratio_name
95
125
  except AttributeError:
96
126
  return "not_written_in_lut"
97
127
  else:
98
- return '/'
128
+ return "/"
99
129
 
100
130
 
101
131
  def timing(logger=logger.debug):
@@ -104,7 +134,7 @@ def timing(logger=logger.debug):
104
134
  def decorator(f):
105
135
  # @wraps(f)
106
136
  def wrapper(*args, **kwargs):
107
- mem_str = ''
137
+ mem_str = ""
108
138
  process = None
109
139
  if mem_monitor:
110
140
  process = Process(os.getpid())
@@ -114,10 +144,11 @@ def timing(logger=logger.debug):
114
144
  endtime = time.time()
115
145
  if mem_monitor:
116
146
  endrss = process.memory_info().rss
117
- mem_str = 'mem: %+.1fMb' % ((endrss - startrss) / (1024 ** 2))
118
- logger(
119
- 'timing %s : %.2fs. %s' % (f.__name__, endtime - starttime, mem_str))
147
+ mem_str = "mem: %+.1fMb" % ((endrss - startrss) / (1024**2))
148
+ logger("timing %s : %.2fs. %s" % (f.__name__, endtime - starttime, mem_str))
120
149
  return result
150
+
121
151
  wrapper.__doc__ = f.__doc__
122
152
  return wrapper
153
+
123
154
  return decorator
@@ -1,46 +1,44 @@
1
- def get_memory_usage(unit='Go', var='ru_maxrss', force_psutil=False):
1
+ def get_memory_usage(unit="Go", var="ru_maxrss", force_psutil=False):
2
2
  """
3
3
  var str: ru_maxrss or ru_ixrss or ru_idrss or ru_isrss or current
4
4
  Returns
5
5
  -------
6
6
 
7
7
  """
8
- if unit == 'Go':
9
- factor = 1000000.
10
- elif unit == 'Mo':
11
- factor = 1000.
12
- elif unit == 'Ko':
13
- factor = 1.
8
+ if unit == "Go":
9
+ factor = 1000000.0
10
+ elif unit == "Mo":
11
+ factor = 1000.0
12
+ elif unit == "Ko":
13
+ factor = 1.0
14
14
  else:
15
- raise Exception('not handle unit')
15
+ raise Exception("not handle unit")
16
16
 
17
17
  try:
18
18
  if force_psutil:
19
19
  on_purpose_error
20
20
  import resource
21
+
21
22
  mems = {}
22
- mems['ru_maxrss'] = resource.getrusage(
23
- resource.RUSAGE_SELF).ru_maxrss / factor
24
- mems['ru_ixrss'] = resource.getrusage(
25
- resource.RUSAGE_SELF).ru_ixrss / factor
26
- mems['ru_idrss'] = resource.getrusage(
27
- resource.RUSAGE_SELF).ru_idrss / factor
28
- mems['ru_isrss'] = resource.getrusage(
29
- resource.RUSAGE_SELF).ru_isrss / factor
30
- mems['current'] = getCurrentMemoryUsage() / factor
23
+ mems["ru_maxrss"] = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / factor
24
+ mems["ru_ixrss"] = resource.getrusage(resource.RUSAGE_SELF).ru_ixrss / factor
25
+ mems["ru_idrss"] = resource.getrusage(resource.RUSAGE_SELF).ru_idrss / factor
26
+ mems["ru_isrss"] = resource.getrusage(resource.RUSAGE_SELF).ru_isrss / factor
27
+ mems["current"] = getCurrentMemoryUsage() / factor
31
28
  # memory_used_go = resource.getrusage(resource.RUSAGE_SELF).get(var) /factor
32
29
  memory_used_go = mems[var]
33
30
  except: # on windows resource is not usable
34
31
  import psutil
35
- memory_used_go = psutil.virtual_memory().used / factor / 1000.
36
- str_mem = 'RAM usage: %1.1f %s' % (memory_used_go, unit)
32
+
33
+ memory_used_go = psutil.virtual_memory().used / factor / 1000.0
34
+ str_mem = "RAM usage: %1.1f %s" % (memory_used_go, unit)
37
35
  return str_mem
38
36
 
39
37
 
40
38
  def getCurrentMemoryUsage():
41
- ''' Memory usage in kB '''
39
+ """Memory usage in kB"""
42
40
 
43
- with open('/proc/self/status') as f:
44
- memusage = f.read().split('VmRSS:')[1].split('\n')[0][:-3]
41
+ with open("/proc/self/status") as f:
42
+ memusage = f.read().split("VmRSS:")[1].split("\n")[0][:-3]
45
43
 
46
44
  return int(memusage.strip())
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: grdwindinversion
3
- Version: 0.3.3
3
+ Version: 0.3.6
4
4
  Summary: Package to perform Wind inversion from GRD Level-1 SAR images
5
5
  Author-email: Antoine Grouazel <antoine.grouazel@ifremer.fr>
6
6
  License: MIT
@@ -35,7 +35,7 @@ Requires-Dist: aiohttp
35
35
  Package to perform Wind inversion from GRD Level-1 SAR images
36
36
 
37
37
  - Free software: MIT license
38
- - Documentation: https://grdwindinversion.readthedocs.io.
38
+ - Documentation: https://cerweb.ifremer.fr/datarmor/doc_sphinx/grdwindinversion/index.html.
39
39
 
40
40
  ## Usage
41
41
 
@@ -0,0 +1,22 @@
1
+ grdwindinversion/.gitignore,sha256=vmDRHGeESYckUdUztsPr7u6ZNfBYMCVR3GE3AJCBnsY,1204
2
+ grdwindinversion/__init__.py,sha256=LEeSGGPADHTtjujV48PD3lRVXxe-dg5_z1zWQTvBJNw,415
3
+ grdwindinversion/config_prod.yaml,sha256=VEAgtJt894v3u4AhYOlcCWjb379vPDMfwBb4PKeDmAw,1314
4
+ grdwindinversion/config_prod_recal.yaml,sha256=74n2J4tzSx1I5vaat3ydwig1jyfDgxGTGDxxw8ALC-U,1222
5
+ grdwindinversion/config_prod_recal_streaks_nrcsmod.yaml,sha256=ob0YmzHrwkI4GLxaR9HzidYtXBrTOAlEYwPYdCK7AqA,1092
6
+ grdwindinversion/config_prod_streaks.yaml,sha256=lJMl4qH6XYqO8ich7yW0WDQsQDrjmWThlLyx1xZy1DA,1313
7
+ grdwindinversion/config_prod_streaks_nrcsmod.yaml,sha256=4yC4KcsC7rUumYHwhpKxM8_LDMe_Je-RIu4-9e1ayp8,1312
8
+ grdwindinversion/data_config.yaml,sha256=FnglUHbAtGwHWg8w86hwZt3-vo-dY8uIjxqyI1jZpv8,567
9
+ grdwindinversion/gradientFeatures.py,sha256=NIeAJzb1zrlJPBq1th7wjEZoNJMxwqDpNHLMWP6FQN0,18198
10
+ grdwindinversion/inversion.py,sha256=gCjuhTbLRvh_vHdx1Ut9XluuqaBPSPOgMYiGTnnrNc4,56099
11
+ grdwindinversion/load_config.py,sha256=ZPozOWt0rf2Pmyc6P2D75cE_9wKUfKfr7RUzlE3WoiY,833
12
+ grdwindinversion/main.py,sha256=Cwmxxz-PEt53JvpTL0Jx1WKLJpWvlIXZ9xtnyGKrGHY,3254
13
+ grdwindinversion/utils.py,sha256=2BRq_UEbKbP5yCy_0X-nV-SQFmmp4aKrFaRgrs5MqJo,4347
14
+ grdwindinversion/utils_memory.py,sha256=NA0bvkpCTkEiqCcJuldG1XsrP40-3AQUUt3HLeoRpbY,1432
15
+ grdwindinversion/.github/ISSUE_TEMPLATE.md,sha256=qiM_a7CCUz3fSrz3Q20Se1nwPNFS8QCc8tkwK_0DSCo,327
16
+ grdwindinversion-0.3.6.dist-info/AUTHORS.rst,sha256=KmhW_5LBKGTIGwWEVkoTm1qx_bvdDR3yYL-1cwbDOFQ,218
17
+ grdwindinversion-0.3.6.dist-info/LICENSE,sha256=-B8mBiTeY3J7OLuayiV1myqmc7yeijBc7s34kc8RTmg,1075
18
+ grdwindinversion-0.3.6.dist-info/METADATA,sha256=XifamxABLa3IIQ7oyioa6ozPB3qQFDXFThmKM2TPUY0,2475
19
+ grdwindinversion-0.3.6.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
20
+ grdwindinversion-0.3.6.dist-info/entry_points.txt,sha256=2rjvlVCy0iasRXjOz3kOIGuy2OCGQ-VTNuwuViQ6cMM,95
21
+ grdwindinversion-0.3.6.dist-info/top_level.txt,sha256=z6lPix3QPEYOo37qq8plA2hY7S3C8MQZY81agRlksMI,17
22
+ grdwindinversion-0.3.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,22 +0,0 @@
1
- grdwindinversion/.gitignore,sha256=vmDRHGeESYckUdUztsPr7u6ZNfBYMCVR3GE3AJCBnsY,1204
2
- grdwindinversion/__init__.py,sha256=VQc2V_j124NX2Gp06Go1oSZDSF4lBIVPYT-W9ZkNBXE,415
3
- grdwindinversion/config_prod.yaml,sha256=VEAgtJt894v3u4AhYOlcCWjb379vPDMfwBb4PKeDmAw,1314
4
- grdwindinversion/config_prod_recal.yaml,sha256=74n2J4tzSx1I5vaat3ydwig1jyfDgxGTGDxxw8ALC-U,1222
5
- grdwindinversion/config_prod_recal_streaks_nrcsmod.yaml,sha256=ob0YmzHrwkI4GLxaR9HzidYtXBrTOAlEYwPYdCK7AqA,1092
6
- grdwindinversion/config_prod_streaks.yaml,sha256=lJMl4qH6XYqO8ich7yW0WDQsQDrjmWThlLyx1xZy1DA,1313
7
- grdwindinversion/config_prod_streaks_nrcsmod.yaml,sha256=4yC4KcsC7rUumYHwhpKxM8_LDMe_Je-RIu4-9e1ayp8,1312
8
- grdwindinversion/data_config.yaml,sha256=FnglUHbAtGwHWg8w86hwZt3-vo-dY8uIjxqyI1jZpv8,567
9
- grdwindinversion/gradientFeatures.py,sha256=pBmsk6L8V9OrfSaAlFnxWztowSMEq2uoNdK93-drCuQ,17234
10
- grdwindinversion/inversion.py,sha256=iqUTEFfYh_PU9AGeKs6PasDHDovsABpznruTKk9SnYM,54437
11
- grdwindinversion/load_config.py,sha256=o0zVRpw3cIk-0fAsgOAb5JYzbHd3wdKmFskT8B3FAok,875
12
- grdwindinversion/main.py,sha256=0DLDW0i14CWhDKAGegzOKlWnCkag_cGn3vzMIAKcv4g,2658
13
- grdwindinversion/utils.py,sha256=bowCr2wKqXE7j0Uo5xkFMjWkr7NhnmjCaPFTO4MYNV4,3803
14
- grdwindinversion/utils_memory.py,sha256=1N3Kh4qVZPELPU6I4onbmkur1CZd7EHZqfbSAa6eaVc,1480
15
- grdwindinversion/.github/ISSUE_TEMPLATE.md,sha256=qiM_a7CCUz3fSrz3Q20Se1nwPNFS8QCc8tkwK_0DSCo,327
16
- grdwindinversion-0.3.3.dist-info/AUTHORS.rst,sha256=KmhW_5LBKGTIGwWEVkoTm1qx_bvdDR3yYL-1cwbDOFQ,218
17
- grdwindinversion-0.3.3.dist-info/LICENSE,sha256=-B8mBiTeY3J7OLuayiV1myqmc7yeijBc7s34kc8RTmg,1075
18
- grdwindinversion-0.3.3.dist-info/METADATA,sha256=smWjGdzzyLLXJa8Ugz0xfAoI6udjTpy3VDLvZnSXiJ4,2441
19
- grdwindinversion-0.3.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
20
- grdwindinversion-0.3.3.dist-info/entry_points.txt,sha256=2rjvlVCy0iasRXjOz3kOIGuy2OCGQ-VTNuwuViQ6cMM,95
21
- grdwindinversion-0.3.3.dist-info/top_level.txt,sha256=z6lPix3QPEYOo37qq8plA2hY7S3C8MQZY81agRlksMI,17
22
- grdwindinversion-0.3.3.dist-info/RECORD,,