idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
237,500
def is_time_included ( self , time ) : if self . _timestamps_data is None : self . _calculate_timestamps ( ) return time . moy in self . _timestamps_data
Check if time is included in analysis period .
237,501
def duplicate ( self ) : return AnalysisPeriod ( self . st_month , self . st_day , self . st_hour , self . end_month , self . end_day , self . end_hour , self . timestep , self . is_leap_year )
Return a copy of the analysis period .
237,502
def to_json ( self ) : return { 'st_month' : self . st_month , 'st_day' : self . st_day , 'st_hour' : self . st_hour , 'end_month' : self . end_month , 'end_day' : self . end_day , 'end_hour' : self . end_hour , 'timestep' : self . timestep , 'is_leap_year' : self . is_leap_year }
Convert the analysis period to a dictionary .
237,503
def _calc_timestamps ( self , st_time , end_time ) : curr = datetime ( st_time . year , st_time . month , st_time . day , st_time . hour , st_time . minute , self . is_leap_year ) end_time = datetime ( end_time . year , end_time . month , end_time . day , end_time . hour , end_time . minute , self . is_leap_year ) whil...
Calculate timesteps between start time and end time .
237,504
def _calculate_timestamps ( self ) : self . _timestamps_data = [ ] if not self . _is_reversed : self . _calc_timestamps ( self . st_time , self . end_time ) else : self . _calc_timestamps ( self . st_time , DateTime . from_hoy ( 8759 ) ) self . _calc_timestamps ( DateTime . from_hoy ( 0 ) , self . end_time )
Return a list of Ladybug DateTime in this analysis period .
237,505
def _calc_daystamps ( self , st_time , end_time ) : start_doy = sum ( self . _num_of_days_each_month [ : st_time . month - 1 ] ) + st_time . day end_doy = sum ( self . _num_of_days_each_month [ : end_time . month - 1 ] ) + end_time . day + 1 return list ( range ( start_doy , end_doy ) )
Calculate days of the year between start time and end time .
237,506
def from_values ( cls , location , direct_normal_irradiance , diffuse_horizontal_irradiance , timestep = 1 , is_leap_year = False ) : err_message = 'For timestep %d, %d number of data for %s is expected. ' '%d is provided.' if len ( direct_normal_irradiance ) % cls . hour_count ( is_leap_year ) == 0 : err_message = err...
Create wea from a list of irradiance values .
237,507
def from_file ( cls , weafile , timestep = 1 , is_leap_year = False ) : assert os . path . isfile ( weafile ) , 'Failed to find {}' . format ( weafile ) location = Location ( ) with open ( weafile , readmode ) as weaf : first_line = weaf . readline ( ) assert first_line . startswith ( 'place' ) , 'Failed to find place ...
Create wea object from a wea file .
237,508
def from_epw_file ( cls , epwfile , timestep = 1 ) : is_leap_year = False epw = EPW ( epwfile ) direct_normal , diffuse_horizontal = cls . _get_data_collections ( epw . direct_normal_radiation . values , epw . diffuse_horizontal_radiation . values , epw . metadata , 1 , is_leap_year ) if timestep != 1 : print ( "Note: ...
Create a wea object using the solar irradiance values in an epw file .
237,509
def from_stat_file ( cls , statfile , timestep = 1 , is_leap_year = False ) : stat = STAT ( statfile ) def check_missing ( opt_data , data_name ) : if opt_data == [ ] : raise ValueError ( 'Stat file contains no optical data.' ) for i , x in enumerate ( opt_data ) : if x is None : raise ValueError ( 'Missing optical dep...
Create an ASHRAE Revised Clear Sky wea object from the monthly sky optical depths in a . stat file .
237,510
def from_zhang_huang_solar ( cls , location , cloud_cover , relative_humidity , dry_bulb_temperature , wind_speed , atmospheric_pressure = None , timestep = 1 , is_leap_year = False , use_disc = False ) : assert len ( cloud_cover ) == len ( relative_humidity ) == len ( dry_bulb_temperature ) == len ( wind_speed ) , 'le...
Create a wea object from climate data using the Zhang - Huang model .
237,511
def datetimes ( self ) : if self . timestep == 1 : return tuple ( dt . add_minute ( 30 ) for dt in self . direct_normal_irradiance . datetimes ) else : return self . direct_normal_irradiance . datetimes
Datetimes in wea file .
237,512
def global_horizontal_irradiance ( self ) : analysis_period = AnalysisPeriod ( timestep = self . timestep , is_leap_year = self . is_leap_year ) header_ghr = Header ( data_type = GlobalHorizontalIrradiance ( ) , unit = 'W/m2' , analysis_period = analysis_period , metadata = self . metadata ) glob_horiz = [ ] sp = Sunpa...
Returns the global horizontal irradiance at each timestep .
237,513
def direct_horizontal_irradiance ( self ) : analysis_period = AnalysisPeriod ( timestep = self . timestep , is_leap_year = self . is_leap_year ) header_dhr = Header ( data_type = DirectHorizontalIrradiance ( ) , unit = 'W/m2' , analysis_period = analysis_period , metadata = self . metadata ) direct_horiz = [ ] sp = Sun...
Returns the direct irradiance on a horizontal surface at each timestep .
237,514
def _get_datetimes ( timestep , is_leap_year ) : hour_count = 8760 + 24 if is_leap_year else 8760 adjust_time = 30 if timestep == 1 else 0 return tuple ( DateTime . from_moy ( 60.0 * count / timestep + adjust_time , is_leap_year ) for count in xrange ( hour_count * timestep ) )
List of datetimes based on timestep .
237,515
def _get_data_collections ( dnr_values , dhr_values , metadata , timestep , is_leap_year ) : analysis_period = AnalysisPeriod ( timestep = timestep , is_leap_year = is_leap_year ) dnr_header = Header ( data_type = DirectNormalIrradiance ( ) , unit = 'W/m2' , analysis_period = analysis_period , metadata = metadata ) dir...
Return two data collections for Direct Normal Diffuse Horizontal
237,516
def get_irradiance_value ( self , month , day , hour ) : dt = DateTime ( month , day , hour , leap_year = self . is_leap_year ) count = int ( dt . hoy * self . timestep ) return self . direct_normal_irradiance [ count ] , self . diffuse_horizontal_irradiance [ count ]
Get direct and diffuse irradiance values for a point in time .
237,517
def get_irradiance_value_for_hoy ( self , hoy ) : count = int ( hoy * self . timestep ) return self . direct_normal_irradiance [ count ] , self . diffuse_horizontal_irradiance [ count ]
Get direct and diffuse irradiance values for an hoy .
237,518
def directional_irradiance ( self , altitude = 90 , azimuth = 180 , ground_reflectance = 0.2 , isotrophic = True ) : def pol2cart ( phi , theta ) : mult = math . cos ( theta ) x = math . sin ( phi ) * mult y = math . cos ( phi ) * mult z = math . sin ( theta ) return Vector3 ( x , y , z ) normal = pol2cart ( math . rad...
Returns the irradiance components facing a given altitude and azimuth .
237,519
def header ( self ) : return "place %s\n" % self . location . city + "latitude %.2f\n" % self . location . latitude + "longitude %.2f\n" % - self . location . longitude + "time_zone %d\n" % ( - self . location . time_zone * 15 ) + "site_elevation %.1f\n" % self . location . elevation + "weather_data_file_units 1\n"
Wea header .
237,520
def write ( self , file_path , hoys = None , write_hours = False ) : if not file_path . lower ( ) . endswith ( '.wea' ) : file_path += '.wea' full_wea = False if not hoys : hoys = self . hoys full_wea = True lines = [ self . header ] if full_wea : for dir_rad , dif_rad , dt in zip ( self . direct_normal_irradiance , se...
Write the wea file .
237,521
def flatten ( input_list ) : for el in input_list : if isinstance ( el , collections . Iterable ) and not isinstance ( el , basestring ) : for sub in flatten ( el ) : yield sub else : yield el
Return a flattened genertor from an input list .
237,522
def unflatten ( guide , falttened_input ) : return [ unflatten ( sub_list , falttened_input ) if isinstance ( sub_list , list ) else next ( falttened_input ) for sub_list in guide ]
Unflatten a falttened generator .
237,523
def color ( self , value ) : assert self . _is_domain_set , "Domain is not set. Use self.domain to set the domain." if self . _ctype == 2 : try : return self . _colors [ self . _domain . index ( value ) ] except ValueError : raise ValueError ( "%s is not a valid input for ordinal type.\n" % str ( value ) + "List of val...
Return color for an input value .
237,524
def _cal_color ( self , value , color_index ) : range_min_p = self . _domain [ color_index ] range_p = self . _domain [ color_index + 1 ] - range_min_p try : factor = ( value - range_min_p ) / range_p except ZeroDivisionError : factor = 0 min_color = self . colors [ color_index ] max_color = self . colors [ color_index...
Blend between two colors based on input value .
237,525
def from_location ( cls , location , north_angle = 0 , daylight_saving_period = None ) : location = Location . from_location ( location ) return cls ( location . latitude , location . longitude , location . time_zone , north_angle , daylight_saving_period )
Create a sun path from a LBlocation .
237,526
def latitude ( self , value ) : self . _latitude = math . radians ( float ( value ) ) assert - self . PI / 2 <= self . _latitude <= self . PI / 2 , "latitude value should be between -90..90."
Set latitude value .
237,527
def longitude ( self , value ) : self . _longitude = math . radians ( float ( value ) ) if abs ( ( value / 15.0 ) - self . time_zone ) > 1 : self . time_zone = value / 15.0
Set longitude value in degrees .
237,528
def is_daylight_saving_hour ( self , datetime ) : if not self . daylight_saving_period : return False return self . daylight_saving_period . isTimeIncluded ( datetime . hoy )
Check if a datetime is a daylight saving time .
237,529
def calculate_sun_from_date_time ( self , datetime , is_solar_time = False ) : if datetime . year != 2016 and self . is_leap_year : datetime = DateTime ( datetime . month , datetime . day , datetime . hour , datetime . minute , True ) sol_dec , eq_of_time = self . _calculate_solar_geometry ( datetime ) hour = datetime ...
Get Sun for an hour of the year .
237,530
def calculate_sunrise_sunset ( self , month , day , depression = 0.833 , is_solar_time = False ) : datetime = DateTime ( month , day , hour = 12 , leap_year = self . is_leap_year ) return self . calculate_sunrise_sunset_from_datetime ( datetime , depression , is_solar_time )
Calculate sunrise noon and sunset .
237,531
def calculate_sunrise_sunset_from_datetime ( self , datetime , depression = 0.833 , is_solar_time = False ) : if datetime . year != 2016 and self . is_leap_year : datetime = DateTime ( datetime . month , datetime . day , datetime . hour , datetime . minute , True ) sol_dec , eq_of_time = self . _calculate_solar_geometr...
Calculate sunrise sunset and noon for a day of year .
237,532
def _calculate_sunrise_hour_angle ( self , solar_dec , depression = 0.833 ) : hour_angle_arg = math . degrees ( math . acos ( math . cos ( math . radians ( 90 + depression ) ) / ( math . cos ( math . radians ( self . latitude ) ) * math . cos ( math . radians ( solar_dec ) ) ) - math . tan ( math . radians ( self . lat...
Calculate hour angle for sunrise time in degrees .
237,533
def _calculate_solar_time ( self , hour , eq_of_time , is_solar_time ) : if is_solar_time : return hour return ( ( hour * 60 + eq_of_time + 4 * math . degrees ( self . _longitude ) - 60 * self . time_zone ) % 1440 ) / 60
Calculate Solar time for an hour .
237,534
def _calculate_solar_time_by_doy ( self , hour , doy ) : raise NotImplementedError ( ) return ( 0.170 * math . sin ( ( 4 * math . pi / 373 ) * ( doy - 80 ) ) - 0.129 * math . sin ( ( 2 * math . pi / 355 ) * ( doy - 8 ) ) + 12 * ( - ( 15 * self . time_zone ) - self . longitude ) / math . pi )
This is how radiance calculates solar time .
237,535
def draw_sunpath ( self , hoys = None , origin = None , scale = 1 , sun_scale = 1 , annual = True , rem_night = True ) : assert ladybug . isplus , '"draw_sunpath" method can only be used in the [+] libraries.' hoys = hoys or ( ) origin = origin or ( 0 , 0 , 0 ) try : origin = tuple ( origin ) except TypeError as e : tr...
Create sunpath geometry . \ This method should only be used from the + libraries .
237,536
def _analemma_position ( self , hour ) : low = self . calculate_sun ( 12 , 21 , hour ) . is_during_day high = self . calculate_sun ( 6 , 21 , hour ) . is_during_day if low and high : return 1 elif low or high : return 0 else : return - 1
Check what the analemma position is for an hour .
237,537
def _analemma_suns ( self ) : for h in xrange ( 0 , 24 ) : if self . _analemma_position ( h ) < 0 : continue elif self . _analemma_position ( h ) == 0 : chours = [ ] prevhour = self . latitude <= 0 num_of_days = 8760 if not self . is_leap_year else 8760 + 24 for hoy in xrange ( h , num_of_days , 24 ) : thishour = self ...
Calculate times that should be used for drawing analemma_curves .
237,538
def _daily_suns ( self , datetimes ) : for dt in datetimes : nss = self . calculate_sunrise_sunset ( dt . month , dt . day ) dts = tuple ( nss [ k ] for k in ( 'sunrise' , 'noon' , 'sunset' ) ) if dts [ 0 ] is None : yield ( self . calculate_sun ( dt . month , dt . day , h ) for h in ( 0 , 12 , 15 ) ) , False else : yi...
Get sun curve for multiple days of the year .
237,539
def _calculate_sun_vector ( self ) : z_axis = Vector3 ( 0. , 0. , - 1. ) x_axis = Vector3 ( 1. , 0. , 0. ) north_vector = Vector3 ( 0. , 1. , 0. ) _sun_vector = north_vector . rotate_around ( x_axis , self . altitude_in_radians ) . rotate_around ( z_axis , self . azimuth_in_radians ) . rotate_around ( z_axis , math . r...
Calculate sun vector for this sun .
237,540
def from_json ( cls , data ) : required_keys = ( 'location' , 'design_days' ) for key in required_keys : assert key in data , 'Required key "{}" is missing!' . format ( key ) return cls ( Location . from_json ( data [ 'location' ] ) , [ DesignDay . from_json ( des_day ) for des_day in data [ 'design_days' ] ] )
Create a DDY from a dictionary .
237,541
def from_ddy_file ( cls , file_path ) : if not os . path . isfile ( file_path ) : raise ValueError ( 'Cannot find a .ddy file at {}' . format ( file_path ) ) if not file_path . lower ( ) . endswith ( '.ddy' ) : raise ValueError ( 'DDY file does not have a .ddy extension.' ) try : iron_python = True if platform . python...
Initalize from a ddy file object from an existing ddy file .
237,542
def save ( self , file_path ) : data = self . location . ep_style_location_string + '\n\n' for d_day in self . design_days : data = data + d_day . ep_style_string + '\n\n' write_to_file ( file_path , data , True )
Save ddy object as a . ddy file .
237,543
def filter_by_keyword ( self , keyword ) : filtered_days = [ ] for des_day in self . design_days : if keyword in des_day . name : filtered_days . append ( des_day ) return filtered_days
Return a list of ddys that have a certain keyword in their name .
237,544
def from_json ( cls , data ) : required_keys = ( 'name' , 'day_type' , 'location' , 'dry_bulb_condition' , 'humidity_condition' , 'wind_condition' , 'sky_condition' ) for key in required_keys : assert key in data , 'Required key "{}" is missing!' . format ( key ) return cls ( data [ 'name' ] , data [ 'day_type' ] , Loc...
Create a Design Day from a dictionary .
237,545
def from_design_day_properties ( cls , name , day_type , location , analysis_period , dry_bulb_max , dry_bulb_range , humidity_type , humidity_value , barometric_p , wind_speed , wind_dir , sky_model , sky_properties ) : dry_bulb_condition = DryBulbCondition ( dry_bulb_max , dry_bulb_range ) humidity_condition = Humidi...
Create a design day object from various key properties .
237,546
def analysis_period ( self ) : return AnalysisPeriod ( self . sky_condition . month , self . sky_condition . day_of_month , 0 , self . sky_condition . month , self . sky_condition . day_of_month , 23 )
The analysisperiod of the design day .
237,547
def hourly_dew_point ( self ) : dpt_data = self . _humidity_condition . hourly_dew_point_values ( self . _dry_bulb_condition ) return self . _get_daily_data_collections ( temperature . DewPointTemperature ( ) , 'C' , dpt_data )
A data collection containing hourly dew points over they day .
237,548
def hourly_relative_humidity ( self ) : dpt_data = self . _humidity_condition . hourly_dew_point_values ( self . _dry_bulb_condition ) rh_data = [ rel_humid_from_db_dpt ( x , y ) for x , y in zip ( self . _dry_bulb_condition . hourly_values , dpt_data ) ] return self . _get_daily_data_collections ( fraction . RelativeH...
A data collection containing hourly relative humidity over they day .
237,549
def hourly_solar_radiation ( self ) : dir_norm , diff_horiz , glob_horiz = self . _sky_condition . radiation_values ( self . _location ) dir_norm_data = self . _get_daily_data_collections ( energyintensity . DirectNormalRadiation ( ) , 'Wh/m2' , dir_norm ) diff_horiz_data = self . _get_daily_data_collections ( energyin...
Three data collections containing hourly direct normal diffuse horizontal and global horizontal radiation .
237,550
def _get_daily_data_collections ( self , data_type , unit , values ) : data_header = Header ( data_type = data_type , unit = unit , analysis_period = self . analysis_period , metadata = { 'source' : self . _location . source , 'country' : self . _location . country , 'city' : self . _location . city } ) return HourlyCo...
Return an empty data collection .
237,551
def hourly_values ( self ) : return [ self . _dry_bulb_max - self . _dry_bulb_range * x for x in self . temp_multipliers ]
A list of temperature values for each hour over the design day .
237,552
def to_json ( self ) : return { 'dry_bulb_max' : self . dry_bulb_max , 'dry_bulb_range' : self . dry_bulb_range , 'modifier_type' : self . modifier_type , 'modifier_schedule' : self . modifier_schedule }
Convert the Dry Bulb Condition to a dictionary .
237,553
def from_json ( cls , data ) : required_keys = ( 'hum_type' , 'hum_value' ) optional_keys = { 'barometric_pressure' : 101325 , 'schedule' : '' , 'wet_bulb_range' : '' } for key in required_keys : assert key in data , 'Required key "{}" is missing!' . format ( key ) for key , val in optional_keys . items ( ) : if key no...
Create a Humidity Condition from a dictionary .
237,554
def to_json ( self ) : return { 'hum_type' : self . hum_type , 'hum_value' : self . hum_value , 'barometric_pressure' : self . barometric_pressure , 'schedule' : self . schedule , 'wet_bulb_range' : self . wet_bulb_range , }
Convert the Humidity Condition to a dictionary .
237,555
def from_json ( cls , data ) : optional_keys = { 'wind_direction' : 0 , 'rain' : False , 'snow_on_ground' : False } assert 'wind_speed' in data , 'Required key "wind_speed" is missing!' for key , val in optional_keys . items ( ) : if key not in data : data [ key ] = val return cls ( data [ 'wind_speed' ] , data [ 'wind...
Create a Wind Condition from a dictionary .
237,556
def to_json ( self ) : return { 'wind_speed' : self . wind_speed , 'wind_direction' : self . wind_direction , 'rain' : self . rain , 'snow_on_ground' : self . snow_on_ground }
Convert the Wind Condition to a dictionary .
237,557
def _get_datetimes ( self , timestep = 1 ) : start_moy = DateTime ( self . _month , self . _day_of_month ) . moy if timestep == 1 : start_moy = start_moy + 30 num_moys = 24 * timestep return tuple ( DateTime . from_moy ( start_moy + ( i * ( 1 / timestep ) * 60 ) ) for i in xrange ( num_moys ) )
List of datetimes based on design day date and timestep .
237,558
def from_analysis_period ( cls , analysis_period , clearness = 1 , daylight_savings_indicator = 'No' ) : _check_analysis_period ( analysis_period ) return cls ( analysis_period . st_month , analysis_period . st_day , clearness , daylight_savings_indicator )
Initialize a OriginalClearSkyCondition from an analysis_period
237,559
def radiation_values ( self , location , timestep = 1 ) : sp = Sunpath . from_location ( location ) altitudes = [ ] dates = self . _get_datetimes ( timestep ) for t_date in dates : sun = sp . calculate_sun_from_date_time ( t_date ) altitudes . append ( sun . altitude ) dir_norm , diff_horiz = ashrae_clear_sky ( altitud...
Lists of driect normal diffuse horiz and global horiz rad at each timestep .
237,560
def from_analysis_period ( cls , analysis_period , tau_b , tau_d , daylight_savings_indicator = 'No' ) : _check_analysis_period ( analysis_period ) return cls ( analysis_period . st_month , analysis_period . st_day , tau_b , tau_d , daylight_savings_indicator )
Initialize a RevisedClearSkyCondition from an analysis_period
237,561
def convert_to_unit ( self , unit ) : self . _values = self . _header . data_type . to_unit ( self . _values , unit , self . _header . unit ) self . _header . _unit = unit
Convert the Data Collection to the input unit .
237,562
def convert_to_ip ( self ) : self . _values , self . _header . _unit = self . _header . data_type . to_ip ( self . _values , self . _header . unit )
Convert the Data Collection to IP units .
237,563
def convert_to_si ( self ) : self . _values , self . _header . _unit = self . _header . data_type . to_si ( self . _values , self . _header . unit )
Convert the Data Collection to SI units .
237,564
def to_unit ( self , unit ) : new_data_c = self . duplicate ( ) new_data_c . convert_to_unit ( unit ) return new_data_c
Return a Data Collection in the input unit .
237,565
def is_in_data_type_range ( self , raise_exception = True ) : return self . _header . data_type . is_in_range ( self . _values , self . _header . unit , raise_exception )
Check if collection values are in physically possible ranges for the data_type .
237,566
def get_highest_values ( self , count ) : count = int ( count ) assert count <= len ( self . _values ) , 'count must be smaller than or equal to values length. {} > {}.' . format ( count , len ( self . _values ) ) assert count > 0 , 'count must be greater than 0. Got {}.' . format ( count ) highest_values = sorted ( se...
Get a list of the the x highest values of the Data Collection and their indices .
237,567
def get_lowest_values ( self , count ) : count = int ( count ) assert count <= len ( self . _values ) , 'count must be <= to Data Collection len. {} > {}.' . format ( count , len ( self . _values ) ) assert count > 0 , 'count must be greater than 0. Got {}.' . format ( count ) lowest_values = sorted ( self . _values ) ...
Get a list of the the x lowest values of the Data Collection and their indices .
237,568
def get_percentile ( self , percentile ) : assert 0 <= percentile <= 100 , 'percentile must be between 0 and 100. Got {}' . format ( percentile ) return self . _percentile ( self . _values , percentile )
Get a value representing a the input percentile of the Data Collection .
237,569
def get_aligned_collection ( self , value = 0 , data_type = None , unit = None , mutable = None ) : header = self . _check_aligned_header ( data_type , unit ) values = self . _check_aligned_value ( value ) if mutable is None : collection = self . __class__ ( header , values , self . datetimes ) else : if self . _enumer...
Return a Collection aligned with this one composed of one repeated value .
237,570
def duplicate ( self ) : collection = self . __class__ ( self . header . duplicate ( ) , self . values , self . datetimes ) collection . _validated_a_period = self . _validated_a_period return collection
Return a copy of the current Data Collection .
237,571
def to_json ( self ) : return { 'header' : self . header . to_json ( ) , 'values' : self . _values , 'datetimes' : self . datetimes , 'validated_a_period' : self . _validated_a_period }
Convert Data Collection to a dictionary .
237,572
def filter_collections_by_statement ( data_collections , statement ) : pattern = BaseCollection . pattern_from_collections_and_statement ( data_collections , statement ) collections = [ coll . filter_by_pattern ( pattern ) for coll in data_collections ] return collections
Generate a filtered data collections according to a conditional statement .
237,573
def pattern_from_collections_and_statement ( data_collections , statement ) : BaseCollection . are_collections_aligned ( data_collections ) correct_var = BaseCollection . _check_conditional_statement ( statement , len ( data_collections ) ) num_statement_clean = BaseCollection . _replace_operators ( statement ) pattern...
Generate a list of booleans from data collections and a conditional statement .
237,574
def are_collections_aligned ( data_collections , raise_exception = True ) : if len ( data_collections ) > 1 : first_coll = data_collections [ 0 ] for coll in data_collections [ 1 : ] : if not first_coll . is_collection_aligned ( coll ) : if raise_exception is True : error_msg = '{} Data Collection is not aligned with '...
Test if a series of Data Collections are aligned with one another .
237,575
def compute_function_aligned ( funct , data_collections , data_type , unit ) : data_colls = [ ] for i , func_input in enumerate ( data_collections ) : if isinstance ( func_input , BaseCollection ) : data_colls . append ( func_input ) else : try : data_collections [ i ] = float ( func_input ) except ValueError : raise T...
Compute a function with a list of aligned data collections or individual values .
237,576
def _check_conditional_statement ( statement , num_collections ) : correct_var = list ( ascii_lowercase ) [ : num_collections ] st_statement = BaseCollection . _remove_operators ( statement ) parsed_st = [ s for s in st_statement if s . isalpha ( ) ] for var in parsed_st : if var not in correct_var : raise ValueError (...
Method to check conditional statements to be sure that they are valid .
237,577
def _filter_by_statement ( self , statement ) : self . __class__ . _check_conditional_statement ( statement , 1 ) _filt_values , _filt_datetimes = [ ] , [ ] for i , a in enumerate ( self . _values ) : if eval ( statement , { 'a' : a } ) : _filt_values . append ( a ) _filt_datetimes . append ( self . datetimes [ i ] ) r...
Filter the data collection based on a conditional statement .
237,578
def _filter_by_pattern ( self , pattern ) : try : _len = len ( pattern ) except TypeError : raise TypeError ( "pattern is not a list of Booleans. Got {}" . format ( type ( pattern ) ) ) _filt_values = [ d for i , d in enumerate ( self . _values ) if pattern [ i % _len ] ] _filt_datetimes = [ d for i , d in enumerate ( ...
Filter the Filter the Data Collection based on a list of booleans .
237,579
def _check_aligned_header ( self , data_type , unit ) : if data_type is not None : assert isinstance ( data_type , DataTypeBase ) , 'data_type must be a Ladybug DataType. Got {}' . format ( type ( data_type ) ) if unit is None : unit = data_type . units [ 0 ] else : data_type = self . header . data_type unit = unit or ...
Check the header inputs whenever get_aligned_collection is called .
237,580
def _check_aligned_value ( self , value ) : if isinstance ( value , Iterable ) and not isinstance ( value , ( str , dict , bytes , bytearray ) ) : assert len ( value ) == len ( self . _values ) , "Length of value ({}) must match " "the length of this collection's values ({})" . format ( len ( value ) , len ( self . _va...
Check the value input whenever get_aligned_collection is called .
237,581
def from_json ( cls , data ) : if 'month' not in data : data [ 'month' ] = 1 if 'day' not in data : data [ 'day' ] = 1 if 'hour' not in data : data [ 'hour' ] = 0 if 'minute' not in data : data [ 'minute' ] = 0 if 'year' not in data : data [ 'year' ] = 2017 leap_year = True if int ( data [ 'year' ] ) == 2016 else False...
Creat datetime from a dictionary .
237,582
def from_hoy ( cls , hoy , leap_year = False ) : return cls . from_moy ( round ( hoy * 60 ) , leap_year )
Create Ladybug Datetime from an hour of the year .
237,583
def from_moy ( cls , moy , leap_year = False ) : if not leap_year : num_of_minutes_until_month = ( 0 , 44640 , 84960 , 129600 , 172800 , 217440 , 260640 , 305280 , 349920 , 393120 , 437760 , 480960 , 525600 ) else : num_of_minutes_until_month = ( 0 , 44640 , 84960 + 1440 , 129600 + 1440 , 172800 + 1440 , 217440 + 1440 ...
Create Ladybug Datetime from a minute of the year .
237,584
def from_date_time_string ( cls , datetime_string , leap_year = False ) : dt = datetime . strptime ( datetime_string , '%d %b %H:%M' ) return cls ( dt . month , dt . day , dt . hour , dt . minute , leap_year )
Create Ladybug DateTime from a DateTime string .
237,585
def _calculate_hour_and_minute ( float_hour ) : hour , minute = int ( float_hour ) , int ( round ( ( float_hour - int ( float_hour ) ) * 60 ) ) if minute == 60 : return hour + 1 , 0 else : return hour , minute
Calculate hour and minutes as integers from a float hour .
237,586
def add_minute ( self , minute ) : _moy = self . moy + int ( minute ) return self . __class__ . from_moy ( _moy )
Create a new DateTime after the minutes are added .
237,587
def to_json ( self ) : return { 'year' : self . year , 'month' : self . month , 'day' : self . day , 'hour' : self . hour , 'minute' : self . minute }
Get date time as a dictionary .
237,588
def fullConn ( self , preCellsTags , postCellsTags , connParam ) : from . . import sim if sim . cfg . verbose : print ( 'Generating set of all-to-all connections (rule: %s) ...' % ( connParam [ 'label' ] ) ) paramsStrFunc = [ param for param in [ p + 'Func' for p in self . connStringFuncParams ] if param in connParam ]...
Generates connections between all pre and post - syn cells
237,589
def fromListConn ( self , preCellsTags , postCellsTags , connParam ) : from . . import sim if sim . cfg . verbose : print ( 'Generating set of connections from list (rule: %s) ...' % ( connParam [ 'label' ] ) ) orderedPreGids = sorted ( preCellsTags ) orderedPostGids = sorted ( postCellsTags ) paramsStrFunc = [ param f...
Generates connections between all pre and post - syn cells based list of relative cell ids
237,590
def setImembPtr ( self ) : jseg = 0 for sec in list ( self . secs . values ( ) ) : hSec = sec [ 'hObj' ] for iseg , seg in enumerate ( hSec ) : self . imembPtr . pset ( jseg , seg . _ref_i_membrane_ ) jseg += 1
Set PtrVector to point to the i_membrane_
237,591
def saveWeights ( sim ) : with open ( sim . weightsfilename , 'w' ) as fid : for weightdata in sim . allWeights : fid . write ( '%0.0f' % weightdata [ 0 ] ) for i in range ( 1 , len ( weightdata ) ) : fid . write ( '\t%0.8f' % weightdata [ i ] ) fid . write ( '\n' ) print ( ( 'Saved weights as %s' % sim . weightsfilena...
Save the weights for each plastic synapse
237,592
def validateFunction ( strFunc , netParamsVars ) : from math import exp , log , sqrt , sin , cos , tan , asin , acos , atan , sinh , cosh , tanh , pi , e rand = h . Random ( ) stringFuncRandMethods = [ 'binomial' , 'discunif' , 'erlang' , 'geometric' , 'hypergeo' , 'lognormal' , 'negexp' , 'normal' , 'poisson' , 'unifo...
returns True if strFunc can be evaluated
237,593
def bandpass ( data , freqmin , freqmax , df , corners = 4 , zerophase = True ) : fe = 0.5 * df low = freqmin / fe high = freqmax / fe if high - 1.0 > - 1e-6 : msg = ( "Selected high corner frequency ({}) of bandpass is at or " "above Nyquist ({}). Applying a high-pass instead." ) . format ( freqmax , fe ) warnings . w...
Butterworth - Bandpass Filter .
237,594
def bandstop ( data , freqmin , freqmax , df , corners = 4 , zerophase = False ) : fe = 0.5 * df low = freqmin / fe high = freqmax / fe if high > 1 : high = 1.0 msg = "Selected high corner frequency is above Nyquist. " + "Setting Nyquist as high corner." warnings . warn ( msg ) if low > 1 : msg = "Selected low corner f...
Butterworth - Bandstop Filter .
237,595
def lowpass ( data , freq , df , corners = 4 , zerophase = False ) : fe = 0.5 * df f = freq / fe if f > 1 : f = 1.0 msg = "Selected corner frequency is above Nyquist. " + "Setting Nyquist as high corner." warnings . warn ( msg ) z , p , k = iirfilter ( corners , f , btype = 'lowpass' , ftype = 'butter' , output = 'zpk'...
Butterworth - Lowpass Filter .
237,596
def integer_decimation ( data , decimation_factor ) : if not isinstance ( decimation_factor , int ) : msg = "Decimation_factor must be an integer!" raise TypeError ( msg ) data = np . array ( data [ : : decimation_factor ] ) return data
Downsampling by applying a simple integer decimation .
237,597
def _distributeCells ( numCellsPop ) : from . . import sim hostCells = { } for i in range ( sim . nhosts ) : hostCells [ i ] = [ ] for i in range ( numCellsPop ) : hostCells [ sim . nextHost ] . append ( i ) sim . nextHost += 1 if sim . nextHost >= sim . nhosts : sim . nextHost = 0 if sim . cfg . verbose : print ( ( "D...
distribute cells across compute nodes using round - robin
237,598
def getCSD ( lfps , sampr , minf = 0.05 , maxf = 300 , norm = True , vaknin = False , spacing = 1.0 ) : datband = getbandpass ( lfps , sampr , minf , maxf ) if datband . shape [ 0 ] > datband . shape [ 1 ] : ax = 1 else : ax = 0 if vaknin : datband = Vaknin ( datband ) if norm : removemean ( datband , ax = ax ) CSD = -...
get current source density approximation using set of local field potentials with equidistant spacing first performs a lowpass filter lfps is a list or numpy array of LFPs arranged spatially by column spacing is in microns
237,599
def createSynapses ( self ) : synsoma = h . ExpSyn ( self . soma ( 0.5 ) ) synsoma . tau = 2 synsoma . e = 0 syndend = h . ExpSyn ( self . dend ( 0.5 ) ) syndend . tau = 2 syndend . e = 0 self . synlist . append ( synsoma ) self . synlist . append ( syndend )
Add an exponentially decaying synapse