# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Plot positions of Øysteins radiation validation stations on a map
"""

from pps_matchup import get_radvaldata

# -------------------------------------------------------------------------
if __name__ == "__main__":

    datapoints = get_radvaldata("radval-stlist.txt")

    lonpos = datapoints['lon']
    latpos = datapoints['lat']

    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(11, 7))
    ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])

    # m = Basemap(llcrnrlon=-180, llcrnrlat=-80,
    #             urcrnrlon=180, urcrnrlat=80, projection='mill')
    m = Basemap(projection='stere', lon_0=0, lat_0=90., lat_ts=60,
                llcrnrlat=40, urcrnrlat=60,
                llcrnrlon=-30, urcrnrlon=120,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Plot positions of Øysteins radiation validation stations on a map
"""

from pps_matchup import get_radvaldata

# -------------------------------------------------------------------------
if __name__ == "__main__":

    datapoints = get_radvaldata("radval-stlist.txt")

    lonpos = datapoints['lon']
    latpos = datapoints['lat']

    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(11, 7))
    ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])

    # m = Basemap(llcrnrlon=-180, llcrnrlat=-80,
    #             urcrnrlon=180, urcrnrlat=80, projection='mill')
    m = Basemap(projection='stere',
                lon_0=0,
                lat_0=90.,
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Filter/reduce the ascii files with synop-satellite matchups to contain only
selected stations

"""
import pandas as pd

#RADVAL_FILE = "./radval-stlist.txt"
RADVAL_FILE = "./radval-stlist-wmo.txt"

SYNOPFILE = "./matchup_synop_all_npp.txt"
OUTPUTFILE = "./matchup_synop_radval_npp.txt"

from pps_matchup import get_radvaldata

datapoints = get_radvaldata(RADVAL_FILE)
pdata = pd.DataFrame(datapoints)

ids = [x[1]['id'] for x in pdata.iterrows()]

with open(SYNOPFILE, "r") as fpt:
    lines = fpt.readlines()

outlines = []
for line in lines[3:]:
    sl_ = line.split()
    if sl_[2] in ids:
        outlines.append(line)

with open(OUTPUTFILE, "w") as fpt:
    fpt.writelines(lines[0:3] + outlines)
"""Filter/reduce the ascii files with synop-satellite matchups to contain only
selected stations

"""
import pandas as pd

#RADVAL_FILE = "./radval-stlist.txt"
RADVAL_FILE = "./radval-stlist-wmo.txt"

SYNOPFILE = "./matchup_synop_all_npp.txt"
OUTPUTFILE = "./matchup_synop_radval_npp.txt"


from pps_matchup import get_radvaldata

datapoints = get_radvaldata(RADVAL_FILE)
pdata = pd.DataFrame(datapoints)

ids = [x[1]['id'] for x in pdata.iterrows()]

with open(SYNOPFILE, "r") as fpt:
    lines = fpt.readlines()

outlines = []
for line in lines[3:]:
    sl_ = line.split()
    if sl_[2] in ids:
        outlines.append(line)

with open(OUTPUTFILE, "w") as fpt:
    fpt.writelines(lines[0:3] + outlines)