text
stringlengths
0
828
unique_key=resources.get(""unique_key"", """"),
)
if output_files_dir is not None:
filename = os.path.join(output_files_dir, filename)
if name.endswith("".gif"") and mime == ""image/png"":
filename = filename.replace("".gif"", "".png"")
# In the resources, make the figure available via
# resources['outputs']['filename'] = data
resources[""outputs""][filename] = data
# now we need to change the cell source so that it links to the
# filename instead of `attachment:`
attach_str = ""attachment:"" + orig_name
if attach_str in cell.source:
cell.source = cell.source.replace(attach_str, filename)
return cell, resources"
1436,"def combine_pdf_as_bytes(pdfs: List[BytesIO]) -> bytes:
""""""Combine PDFs and return a byte-string with the result.
Arguments
---------
pdfs
A list of BytesIO representations of PDFs
""""""
writer = PdfWriter()
for pdf in pdfs:
writer.addpages(PdfReader(pdf).pages)
bio = BytesIO()
writer.write(bio)
bio.seek(0)
output = bio.read()
bio.close()
return output"
1437,"def split(self, granularity_after_split, exclude_partial=True):
""""""
Split a period into a given granularity. Optionally include partial
periods at the start and end of the period.
""""""
if granularity_after_split == Granularity.DAY:
return self.get_days()
elif granularity_after_split == Granularity.WEEK:
return self.get_weeks(exclude_partial)
elif granularity_after_split == Granularity.MONTH:
return self.get_months(exclude_partial)
elif granularity_after_split == Granularity.QUARTER:
return self.get_quarters(exclude_partial)
elif granularity_after_split == Granularity.HALF_YEAR:
return self.get_half_years(exclude_partial)
elif granularity_after_split == Granularity.YEAR:
return self.get_years(exclude_partial)
else:
raise Exception(""Invalid granularity: %s"" % granularity_after_split)"
1438,"def fit_fb_calibration(df, calibration):
'''
Fit feedback calibration data to solve for values of `C_fb[:]` and
`R_fb[:]`.
Returns a `pandas.DataFrame` indexed by the feedback resistor/capacitance
index, and with the following columns:
- Model: Either with parasitic capacitance term or not.
- N: Number of samples used for fit.
- F: F-value
- p-value: p-value from Chi squared test.
- R_fb: Feedback resistor value based on fit.
- R-CI %: Confidence interval for feedback resistor value.
- C_fb: Feedback capacitor value based on fit (0 if no-capacitance model
is used).
- C-CI %: Confidence interval for feedback capacitance value.
__N.B.__ This function does not actually _update_ the calibration, it only
performs the fit.
See `apply_calibration`.
'''
# Set initial guesses for the feedback parameters.
R_fb = pd.Series([2e2, 2e3, 2e4, 2e5, 2e6])
C_fb = pd.Series(len(calibration.C_fb) * [50e-12])
# Error function.
def error(p0, df, calibration):
# Impedance of the reference resistor on the HV attenuator circuit.
Z = 10e6
R_fb = p0[0]
# If the parameter vector only contains one variable, the capacitance
# is zero
if len(p0) == 2:
C_fb = p0[1]
else: