Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
issue #23 - rivm aps2raster refined
Browse files Browse the repository at this point in the history
  • Loading branch information
justb4 committed Oct 8, 2015
1 parent 4944da4 commit f0042dd
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 110 deletions.
Binary file added data/rivm-rio/aps2raster/2015091611_no2.tif
Binary file not shown.
Binary file added data/rivm-rio/aps2raster/2015091611_o3.tif
Binary file not shown.
Binary file added data/rivm-rio/aps2raster/2015091611_pm10.tif
Binary file not shown.
3 changes: 3 additions & 0 deletions src/rivm-rio/aps2raster-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./aps2raster.py ../../data/rivm-rio/output/2015091611_no2.aps ../../data/rivm-rio/aps2raster/2015091611_no2.tif
./aps2raster.py ../../data/rivm-rio/output/2015091611_o3.aps ../../data/rivm-rio/aps2raster/2015091611_o3.tif
./aps2raster.py ../../data/rivm-rio/output/2015091611_pm10.aps ../../data/rivm-rio/aps2raster/2015091611_pm10.tif
59 changes: 40 additions & 19 deletions src/rivm-rio/aps2raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
# APS metadata provide input parameters for the GDAL functions, in particular the origin and
# pixelsize. Projection is fixed at the Dutch EPSG:28992 (RD) projection. Although the APS
# data are floats, they are rounded and converted to ints (0-255) in order to fit into the GeoTIFF.
# Negative values in the APS data like -999.0 are assumed to be 0 (TODO: maybe GDAL.NO_DATA later).
# Negative values in the APS data like -999.0 are assumed to be No Data values.
#
# This utility depends on the GDAL and NumPy Python libraries.
#
# Usage: python aps2raster.py <input APS file> <output GeoTIFF file>
import sys
import gdal,osr
import gdal, osr
import numpy as np

def array2raster(out_file, origin, pixel_width, pixel_height, array, epsg_code):

def array2raster(out_file, origin, pixel_width, pixel_height, array, meta, epsg_code):
cols = array.shape[1]
rows = array.shape[0]
origin_x = origin[0]
Expand All @@ -33,7 +38,13 @@ def array2raster(out_file, origin, pixel_width, pixel_height, array, epsg_code):

# Write array data to first rasterband
out_band = out_raster.GetRasterBand(1)
out_band.SetUnitType('ug/m3')
out_band.SetNoDataValue(-999)

metadata = {
'name': 'concentration'
}
out_band.SetMetadata(metadata)
out_band.WriteArray(array)

# Project
Expand All @@ -44,16 +55,23 @@ def array2raster(out_file, origin, pixel_width, pixel_height, array, epsg_code):
# Writeout
out_band.FlushCache()


def parse_aps_meta(meta_line):
# APS Header
# Y M D H C unit sys comment format proj orig_x orig_y cols rows pix_w pix_h
# Y M D H C unit sys comment format proj orig_x orig_y cols rows pix_w pix_h
# 15 9 16 10 NO2 ug/m3 RIO uurwaarden f7.1 1 0.000 620.000 70 80 4.000 4.000

# Slice the string first as the "comment" field may have multiple words
# Becomes like '15 9 16 10 NO2 ug/m3 1 0.000 620.000 70 80 4.000 4.000'
meta_line_1 = meta_line[0:34]
meta_line_2 = meta_line[75:]

meta_line_min = meta_line_1 + meta_line_2
# Remove excess whitespace
meta_line = " ".join(meta_line.split())
meta_line_min = " ".join(meta_line_min.split())

# Now split with single whitespace
meta_arr = meta_line.split(' ')
meta_arr = meta_line_min.split(' ')

# Build-up dict from array, do conversions where needed
meta = dict()
Expand All @@ -64,29 +82,31 @@ def parse_aps_meta(meta_line):
meta['hour'] = int(meta_arr[3])
meta['component'] = meta_arr[4]
meta['unit'] = meta_arr[5]
meta['system'] = meta_arr[6]
meta['comment'] = meta_arr[7]
meta['cell_format'] = meta_arr[8]
# meta['system'] = meta_arr[6]
# meta['comment'] = meta_arr[7]
# meta['cell_format'] = meta_arr[8]

# Code voor coordinatenstelsel
# 1. Amersfoortse coordinaten
# 2. Geografische coordinaten
# 3. Projectie op 50 NB (shifted pole) 4. projectie op 60 NB (shifted pole) 5. EMEP-coordinaten
# 6. IE-coordinaten (EMEP/2.)
# 7. OECD-coordinaten (EMEP/3.)
meta['projection'] = int(meta_arr[9])
meta['projection'] = int(meta_arr[6])

