Returns metta metadata for a quarter's SOC code classifier matrix

    Args:
        quarter (str) quarter, in format '2015Q1'
        num_dimensions (int) Number of features in matrix

    Returns: (dict) metadata suitable for metta.archive_train_test
197054
def metta_config(quarter, num_dimensions):
    
    first_day, last_day = quarter_boundaries(quarter)
    return {
        'start_time': first_day,
        'end_time': last_day,
        'prediction_window': 3, # ???
        'label_name': 'onet_soc_code',
        'label_type': 'categorical',
        'matrix_id': 'job_postings_{}'.format(quarter),
        'feature_names': ['doc2vec_{}'.format(i) for i in range(num_dimensions)],
    }
89509
def get_metadata_freq_df(self, label_append=' freq'):
        '''
        
        '''
        row = self._row_category_ids_for_meta()
        newX = csr_matrix((self._mX.data, (row, self._mX.indices)))
        return self._metadata_freq_df_from_matrix(newX, label_append)
1065028
def read_series_matrix(path, encoding):
    """"""
    assert isinstance(path, str)

    accessions = None
    titles = None
    celfile_urls = None
    with misc.smart_open_read(path, mode='rb', try_gzip=True) as fh:
        reader = csv.reader(fh, dialect='excel-tab', encoding=encoding)
        for l in reader:
            if not l:
                continue
            if l[0] == '!Sample_geo_accession':
                accessions = l[1:]
            elif l[0] == '!Sample_title':
                titles = l[1:]
            elif l[0] == '!Sample_supplementary_file' and celfile_urls is None:
                celfile_urls = l[1:]
            elif l[0] == '!series_matrix_table_begin':
                # we've read the end of the section containing metadata
                break
    return accessions, titles, celfile_urls
896524
def _get_extended_metadata(h5group):
    
    meta = dict()

    # get PSD
    try:
        psd = h5group['psd']
    except KeyError:
        pass
    else:
        from gwpy.frequencyseries import FrequencySeries
        meta['psd'] = FrequencySeries(
            psd[:], f0=0, df=psd.attrs['delta_f'], name='pycbc_live')

    # get everything else
    for key in META_COLUMNS - {'psd'}:
        try:
            value = h5group[key][:]
        except KeyError:
            pass
        else:
            meta[key] = value

    return meta
350429
def get_dimension(self, dataset, dimension):
        """"""

        path = '/api/1.0/meta/dataset/{}/dimension/{}'
        return self._api_get(definition.Dimension, path.format(dataset, dimension))
727704
def _fetch_dimensions(self, dataset):
        
        yield Dimension(u"school")
        yield Dimension(u"year",
                        datatype="year")
        yield Dimension(u"semester",
                        datatype="academic_term",
                        dialect="swedish")  # HT/VT
        yield Dimension(u"municipality",
                        datatype="year",
                        domain="sweden/municipalities")
807322
def _metadata(image, datapath):
    
    metadata = {'series_number': 0, 'datadir': datapath}
    spacing = image.GetSpacing()
    metadata['voxelsize_mm'] = [
        spacing[2],
        spacing[0],
        spacing[1],
    ]
    return metadata
418352
def dimension(self):
        
        if self.dim > -1:
            return self.dim
        d = None
        if self.dim != -1 and not self._estimated:  # fixed parametrization
            d = self.dim
        elif self._estimated:  # parametrization finished. Dimension is known
            dim = len(self.eigenvalues)
            if self.var_cutoff < 1.0:  # if subspace_variance, reduce the  if needed
                dim = min(dim, np.searchsorted(self.cumvar, self.var_cutoff) + 1)
            d = dim
        elif self.var_cutoff == 1.0:  # We only know that all dimensions are wanted, so return input dim
            d = self.data_producer.dimension()
        else:  # We know nothing. Give up
            raise RuntimeError('Requested dimension, but the dimension depends on the cumulative variance and the '
                               'transformer has not yet been estimated. Call estimate() before.')
        return d
970981
def _load(self, metrix):
    
    if isinstance(metrix, TimeSeries):
      return metrix
    if isinstance(metrix, dict):
      return TimeSeries(metrix)
    return TimeSeries(utils.read_csv(metrix))
1147363
def get_new_term_doc_mat(self, doc_domains):
		'''
		

		'''
		assert len(doc_domains) == self.term_doc_matrix.get_num_docs()
		doc_domain_set = set(doc_domains)
		num_terms = self.term_doc_matrix.get_num_terms()
		num_domains = len(doc_domain_set)
		domain_mat = lil_matrix((num_domains, num_terms), dtype=int)
		X = self.term_doc_matrix.get_term_doc_mat()
		for i, domain in enumerate(doc_domain_set):
			domain_mat[i, :] = X[np.array(doc_domains == domain)].sum(axis=0)
		return domain_mat.tocsr()
907271
def datetime_to_year_quarter(dt):
    
    year = dt.year
    quarter = int(math.ceil(float(dt.month)/3))
    return (year, quarter)
1188468
def quarter_boundaries(quarter):
    
    year, quarter = quarter.split('Q')
    year = int(year)
    quarter = int(quarter)
    first_month_of_quarter = 3 * quarter - 2
    last_month_of_quarter = 3 * quarter
    first_day = date(year, first_month_of_quarter, 1)
    last_day = date(year, last_month_of_quarter, monthrange(year, last_month_of_quarter)[1])
    return first_day, last_day
1145261
def _get_dimension_scales(self, dimension, preserve_domain=False):
        
        if preserve_domain:
            return [
                self.scales[k] for k in self.scales if (
                    k in self.scales_metadata and
                    self.scales_metadata[k].get('dimension') == dimension and
                    not self.preserve_domain.get(k)
                )
            ]
        else:
            return [
                self.scales[k] for k in self.scales if (
                    k in self.scales_metadata and
                    self.scales_metadata[k].get('dimension') == dimension
                )
            ]
199858
def quarter(dt):
    
    quarters = rrule.rrule(
       rrule.MONTHLY,
       bymonth = (1, 4, 7, 10),
       bysetpos = -1,
       dtstart = datetime(dt.year, 1, 1),
       count = 8
    )
    first_day = quarters.before(dt, True)
    last_day = quarters.after(dt) - relativedelta.relativedelta(days=1)
    return (first_day, last_day)
862197
def _read_routine_metadata(self):
        
        metadata = {}
        if os.path.isfile(self._metadata_filename):
            with open(self._metadata_filename, 'r') as file:
                metadata = json.load(file)

        return metadata
1031618
def predict_given_context(self, x, c, c_dims):
        
        assert len(c) == len(c_dims)
        _, index = self.dataset.nn_dims(x, c, range(self.dim_x), list(np.array(c_dims) + self.dim_x), k=1)
        return self.dataset.get_y(index[0])
821363
def get_input_score_start_range_metadata(self):
        
        # Implemented from template for osid.resource.ResourceForm.get_group_metadata_template
        metadata = dict(self._mdata['input_score_start_range'])
        metadata.update({'existing_decimal_values': self._my_map['inputScoreStartRange']})
        return Metadata(**metadata)