idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
237,400
def storedata ( self , fieldName , values , data_type , vName , vClass ) : nrecs = len ( values ) if type ( values [ 0 ] ) in [ list , tuple ] : order = len ( values [ 0 ] ) newValues = [ ] for el in values : for e in el : newValues . append ( e ) values = newValues else : order = 1 n_values = nrecs * order if data_typ...
Create and initialize a single field vdata returning the vdata reference number .
237,401
def field ( self , name_index ) : if isinstance ( name_index , str ) : status , index = _C . VSfindex ( self . _id , name_index ) _checkErr ( 'field' , status , "illegal field name: %s" % name_index ) else : n = _C . VFnfields ( self . _id ) _checkErr ( 'field' , n , 'cannot execute' ) index = name_index if index >= n ...
Get a VDField instance representing a field of the vdata .
237,402
def seek ( self , recIndex ) : if recIndex > self . _nrecs - 1 : if recIndex == self . _nrecs : return self . seekend ( ) else : raise HDF4Error ( "attempt to seek past last record" ) n = _C . VSseek ( self . _id , recIndex ) _checkErr ( 'seek' , n , 'cannot seek' ) self . _offset = n return n
Seek to the beginning of the record identified by its record index . A succeeding read will load this record in memory .
237,403
def inquire ( self ) : status , nRecs , interlace , fldNames , size , vName = _C . VSinquire ( self . _id ) _checkErr ( 'inquire' , status , "cannot query vdata info" ) return nRecs , interlace , fldNames . split ( ',' ) , size , vName
Retrieve info about the vdata .
237,404
def fieldinfo ( self ) : lst = [ ] for n in range ( self . _nfields ) : fld = self . field ( n ) lst . append ( ( fld . _name , fld . _type , fld . _order , fld . _nattrs , fld . _index , fld . _esize , fld . _isize ) ) return lst
Retrieve info about all vdata fields .
237,405
def sizeof ( self , fields ) : if type ( fields ) in [ tuple , list ] : str = ',' . join ( fields ) else : str = fields n = _C . VSsizeof ( self . _id , str ) _checkErr ( 'sizeof' , n , "cannot retrieve field sizes" ) return n
Retrieve the size in bytes of the given fields .
237,406
def fexist ( self , fields ) : if type ( fields ) in [ tuple , list ] : str = ',' . join ( fields ) else : str = fields ret = _C . VSfexist ( self . _id , str ) if ret < 0 : return 0 else : return 1
Check if a vdata contains a given set of fields .
237,407
def find ( self , name ) : try : att = self . attr ( name ) if att . _index is None : att = None except HDF4Error : att = None return att
Search the field for a given attribute .
237,408
def set ( self , data_type , values ) : try : n_values = len ( values ) except : values = [ values ] n_values = 1 if data_type == HC . CHAR8 : buf = _C . array_byte ( n_values ) values = list ( values ) for n in range ( n_values ) : if not isinstance ( values [ n ] , int ) : values [ n ] = ord ( values [ n ] ) elif dat...
Set the attribute value .
237,409
def getlibversion ( ) : status , major_v , minor_v , release , info = _C . Hgetlibversion ( ) _checkErr ( 'getlibversion' , status , "cannot get lib version" ) return major_v , minor_v , release , info
Get the library version info .
237,410
def getfileversion ( self ) : status , major_v , minor_v , release , info = _C . Hgetfileversion ( self . _id ) _checkErr ( 'getfileversion' , status , "cannot get file version" ) return major_v , minor_v , release , info
Get file version info .
237,411
def colorize ( lead , num , color ) : if num != 0 and ANSIBLE_COLOR and color is not None : return "%s%s%-15s" % ( stringc ( lead , color ) , stringc ( "=" , color ) , stringc ( str ( num ) , color ) ) else : return "%s=%-4s" % ( lead , str ( num ) )
Print lead = num in color
237,412
def timeline ( self , request , drip_id , into_past , into_future ) : from django . shortcuts import render , get_object_or_404 drip = get_object_or_404 ( Drip , id = drip_id ) shifted_drips = [ ] seen_users = set ( ) for shifted_drip in drip . drip . walk ( into_past = int ( into_past ) , into_future = int ( into_futu...
Return a list of people who should get emails .
237,413
def walk ( self , into_past = 0 , into_future = 0 ) : walked_range = [ ] for shift in range ( - into_past , into_future ) : kwargs = dict ( drip_model = self . drip_model , name = self . name , now_shift_kwargs = { 'days' : shift } ) walked_range . append ( self . __class__ ( ** kwargs ) ) return walked_range
Walk over a date range and create new instances of self with new ranges .
237,414
def run ( self ) : if not self . drip_model . enabled : return None self . prune ( ) count = self . send ( ) return count
Get the queryset prune sent people and send it .
237,415
def prune ( self ) : target_user_ids = self . get_queryset ( ) . values_list ( 'id' , flat = True ) exclude_user_ids = SentDrip . objects . filter ( date__lt = conditional_now ( ) , drip = self . drip_model , user__id__in = target_user_ids ) . values_list ( 'user_id' , flat = True ) self . _queryset = self . get_querys...
Do an exclude for all Users who have a SentDrip already .
237,416
def send ( self ) : if not self . from_email : self . from_email = getattr ( settings , 'DRIP_FROM_EMAIL' , settings . DEFAULT_FROM_EMAIL ) MessageClass = message_class_for ( self . drip_model . message_class ) count = 0 for user in self . get_queryset ( ) : message_instance = MessageClass ( self , user ) try : result ...
Send the message to each user on the queryset .
237,417
def angle ( self , other ) : return math . acos ( self . dot ( other ) / ( self . magnitude ( ) * other . magnitude ( ) ) )
Return the angle to the vector other
237,418
def project ( self , other ) : n = other . normalized ( ) return self . dot ( n ) * n
Return one vector projected on the vector other
237,419
def rotate_around ( self , axis , theta ) : x , y , z = self . x , self . y , self . z u , v , w = axis . x , axis . y , axis . z r2 = u ** 2 + v ** 2 + w ** 2 r = math . sqrt ( r2 ) ct = math . cos ( theta ) st = math . sin ( theta ) / r dt = ( u * x + v * y + w * z ) * ( 1 - ct ) / r2 return Vector3 ( ( u * dt + x * ...
Return the vector rotated around axis through angle theta .
237,420
def preparedir ( target_dir , remove_content = True ) : if os . path . isdir ( target_dir ) : if remove_content : nukedir ( target_dir , False ) return True else : try : os . makedirs ( target_dir ) return True except Exception as e : print ( "Failed to create folder: %s\n%s" % ( target_dir , e ) ) return False
Prepare a folder for analysis .
237,421
def nukedir ( target_dir , rmdir = False ) : d = os . path . normpath ( target_dir ) if not os . path . isdir ( d ) : return files = os . listdir ( d ) for f in files : if f == '.' or f == '..' : continue path = os . path . join ( d , f ) if os . path . isdir ( path ) : nukedir ( path ) else : try : os . remove ( path ...
Delete all the files inside target_dir .
237,422
def write_to_file_by_name ( folder , fname , data , mkdir = False ) : if not os . path . isdir ( folder ) : if mkdir : preparedir ( folder ) else : created = preparedir ( folder , False ) if not created : raise ValueError ( "Failed to find %s." % folder ) file_path = os . path . join ( folder , fname ) with open ( file...
Write a string of data to file by filename and folder .
237,423
def copy_files_to_folder ( files , target_folder , overwrite = True ) : if not files : return [ ] for f in files : target = os . path . join ( target_folder , os . path . split ( f ) [ - 1 ] ) if target == f : return target if os . path . exists ( target ) : if overwrite : try : os . remove ( target ) except Exception ...
Copy a list of files to a new target folder .
237,424
def bat_to_sh ( file_path ) : sh_file = file_path [ : - 4 ] + '.sh' with open ( file_path , 'rb' ) as inf , open ( sh_file , 'wb' ) as outf : outf . write ( '#!/usr/bin/env bash\n\n' ) for line in inf : if line . strip ( ) : continue else : break for line in inf : if line . startswith ( 'echo' ) : continue modified_lin...
Convert honeybee . bat file to . sh file .
237,425
def _download_py2 ( link , path , __hdr__ ) : try : req = urllib2 . Request ( link , headers = __hdr__ ) u = urllib2 . urlopen ( req ) except Exception as e : raise Exception ( ' Download failed with the error:\n{}' . format ( e ) ) with open ( path , 'wb' ) as outf : for l in u : outf . write ( l ) u . close ( )
Download a file from a link in Python 2 .
237,426
def _download_py3 ( link , path , __hdr__ ) : try : req = urllib . request . Request ( link , headers = __hdr__ ) u = urllib . request . urlopen ( req ) except Exception as e : raise Exception ( ' Download failed with the error:\n{}' . format ( e ) ) with open ( path , 'wb' ) as outf : for l in u : outf . write ( l ) u...
Download a file from a link in Python 3 .
237,427
def download_file_by_name ( url , target_folder , file_name , mkdir = False ) : __hdr__ = { 'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 ' '(KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' , 'Accept' : 'text/html,application/xhtml+xml,' 'application/xml;q=0.9,*/*;q=0.8' , 'Accept-Charset' : ...
Download a file to a directory .
237,428
def unzip_file ( source_file , dest_dir = None , mkdir = False ) : if dest_dir is None : dest_dir , fname = os . path . split ( source_file ) elif not os . path . isdir ( dest_dir ) : if mkdir : preparedir ( dest_dir ) else : created = preparedir ( dest_dir , False ) if not created : raise ValueError ( "Failed to find ...
Unzip a compressed file .
237,429
def csv_to_matrix ( csv_file_path ) : mtx = [ ] with open ( csv_file_path ) as csv_data_file : for row in csv_data_file : mtx . append ( row . split ( ',' ) ) return mtx
Load a CSV file into a Python matrix of strings .
237,430
def csv_to_num_matrix ( csv_file_path ) : mtx = [ ] with open ( csv_file_path ) as csv_data_file : for row in csv_data_file : mtx . append ( [ float ( val ) for val in row . split ( ',' ) ] ) return mtx
Load a CSV file consisting only of numbers into a Python matrix of floats .
237,431
def from_json ( cls , data ) : stat_ob = cls ( None ) option_keys_none = ( 'ashrae_climate_zone' , 'koppen_climate_zone' , 'extreme_cold_week' , 'extreme_hot_week' , 'standard_pressure_at_elev' ) option_keys_list = ( 'monthly_db_50' , 'monthly_wb_50' , 'monthly_db_range_50' , 'monthly_wb_range_50' , 'monthly_db_100' , ...
Create STAT from json dictionary .
237,432
def monthly_cooling_design_days_050 ( self ) : if self . monthly_found is False or self . _monthly_db_50 == [ ] or self . _monthly_wb_50 == [ ] : return [ ] else : db_conds = [ DryBulbCondition ( x , y ) for x , y in zip ( self . _monthly_db_50 , self . _monthly_db_range_50 ) ] hu_conds = [ HumidityCondition ( 'Wetbulb...
A list of 12 objects representing monthly 5 . 0% cooling design days .
237,433
def monthly_cooling_design_days_100 ( self ) : if self . monthly_found is False or self . _monthly_db_100 == [ ] or self . _monthly_wb_100 == [ ] : return [ ] else : db_conds = [ DryBulbCondition ( x , y ) for x , y in zip ( self . _monthly_db_100 , self . _monthly_db_range_50 ) ] hu_conds = [ HumidityCondition ( 'Wetb...
A list of 12 objects representing monthly 10 . 0% cooling design days .
237,434
def monthly_cooling_design_days_020 ( self ) : if self . monthly_found is False or self . _monthly_db_20 == [ ] or self . _monthly_wb_20 == [ ] : return [ ] else : db_conds = [ DryBulbCondition ( x , y ) for x , y in zip ( self . _monthly_db_20 , self . _monthly_db_range_50 ) ] hu_conds = [ HumidityCondition ( 'Wetbulb...
A list of 12 objects representing monthly 2 . 0% cooling design days .
237,435
def monthly_cooling_design_days_004 ( self ) : if self . monthly_found is False or self . _monthly_db_04 == [ ] or self . _monthly_wb_04 == [ ] : return [ ] else : db_conds = [ DryBulbCondition ( x , y ) for x , y in zip ( self . _monthly_db_04 , self . _monthly_db_range_50 ) ] hu_conds = [ HumidityCondition ( 'Wetbulb...
A list of 12 objects representing monthly 0 . 4% cooling design days .
237,436
def monthly_wind_conditions ( self ) : return [ WindCondition ( x , y ) for x , y in zip ( self . _monthly_wind , self . monthly_wind_dirs ) ]
A list of 12 monthly wind conditions that are used on the design days .
237,437
def monthly_wind_dirs ( self ) : mwd = zip ( * self . _monthly_wind_dirs ) return [ self . _wind_dirs [ mon . index ( max ( mon ) ) ] for mon in mwd ]
A list of prevailing wind directions for each month .
237,438
def monthly_clear_sky_conditions ( self ) : if self . _monthly_tau_diffuse is [ ] or self . _monthly_tau_beam is [ ] : return [ OriginalClearSkyCondition ( i , 21 ) for i in xrange ( 1 , 13 ) ] return [ RevisedClearSkyCondition ( i , 21 , x , y ) for i , x , y in zip ( list ( xrange ( 1 , 13 ) ) , self . _monthly_tau_b...
A list of 12 monthly clear sky conditions that are used on the design days .
237,439
def to_json ( self ) : def jsonify_dict ( base_dict ) : new_dict = { } for key , val in base_dict . items ( ) : if isinstance ( val , list ) : new_dict [ key ] = [ v . to_json ( ) for v in val ] else : new_dict [ key ] = val . to_json ( ) return new_dict return { 'location' : self . location . to_json ( ) , 'ashrae_cli...
Convert the STAT object to a dictionary .
237,440
def from_json ( cls , data ) : assert 'name' in data , 'Required keyword "name" is missing!' assert 'data_type' in data , 'Required keyword "data_type" is missing!' if cls . _type_enumeration is None : cls . _type_enumeration = _DataTypeEnumeration ( import_modules = False ) if data [ 'data_type' ] == 'GenericType' : a...
Create a data type from a dictionary .
237,441
def is_unit_acceptable ( self , unit , raise_exception = True ) : _is_acceptable = unit in self . units if _is_acceptable or raise_exception is False : return _is_acceptable else : raise ValueError ( '{0} is not an acceptable unit type for {1}. ' 'Choose from the following: {2}' . format ( unit , self . __class__ . __n...
Check if a certain unit is acceptable for the data type .
237,442
def _is_numeric ( self , values ) : if len ( values ) > 0 : assert isinstance ( values [ 0 ] , ( float , int ) ) , "values must be numbers to perform math operations. Got {}" . format ( type ( values [ 0 ] ) ) return True
Check to be sure values are numbers before doing numerical operations .
237,443
def _to_unit_base ( self , base_unit , values , unit , from_unit ) : self . _is_numeric ( values ) namespace = { 'self' : self , 'values' : values } if not from_unit == base_unit : self . is_unit_acceptable ( from_unit , True ) statement = '[self._{}_to_{}(val) for val in values]' . format ( self . _clean ( from_unit )...
Return values in a given unit given the input from_unit .
237,444
def name ( self ) : if self . _name is None : return re . sub ( r"(?<=\w)([A-Z])" , r" \1" , self . __class__ . __name__ ) else : return self . _name
The data type name .
237,445
def from_json ( cls , data ) : assert 'data_type' in data , 'Required keyword "data_type" is missing!' keys = ( 'data_type' , 'unit' , 'analysis_period' , 'metadata' ) for key in keys : if key not in data : data [ key ] = None data_type = DataTypeBase . from_json ( data [ 'data_type' ] ) ap = AnalysisPeriod . from_json...
Create a header from a dictionary .
237,446
def duplicate ( self ) : a_per = self . analysis_period . duplicate ( ) if self . analysis_period else None return self . __class__ ( self . data_type , self . unit , a_per , deepcopy ( self . metadata ) )
Return a copy of the header .
237,447
def to_tuple ( self ) : return ( self . data_type , self . unit , self . analysis_period , self . metadata )
Return Ladybug header as a list .
237,448
def to_json ( self ) : a_per = self . analysis_period . to_json ( ) if self . analysis_period else None return { 'data_type' : self . data_type . to_json ( ) , 'unit' : self . unit , 'analysis_period' : a_per , 'metadata' : self . metadata }
Return a header as a dictionary .
237,449
def ashrae_clear_sky ( altitudes , month , sky_clearness = 1 ) : MONTHLY_A = [ 1202 , 1187 , 1164 , 1130 , 1106 , 1092 , 1093 , 1107 , 1136 , 1166 , 1190 , 1204 ] MONTHLY_B = [ 0.141 , 0.142 , 0.149 , 0.164 , 0.177 , 0.185 , 0.186 , 0.182 , 0.165 , 0.152 , 0.144 , 0.141 ] dir_norm_rad = [ ] dif_horiz_rad = [ ] for i , ...
Calculate solar flux for an original ASHRAE Clear Sky
237,450
def zhang_huang_solar ( alt , cloud_cover , relative_humidity , dry_bulb_present , dry_bulb_t3_hrs , wind_speed , irr_0 = 1355 ) : C0 , C1 , C2 , C3 , C4 , C5 , D_COEFF , K_COEFF = 0.5598 , 0.4982 , - 0.6762 , 0.02842 , - 0.00317 , 0.014 , - 17.853 , 0.843 glob_ir = 0 if alt > 0 : sin_alt = math . sin ( math . radians ...
Calculate global horizontal solar irradiance using the Zhang - Huang model .
237,451
def zhang_huang_solar_split ( altitudes , doys , cloud_cover , relative_humidity , dry_bulb_present , dry_bulb_t3_hrs , wind_speed , atm_pressure , use_disc = False ) : glob_ir = [ ] for i in range ( len ( altitudes ) ) : ghi = zhang_huang_solar ( altitudes [ i ] , cloud_cover [ i ] , relative_humidity [ i ] , dry_bulb...
Calculate direct and diffuse solar irradiance using the Zhang - Huang model .
237,452
def calc_horizontal_infrared ( sky_cover , dry_bulb , dew_point ) : SIGMA = 5.6697e-8 db_k = dry_bulb + 273.15 dp_k = dew_point + 273.15 sky_emiss = ( 0.787 + ( 0.764 * math . log ( dp_k / 273.15 ) ) ) * ( 1 + ( 0.022 * sky_cover ) - ( 0.0035 * ( sky_cover ** 2 ) ) + ( 0.00028 * ( sky_cover ** 3 ) ) ) horiz_ir = sky_em...
Calculate horizontal infrared radiation intensity .
237,453
def set_domain ( self , values ) : _flattenedList = sorted ( flatten ( values ) ) self . domain = tuple ( _flattenedList [ 0 ] if d == 'min' else d for d in self . domain ) self . domain = tuple ( _flattenedList [ - 1 ] if d == 'max' else d for d in self . domain )
Set domain of the colors based on min and max of a list of values .
237,454
def timestep_text ( self ) : if self . header . analysis_period . timestep == 1 : return 'Hourly' else : return '{} Minute' . format ( int ( 60 / self . header . analysis_period . timestep ) )
Return a text string representing the timestep of the collection .
237,455
def moys_dict ( self ) : moy_dict = { } for val , dt in zip ( self . values , self . datetimes ) : moy_dict [ dt . moy ] = val return moy_dict
Return a dictionary of this collection s values where the keys are the moys .
237,456
def filter_by_analysis_period ( self , analysis_period ) : self . _check_analysis_period ( analysis_period ) _filtered_data = self . filter_by_moys ( analysis_period . moys ) _filtered_data . header . _analysis_period = analysis_period return _filtered_data
Filter a Data Collection based on an analysis period .
237,457
def group_by_month_per_hour ( self ) : data_by_month_per_hour = OrderedDict ( ) for m in xrange ( 1 , 13 ) : for h in xrange ( 0 , 24 ) : data_by_month_per_hour [ ( m , h ) ] = [ ] for v , dt in zip ( self . values , self . datetimes ) : data_by_month_per_hour [ ( dt . month , dt . hour ) ] . append ( v ) return data_b...
Return a dictionary of this collection s values grouped by each month per hour .
237,458
def interpolate_holes ( self ) : assert self . validated_a_period is True , 'validated_a_period property must be' ' True to use interpolate_holes(). Run validate_analysis_period().' mins_per_step = int ( 60 / self . header . analysis_period . timestep ) new_datetimes = self . header . analysis_period . datetimes new_va...
Linearly interpolate over holes in this collection to make it continuous .
237,459
def cull_to_timestep ( self , timestep = 1 ) : valid_s = self . header . analysis_period . VALIDTIMESTEPS . keys ( ) assert timestep in valid_s , 'timestep {} is not valid. Choose from: {}' . format ( timestep , valid_s ) new_ap , new_values , new_datetimes = self . _timestep_cull ( timestep ) new_header = self . heade...
Get a collection with only datetimes that fit a timestep .
237,460
def convert_to_culled_timestep ( self , timestep = 1 ) : valid_s = self . header . analysis_period . VALIDTIMESTEPS . keys ( ) assert timestep in valid_s , 'timestep {} is not valid. Choose from: {}' . format ( timestep , valid_s ) new_ap , new_values , new_datetimes = self . _timestep_cull ( timestep ) self . header ....
Convert this collection to one that only has datetimes that fit a timestep .
237,461
def _xxrange ( self , start , end , step_count ) : _step = ( end - start ) / float ( step_count ) return ( start + ( i * _step ) for i in xrange ( int ( step_count ) ) )
Generate n values between start and end .
237,462
def _filter_by_moys_slow ( self , moys ) : _filt_values = [ ] _filt_datetimes = [ ] for i , d in enumerate ( self . datetimes ) : if d . moy in moys : _filt_datetimes . append ( d ) _filt_values . append ( self . _values [ i ] ) return _filt_values , _filt_datetimes
Filter the Data Collection with a slow method that always works .
237,463
def _timestep_cull ( self , timestep ) : new_values = [ ] new_datetimes = [ ] mins_per_step = int ( 60 / timestep ) for i , date_t in enumerate ( self . datetimes ) : if date_t . moy % mins_per_step == 0 : new_datetimes . append ( date_t ) new_values . append ( self . values [ i ] ) a_per = self . header . analysis_per...
Cull out values that do not fit a timestep .
237,464
def _time_interval_operation ( self , interval , operation , percentile = 0 ) : if operation == 'average' : funct = self . _average elif operation == 'total' : funct = self . _total else : assert 0 <= percentile <= 100 , 'percentile must be between 0 and 100. Got {}' . format ( percentile ) funct = self . _get_percenti...
Get a collection of a certain time interval with a given math operation .
237,465
def datetimes ( self ) : if self . _datetimes is None : self . _datetimes = tuple ( self . header . analysis_period . datetimes ) return self . _datetimes
Return datetimes for this collection as a tuple .
237,466
def interpolate_to_timestep ( self , timestep , cumulative = None ) : assert timestep % self . header . analysis_period . timestep == 0 , 'Target timestep({}) must be divisable by current timestep({})' . format ( timestep , self . header . analysis_period . timestep ) if cumulative is not None : assert isinstance ( cum...
Interpolate data for a finer timestep using a linear interpolation .
237,467
def filter_by_hoys ( self , hoys ) : existing_hoys = self . header . analysis_period . hoys hoys = [ h for h in hoys if h in existing_hoys ] _moys = tuple ( int ( hour * 60 ) for hour in hoys ) return self . filter_by_moys ( _moys )
Filter the Data Collection based onva list of hoys .
237,468
def to_immutable ( self ) : if self . _enumeration is None : self . _get_mutable_enumeration ( ) col_obj = self . _enumeration [ 'immutable' ] [ self . _collection_type ] return col_obj ( self . header , self . values )
Get an immutable version of this collection .
237,469
def to_discontinuous ( self ) : collection = HourlyDiscontinuousCollection ( self . header . duplicate ( ) , self . values , self . datetimes ) collection . _validated_a_period = True return collection
Return a discontinuous version of the current collection .
237,470
def _get_analysis_period_subset ( self , a_per ) : if self . header . analysis_period . is_annual : return a_per new_needed = False n_ap = [ a_per . st_month , a_per . st_day , a_per . st_hour , a_per . end_month , a_per . end_day , a_per . end_hour , a_per . timestep , a_per . is_leap_year ] if a_per . st_hour < self ...
Return an analysis_period is always a subset of the Data Collection
237,471
def _monthly_operation ( self , operation , percentile = 0 ) : if operation == 'average' : funct = self . _average elif operation == 'total' : funct = self . _total else : assert 0 <= percentile <= 100 , 'percentile must be between 0 and 100. Got {}' . format ( percentile ) funct = self . _get_percentile_function ( per...
Get a MonthlyCollection given a certain operation .
237,472
def to_unit ( self , values , unit , from_unit ) : return self . _to_unit_base ( 'degC-days' , values , unit , from_unit )
Return values converted to the unit given the input from_unit .
237,473
def bisect ( a , b , fn , epsilon , target ) : while ( abs ( b - a ) > 2 * epsilon ) : midpoint = ( b + a ) / 2 a_t = fn ( a ) b_t = fn ( b ) midpoint_t = fn ( midpoint ) if ( a_t - target ) * ( midpoint_t - target ) < 0 : b = midpoint elif ( b_t - target ) * ( midpoint_t - target ) < 0 : a = midpoint else : return - 9...
The simplest root - finding algorithm .
237,474
def from_json ( cls , data ) : optional_keys = ( 'city' , 'state' , 'country' , 'latitude' , 'longitude' , 'time_zone' , 'elevation' , 'station_id' , 'source' ) for key in optional_keys : if key not in data : data [ key ] = None return cls ( data [ 'city' ] , data [ 'state' ] , data [ 'country' ] , data [ 'latitude' ] ...
Create a location from a dictionary .
237,475
def from_location ( cls , location ) : if not location : return cls ( ) try : if hasattr ( location , 'isLocation' ) : return location elif hasattr ( location , 'Latitude' ) : return cls ( city = str ( location . Name . replace ( "," , " " ) ) , latitude = location . Latitude , longitude = location . Longitude ) elif l...
Try to create a Ladybug location from a location string .
237,476
def duplicate ( self ) : return Location ( self . city , self . state , self . country , self . latitude , self . longitude , self . time_zone , self . elevation , self . station_id , self . source )
Duplicate location .
237,477
def ep_style_location_string ( self ) : return "Site:Location,\n " + self . city + ',\n ' + str ( self . latitude ) + ', !Latitude\n ' + str ( self . longitude ) + ', !Longitude\n ' + str ( self . time_zone ) + ', !Time Zone\n ' + str ( self . elevation ) + '; !Elevation'
Return EnergyPlus s location string .
237,478
def from_missing_values ( cls , is_leap_year = False ) : epw_obj = cls ( None ) epw_obj . _is_leap_year = is_leap_year epw_obj . _location = Location ( ) analysis_period = AnalysisPeriod ( is_leap_year = is_leap_year ) headers = [ ] for field_number in xrange ( epw_obj . _num_of_fields ) : field = EPWFields . field_by_...
Initalize an EPW object with all data missing or empty .
237,479
def from_json ( cls , data ) : epw_obj = cls ( None ) epw_obj . _is_header_loaded = True epw_obj . _is_data_loaded = True required_keys = ( 'location' , 'data_collections' ) option_keys_dict = ( 'metadata' , 'heating_dict' , 'cooling_dict' , 'extremes_dict' , 'extreme_hot_weeks' , 'extreme_cold_weeks' , 'typical_weeks'...
Create EPW from json dictionary .
237,480
def annual_cooling_design_day_010 ( self ) : self . _load_header_check ( ) if bool ( self . _cooling_dict ) is True : avg_press = self . atmospheric_station_pressure . average avg_press = None if avg_press == 999999 else avg_press return DesignDay . from_ashrae_dict_cooling ( self . _cooling_dict , self . location , Tr...
A design day object representing the annual 1 . 0% cooling design day .
237,481
def _des_dict_check ( self , des_dict , req_keys , cond_name ) : assert isinstance ( des_dict , dict ) , '{}' ' must be a dictionary. Got {}.' . format ( cond_name , type ( des_dict ) ) if bool ( des_dict ) is True : input_keys = list ( des_dict . keys ( ) ) for key in req_keys : assert key in input_keys , 'Required ke...
Check if an input design condition dictionary is acceptable .
237,482
def _format_week ( self , name , type , a_per ) : return '{},{},{}/{},{}/{}' . format ( name , type , a_per . st_month , a_per . st_day , a_per . end_month , a_per . end_day )
Format an AnalysisPeriod into string for the EPW header .
237,483
def _format_grndt ( self , data_c ) : monthly_str = '{},{},{},{}' . format ( data_c . header . metadata [ 'soil conductivity' ] , data_c . header . metadata [ 'soil density' ] , data_c . header . metadata [ 'soil specific heat' ] , ',' . join ( [ '%.2f' % x for x in data_c . values ] ) ) return monthly_str
Format monthly ground data collection into string for the EPW header .
237,484
def save ( self , file_path ) : if not self . is_data_loaded : self . _import_data ( ) originally_ip = False if self . is_ip is True : self . convert_to_si ( ) originally_ip = True lines = self . header try : for field in xrange ( 0 , self . _num_of_fields ) : point_in_time = self . _data [ field ] . header . data_type...
Save epw object as an epw file .
237,485
def convert_to_ip ( self ) : if not self . is_data_loaded : self . _import_data ( ) if self . is_ip is False : for coll in self . _data : coll . convert_to_ip ( ) self . _is_ip = True
Convert all Data Collections of this EPW object to IP units .
237,486
def _get_data_by_field ( self , field_number ) : if not self . is_data_loaded : self . _import_data ( ) if not 0 <= field_number < self . _num_of_fields : raise ValueError ( "Field number should be between 0-%d" % self . _num_of_fields ) return self . _data [ field_number ]
Return a data field by field number .
237,487
def sky_temperature ( self ) : sky_temp_header = Header ( data_type = temperature . SkyTemperature ( ) , unit = 'C' , analysis_period = AnalysisPeriod ( ) , metadata = self . _metadata ) horiz_ir = self . _get_data_by_field ( 12 ) . values sky_temp_data = [ calc_sky_temperature ( hir ) for hir in horiz_ir ] return Hour...
Return annual Sky Temperature as a Ladybug Data Collection .
237,488
def to_wea ( self , file_path , hoys = None ) : hoys = hoys or xrange ( len ( self . direct_normal_radiation . datetimes ) ) if not file_path . lower ( ) . endswith ( '.wea' ) : file_path += '.wea' originally_ip = False if self . is_ip is True : self . convert_to_si ( ) originally_ip = True lines = [ self . _get_wea_he...
Write an wea file from the epw file .
237,489
def to_json ( self ) : if not self . is_data_loaded : self . _import_data ( ) def jsonify_dict ( base_dict ) : new_dict = { } for key , val in base_dict . items ( ) : new_dict [ key ] = val . to_json ( ) return new_dict hot_wks = jsonify_dict ( self . extreme_hot_weeks ) cold_wks = jsonify_dict ( self . extreme_cold_we...
Convert the EPW to a dictionary .
237,490
def from_analysis_period ( cls , analysis_period = None ) : if not analysis_period : return cls ( ) elif hasattr ( analysis_period , 'isAnalysisPeriod' ) : return analysis_period elif isinstance ( analysis_period , str ) : try : return cls . from_string ( analysis_period ) except Exception as e : raise ValueError ( "{}...
Create and AnalysisPeriod from an analysis period .
237,491
def from_string ( cls , analysis_period_string ) : is_leap_year = True if analysis_period_string . strip ( ) [ - 1 ] == '*' else False ap = analysis_period_string . lower ( ) . replace ( ' ' , '' ) . replace ( 'to' , ' ' ) . replace ( 'and' , ' ' ) . replace ( '/' , ' ' ) . replace ( 'between' , ' ' ) . replace ( '@' ,...
Create an Analysis Period object from an analysis period string .
237,492
def datetimes ( self ) : if self . _timestamps_data is None : self . _calculate_timestamps ( ) return tuple ( DateTime . from_moy ( moy , self . is_leap_year ) for moy in self . _timestamps_data )
A sorted list of datetimes in this analysis period .
237,493
def hoys ( self ) : if self . _timestamps_data is None : self . _calculate_timestamps ( ) return tuple ( moy / 60.0 for moy in self . _timestamps_data )
A sorted list of hours of year in this analysis period .
237,494
def hoys_int ( self ) : if self . _timestamps_data is None : self . _calculate_timestamps ( ) return tuple ( int ( moy / 60.0 ) for moy in self . _timestamps_data )
A sorted list of hours of year in this analysis period as integers .
237,495
def doys_int ( self ) : if not self . _is_reversed : return self . _calc_daystamps ( self . st_time , self . end_time ) else : doys_st = self . _calc_daystamps ( self . st_time , DateTime . from_hoy ( 8759 ) ) doys_end = self . _calc_daystamps ( DateTime . from_hoy ( 0 ) , self . end_time ) return doys_st + doys_end
A sorted list of days of the year in this analysis period as integers .
237,496
def months_int ( self ) : if not self . _is_reversed : return list ( xrange ( self . st_time . month , self . end_time . month + 1 ) ) else : months_st = list ( xrange ( self . st_time . month , 13 ) ) months_end = list ( xrange ( 1 , self . end_time . month + 1 ) ) return months_st + months_end
A sorted list of months of the year in this analysis period as integers .
237,497
def months_per_hour ( self ) : month_hour = [ ] hour_range = xrange ( self . st_hour , self . end_hour + 1 ) for month in self . months_int : month_hour . extend ( [ ( month , hr ) for hr in hour_range ] ) return month_hour
A list of tuples representing months per hour in this analysis period .
237,498
def is_annual ( self ) : if ( self . st_month , self . st_day , self . st_hour , self . end_month , self . end_day , self . end_hour ) == ( 1 , 1 , 0 , 12 , 31 , 23 ) : return True else : return False
Check if an analysis period is annual .
237,499
def is_possible_hour ( self , hour ) : if hour > 23 and self . is_possible_hour ( 0 ) : hour = int ( hour ) if not self . _is_overnight : return self . st_time . hour <= hour <= self . end_time . hour else : return self . st_time . hour <= hour <= 23 or 0 <= hour <= self . end_time . hour
Check if a float hour is a possible hour for this analysis period .