Commit 89f59960 authored by Espen Sollum's avatar Espen Sollum
Browse files

Issue with string.split()

parent 3f1b90fc
......@@ -3,7 +3,6 @@
from __future__ import print_function
from __future__ import absolute_import
from .utils import remap_extract, find_header
import string
import pycif.utils.check as check
......@@ -32,7 +31,7 @@ def get_header(obs_file, maxlen):
return lines
if 'HEADER LINES' in line:
nheader = int(string.split(line, ':')[1])
nheader = int(line.split(':')[1])
if len(lines) > maxlen:
break
......@@ -44,7 +43,7 @@ def get_header(obs_file, maxlen):
# on the first line of the document
if nheader == 0:
try:
nheader = int(string.split(lines[0])[1])
nheader = int(lines[0].split()[1])
except:
raise ValueError("More than {} Header Lines in WDCGG File. " \
......@@ -78,7 +77,7 @@ def parse_header(header, spec, list_extract,
"""
# Minimize all characters to facilitate comparisons
head = [s.lower() for s in string.split(header[-1])[1:]]
head = [s.lower() for s in header[-1].split()[1:]]
# Parsing time information
try:
......
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import string
import os
from dateutil.tz import tzoffset
import numpy as np
......@@ -39,7 +38,8 @@ def find_header(id_extract, header):
for ln in header:
if remap_head(id_extract) in ln.lower():
value = string.split(ln.lower(), ':')[1].strip()
# value = string.split(ln.lower(), ':')[1].strip()
value = ln.lower().split(':')[1].strip()
try:
return float(value)
except ValueError:
......@@ -96,7 +96,7 @@ def parse_file(obs_file):
http://ds.data.jma.go.jp/gmd/wdcgg/pub/data/WDCGG_filename_format.pdf
"""
filesplit = string.split(os.path.basename(obs_file), '.')
filesplit = os.path.basename(obs_file).split('.')
infos = {}
infos['stat'] = filesplit[0][:3]
......
from builtins import zip
import datetime
import numpy as np
import pandas as pd
......@@ -48,7 +49,7 @@ def date_range(datei, datef, period='1000000H', subperiod=''):
return np.array(list_dates)
# Otherwise, split simulation window along base periods
date_range = pd.date_range(datei, datef, freq=period)
drange = pd.date_range(datei, datef, freq=period)
# If period is longer than the length of the simulation window,
# returns a very far away end date
......@@ -56,20 +57,20 @@ def date_range(datei, datef, period='1000000H', subperiod=''):
# This is done in case the last time stamp should be use
# for interpolation in the last hours of the run
if datei + pd.to_timedelta(period) > datef:
return date_range.union([date_range[-1] + pd.to_timedelta(period)]) \
.to_pydatetime()
return drange.union([drange[-1] + pd.to_timedelta(period)]) \
.to_series().dt.to_pydatetime()
else:
date_range = date_range.union([datef])
drange = drange.union([datef])
# One can specify sub-periods to split main periods
if subperiod == '':
list_dates = date_range.to_pydatetime()
list_dates = drange.to_series().dt.to_pydatetime()
else:
list_dates = []
for d0, d1 in zip(date_range[:-1], date_range[1:]):
for d0, d1 in zip(drange[:-1], drange[1:]):
drange = pd.date_range(d0, d1, freq=subperiod.format(period))
list_dates.extend(drange.to_pydatetime())
list_dates.extend(drange.to_series().dt.to_pydatetime())
if datef not in list_dates:
list_dates.append(datef)
......
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