Esempio n. 1
0
def weeks_in_range(week_range: Tuple[int, int]) -> int:
    start = week_value_to_week(week_range[0])
    end = week_value_to_week(week_range[1])
    acc = end.week - start.week
    # accumulate the number of weeks in the years between
    for y in range(start.year, end.year):
        year = Year(y)
        acc += year.totalweeks()
    return acc + 1  # same week should lead to 1 week that will be queried
Esempio n. 2
0
 def fromEpiWeek2ModelWeek(self):
     """ Convert epiweek to model week, defined as the number of epidemic weeks from 197001
     """
     week = self.epiWeek
     numWeeks = 0
     w = self.refew
     while True:
         if w.year < week.year:
             numWeeks += Year(w.year).totalweeks
             w = Week(w.year + 1, 1)
         else:
             break
     while w < week:
         numWeeks += 1
         w += 1
     self.modelweek = numWeeks
Esempio n. 3
0
    def fromEpiWeek2ModelWeek(self, week):
        from epiweeks import Week, Year
        if type(week) is Week:
            pass
        elif type(week) is str:
            week = Week(int(week[:4]), int(week[4:]))
        elif type(week) is int:
            week = str(week)
            week = Week(int(week[:4]), int(week[4:]))

        numWeeks = 0
        w = Week(1970, 1)
        while True:
            if w.year < week.year:
                numWeeks += Year(w.year).totalweeks
                w = Week(w.year + 1, 1)
            else:
                break
        while w < week:
            numWeeks += 1
            w += 1
        return numWeeks
Esempio n. 4
0
def date_string_to_epi_week(date_string):
    """
    parse a date string in YYYY-MM-DD format and return
    cumulative epi week which is cumulative total epidemiological
    weeks since 2019-12-22. Week beginning 2019-12-22 is week 0
    """
    try:
        date = datetime.strptime(date_string, '%Y-%m-%d').date()
    except:
        return ""
    # this is epi-week:
    week = Week.fromdate(date)
    if week.year < 2019 or (week.year == 2019 and week.week < 52):
        return ""
    elif week.year == 2019:
        return ("0")
    else:
        cum_epi_week = week.week + len(
            list(
                chain(*[[x for x in Year(y).iterweeks()]
                        for y in range(2020, week.year)])))
        return str(cum_epi_week)
Esempio n. 5
0
import numpy as np
import geopandas as gpd
import pandas as pd
import seaborn as sns
from epiweeks import Week, Year
file_mask = 'D:/Utilisateurs/guillaume/Documents/GitHub/InSIGHT-PHAC/Mask/'
pr_in = 'K:/DATA/REANALYSES/ERA5/PR/'

data = pr_in + 'ERA5_PR_*.nc4'
ds = xr.open_mfdataset(data)
ds = ds * 1000  # convert from meter to mm

year_to_study = 2016
# compute epiweek for 2015 and 2016
df_epi = []
for week in Year(year_to_study).iterweeks():
    day = week.week
    day_ini = week.startdate().strftime("%Y-%m-%d")
    day_end = week.enddate().strftime("%Y-%m-%d")
    data = {'Week': [day], 'datei': [day_ini], 'datef': [day_end]}
    df = pd.DataFrame(data)
    df_epi.append(pd.DataFrame(data).set_index('Week'))

df_epi = pd.concat(df_epi, axis=0).sort_index()

lat_bnd = [62, -70]
lon_bnd = [230, 340]

Imp_Lats = ds.sel(
    longitude=slice(*lon_bnd),
    latitude=slice(*lat_bnd),
Esempio n. 6
0
def make_epiweeks():

    weeks = list(Year(2020).iterweeks())

    return weeks
Esempio n. 7
0
 def get_weeks(self, year):
     year = Year(year)
     return year.totalweeks()
Esempio n. 8
0
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 20 12:12:33 2019

@author: guillaume
"""
import pandas as pd
from epiweeks import Week, Year
df_epi = []
for week in Year(2015).iterweeks():
    day = week.week
    day_ini = week.startdate().strftime("%Y-%m-%d")
    day_end = week.enddate().strftime("%Y-%m-%d")
    data = {'Week': [day], 'datei': [day_ini], 'datef': [day_end]}
    df = pd.DataFrame(data)
    df_epi.append(pd.DataFrame(data).set_index('Week'))

df_epi = pd.concat(df_epi, axis=0).sort_index()
Esempio n. 9
0
def make_epiweeks():

    weeks = list(Year(2019).iterweeks())
    weeks.extend(list(Year(2020).iterweeks()))

    return weeks