# Upper left of upper left pixel
meta['origin_x'] = float(meta_arr[10])*1000
meta['origin_y'] = float(meta_arr[11])*1000
meta['origin_x'] = float(meta_arr[7]) * 1000
meta['origin_y'] = float(meta_arr[8]) * 1000

meta['columns'] = int(meta_arr[12])
meta['rows'] = int(meta_arr[13])
meta['pixel_width'] = float(meta_arr[14])*1000
meta['pixel_height'] = float(meta_arr[15])*1000
meta['columns'] = int(meta_arr[9])
meta['rows'] = int(meta_arr[10])
meta['pixel_width'] = float(meta_arr[11]) * 1000
meta['pixel_height'] = float(meta_arr[12]) * 1000
meta['meta'] = meta_line

return meta


def read_aps_file(file_path):
file = open(file_path, 'r')

Expand All @@ -112,11 +132,12 @@ def read_aps_file(file_path):

return meta, raster_array


if __name__ == "__main__":
args = sys.argv

in_file = args[1] # '../../data/rivm-rio/output/2015091611_no2.aps'
out_file = args[2] # 'aps_no2.tif'
in_file = args[1] # '../../data/rivm-rio/output/2015091611_no2.aps'
out_file = args[2] # '../../data/rivm-rio/aps2raster/2015091611_no2.tif'

aps_meta, aps_array = read_aps_file(in_file)
origin = (aps_meta['origin_x'], aps_meta['origin_y'], 0)
Expand All @@ -138,5 +159,5 @@ def read_aps_file(file_path):
# aps_list = aps_array.tolist()

# Convert to raster file
array2raster(out_file, origin, pixel_width, pixel_height, aps_array, 28992)
array2raster(out_file, origin, pixel_width, pixel_height, aps_array, aps_meta, 28992)

30 changes: 30 additions & 0 deletions src/rivm-rio/sld/aps_03.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>rivm_aps_o3</Name>
<UserStyle>
<Name>rivm_aps_o3</Name>
<Title>rivm_aps_o3</Title>
<Abstract>Style for RIVM APS raster O3</Abstract>
<FeatureTypeStyle>
<FeatureTypeName>Feature</FeatureTypeName>
<Rule>
<RasterSymbolizer>
<ColorMap type="intervals">
<ColorMapEntry color="#FFFFFF" quantity="0" label="No Data" opacity="0.0"/>
<ColorMapEntry color="#6699CC" quantity="60" label="&lt; 60 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#99CCCC" quantity="120" label="60-120 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#CCFFFF" quantity="180" label="120-180 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#FFFFCC" quantity="200" label="180-200 ug/m3" opacity="1.0"/> <!-- Yellow -->
<ColorMapEntry color="#FFCC66" quantity="220" label="200-220 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#FF9966" quantity="240" label="220-240 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#990033" quantity="20000" label="&gt; 240 ug/m3" opacity="1.0"/>
</ColorMap>
</RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
16 changes: 8 additions & 8 deletions src/rivm-rio/sld/aps_no2.sld
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<Rule>
<RasterSymbolizer>
<ColorMap type="intervals">
<ColorMapEntry color="#FFFFFF" quantity="0.0001" opacity="0.0"/>
<ColorMapEntry color="#6699CC" quantity="20.00" opacity="1.0"/>
<ColorMapEntry color="#99CCCC" quantity="50.00" opacity="1.0"/>
<ColorMapEntry color="#CCFFFF" quantity="200.00" opacity="1.0"/>
<ColorMapEntry color="#FFFFCC" quantity="250.00" opacity="1.0"/> <!-- Yellow -->
<ColorMapEntry color="#FFCC66" quantity="350.00" opacity="1.0"/>
<ColorMapEntry color="#FF9966" quantity="400.00" opacity="1.0"/>
<ColorMapEntry color="#990033" quantity="2000.00" opacity="1.0"/>
<ColorMapEntry color="#FFFFFF" quantity="0" label="No Data" opacity="0.0"/>
<ColorMapEntry color="#6699CC" quantity="20" label="&lt; 20 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#99CCCC" quantity="50" label="20-50 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#CCFFFF" quantity="200" label="50-200 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#FFFFCC" quantity="250" label="200-250 ug/m3" opacity="1.0"/> <!-- Yellow -->
<ColorMapEntry color="#FFCC66" quantity="350" label="250-350 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#FF9966" quantity="400" label="350-400 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#990033" quantity="20000" label="&gt; 400 ug/m3" opacity="1.0"/>
</ColorMap>
</RasterSymbolizer>
</Rule>
Expand Down
30 changes: 30 additions & 0 deletions src/rivm-rio/sld/aps_pm10.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>rivm_aps_pm10</Name>
<UserStyle>
<Name>rivm_aps_pm10</Name>
<Title>rivm_aps_pm10</Title>
<Abstract>Style for RIVM APS raster PM10</Abstract>
<FeatureTypeStyle>
<FeatureTypeName>Feature</FeatureTypeName>
<Rule>
<RasterSymbolizer>
<ColorMap type="intervals">
<ColorMapEntry color="#FFFFFF" quantity="0" label="No Data" opacity="0.0"/>
<ColorMapEntry color="#6699CC" quantity="10" label="&lt; 10 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#99CCCC" quantity="30" label="10-30 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#CCFFFF" quantity="50" label="30-50 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#FFFFCC" quantity="75" label="50-75 ug/m3" opacity="1.0"/> <!-- Yellow -->
<ColorMapEntry color="#FFCC66" quantity="125" label="75-125 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#FF9966" quantity="200" label="125-200 ug/m3" opacity="1.0"/>
<ColorMapEntry color="#990033" quantity="20000" label="&gt; 200 ug/m3" opacity="1.0"/>
</ColorMap>
</RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
41 changes: 28 additions & 13 deletions www/heronviewer/config/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ Heron.options.urls = Heron.scratch.urls;

