-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from metno/obs-mod-relative-altitude-filter
Implement relative altitude filter
- Loading branch information
Showing
10 changed files
with
388 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pyaro | ||
import csv | ||
import time | ||
import random | ||
import os | ||
|
||
# Generate test-data | ||
if not os.path.exists("tmp_data.csv"): | ||
with open("tmp_data.csv", "w", newline='') as csvfile: | ||
writer = csv.writer(csvfile) | ||
variable = "NOx" | ||
unit = "Gg" | ||
for i in range(75000): | ||
name = f"station{i}" | ||
lat = random.uniform(30.05, 81.95) | ||
lon = random.uniform(-29.95, 89.95) | ||
value = random.uniform(0, 1) | ||
altitude = random.randrange(0, 1000) | ||
start_time = "1997-01-01 00:00:00" | ||
end_time = "1997-01-02 00:00:00" | ||
|
||
|
||
writer.writerow((variable, name, lon, lat, value, unit, start_time, end_time, altitude)) | ||
|
||
# Benchmark | ||
engines = pyaro.list_timeseries_engines() | ||
with engines["csv_timeseries"].open( | ||
filename="tmp_data.csv", | ||
#filters=[pyaro.timeseries.filters.get("altitude", min_altitude=200)], # 0.023s | ||
filters=[pyaro.timeseries.filters.get("relaltitude", topo_file = "../tests/testdata/datadir_elevation/topography.nc", rdiff=90)], # 27.133s | ||
columns={ | ||
"variable": 0, | ||
"station": 1, | ||
"longitude": 2, | ||
"latitude": 3, | ||
"value": 4, | ||
"units": 5, | ||
"start_time": 6, | ||
"end_time": 7, | ||
"altitude": 8, | ||
"country": "NO", | ||
"standard_deviation": "NaN", | ||
"flag": "0", | ||
}) as ts: | ||
start_time = time.perf_counter() | ||
ts.stations() | ||
end_time = time.perf_counter() | ||
|
||
|
||
print(f"Total time: {end_time-start_time:.3f} seconds") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import xarray as xr | ||
|
||
# Script which extracts only the first time point and topography value from the emep topography | ||
# file to reduce data for the tests. | ||
data = xr.open_dataset("/lustre/storeB/project/fou/kl/emep/Auxiliary/topography.nc") | ||
|
||
start_time = data["time"][0] | ||
|
||
data = data.sel(time=slice(start_time)) | ||
|
||
data = data["topography"] | ||
|
||
|
||
data.to_netcdf("tests/testdata/datadir_elevation/topography.nc") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.