Commit f3b69c9d authored by Willi Rath's avatar Willi Rath

Add draft for ASCAT missing data treatment

parent d86f3767
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"from pathlib import Path\n",
"import re\n",
"import xarray as xr"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"base_path = Path(\"/data/c2/TMdata/git_geomar_de_data/\")\n",
"ASCAT_ref = \"v1.x.x\"\n",
"daily_data_path = base_path / \"ASCAT\" / ASCAT_ref / \"data/Daily/Netcdf\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2007032100_2007032200_daily-ifremer-L3-MWF-GLO-20110531232401-01.0.nc\r\n"
]
}
],
"source": [
"!ls -1 /data/c2/TMdata/git_geomar_de_data/ASCAT/v1.x.x/data/Daily/Netcdf/2007/03/21/"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def expected_ts_for_year(year):\n",
" first_ts = np.datetime64(\"{}-01-01T12:00:00\".format(year))\n",
" second_ts = np.datetime64(\"{}-01-02T12:00:00\".format(year))\n",
" del_t = second_ts - first_ts\n",
" last_ts = np.datetime64(\"{}-01-01T12:00:00\".format(year+1)) - del_t\n",
" num_ts = (last_ts - first_ts + del_t) / del_t\n",
" expected_ts = [first_ts + n * del_t for n in range(int(num_ts))]\n",
" return expected_ts\n",
"\n",
"assert len(expected_ts_for_year(2016)) == 366"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def existing_ts_for_year(year):\n",
" all_files = [str(fn) for fn in daily_data_path.glob(\"{}/??/??/*.nc\".format(year))]\n",
" raw_data_set = xr.open_mfdataset(all_files)\n",
" existing_ts = raw_data_set.time[:]\n",
" return existing_ts"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def is_timestamp_in(time_stamp, ts_iter):\n",
" return any(time_stamp == ts for ts in ts_iter)\n",
"\n",
"assert is_timestamp_in(np.datetime64(\"2001-01-01T12:00:00\"), \n",
" [np.datetime64(\"2001-01-01T12:00\")])\n",
"assert not is_timestamp_in(np.datetime64(\"2001-01-01T12:00:00\"), \n",
" [np.datetime64(\"2001-01-01T12:00:01\")])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def are_timestamps_in(expected_ts, existing_ts):\n",
" return list(map(lambda ts: is_timestamp_in(ts, existing_ts), expected_ts))\n",
"\n",
"assert are_timestamps_in([np.datetime64(\"2001-01-01\"), np.datetime64(\"2001-01-02\")],\n",
" [np.datetime64(\"2001-01-01\"),]) == [True, False]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False, True, True, True, True, True, True, True, True, True, True, True, True, True, False, False, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]\n"
]
}
],
"source": [
"expected_ts = expected_ts_for_year(2016)\n",
"existing_ts = existing_ts_for_year(2016)\n",
"print(are_timestamps_in(expected_ts, existing_ts))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "SSH wrath@taurus.geomar.de python_py3_std_/home/wrath/nb",
"language": "",
"name": "rik_ssh_wrath_taurus_geomar_de_python_py3_std_homewrathnb"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Markdown is supported
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