Skip to content

Commit 2ce65d4

Browse files
authored
Merge pull request #105 from metno/osisaf_seaice_fixes
Osisaf seaice fixes
2 parents ac1c055 + c315fe9 commit 2ce65d4

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

mapgen/modules/generic_quicklook.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def generic_quicklook(netcdf_path: str,
140140

141141
qp = _parse_request(query_string)
142142

143+
mapserver_map_file = None
143144
layer_no = 0
144145
map_object = None
145146
actual_variable = None
@@ -168,7 +169,7 @@ def generic_quicklook(netcdf_path: str,
168169
if netcdf_path.endswith('ncml'):
169170
netcdf_files = _read_netcdfs_from_ncml(netcdf_path)
170171
for variable in variables:
171-
if variable in ['longitude', 'latitude', 'forecast_reference_time', 'projection_lambert', 'p0', 'ap', 'b', 'time_bnds']:
172+
if variable in ['longitude', 'latitude', 'forecast_reference_time', 'projection_lambert', 'p0', 'ap', 'b' , 'Lambert_Azimuthal_Grid', 'time_bnds']:
172173
logger.debug(f"Skipping variable or dimension: {variable}")
173174
continue
174175
layer = mapscript.layerObj()
@@ -193,7 +194,7 @@ def generic_quicklook(netcdf_path: str,
193194
raise HTTPError(response_code='500 Internal Server Error', response=("Could not find any variables to turn into OGC WMS layers. One reason can be your data does "
194195
"not have a valid grid_mapping (Please see CF grid_mapping), or internal resampling failed."))
195196

196-
map_object.save(os.path.join(_get_mapfiles_path(product_config), f'generic-{forecast_time:%Y%m%d%H%M%S}.map'))
197+
map_object.save(mapserver_map_file)
197198

198199
# Handle the request and return results.
199200
return handle_request(map_object, query_string)

mapgen/modules/helpers.py

+22-13
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ def _find_summary_from_csw(search_fname, forecast_time, scheme, netloc):
289289
return summary_text
290290

291291
def _size_x_y(xr_dataset):
292-
x_l = ['x', 'X', 'Xc', 'longitude', 'lon']
293-
y_l = ['y', 'Y', 'Yc', 'latitude', 'lat']
292+
x_l = ['x', 'X', 'Xc', 'xc', 'longitude', 'lon']
293+
y_l = ['y', 'Y', 'Yc', 'yc', 'latitude', 'lat']
294294
for x,y in zip(x_l, y_l):
295295
try:
296296
return xr_dataset.dims[x], xr_dataset.dims[y]
@@ -311,11 +311,9 @@ def _fill_metadata_to_mapfile(orig_netcdf_path, forecast_time, map_object, schem
311311
summary_cache[bn] = "Not Available."
312312
map_object.web.metadata.set("wms_title", wms_title)
313313
map_object.web.metadata.set("wms_onlineresource", f"{scheme}://{netloc}/api/get_quicklook{orig_netcdf_path}")
314-
map_object.web.metadata.set("wms_srs", "EPSG:3857 EPSG:3978 EPSG:4269 EPSG:4326 EPSG:25832 EPSG:25833 EPSG:25835 EPSG:32632 EPSG:32633 EPSG:32635 EPSG:32661")
314+
map_object.web.metadata.set("wms_srs", "EPSG:3857 EPSG:3978 EPSG:4269 EPSG:4326 EPSG:25832 EPSG:25833 EPSG:25835 EPSG:32632 EPSG:32633 EPSG:32635 EPSG:32661 EPSG:3575")
315315
map_object.web.metadata.set("wms_enable_request", "*")
316316
map_object.setProjection("AUTO")
317-
_x, _y = _size_x_y(xr_dataset)
318-
map_object.setSize(_x, _y)
319317

320318
# try:
321319
# map_object.setSize(xr_dataset.dims['x'], xr_dataset.dims['y'])
@@ -345,6 +343,11 @@ def _fill_metadata_to_mapfile(orig_netcdf_path, forecast_time, map_object, schem
345343
except KeyError:
346344
logger.debug("Could not detect extent of dataset. Force full Earth.")
347345
map_object.setExtent(-180, -90, 180, 90)
346+
347+
# Need to set size of map object after extent is set
348+
_x, _y = _size_x_y(xr_dataset)
349+
logger.debug(f"x and y dimensions in dataset {_x} {_y}")
350+
map_object.setSize(_x, _y)
348351
return
349352

350353
def _find_projection(ds, variable, grid_mapping_cache):
@@ -368,16 +371,15 @@ def _find_projection(ds, variable, grid_mapping_cache):
368371

369372
def _extract_extent(ds, variable):
370373
"""Extract extent of variable."""
371-
x_l = ['x', 'X', 'Xc', 'longitude', 'lon']
372-
y_l = ['y', 'Y', 'Yc', 'latitude', 'lat']
374+
x_l = ['x', 'X', 'Xc', 'xc', 'longitude', 'lon']
375+
y_l = ['y', 'Y', 'Yc', 'yc', 'latitude', 'lat']
373376
for x, y in zip(x_l, y_l):
374377
try:
375378

376379
ll_x = min(ds[variable].coords[x].data)
377380
ur_x = max(ds[variable].coords[x].data)
378381
ll_y = min(ds[variable].coords[y].data)
379382
ur_y = max(ds[variable].coords[y].data)
380-
print(ds[variable].coords[x])
381383
return ll_x,ur_x,ll_y,ur_y
382384
except KeyError:
383385
pass
@@ -536,6 +538,10 @@ def _generate_getcapabilities(layer, ds, variable, grid_mapping_cache, netcdf_fi
536538
ll_x, ur_x, ll_y, ur_y = _extract_extent(ds, variable)
537539
logger.debug(f"ll_x, ur_x, ll_y, ur_y {ll_x} {ur_x} {ll_y} {ur_y}")
538540
layer.setProjection(grid_mapping_cache[grid_mapping_name])
541+
if "units=km" in grid_mapping_cache[grid_mapping_name]:
542+
layer.units = mapscript.MS_KILOMETERS
543+
elif "units=m" in grid_mapping_cache[grid_mapping_name]:
544+
layer.units = mapscript.MS_METERS
539545
layer.status = 1
540546
layer.data = f'NETCDF:{netcdf_file}:{variable}'
541547
layer.type = mapscript.MS_LAYER_RASTER
@@ -564,7 +570,7 @@ def _generate_getcapabilities(layer, ds, variable, grid_mapping_cache, netcdf_fi
564570
# logger.debug("Could not use time_coverange_start global attribute. wms_timeextent is not added")
565571

566572
for dim_name in ds[variable].dims:
567-
if dim_name in ['x', 'X', 'Xc', 'y', 'Y', 'Yc', 'longitude', 'latitude', 'lon', 'lat']:
573+
if dim_name in ['x', 'X', 'Xc', 'xc', 'y', 'Y', 'Yc', 'yc', 'longitude', 'latitude', 'lon', 'lat']:
568574
continue
569575
logger.debug(f"Checking dimension: {dim_name}")
570576
if dim_name in 'time':
@@ -629,7 +635,6 @@ def _generate_getcapabilities(layer, ds, variable, grid_mapping_cache, netcdf_fi
629635
style1.rangeitem = 'pixel'
630636
style1.mincolor = mapscript.colorObj(red=0, green=0, blue=0)
631637
style1.maxcolor = mapscript.colorObj(red=255, green=255, blue=255)
632-
633638
return True
634639

635640
def _generate_getcapabilities_vector(layer, ds, variable, grid_mapping_cache, netcdf_file, direction_speed=False, last_ds=None, netcdf_files=[], product_config=None):
@@ -679,7 +684,7 @@ def _generate_getcapabilities_vector(layer, ds, variable, grid_mapping_cache, ne
679684
except Exception:
680685
logger.debug("Could not use time_coverange_start global attribute. wms_timeextent is not added")
681686
for dim_name in ds[variable].dims:
682-
if dim_name in ['x', 'X', 'Xc', 'y', 'Y', 'Yc', 'longitude', 'latitude', 'lon', 'lat']:
687+
if dim_name in ['x', 'X', 'Xc', 'xc', 'y', 'Y', 'Yc', 'yc', 'longitude', 'latitude', 'lon', 'lat']:
683688
continue
684689
if dim_name in 'time':
685690
logger.debug("handle time")
@@ -758,7 +763,7 @@ def _find_dimensions(ds, actual_variable, variable, qp, netcdf_file, last_ds):
758763
# Find available dimension not larger than 1
759764
dimension_search = []
760765
for dim_name in ds[actual_variable].dims:
761-
if dim_name in ['x', 'X', 'Xc', 'y', 'Y', 'Yc', 'longitude', 'latitude', 'lon', 'lat']:
766+
if dim_name in ['x', 'X', 'Xc', 'xc', 'y', 'Y', 'Yc', 'yc', 'longitude', 'latitude', 'lon', 'lat']:
762767
continue
763768
for _dim_name in [dim_name, f'dim_{dim_name}']:
764769
if _dim_name == 'height' or _dim_name == 'dim_height':
@@ -975,6 +980,10 @@ def _generate_layer(layer, ds, grid_mapping_cache, netcdf_file, qp, map_obj, pro
975980

976981
set_scale_processing_key = False
977982
layer.setProjection(grid_mapping_cache[grid_mapping_name])
983+
if "units=km" in grid_mapping_cache[grid_mapping_name]:
984+
layer.units = mapscript.MS_KILOMETERS
985+
elif "units=m" in grid_mapping_cache[grid_mapping_name]:
986+
layer.units = mapscript.MS_METERS
978987
layer.status = 1
979988
if variable.endswith('_vector') or variable.endswith("_vector_from_direction_and_speed"):
980989

@@ -1321,7 +1330,7 @@ def _generate_layer(layer, ds, grid_mapping_cache, netcdf_file, qp, map_obj, pro
13211330
min_val = np.nanmin(ds[actual_variable][:,:].data)
13221331
max_val = np.nanmax(ds[actual_variable][:,:].data)
13231332
elif len(dimension_search) == 1:
1324-
logger.debug("Len 1")
1333+
logger.debug(f"Len 1 of {actual_variable}")
13251334
min_val = np.nanmin(ds[actual_variable][dimension_search[0]['selected_band_number'],:,:].data)
13261335
max_val = np.nanmax(ds[actual_variable][dimension_search[0]['selected_band_number'],:,:].data)
13271336
if '_FillValue' in ds[actual_variable].attrs:

tests/test_arome_arctic.py

+1-1
Large diffs are not rendered by default.

url-path-regexp-patterns.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
#'base_netcdf_directory': '/lustre/storeB/project/fou/hi/roms_hindcast/barents2500_2010/daily_average'
111111
'base_netcdf_directory': '/lustre/storeB'
112112
#'base_netcdf_directory': '/home/trygveas/testdata'
113+
#'base_netcdf_directory': '/home/trygveas'
113114
'module': 'mapgen.modules.generic_quicklook'
114115
'module_function': 'generic_quicklook'
115116
'mapfiles_path': '/tmp'

0 commit comments

Comments
 (0)