// Create end interval date from current date for timeseries slider config.
Heron.date = new Date();
Heron.date.setHours(Heron.date.getHours()-1);
Heron.date.setHours(Heron.date.getHours() - 1);
Heron.date.setMinutes(0);
Heron.date.setSeconds(0);
Heron.date.setMilliseconds(0);

Heron.date = Heron.date.toISOString();

Heron.cdate = new Date();
Heron.cdate.setHours(Heron.cdate.getHours()-3);
Heron.cdate.setHours(Heron.cdate.getHours() - 3);
Heron.cdate.setMinutes(0);
Heron.cdate.setSeconds(0);
Heron.cdate.setMilliseconds(0);
Expand Down Expand Up @@ -180,43 +180,58 @@ Heron.layout = {
// layer sources
defaultSourceType: "gxp_wmssource",
sources: {
rivm_wms: {
ptype: "gxp_wmssource",
url: 'http://geodata.rivm.nl/geoserver/ows?',
version: "1.1.1",
title: 'RIVM WMS',
owsPreviewStrategies: ['getlegendgraphic'] // or 'no preview available' if empty array
},
rivm_inspire_wms: {
ptype: "gxp_wmssource",
url: 'http://inspire.rivm.nl/geoserver/wms?',
version: "1.1.1",
title: 'RIVM INSPIRE WMS',
owsPreviewStrategies: ['getlegendgraphic'] // or 'no preview available' if empty array
},

//geonovum_sospilot_wms: {
// ptype: "gxp_wmssource",
// url: 'http://sensors.geonovum.nl/gs/sensors/wms?',
// version: "1.1.1",
// title: 'Geonovum SOSPilot WMS',
// owsPreviewStrategies: ['getlegendgraphic'] // or 'no preview available' if empty array
//},
pdok_bagviewer_wms: {
ptype: "gxp_wmssource",
url: Heron.options.urls.PDOK + '/bagviewer/wms',
version: "1.1.0",
title: 'PDOK BAG WMS',
owsPreviewStrategies: ['getlegendgraphic'] // or 'no preview available' if empty array
},
pdok_bestuurlijkegrenzen_wms: {
ptype: "gxp_wmssource",
url: Heron.options.urls.PDOK + '/bestuurlijkegrenzen/wms',
version: "1.1.0",
title: 'PDOK Bestuurlijke Grenzen WMS',
owsPreviewStrategies: ['getlegendgraphic'] // or 'no preview available' if empty array
},
pdok_bagviewer_wfs: {
ptype: "gxp_wfssource",
url: Heron.options.urls.PDOK + '/bagviewer/wfs',
version: "1.1.0",
title: 'PDOK BAG WFS',
owsPreviewStrategies: ['randomcolor'] // or 'no preview available' if empty array
},
pdok_nwbspoorwegen_wfs: {
ptype: "gxp_wfssource",
url: Heron.options.urls.PDOK + '/nwbspoorwegen/wfs',
version: "1.1.0",
title: 'PDOK NWB Spoorwegen WFS',
owsPreviewStrategies: ['randomcolor'] // or 'no preview available' if empty array
},
pdok_tms: {
map5_tms: {
ptype: "gxp_tmssource",
url: Heron.options.urls.PDOK + '/tms/',
url: 'http://s.map5.nl/map/gast/tms/1.0.0/',
isBaseLayer: true, // default is true
group: 'background' // 'background' or 'default', default value is 'background'
},
geodan_tms: {
pdok_tms: {
ptype: "gxp_tmssource",
url: 'http://services.geodan.nl/tms/',
url: Heron.options.urls.PDOK + '/tms/',
isBaseLayer: true, // default is true
group: 'background' // 'background' or 'default', default value is 'background'
}
Expand Down
Loading

0 comments on commit f0042dd

Please sign in to comment.