Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specification of file for linear defaultstyle #1028

Merged
merged 2 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mslib/mswms/_tests/test_mss_plot_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ def test_LS_DefaultStyle(self):
img = self.plot(mpl_lsec_styles.LS_DefaultStyle(driver=self.lsec, variable=variable))
assert img is not None

def test_LS_DefaultStyle_PL(self):
img = self.plot(mpl_lsec_styles.LS_DefaultStyle(driver=self.lsec, variable="air_potential_temperature",
filetype="pl"))
assert img is not None

def test_LS_RelativeHumdityStyle_01(self):
img = self.plot(mpl_lsec_styles.LS_RelativeHumdityStyle_01(driver=self.lsec))
assert img is not None
Expand Down
6 changes: 4 additions & 2 deletions mslib/mswms/mpl_lsec_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ class LS_DefaultStyle(AbstractLinearSectionStyle):
"""
Style for single variables that require no further calculation
"""
def __init__(self, driver, variable="air_temperature"):
def __init__(self, driver, variable="air_temperature", filetype="ml"):
super(AbstractLinearSectionStyle, self).__init__(driver=driver)
self.variable = variable
self.required_datafields = [("ml", "air_pressure", "Pa"), ("ml", self.variable, None)]
self.required_datafields = [(filetype, self.variable, None)]
if filetype != "pl":
self.required_datafields.insert(0, (filetype, "air_pressure", "Pa"))
abbreviation = "".join([text[0] for text in self.variable.split("_")])
self.name = f"LS_{str.upper(abbreviation)}"
self.title = f"{self.variable} Linear Plot"
Expand Down
13 changes: 8 additions & 5 deletions mslib/mswms/mss_plot_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,11 @@ def _load_interpolate_timestep(self):
lon_data = lon_data[lon_indices]
factors = []

# Make sure air_pressure is the first to be evaluated
# Make sure air_pressure is the first to be evaluated if needed
variables = list(self.data_vars)
if variables[0] != "air_pressure":
variables.insert(0, variables.pop(variables.index("air_pressure")))
if "air_pressure" in self.data_vars:
if variables[0] != "air_pressure":
variables.insert(0, variables.pop(variables.index("air_pressure")))

for name in variables:
var = self.data_vars[name]
Expand All @@ -796,9 +797,10 @@ def _load_interpolate_timestep(self):
cross_section = utils.interpolate_vertsec(var_data, self.lat_data, lon_data, self.lats, self.lons)
# Create vertical interpolation factors and indices for subsequent variables
# TODO: Improve performance for this interpolation in general
if name == "air_pressure":
if len(factors) == 0:
for index_lonlat, alt in enumerate(self.alts):
pressures = cross_section[:, index_lonlat]
pressures = cross_section[:, index_lonlat] if name == "air_pressure" \
else self.vert_data[::-self.vert_order] * (100 if self.vert_units.lower() == "hpa" else 1)
closest = 0
direction = 1
for index_altitude, pressure in enumerate(pressures):
Expand All @@ -818,6 +820,7 @@ def _load_interpolate_timestep(self):
[[closest, 1 - (abs(pressures[closest] - alt) / distance)],
[next_closest, 1 - (abs(pressures[next_closest] - alt) / distance)]])

# Interpolate with the previously calculated pressure indices and factors
for index in range(len(self.alts)):
cur_factor = factors[index]
value = cross_section[cur_factor[0][0], index] * cur_factor[0][1] + \
Expand Down
8 changes: 5 additions & 3 deletions mslib/mswms/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ def __init__(self):
mss_wms_settings.register_linear_layers = []
for layer in mss_wms_settings.register_linear_layers:
if len(layer) == 3:
self.register_lsec_layer(layer[2], layer[1], layer[0])
self.register_lsec_layer(layer[2], layer[1], layer_class=layer[0])
elif len(layer) == 4:
self.register_lsec_layer(layer[3], layer[1], layer[2], layer[0])
else:
self.register_lsec_layer(layer[1], layer_class=layer[0])

Expand Down Expand Up @@ -262,7 +264,7 @@ def register_vsec_layer(self, datasets, layer_class):
raise ValueError("dataset '%s' not available", dataset)
self.vsec_layer_registry[dataset][layer.name] = layer

def register_lsec_layer(self, datasets, variable=None, layer_class=None):
def register_lsec_layer(self, datasets, variable=None, filetype="ml", layer_class=None):
"""
Register linear section layer in internal dict of layers.

Expand All @@ -274,7 +276,7 @@ def register_lsec_layer(self, datasets, variable=None, layer_class=None):
for dataset in datasets:
try:
if variable:
layer = layer_class(self.lsec_drivers[dataset], variable)
layer = layer_class(self.lsec_drivers[dataset], variable, filetype)
else:
layer = layer_class(self.lsec_drivers[dataset])
except KeyError as ex:
Expand Down
1 change: 1 addition & 0 deletions mslib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

UR.define("fraction = [] = frac")
UR.define("sigma = 1 fraction")
UR.define("level = sigma")
UR.define("percent = 1e-2 fraction")
UR.define("permille = 1e-3 fraction")
UR.define("ppm = 1e-6 fraction")
Expand Down