Commit 1466f9d8 authored by Niklas Selke's avatar Niklas Selke
Browse files

activated the nox emissions service

parent 6157378f
Pipeline #96920 passed with stages
in 51 seconds
......@@ -50,7 +50,7 @@ INSTALLED_APPS = [
# 'services.rice_production',
'services.ecoregions',
'services.climatic_zones',
# 'services.nox_emissions',
'services.nox_emissions',
# 'services.omi_no2',
'services.htap_regions_tier1',
# 'services.htap_regions_tier2',
......
......@@ -14,7 +14,7 @@ urlpatterns = [
# re_path(r'rice_production/', include('services.rice_production.urls'), name='rice_production'),
re_path(r'ecoregions/', include('services.ecoregions.urls'), name='ecoregions'),
re_path(r'climatic_zones/', include('services.climatic_zones.urls'), name='climatic_zones'),
# re_path(r'nox_emissions/', include('services.nox_emissions.urls'), name='nox_emissions'),
re_path(r'nox_emissions/', include('services.nox_emissions.urls'), name='nox_emissions'),
# re_path(r'omi_no2/', include('services.omi_no2.urls'), name='omi_no2'),
re_path(r'htap_regions_tier1/', include('services.htap_regions_tier1.urls'), name='htap_regions_tier1'),
# re_path(r'htap_regions_tier2/', include('services.htap_regions_tier2.urls'), name='htap_regions_tier2'),
......
......@@ -41,7 +41,7 @@ class LocationServicesRootView(APIView):
# ('rice_production', request.build_absolute_uri()+'rice_production/'),
('ecoregions', request.build_absolute_uri()+'ecoregions/'),
('climatic_zones', request.build_absolute_uri()+'climatic_zones/'),
# ('nox_emissions', request.build_absolute_uri()+'nox_emissions/'),
('nox_emissions', request.build_absolute_uri()+'nox_emissions/'),
# ('omi_no2', request.build_absolute_uri()+'omi_no2/'),
('htap_regions_tier1', request.build_absolute_uri()+'htap_regions_tier1/'),
# ('htap_regions_tier2', request.build_absolute_uri()+'htap_regions_tier2/'),
......
from django.apps import AppConfig
class NoxEmissionConfig(AppConfig): # pragma: no cover
name = 'nox_emissions'
class NoxEmissionsConfig(AppConfig): # pragma: no cover
name = 'services.nox_emissions'
"""serializer for NOx emission data
"""serializer for nox emissions data
"""
from collections import OrderedDict
import datetime as dt
from utils.agg_serializer import GeneralAggSerializer
# helper functions
def get_provenance(obj):
"""construct provenance information on NOx emission dataset"""
prov = OrderedDict([
('dataset_name', 'NOx emissions EDGARv4.3'),
('dataset_description', """This service uses the HTAP_V2 2010 NOx emissions inventory. This dataset consists of
0.1deg x0.1deg gridmaps (lat-lon at center of each grid cell) of NOx emissions (reported as NO2) for the year
2010. It uses nationally reported emissions combined with regional scientific inventories in the format of
sector-specific gridmaps. The gridmaps are complemented with EDGARv4.3 data for those regions where data are
absent. The global gridmaps are a joint effort from US-EPA, the MICS-Asia group, EMEP/TNO, the REAS and the
EDGAR group to serve the scientific community for hemispheric transport of air pollution."""),
('data_source', """edgar"""),
('datacenter_url', 'http://edgar.jrc.ec.europa.eu/htap_v2/index.php?SECURE=123'),
('download_date', '?'),
('timestamp', dt.datetime.now().isoformat()),
('Terms of use', """Conditions of emission data use and code of conduct\n
Users of the data are obliged to acknowledge the source of the data with a reference to the HTAP_V2 website (and
publication as soon as available). The data providers are collecting feedback from users (just email your
comment/requests to greet.maenhout@jrc.ec.europa.eu), but the version on the website is frozen. No conversions
to other spatial resolutions will be provided. For important comments or potential errors, a corrigendum will be
posted on the website. The emission datasets should not be passed on to third parties or projects without
notification to the data provider. The data providers accept no responsibility with regard to problems incurred
as a result of errors in the data.""")
])
return prov
# serializer classes
class AggSerializer(GeneralAggSerializer):
def __init__(self, instance):
instance['unit'] = 'g m-2 yr-1'
instance['get_provenance'] = get_provenance
super(AggSerializer, self).__init__(instance)
\ No newline at end of file
instance['unit'] = 'kg m-2 s-1'
super(AggSerializer, self).__init__(instance)
from django.test import TestCase
from services.nox_emissions.serializers import get_provenance, AggSerializer
from services.nox_emissions.views import NOxView
from services.nox_emissions.serializers import AggSerializer
from services.nox_emissions.views import NoxEmissionsView
import geo_location_services.settings as settings
from collections import OrderedDict
class TestSerializers(TestCase):
def test_get_provenance(self):
required_elements = ['dataset_name', 'dataset_description', 'data_source', 'datacenter_url', 'download_date',
'timestamp', 'Terms of use']
self.assertListEqual(required_elements, list(get_provenance(None).keys()))
def test_AggSerializer(self):
rawdata = OrderedDict([
("lat", settings.DEFAULT_LAT),
......@@ -23,15 +18,14 @@ class TestSerializers(TestCase):
('mean', 10),
])
serializer = AggSerializer(rawdata)
self.assertEqual(serializer.instance["unit"], 'g m-2 yr-1')
self.assertEqual(serializer.instance["unit"], 'kg m-2 s-1')
self.assertEqual(serializer.instance["radius"], 5000)
self.assertTrue(serializer.instance["get_provenance"] is get_provenance)
class TestViews(TestCase):
def test_NOxView(self):
view = NOxView()
def test_NoxEmissionsView(self):
view = NoxEmissionsView()
self.assertEqual(view.min_valid, 0)
self.assertEqual(view.max_valid, 2.e6)
self.assertTrue(view.AggSerializer is AggSerializer)
......
from django.urls import re_path
from .views import NOxView
from .views import NoxEmissionsView
urlpatterns = [
re_path(r'^$', NOxView.as_view()),
re_path(r'^$', NoxEmissionsView.as_view()),
]
......@@ -2,7 +2,8 @@ from rest_framework.views import APIView
# from geo_location_services.settings import DEBUG, USE_LOCAL_DATA, USE_SMALL_DATA
# from services.file_extractions.nox_emissions_file_extraction import read_proxydata
from .serializers import AggSerializer
from utils.views_commons import CommonViews
from utils.views_commons import CommonViewsWithYear
from .apps import NoxEmissionsConfig as Config
# if USE_LOCAL_DATA: # pragma: no cover
......@@ -15,15 +16,13 @@ from utils.views_commons import CommonViews
# print("File %s successfully loaded" % FILENAME, datainfo)
class NOxView(APIView, CommonViews):
class NoxEmissionsView(APIView, CommonViewsWithYear):
def __init__(self):
opts = dict(# lonvec=lonvec,
# latvec=latvec,
# data=data,
min_valid=0.,
opts = dict(min_valid=0.,
max_valid=2.e6,
serializer=AggSerializer)
serializer=AggSerializer,
service_type=Config.name)
CommonViews.__init__(self, **opts)
CommonViewsWithYear.__init__(self, **opts)
......@@ -141,7 +141,10 @@ def extract_circle(lonvec, latvec, data, ilon, ilat, nlon, nlat,
xlat = ilat + j
if xlat < 0 or xlat >= latvec.size:
continue
tmp = data[xlat, xlon]
try:
tmp = data[xlat, xlon]
except IndexError:
continue
if (min_valid is not None and tmp < min_valid) \
or (max_valid is not None and tmp > max_valid):
continue
......
......@@ -16,6 +16,7 @@ class GeoCube:
'services.population_number': 'population_number__ghsl_09ss',
'services.population_number_coarse': 'population_number__ghsl_30ss',
'services.landcover': 'land_cover_class__esa',
'services.nox_emissions': 'nox_sum__cams',
# 'rice_production': 'rice',
# 'wheat_production': 'wheat'
}
......@@ -170,7 +171,7 @@ class GeoCube:
break
if timestamp is None:
raise ValueError("The given year ({}) is not available. Please select one "
"of: {}".format(year, ", ".join([time[:4] for time in self.metadata['years']])))
"of: {}".format(year, ", ".join(sorted({time[:4] for time in self.metadata['years']}))))
self.set_subsets([(self.metadata['time_label'], timestamp, timestamp),
(self.metadata['lat_label'], lat-dlatdeg, lat+dlatdeg),
(self.metadata['lon_label'], lon-dlondeg, lon+dlondeg)])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment