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

Module crepyscule_tools

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

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

Function Details

check_value_over_24(lSunset)

Check the value of sunset to see if there is some values over 24.
Parameters:
lSunset - list containing all the value of sunset.
           (type=list)
Returns:
(nStart, nEnd) where nStart is the value where the curve goes over 24 and nEnd is the value where the curve goes under 24.
           (type=tuple)

check_value_under_0(lSunrise)

Check the value of sunset to see if there is some values over 24.
Parameters:
lSunrise - list containing all the value of sunset.
           (type=list)
Returns:
(nStart, nEnd) where nStart is the value where the curve goes under 0 and nEnd is the value where the curve goes over 0.
           (type=tuple)

correct_sun_bugs(lSunrise, lSunset)

Correct some bugs related to time of Sun file.
Parameters:
lSunrise - list containing the sunrise value
           (type=list)
lSunset - list containing the sunset value
           (type=list)
Returns:
tuple containing the corrected value (npSunrise, npSunset),
           (type=tuple)

ctime_to_iso8601(ctime)

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

get_daylength(ctime, fLat, fLon)

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

get_daylength_day(ctime, fLat, fLon)

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

get_daylight_variation(lDaylightInOneDay)

Compute the time gained or lost for each day.
Parameters:
lDaylightInOneDay - Contains the length of day, i.e. sunset-sunrise.
           (type=list)
