Module crepyscule_tools
[hide private]
[frames] | no frames]

Module crepyscule_tools

source code

Usefull methods regarding time, sun, math, strings and CSV format for crepyscule module.

Project home page is http://ptaff.ca/crepyscule/

Functions [hide private]
string
ctime_to_iso8601(ctime)
Convert a ctime value in iso8601.
source code
string
get_iso_8601(nYear, nMonth, nDay, nHour=0, nMinute=0, nSecond=0)
Convert numbers of date in the iso 8601 format.
source code
tuple
tranform_decimal_hour_in_minutes(fTimeHour, sRound='')
Description: Return an array containing the hour, the minutes and the secondes, respectively.
source code
list
get_one_year_of_iso8601(ctime)
Return a list containing all the dates to the year corresponding to the ctime in in iso8601 format.
source code
tuple
get_yesterday(nYear, nMonth, nDay)
Given a tuple containing (nYear, nMonth, nDay), remove one day and returns the tuple.
source code
tuple
get_one_year_data(fLat, fLon, ctime, fUTC, sTimezone)
Generate the information (sunset, sunrise, altitude) for one year.
source code
tuple
check_value_over_24(lSunset)
Check the value of sunset to see if there is some values over 24.
source code
tuple
check_value_under_0(lSunrise)
Check the value of sunset to see if there is some values over 24.
source code
tuple
correct_sun_bugs(lSunrise, lSunset)
Correct some bugs related to time of Sun file.
source code
list
get_one_year_max_sf(nYear, fLat)
Get the solar flux for a whole year.
source code
bool
is_summer_time(nJulianDay, nYear, sSummerTime)
Is this julian day during summer time?
source code
list
get_daylight_variation(lDaylightInOneDay)
Compute the time gained or lost for each day.
source code
dictionnary
get_dictionary(sValue, fLat, fLon, ctime, fUTC=None, sSummerTime='')
Compute the values indicated by sValue and return a dictionnary with the date in iso8601 as keys.
source code
float
get_one_value(sValue, fLat, fLon, tuple_or_ctime, fUTC=0, sSummerTime='')
Compute the value indicated by sValue and return it.
source code
string
str_to_at_least_two_digits(nNumber)
Take an int and return '01' instead of '1'.
source code
string
remove_extension(sFilename)
Remove the extension of a string file.
source code
 
