Skip to content

Commit

Permalink
Merge pull request #8 from efmkoene/master
Browse files Browse the repository at this point in the history
Added testcase for rlon=0
  • Loading branch information
gredvis authored Dec 29, 2021
2 parents 1386aea + 967cfba commit 4fbe92a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
Binary file added tests/test_emissions.nc
Binary file not shown.
39 changes: 39 additions & 0 deletions tests/test_performance_at_rlon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import shutil
import subprocess

import netCDF4 as nc
import amrs.nc

import zipfile

import pytest

def test_performance_at_rlon():
"""\
Execute processing case which has rlon==0. Hard-coded (in shell) to save
effort of sending in all correct arguments otherwise...
"""

# working directory
cwd = os.path.dirname(__file__)

# remove outputs from previous tests
try:
shutil.rmtree(os.path.join(cwd, 'outputs'))
except FileNotFoundError:
pass

# run emiproc
subprocess.run(["python", "-m", "emiproc", "grid", "--case-file",
"tno_rlon.py"], shell=False,
cwd=cwd)

# compare output with reference
out_filename = os.path.join(cwd, "outputs", "online", "outgrid.nc")
out_filename_ref = os.path.join(cwd, "tno_ref.nc")

# assert that the two datasets are (nearly) identical
with nc.Dataset(out_filename) as own, nc.Dataset(out_filename_ref) as ref:
check1, check2 = amrs.nc.compare.datasets_equal(own, ref, [])
assert check1 and check2
Binary file added tests/tno_ref.nc
Binary file not shown.
73 changes: 73 additions & 0 deletions tests/tno_rlon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import os
import time

from emiproc.grids import COSMOGrid, TNOGrid, ICONGrid

# inventory
inventory = 'TNO'

# model either "cosmo-art", "cosmo-ghg" or "icon" (affects the
# output units and handling of the output grid)
model = 'cosmo-ghg'

# path to input inventory
input_path = "test_emissions.nc"

# input grid
input_grid = TNOGrid(input_path)

# input species
species = ['co2_ff']

# input categories
categories = [
"A",
]

# mapping from input to output species (input is used for missing keys)
in2out_species = {
'co2_ff': 'CO2',
}

# mapping from input to output species (input is used for missing keys)
in2out_category = {
}

# output variables are written in the following format using species and
# category after applying mapping as well as source_type (AREA or POINT) for
# TNO inventories
varname_format = '{species}_{category}_{source_type}' # not providing source_type will add up
# point and area sources

# COSMO domain
output_grid = COSMOGrid(
nx=26, #900
ny=26, #600
dx=0.01, #0.01
dy=0.01, #0.01
xmin=-0.13,
ymin=-0.13,
pollon=-169.0,
pollat=43.0,
)


# output path and filename
output_path = os.path.join('outputs', '{online}')
output_name = "outgrid.nc"

# resolution of shape file used for country mask
shpfile_resolution = "110m"

# number of processes computing the mapping inventory->COSMO-grid
nprocs = 18

# metadata added as global attributes to netCDF output file
nc_metadata = {
"DESCRIPTION": "Gridded annual emissions",
"DATAORIGIN": "TNO",
"CREATOR": "Erik Koene",
"EMAIL": "erik.koene@empa.ch",
"AFFILIATION": "Empa Duebendorf, Switzerland",
"DATE CREATED": time.ctime(time.time()),
}

0 comments on commit 4fbe92a

Please sign in to comment.