Returns:
Result in a list in minutes.
           (type=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. header (first element): year place1 lat1 place2 lat2
Parameters:
lDateISO8601 - List of strings for one year in iso8601 format.
           (type=list)
lDaylength1 - list containing the values of daylight in hours for the first place
           (type=list)
fLat1 - latitude of the first place. Latitude is in decimal
           (type=float)
lDaylength2 - list containing the values of daylight in hours for the second place
           (type=list)
fLat2 - latitude of the second place. See fLat1.
           (type=float)
Returns:
A list containing the daylight variation values in the CSV format. One line per element of list.
           (type=list)

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.
Parameters:
sValue - Any string in lPossibleValues
           (type=string)
fLat - latitude of the first place. Latitude is in decimal degrees. Example: 30°30' should be 30.5
           (type=float)
fLon - 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.
           (type=float)
ctime - 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.
           (type=float)
fUTC - Time to add/substract for each time values for the first place. Usually used for UTC value of place.
           (type=float)
sSummerTime - 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.
           (type=string)
Returns:
Dictionnary with key in iso8601 format like 'YYYY-MM-DD' and the corresponding value.
           (type=dictionnary)

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

Convert numbers of date in the iso 8601 format. We assume UTC time zone.
Parameters:
nYear - year for this date
           (type=int)
nMonth - month for this date
           (type=int)
nDay - day for this date
           (type=int)
nHour - hour for this date
           (type=int)
nMinute - minute for this date
           (type=int)
nSecond - second for this date
           (type=int)
Returns:
iso9601 date in the format YYYY-MM-DDTHH:mm:ssZ.
           (type=string)

get_max_solar_flux(ctime, fLat)

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

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

Compute the value indicated by sValue and return it.
Parameters:
sValue - Any string in lPossibleValues
           (type=string)
fLat - latitude of the first place. Latitude is in decimal degrees. Example: 30°30' should be 30.5
           (type=float)
fLon - 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.
           (type=float)
tuple_or_ctime - can be called either with a ctime value or a tuple with (nYear, nMonth, nDay) for the specific day.
           (type=tuple or float)
fUTC - Time to add/substract for each time values for the first place. Usually used for UTC value of place.
           (type=float)
sSummerTime - 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.
           (type=string)
Returns:
Value corresponding to the date and the key
           (type=float)

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

Generate the information (sunset, sunrise, altitude) for one year.
Parameters:
fLat - Latitude in decimal.
           (type=float)
fLon - Longitude in decimal. West longitude are negative East longitude are positive.
           (type=float)
ctime - Any ctime in the year of the result.
           (type=float)
fUTC - Time to add/substract for each time values. Usually used for UTC value of place.
           (type=float)
sTimezone - 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.
           (type=string)
Returns:
(lSunrise, lSunset, lSunAltitude, tToday)
           (type=tuple)

get_one_year_max_sf(nYear, fLat)

Get the solar flux for a whole year.
Parameters:
nYear - Year for which to get the solar flux.
           (type=int)
fLat - Latitude in decimal for the place.
           (type=float)
Returns:
List of the daily maximal solar fluxes.
           (type=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.
Parameters:
ctime - Any ctime in the year of the result.
           (type=float)
Returns:
List with all the dates for one year.
           (type=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. header (first element): year place1 lat1 place2 lat2 data: date, max_solar_flux1 (optional), max_solar_flux2
Parameters:
lDateISO8601 - List of strings for one year in iso8601 format.
           (type=list)
fLat1 - latitude of the first place. Latitude is in decimal
           (type=float)
lFlux1 - list containing the values of maximal solar fluxes for the first place.
           (type=list)
fLat2 - latitude of the second place. See fLat1.
           (type=float)
lFlux2 - list containing the values of maximal solar fluxes for the second place
           (type=list)
Returns:
A list containing the daily maximal solar fluxes in the CSV format. One line per element of list.
           (type=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. header (first element): year place1 lat1 place2 lat2 data: date, sun_altitude1 (optional), sun_altitude2
Parameters:
lDateISO8601 - List of strings for one year in iso8601 format.
           (type=list)
fLat1 - latitude of the first place. Latitude is in decimal
           (type=float)
lAltitude1 - list containing the values of sun altitude for the first place.
           (type=list)
fLat2 - latitude of the second place. See fLat1.
           (type=float)
lAltitude2 - list containing the values of sun altitude for the second place.
           (type=list)
Returns:
A list containing the altitude values in the CSV format. One line per element of list.
           (type=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. 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 of strings for one year in iso8601 format.
           (type=list)
lSunrise1 - list containing the values of sunrise for the first place.
           (type=list)
lSunset1 - list containing the values of sunset for the first place.
           (type=list)
lDaylength1 - list containing the values of daylight in hours for the first place
           (type=list)
fLat1 - latitude of the first place. Latitude is in decimal degrees. Example: 30°30' should be 30.5
           (type=float)
fLon1 - 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.
           (type=float)
fUTC1 - Time to add/substract for each time values for the first place. Usually used for UTC value of place.
           (type=float)
sSummerTime1 - 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.
           (type=string)
lSunrise2 - list containing the values of sunrise for the first place.
           (type=list)
lSunset2 - list containing the values of sunset for the first place.
           (type=list)
lDaylength2 - list containing the values of daylight in hours for the second place
           (type=list)
fLat2 - latitude of the second place. See fLat1.
           (type=float)
fLon2 - longitude of the second place. See fLon1.
           (type=float)
fUTC2 - Time to add/substract for each time values for the second place.
           (type=float)
sSummerTime2 - 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.
           (type=string)
Returns:
A list containing the sunrise/sunset/length CSV values. One line per element of list.
           (type=list)

get_twilight_length(nYear, nMonth, nDay, fLat)

Get the twilight length in minute for this day and latitude.
Parameters:
nYear - year for this date
           (type=int)
nMonth - month for this date
           (type=int)
nDay - day for this date
           (type=int)
Returns:
Twilight length, in minute
           (type=float)

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. header (first element): year place1 lat1 place2 lat2 data: date, twilight_length1, twilight_length2 (optional)
Parameters:
lDateISO8601 - List of strings for one year in iso8601 format.
           (type=list)
fLat1 - latitude of the first place. Latitude is in decimal
           (type=float)
lLength1 - list containing the twilight length for the first place.
           (type=list)
fLat2 - latitude of the second place. See fLat1.
           (type=float)
lLength2 - list containing the twilitght for the second place
           (type=list)
Returns:
A list containing the twilight in the CSV format. One line per element of list.
           (type=list)

get_twilight_length_day(ctime, fLat)

Get the twilight length in minute for this day and latitude.
Parameters:
ctime - ctime value
           (type=float)
fLat - Latitude in decimal for the place.
           (type=float)
Returns:
Twilight length, in minute
           (type=float)

get_twilight_length_year(ctime, fLat)

Get the twilight length in minute for the year of this day and latitude.
Parameters:
ctime - ctime value
           (type=float)
fLat - Latitude in decimal for the place.
           (type=float)
Returns:
list containing the twilight length in minute
           (type=list)

get_yesterday(nYear, nMonth, nDay)

Given a tuple containing (nYear, nMonth, nDay), remove one day and returns the tuple.
Parameters:
nYear - year for this date
           (type=int)
nMonth - month for this date
           (type=int)
nDay - day for this date
           (type=int)
Returns:
(nYear, nMonth, nDay-1)
           (type=tuple)

is_summer_time(nJulianDay, nYear, sSummerTime)

Is this julian day during summer time?
Parameters:
nJulianDay - Julian day, january 1st is '1', last day of year is '365' in a non-bisextil year.
           (type=int)
nYear - Year in which the julian day belongs
           (type=int)
sSummerTime - 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.
           (type=string)
Returns:
True if the Julian day is during summertime, False otherwise.
           (type=bool)

remove_extension(sFilename)

Remove the extension of a string file. Extension is defined as the letters after the right most '.'
Parameters:
sFilename - The filename from which the extension must be removed.
           (type=string)
Returns:
A string with the filename without the extension.
           (type=string)

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.
Parameters:
sFilename -

Filename for the text file to be written.

For other params, see get_sunrise_sunset_as_csv
           (type=string)

str_to_at_least_two_digits(nNumber)

Take an int and return '01' instead of '1'.
Parameters:
nNumber - Number to return with at least 2 digits.
           (type=int)
Returns:
a string with 2 digits.
           (type=string)

tranform_decimal_hour_in_minutes(fTimeHour, sRound='')

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

Generated by Epydoc 2.1 on Wed Jan 28 21:01:07 2009 http://epydoc.sf.net