save_info_flat_file(sFilename, lDateISO8601, lSunrise1, lSunset1, lDaylength1, fLat1, fLon1, fUTC1, sSummerTime1, lSunrise2=None, lSunset2=None, lDaylength2=None, fLat2=None, fLon2=None, fUTC2=None, sSummerTime2=None)
Simply call get_sunrise_sunset_as_csv and save it into a text file.
source code
list
get_sunrise_sunset_as_csv(lDateISO8601, lSunrise1, lSunset1, lDaylength1, fLat1, fLon1, fUTC1, sSummerTime1, lSunrise2=None, lSunset2=None, lDaylength2=None, fLat2=None, fLon2=None, fUTC2=None, sSummerTime2=None)
Returns a list containing the date, sunrise, sunset, daylength, like the CSV file.
source code
list
get_sun_altitude_as_csv(lDateISO8601, fLat1, lAltitude1, fLat2=None, lAltitude2=None)
Returns a list containing the date, sun altitude like the CSV file.
source code
list
get_daylight_variation_as_csv(lDateISO8601, lDaylength1, fLat1, lDaylength2=None, fLat2=None)
Returns a list containing the date and the daylight variation in minutes.
source code
list
get_solar_flux_as_csv(lDateISO8601, fLat1, lFlux1, fLat2=None, lFlux2=None)
Returns a list containing the date, maximal solar flux for each day.
source code
list
get_twilight_length_as_csv(lDateISO8601, fLat1, lLength1, fLat2=None, lLength2=None)
Returns a list containing the date, twilight length in minute for each day.
source code
float
get_max_solar_flux(ctime, fLat)
Get the maximum solar flux value for this day.
source code
list
get_daylength(ctime, fLat, fLon)
Get the daylength for all the year corresponding to this ctime.
source code
float
get_daylength_day(ctime, fLat, fLon)
Get the daylength for the day corresponding to this ctime.
source code
float
get_twilight_length(nYear, nMonth, nDay, fLat)
Get the twilight length in minute for this day and latitude.
source code
float
get_twilight_length_day(ctime, fLat)
Get the twilight length in minute for this day and latitude.
source code
list
get_twilight_length_year(ctime, fLat)
Get the twilight length in minute for the year of this day and latitude.
source code
Variables [hide private]
  t = gettext.translation('crepyscule_tools', sys.path [0]+ '/lo...
  HALF_YEAR = 182.62
  OBLIQUITY_OF_ECLIPTIC = 23.439
Function Details [hide private]

ctime_to_iso8601(ctime)

source code 

Convert a ctime value in iso8601.

Parameters:
  • ctime (float) - ctime value to be converted in iso8601
Returns: string
iso9601 date in the format YYYY-MM-DDTHH:mm:ssZ. See get_iso_8601

get_iso_8601(nYear, nMonth, nDay, nHour=0, nMinute=0, nSecond=0)

source code 

Convert numbers of date in the iso 8601 format. We assume UTC time zone.

Parameters:
  • nYear (int) - year for this date
  • nMonth (int) - month for this date
  • nDay (int) - day for this date
  • nHour (int) - hour for this date
  • nMinute (int) - minute for this date
  • nSecond (int) - second for this date
Returns: string
iso9601 date in the format YYYY-MM-DDTHH:mm:ssZ.

tranform_decimal_hour_in_minutes(fTimeHour, sRound='')

source code 

Description: Return an array containing the hour, the minutes and the secondes, respectively.

Parameters:
  • fTimeHour (float) - Time in decimal form. Eg 1.90 for 1h54:00
  • sRound (string) - Round the result to the minutes (seconds =0) or hours (seconds =0, minutes=0). Must be in ['minute', 'hour'],
Returns: tuple
(nHour, nMinute, nSecond)

get_one_year_of_iso8601(ctime)

source code 

Return a list containing all the dates to the year corresponding to the ctime in in iso8601 format.

Parameters:
  • ctime (float) - Any ctime in the year of the result.
Returns: list
List with all the dates for one year.

get_yesterday(nYear, nMonth, nDay)

source code 

Given a tuple containing (nYear, nMonth, nDay), remove one day and returns the tuple.

Parameters:
  • nYear (int) - year for this date
  • nMonth (int) - month for this date
  • nDay (int) - day for this date
Returns: tuple
(nYear, nMonth, nDay-1)

get_one_year_data(fLat, fLon, ctime, fUTC, sTimezone)

source code 

Generate the information (sunset, sunrise, altitude) for one year.

Parameters:
  • fLat (float) - Latitude in decimal.
  • fLon (float) - Longitude in decimal. West longitude are negative East longitude are positive.
  • ctime (float) - Any ctime in the year of the result.
  • fUTC (float) - Time to add/substract for each time values. Usually used for UTC value of place.
  • sTimezone (string) - This variable is a 2 letters code indicating when is the daylight saving time (DST) starting and ending in the year for the first place.
Returns: tuple
(lSunrise, lSunset, lSunAltitude, tToday)

check_value_over_24(lSunset)

source code 

Check the value of sunset to see if there is some values over 24.

Parameters:
  • lSunset (list) - list containing all the value of sunset.
Returns: tuple
(nStart, nEnd) where nStart is the value where the curve goes over 24 and nEnd is the value where the curve goes under 24.

check_value_under_0(lSunrise)

source code 

Check the value of sunset to see if there is some values over 24.

Parameters:
  • lSunrise (list) - list containing all the value of sunset.
Returns: tuple
(nStart, nEnd) where nStart is the value where the curve goes under 0 and nEnd is the value where the curve goes over 0.

correct_sun_bugs(lSunrise, lSunset)

source code 

Correct some bugs related to time of Sun file.

Parameters:
  • lSunrise (list) - list containing the sunrise value
  • lSunset (list) - list containing the sunset value
Returns: tuple
tuple containing the corrected value (npSunrise, npSunset),

get_one_year_max_sf(nYear, fLat)

source code 

Get the solar flux for a whole year.

Parameters:
  • nYear (int) - Year for which to get the solar flux.
  • fLat (float) - Latitude in decimal for the place.
Returns: list
List of the daily maximal solar fluxes.

is_summer_time(nJulianDay, nYear, sSummerTime)

source code 

Is this julian day during summer time?

Parameters:
  • nJulianDay (int) - Julian day, january 1st is '1', last day of year is '365' in a non-bisextil year.
  • nYear (int) - Year in which the julian day belongs
  • sSummerTime (string) - This variable is a 2 letters code indicating when is the daylight saving time (DST) starting and ending in the year for the first place.
Returns: bool
True if the Julian day is during summertime, False otherwise.

get_daylight_variation(lDaylightInOneDay)

source code 

Compute the time gained or lost for each day.

Parameters:
  • lDaylightInOneDay (list) - Contains the length of day, i.e. sunset-sunrise.
Returns: list
Result in a list in minutes.

get_dictionary(sValue, fLat, fLon, ctime, fUTC=None, sSummerTime='')

source code 

Compute the values indicated by sValue and return a dictionnary with the date in iso8601 as keys.

Parameters:
  • sValue (string) - Any string in lPossibleValues
  • fLat (float) - latitude of the first place. Latitude is in decimal degrees. Example: 30°30' should be 30.5
  • fLon (float) - longitude of the first place. Longitude is in decimal degrees. Example: 30°30' should be 30.5. West longitude are negative East longitude are positive.
  • ctime (float) - Any ctime in the day for the wanted value. If a graphic is created and there is only one place, a line is drawn with the values written at the intersection for this specific day.
  • fUTC (float) - Time to add/substract for each time values for the first place. Usually used for UTC value of place.
  • sSummerTime (string) - This variable is a 2 letters code indicating when is the daylight saving time (DST) starting and ending in the year for the first place. Default is no DST. For a list of DST code, see crepyscule_summer_time.lTimezone.
Returns: dictionnary
Dictionnary with key in iso8601 format like 'YYYY-MM-DD' and the corresponding value.

get_one_value(sValue, fLat, fLon, tuple_or_ctime, fUTC=0, sSummerTime='')

source code 

Compute the value indicated by sValue and return it.

Parameters:
  • sValue (string) - Any string in lPossibleValues
  • fLat (float) - latitude of the first place. Latitude is in decimal degrees. Example: 30°30' should be 30.5
  • fLon (float) - longitude of the first place. Longitude is in decimal degrees. Example: 30°30' should be 30.5. West longitude are negative East longitude are positive.
  • tuple_or_ctime (tuple or float) - can be called either with a ctime value or a tuple with (nYear, nMonth, nDay) for the specific day.
  • fUTC (float) - Time to add/substract for each time values for the first place. Usually used for UTC value of place.
  • sSummerTime (string) - This variable is a 2 letters code indicating when is the daylight saving time (DST) starting and ending in the year for the first place. Default is no DST. For a list of DST code, see crepyscule_summer_time.lTimezone.
Returns: float
Value corresponding to the date and the key

str_to_at_least_two_digits(nNumber)

source code 

Take an int and return '01' instead of '1'.

Parameters:
  • nNumber (int) - Number to return with at least 2 digits.
Returns: string
a string with 2 digits.

remove_extension(sFilename)

source code 

Remove the extension of a string file. Extension is defined as the letters after the right most '.'

Parameters:
  • sFilename (string) - The filename from which the extension must be removed.
Returns: string
A string with the filename without the extension.

save_info_flat_file(sFilename, lDateISO8601, lSunrise1, lSunset1, lDaylength1, fLat1, fLon1, fUTC1, sSummerTime1, lSunrise2=None, lSunset2=None, lDaylength2=None, fLat2=None, fLon2=None, fUTC2=None, sSummerTime2=None)

source code 

Simply call get_sunrise_sunset_as_csv and save it into a text file.

Parameters:

get_sunrise_sunset_as_csv(lDateISO8601, lSunrise1, lSunset1, lDaylength1, fLat1, fLon1, fUTC1, sSummerTime1, lSunrise2=None, lSunset2=None, lDaylength2=None, fLat2=None, fLon2=None, fUTC2=None, sSummerTime2=None)

source code 

Returns a list containing the date, sunrise, sunset, daylength, like the CSV file. header (first element): year place1 lat1 lon1 UTC1 summer_time_code1 (optional) place2 lat2 lon2 UTC2 summer_time_code2 data: date, sunrise1, sunset1, (optional) sunrise2, sunset2

Parameters:
  • lDateISO8601 (list) - List of strings for one year in iso8601 format.
  • lSunrise1 (list) - list containing the values of sunrise for the first place.
  • lSunset1 (list) - list containing the values of sunset for the first place.
  • lDaylength1 (list) - list containing the values of daylight in hours for the first place
  • fLat1 (float) - latitude of the first place. Latitude is in decimal degrees. Example: 30°30' should be 30.5
  • fLon1 (float) - longitude of the first place. Longitude is in decimal degrees. Example: 30°30' should be 30.5. West longitude are negative East longitude are positive.
  • fUTC1 (float) - Time to add/substract for each time values for the first place. Usually used for UTC value of place.
  • sSummerTime1 (string) - This variable is a 2 letters code indicating when is the daylight saving time (DST) starting and ending in the year for the first place. Default is no DST. For a list of DST code, see crepyscule_summer_time.lTimezone.
  • lSunrise2 (list) - list containing the values of sunrise for the first place.
  • lSunset2 (list) - list containing the values of sunset for the first place.
  • lDaylength2 (list) - list containing the values of daylight in hours for the second place
  • fLat2 (float) - latitude of the second place. See fLat1.
  • fLon2 (float) - longitude of the second place. See fLon1.
  • sSummerTime2 (string) - This variable is a 2 letters code indicating when is the daylight saving time (DST) starting and ending in the year for the seconde place. Default is no DST. For a list of DST code, see crepyscule_summer_time.lTimezone.
  • fUTC2 (float) - Time to add/substract for each time values for the second place.
Returns: list
A list containing the sunrise/sunset/length CSV values. One line per element of list.

get_sun_altitude_as_csv(lDateISO8601, fLat1, lAltitude1, fLat2=None, lAltitude2=None)

source code 

Returns a list containing the date, sun altitude like the CSV file. header (first element): year place1 lat1 place2 lat2 data: date, sun_altitude1 (optional), sun_altitude2

Parameters:
  • lDateISO8601 (list) - List of strings for one year in iso8601 format.
  • fLat1 (float) - latitude of the first place. Latitude is in decimal
  • lAltitude1 (list) - list containing the values of sun altitude for the first place.
  • fLat2 (float) - latitude of the second place. See fLat1.
  • lAltitude2 (list) - list containing the values of sun altitude for the second place.
Returns: list
A list containing the altitude values in the CSV format. One line per element of list.

get_daylight_variation_as_csv(lDateISO8601, lDaylength1, fLat1, lDaylength2=None, fLat2=None)

source code 

Returns a list containing the date and the daylight variation in minutes. header (first element): year place1 lat1 place2 lat2

Parameters:
  • lDateISO8601 (list) - List of strings for one year in iso8601 format.
  • lDaylength1 (list) - list containing the values of daylight in hours for the first place
  • fLat1 (float) - latitude of the first place. Latitude is in decimal
  • lDaylength2 (list) - list containing the values of daylight in hours for the second place
  • fLat2 (float) - latitude of the second place. See fLat1.
Returns: list
A list containing the daylight variation values in the CSV format. One line per element of list.

get_solar_flux_as_csv(lDateISO8601, fLat1, lFlux1, fLat2=None, lFlux2=None)

source code 

Returns a list containing the date, maximal solar flux for each day. header (first element): year place1 lat1 place2 lat2 data: date, max_solar_flux1 (optional), max_solar_flux2

Parameters:
  • lDateISO8601 (list) - List of strings for one year in iso8601 format.
  • fLat1 (float) - latitude of the first place. Latitude is in decimal
  • lFlux1 (list) - list containing the values of maximal solar fluxes for the first place.
  • fLat2 (float) - latitude of the second place. See fLat1.
  • lFlux2 (list) - list containing the values of maximal solar fluxes for the second place
Returns: list
A list containing the daily maximal solar fluxes in the CSV format. One line per element of list.

get_twilight_length_as_csv(lDateISO8601, fLat1, lLength1, fLat2=None, lLength2=None)

source code 

Returns a list containing the date, twilight length in minute for each day. header (first element): year place1 lat1 place2 lat2 data: date, twilight_length1, twilight_length2 (optional)

Parameters:
  • lDateISO8601 (list) - List of strings for one year in iso8601 format.
  • fLat1 (float) - latitude of the first place. Latitude is in decimal
  • lLength1 (list) - list containing the twilight length for the first place.
  • fLat2 (float) - latitude of the second place. See fLat1.
  • lLength2 (list) - list containing the twilitght for the second place
Returns: list
A list containing the twilight in the CSV format. One line per element of list.

get_max_solar_flux(ctime, fLat)

source code 

Get the maximum solar flux value for this day.

Parameters:
  • ctime (float) - Any ctime in the year of the result.
  • fLat (float) - Latitude in decimal for the place.
Returns: float
Maximum solar flux for this day in float. Solar flux is in watt per meter square.

get_daylength(ctime, fLat, fLon)

source code 

Get the daylength for all the year corresponding to this ctime.

Parameters:
  • ctime (float) - ctime value
  • fLat (float) - Latitude in decimal for the place.
  • fLon (float) - longitude of the first place. Longitude is in decimal degrees. Example: 30°30' should be 30.5. West longitude are negative
Returns: list
List of daylength, in hour

get_daylength_day(ctime, fLat, fLon)

source code 

Get the daylength for the day corresponding to this ctime.

Parameters:
  • ctime (float) - ctime value
  • fLat (float) - Latitude in decimal for the place.
  • fLon (float) - longitude of the first place. Longitude is in decimal degrees. Example: 30°30' should be 30.5. West longitude are negative
Returns: float
Daylength, in hour

get_twilight_length(nYear, nMonth, nDay, fLat)

source code 

Get the twilight length in minute for this day and latitude.

Parameters:
  • nYear (int) - year for this date
  • nMonth (int) - month for this date
  • nDay (int) - day for this date
Returns: float
Twilight length, in minute

get_twilight_length_day(ctime, fLat)

source code 

Get the twilight length in minute for this day and latitude.

Parameters:
  • ctime (float) - ctime value
  • fLat (float) - Latitude in decimal for the place.
Returns: float
Twilight length, in minute

get_twilight_length_year(ctime, fLat)

source code 

Get the twilight length in minute for the year of this day and latitude.

Parameters:
  • ctime (float) - ctime value
  • fLat (float) - Latitude in decimal for the place.
Returns: list
list containing the twilight length in minute

Variables Details [hide private]

t

Value:
gettext.translation('crepyscule_tools', sys.path [0]+ '/locale')