grdwindinversion 0.3.2__py3-none-any.whl → 0.3.5__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
@@ -44,17 +45,19 @@ def check_incidence_range(incidence, models, **kwargs):
44
45
  rets = []
45
46
  for model_name in models:
46
47
  lut_range = xsarsea.windspeed.get_model(model_name).inc_range
47
- if 'inc_range' in kwargs:
48
+ if "inc_range" in kwargs:
48
49
  logging.debug(
49
- f"GMF {model_name} inc_range will be changed by kwargs to {kwargs['inc_range']}")
50
- lut_range = kwargs['inc_range']
50
+ f"GMF {model_name} inc_range will be changed by kwargs to {kwargs['inc_range']}"
51
+ )
52
+ lut_range = kwargs["inc_range"]
51
53
 
52
54
  inc_range = [incidence.min(), incidence.max()]
53
- if (inc_range[0] >= lut_range[0] and inc_range[1] <= lut_range[1]):
55
+ if inc_range[0] >= lut_range[0] and inc_range[1] <= lut_range[1]:
54
56
  rets.append(True)
55
57
  else:
56
58
  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")
59
+ 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"
60
+ )
58
61
  rets.append(False)
59
62
 
60
63
  return rets
@@ -76,26 +79,28 @@ def get_pol_ratio_name(model_co):
76
79
  """
77
80
 
78
81
  model = xsarsea.windspeed.get_model(model_co)
79
- if model.pol == 'HH':
82
+ if model.pol == "HH":
80
83
  try:
81
84
  import re
82
85
 
83
86
  def check_format(s):
84
- pattern = r'^([a-zA-Z0-9]+)_R(high|low)_hh_([a-zA-Z0-9_]+)$'
87
+ pattern = r"^([a-zA-Z0-9]+)_R(high|low)_hh_([a-zA-Z0-9_]+)$"
85
88
  match = re.match(pattern, s)
86
89
  if match:
87
90
  vvgmf, res, polrationame = match.groups()
88
91
  return polrationame
89
92
  else:
90
93
  logging.warn(
91
- f"String format is not correct for polarization ratio name = {s}\nReturning '/'")
94
+ f"String format is not correct for polarization ratio name = {s}\nReturning '/'"
95
+ )
92
96
  return "/"
97
+
93
98
  get_pol_ratio_name = check_format(model_co)
94
99
  return get_pol_ratio_name
95
100
  except AttributeError:
96
101
  return "not_written_in_lut"
97
102
  else:
98
- return '/'
103
+ return "/"
99
104
 
100
105
 
101
106
  def timing(logger=logger.debug):
@@ -104,7 +109,7 @@ def timing(logger=logger.debug):
104
109
  def decorator(f):
105
110
  # @wraps(f)
106
111
  def wrapper(*args, **kwargs):
107
- mem_str = ''
112
+ mem_str = ""
108
113
  process = None
109
114
  if mem_monitor:
110
115
  process = Process(os.getpid())
@@ -114,10 +119,11 @@ def timing(logger=logger.debug):
114
119
  endtime = time.time()
115
120
  if mem_monitor:
116
121
  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))
122
+ mem_str = "mem: %+.1fMb" % ((endrss - startrss) / (1024**2))
123
+ logger("timing %s : %.2fs. %s" % (f.__name__, endtime - starttime, mem_str))
120
124
  return result
125
+
121
126
  wrapper.__doc__ = f.__doc__
122
127
  return wrapper
128
+
123
129
  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.2
3
+ Version: 0.3.5
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
@@ -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=rRqmDDL0byTJPu5PZIalTALSaQBNiIXYJpdS2eGYDiI,56525
11
+ grdwindinversion/load_config.py,sha256=ZPozOWt0rf2Pmyc6P2D75cE_9wKUfKfr7RUzlE3WoiY,833
12
+ grdwindinversion/main.py,sha256=Cwmxxz-PEt53JvpTL0Jx1WKLJpWvlIXZ9xtnyGKrGHY,3254
13
+ grdwindinversion/utils.py,sha256=Jj2M433WC9z5Yk4yZaUxSnKwCskfCzB_EsIbVDW5PPw,3818
14
+ grdwindinversion/utils_memory.py,sha256=NA0bvkpCTkEiqCcJuldG1XsrP40-3AQUUt3HLeoRpbY,1432
15
+ grdwindinversion/.github/ISSUE_TEMPLATE.md,sha256=qiM_a7CCUz3fSrz3Q20Se1nwPNFS8QCc8tkwK_0DSCo,327
16
+ grdwindinversion-0.3.5.dist-info/AUTHORS.rst,sha256=KmhW_5LBKGTIGwWEVkoTm1qx_bvdDR3yYL-1cwbDOFQ,218
17
+ grdwindinversion-0.3.5.dist-info/LICENSE,sha256=-B8mBiTeY3J7OLuayiV1myqmc7yeijBc7s34kc8RTmg,1075
18
+ grdwindinversion-0.3.5.dist-info/METADATA,sha256=Ox0BIVGEoEmbnEyv9a3SH7fQLwAXfo_RV7VeTXgZh7g,2441
19
+ grdwindinversion-0.3.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
20
+ grdwindinversion-0.3.5.dist-info/entry_points.txt,sha256=2rjvlVCy0iasRXjOz3kOIGuy2OCGQ-VTNuwuViQ6cMM,95
21
+ grdwindinversion-0.3.5.dist-info/top_level.txt,sha256=z6lPix3QPEYOo37qq8plA2hY7S3C8MQZY81agRlksMI,17
22
+ grdwindinversion-0.3.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.8.0)
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=Tup2TbjKzxHA4aF-0BOXFrUX_ILHbrKtMi2SVZ4JMgo,53972
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.2.dist-info/AUTHORS.rst,sha256=KmhW_5LBKGTIGwWEVkoTm1qx_bvdDR3yYL-1cwbDOFQ,218
17
- grdwindinversion-0.3.2.dist-info/LICENSE,sha256=-B8mBiTeY3J7OLuayiV1myqmc7yeijBc7s34kc8RTmg,1075
18
- grdwindinversion-0.3.2.dist-info/METADATA,sha256=qpJr7Mfj2Tk8PanobOIlMbUp5ag-Md1EcnHF-M42nwc,2441
19
- grdwindinversion-0.3.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
20
- grdwindinversion-0.3.2.dist-info/entry_points.txt,sha256=2rjvlVCy0iasRXjOz3kOIGuy2OCGQ-VTNuwuViQ6cMM,95
21
- grdwindinversion-0.3.2.dist-info/top_level.txt,sha256=z6lPix3QPEYOo37qq8plA2hY7S3C8MQZY81agRlksMI,17
22
- grdwindinversion-0.3.2.dist-info/RECORD,,