<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Table of Contents
<p><div class="lev1 toc-item"><a data-toc-modified-id="Using-Brazilian-epidemiological-week-definition-1" href="#Using-Brazilian-epidemiological-week-definition"><span class="toc-item-num">1&nbsp;&nbsp;</span>Using Brazilian epidemiological week definition</a></div><div class="lev2 toc-item"><a data-toc-modified-id="Import-module-episem-11" href="#Import-module-episem"><span class="toc-item-num">1.1&nbsp;&nbsp;</span>Import module episem</a></div><div class="lev2 toc-item"><a data-toc-modified-id="Example-1
Step1:  Example 1
Step2:  Passing datetime.datetime
Step3:  Example 2
Step4:  Therefore, according to Brazilian epiweek system, it should fall on the last epiweek of year 2105
Step5:  Example 3
Step6:  Comparing with isocalendar
The week of the year, according to ISO calendar, is calculated slightly different from the Brazilian epiweek system. Thefore, although for some days of the year it can be the same numeral, for others the results can differ. In particular, the base year change and the introduction or not of week 53 are very sensitive. We show here the comparison between the two systems for the dates already used to highlight this issue.
The function isocalendar returns the base year, the week and the weekday for a given date.
<ASSISTANT_TASK:>
Python Code:
from episem import episem
Explanation: Table of Contents
<p><div class="lev1 toc-item"><a data-toc-modified-id="Using-Brazilian-epidemiological-week-definition-1" href="#Using-Brazilian-epidemiological-week-definition"><span class="toc-item-num">1&nbsp;&nbsp;</span>Using Brazilian epidemiological week definition</a></div><div class="lev2 toc-item"><a data-toc-modified-id="Import-module-episem-11" href="#Import-module-episem"><span class="toc-item-num">1.1&nbsp;&nbsp;</span>Import module episem</a></div><div class="lev2 toc-item"><a data-toc-modified-id="Example-1:-2016-10-31-12" href="#Example-1:-2016-10-31"><span class="toc-item-num">1.2&nbsp;&nbsp;</span>Example 1: 2016-10-31</a></div><div class="lev3 toc-item"><a data-toc-modified-id="Passing-string-121" href="#Passing-string"><span class="toc-item-num">1.2.1&nbsp;&nbsp;</span>Passing string</a></div><div class="lev3 toc-item"><a data-toc-modified-id="Passing-datetime.datetime-122" href="#Passing-datetime.datetime"><span class="toc-item-num">1.2.2&nbsp;&nbsp;</span>Passing datetime.datetime</a></div><div class="lev2 toc-item"><a data-toc-modified-id="Example-2:-2016-01-01-13" href="#Example-2:-2016-01-01"><span class="toc-item-num">1.3&nbsp;&nbsp;</span>Example 2: 2016-01-01</a></div><div class="lev2 toc-item"><a data-toc-modified-id="Example-3:-2017-01-01-14" href="#Example-3:-2017-01-01"><span class="toc-item-num">1.4&nbsp;&nbsp;</span>Example 3: 2017-01-01</a></div><div class="lev2 toc-item"><a data-toc-modified-id="Comparing-with-isocalendar-15" href="#Comparing-with-isocalendar"><span class="toc-item-num">1.5&nbsp;&nbsp;</span>Comparing with isocalendar</a></div>
# Using Brazilian epidemiological week definition
Brazilian epidemiological week (epiweek) is definied from Sunday to Saturday.
Wednesday is defined as the turning point for changing from one year to another and deciding wether Jan 1st is inlcuded in the first epiweek of the new year or still in the last epiweek of the previous one.
That is, if the weekday of Jan 1st is between Sunday to Wednesday (included), then it is epiweek 01 of the new year. If the weekday is between Thursday-Saturday, then it falls in the last epiweek of the previous year (typically epiweek 52).
The function epiweek takes both information into account to return the epiweek relative to a given date. Input can be a string in the format YYYY-MM-DD or type datetime.datetime
See episem.py for details
## Import module episem
End of explanation
d = '2010-10-01'
episem(d)
episem(d,out='W')
Explanation: Example 1: 2016-10-31
Function episem can take 1 to 3 inputs:
episem(x, sep='W', out='YW')
'''
@param x: date in format string YYYY-MM-DD or as datetime.datetime
@param sep: separator character
@param out: returned info. Y returns epiyear alone, W returns only epiweek and YW returns
epiyear and epiweek separated by sep
returns str
'''
Passing string
End of explanation
import datetime
datetime.datetime.strptime(d, '%Y-%m-%d')
dt = datetime.datetime.strptime(d, '%Y-%m-%d')
episem(dt)
Explanation: Passing datetime.datetime
End of explanation
dt2 = datetime.datetime.strptime('2016-01-01', '%Y-%m-%d')
dt2.isoweekday()
Explanation: Example 2: 2016-01-01
2016-10-01 was a Friday, as can be seen by isoweekday function, which returns 1 for Monday and 7 for Sunday:
End of explanation
episem(dt2)
Explanation: Therefore, according to Brazilian epiweek system, it should fall on the last epiweek of year 2105:
End of explanation
dt3 = datetime.datetime.strptime('2017-01-01', '%Y-%m-%d')
dt3.isoweekday()
episem(dt3)
Explanation: Example 3: 2017-01-01
2017-10-01 is a Sunday. Therefore, it should fall on the first epiweek of 2017:
End of explanation
print('Date: %s\nISO-calendar: %s\nBR-epiweek: %s\n' % (dt.date(), dt.isocalendar(), episem(dt)))
print('Date: %s\nISO-calendar: %s\nBR-epiweek: %s\n' % (dt2.date(), dt2.isocalendar(), episem(dt2)))
print('Date: %s\nISO-calendar: %s\nBR-epiweek: %s\n' % (dt3.date(), dt3.isocalendar(), episem(dt3)))
Explanation: Comparing with isocalendar
The week of the year, according to ISO calendar, is calculated slightly different from the Brazilian epiweek system. Thefore, although for some days of the year it can be the same numeral, for others the results can differ. In particular, the base year change and the introduction or not of week 53 are very sensitive. We show here the comparison between the two systems for the dates already used to highlight this issue.
The function isocalendar returns the base year, the week and the weekday for a given date.
End of explanation
<END_TASK>