-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from vincelhx/main
wind convention parameters
- Loading branch information
Showing
7 changed files
with
310 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
no_subdir: True | ||
winddir_convention: "meteorological" | ||
S1A: | ||
GMF_VV_NAME: "gmf_cmod5n" | ||
GMF_VH_NAME: "gmf_s1_v2" | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,83 @@ | ||
def get_memory_usage(unit='Go', var='ru_maxrss', force_psutil=False): | ||
import logging | ||
import xsarsea | ||
|
||
|
||
def check_incidence_range(incidence, models, **kwargs): | ||
""" | ||
var str: ru_maxrss or ru_ixrss or ru_idrss or ru_isrss or current | ||
Check if the incidence range of the dataset is within the range of the LUT of the model. | ||
If not, warn the user : inversion will be approximate. | ||
Parameters | ||
---------- | ||
incidence : xr.DataArray | ||
incidence angle in degrees | ||
models : list of str | ||
list of model names | ||
Returns | ||
------- | ||
list of bool | ||
for each model, | ||
True if the incidence range is within the range of the LUT of the model (correct) | ||
False otherwise | ||
""" | ||
if isinstance(models, str): | ||
models = [models] | ||
elif not isinstance(models, list): | ||
raise TypeError("models should be a string or a list of strings") | ||
|
||
rets = [] | ||
for model_name in models: | ||
lut_range = xsarsea.windspeed.get_model(model_name).inc_range | ||
if 'inc_range' in kwargs: | ||
logging.debug( | ||
f"GMF {model_name} inc_range will be changed by kwargs to {kwargs['inc_range']}") | ||
lut_range = kwargs['inc_range'] | ||
|
||
inc_range = [incidence.values.min(), incidence.values.max()] | ||
if (inc_range[0] >= lut_range[0] and inc_range[1] <= lut_range[1]): | ||
rets.append(True) | ||
else: | ||
logging.warn( | ||
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") | ||
rets.append(False) | ||
|
||
return rets | ||
|
||
|
||
def get_pol_ratio_name(model_co): | ||
""" | ||
Return polarization ration name of copol model | ||
Parameters | ||
---------- | ||
model_co : str | ||
copol model name | ||
Returns | ||
------- | ||
str | ||
if pol = 'HH', return polarization ratio name ; else return '/' | ||
""" | ||
if unit == 'Go': | ||
factor = 1000000. | ||
elif unit == 'Mo': | ||
factor = 1000. | ||
elif unit == 'Ko': | ||
factor = 1. | ||
|
||
model = xsarsea.windspeed.get_model(model_co) | ||
if model.pol == 'HH': | ||
try: | ||
import re | ||
|
||
def check_format(s): | ||
pattern = r'^([a-zA-Z0-9]+)_R(high|low)_hh_([a-zA-Z0-9_]+)$' | ||
match = re.match(pattern, s) | ||
if match: | ||
vvgmf, res, polrationame = match.groups() | ||
return polrationame | ||
else: | ||
logging.warn( | ||
f"String format is not correct for polarization ratio name = {s}\nReturning '/'") | ||
return "/" | ||
get_pol_ratio_name = check_format(model_co) | ||
return get_pol_ratio_name | ||
except AttributeError: | ||
return "not_written_in_lut" | ||
else: | ||
raise Exception('not handle unit') | ||
|
||
try: | ||
if force_psutil: | ||
on_purpose_error | ||
import resource | ||
mems = {} | ||
mems['ru_maxrss'] = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / factor | ||
mems['ru_ixrss'] = resource.getrusage(resource.RUSAGE_SELF).ru_ixrss / factor | ||
mems['ru_idrss'] = resource.getrusage(resource.RUSAGE_SELF).ru_idrss / factor | ||
mems['ru_isrss'] = resource.getrusage(resource.RUSAGE_SELF).ru_isrss / factor | ||
mems['current'] = getCurrentMemoryUsage() / factor | ||
# memory_used_go = resource.getrusage(resource.RUSAGE_SELF).get(var) /factor | ||
memory_used_go = mems[var] | ||
except: # on windows resource is not usable | ||
import psutil | ||
memory_used_go = psutil.virtual_memory().used / factor / 1000. | ||
str_mem = 'RAM usage: %1.1f %s' % (memory_used_go, unit) | ||
return str_mem | ||
|
||
|
||
def getCurrentMemoryUsage(): | ||
''' Memory usage in kB ''' | ||
|
||
with open('/proc/self/status') as f: | ||
memusage = f.read().split('VmRSS:')[1].split('\n')[0][:-3] | ||
|
||
return int(memusage.strip()) | ||
return '/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
def get_memory_usage(unit='Go', var='ru_maxrss', force_psutil=False): | ||
""" | ||
var str: ru_maxrss or ru_ixrss or ru_idrss or ru_isrss or current | ||
Returns | ||
------- | ||
""" | ||
if unit == 'Go': | ||
factor = 1000000. | ||
elif unit == 'Mo': | ||
factor = 1000. | ||
elif unit == 'Ko': | ||
factor = 1. | ||
else: | ||
raise Exception('not handle unit') | ||
|
||
try: | ||
if force_psutil: | ||
on_purpose_error | ||
import resource | ||
mems = {} | ||
mems['ru_maxrss'] = resource.getrusage( | ||
resource.RUSAGE_SELF).ru_maxrss / factor | ||
mems['ru_ixrss'] = resource.getrusage( | ||
resource.RUSAGE_SELF).ru_ixrss / factor | ||
mems['ru_idrss'] = resource.getrusage( | ||
resource.RUSAGE_SELF).ru_idrss / factor | ||
mems['ru_isrss'] = resource.getrusage( | ||
resource.RUSAGE_SELF).ru_isrss / factor | ||
mems['current'] = getCurrentMemoryUsage() / factor | ||
# memory_used_go = resource.getrusage(resource.RUSAGE_SELF).get(var) /factor | ||
memory_used_go = mems[var] | ||
except: # on windows resource is not usable | ||
import psutil | ||
memory_used_go = psutil.virtual_memory().used / factor / 1000. | ||
str_mem = 'RAM usage: %1.1f %s' % (memory_used_go, unit) | ||
return str_mem | ||
|
||
|
||
def getCurrentMemoryUsage(): | ||
''' Memory usage in kB ''' | ||
|
||
with open('/proc/self/status') as f: | ||
memusage = f.read().split('VmRSS:')[1].split('\n')[0][:-3] | ||
|
||
return int(memusage.strip()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
no_subdir: True | ||
convention: "meteorological" | ||
S1A: | ||
GMF_VV_NAME: "gmf_cmod5n" | ||
GMF_VH_NAME: "gmf_s1_v2" | ||
|