Пример #1
0
def notebook_dir(directory, recursive=False):
    """Display IPython FileLinks object in the notebook

    :param directory: location of the directory
    :param recursive: if all subdirectories should be shown also, defaults to False
    """
    if directory:
        display(FileLinks(directory, recursive=recursive))
def tutorial(overwrite=False):
    """Copy the Databaker tutorial notebooks into ./DatabakerTutorial and show a link in the notebook."""
    copy_tutorial(overwrite=overwrite)
    print('Click on the following notebooks to explore the tutorial:')
    from IPython.display import FileLinks, display
    file_links = FileLinks(path=DEST_PATH,
                           included_suffixes=['.ipynb'],
                           recursive=False)
    display(file_links)
Пример #3
0
    def line_ls(self, path=".", recursive=False):
        """
        %ls PATH - list files and directories under PATH

        This line magic is used to list the directory contents.

        Examples:
            %ls .
            %ls ..
        """
        path = os.path.expanduser(path)
        self.retval = FileLinks(path, recursive=recursive)
Пример #4
0
def tutorial(overwrite=False):
    """Copy the Altair tutorial notebooks into ./AltairTutorial and show a link in the notebook."""
    copy_tutorial(overwrite=overwrite)
    print('Click on the following notebooks to explore the tutorial:')
    from IPython.display import FileLinks, display
    display(FileLinks(DEST_PATH))
Пример #5
0
i = Image(filename='logo/logo.png')

i

display(i)

Image(url='http://python.org/images/python-logo.gif')

from IPython.display import SVG
SVG(filename='python-logo.svg')

from IPython.display import FileLink, FileLinks
FileLink('Part 1 - Running Code.ipynb')

FileLinks('.')

from IPython.display import Image

# by default Image data are embedded
Embed      = Image(    'http://scienceview.berkeley.edu/view/images/newview.jpg')

# if kwarg `url` is given, the embedding is assumed to be false
SoftLinked = Image(url='http://scienceview.berkeley.edu/view/images/newview.jpg')

# In each case, embed can be specified explicitly with the `embed` kwarg
# ForceEmbed = Image(url='http://scienceview.berkeley.edu/view/images/newview.jpg', embed=True)

Embed

SoftLinked
# Let's try testing the model with a set of images.  They are shown below.
#
# <img src="test_images/image-1-1.jpg" width="64px" /> <div style="text-align:center;">image-1-1.jpg</div>
# <img src="test_images/image-2-1.jpg" width="64px" /> <div style="text-align:center;">image-2-1.jpg</div>
# <img src="test_images/image-3-1.jpg" width="64px" /> <div style="text-align:center;">image-3-1.jpg</div>
# <img src="test_images/image-4-1.jpg" width="64px" /> <div style="text-align:center;">image-4-1.jpg</div>
# <img src="test_images/image-7-1.jpg" width="64px" /> <div style="text-align:center;">image-7-1.jpg</div>
# <img src="test_images/image-8-1.jpg" width="64px" /> <div style="text-align:center;">image-8-1.jpg</div>
# <img src="test_images/image-8-2.jpg" width="64px" /> <div style="text-align:center;">image-8-2.jpg</div>
#
# We can classify multiple files if we put them in the list. In the link below, execute the code block and a link to the file an_image.list will appear.  Right click on an_image.list and save that to a file on your local computer(right click and "Save As"). Remember the directory in which it is saved.

# In[2]:

from IPython.display import FileLink, FileLinks
FileLinks('test_images_list')

# On the right side of the DIGITS model page, there is an option to "test a list of images".  Press the button **Browse** and select the `an_image.list` file you just downloaded. Then press the **Classify Many** button.  After several seconds, you will see the results from Caffe trying to classify these images with the generated model.  In the image name, the first number is the digit in the image (ex. image-3-1.jpg is a 3). Your results should be similar to this:
#
# ![](images/classify-many-images-small.png)
#
# What is shown here is the probability that the model predicts the class of the image.  The results are sorted from highest probability to lowest.  Our model didn't do so well.
#
# While the accuracy of the model was 87%, it could not correctly classify any of the images that we tested.  What can we do to improve the classification of these images?

# At this point it's time to be a bit more intentional. After we can successfully train a model, what comes next comes from understanding and experimentation. To build a better understanding of THIS project, we should start with our data. To build a better understanding of anything, we should start with primary sources.
#
# The dataset that we are learning from is a subset of the [MNIST](http://yann.lecun.com/exdb/mnist/) dataset. A close read of the documentation would likely yield a lot of insight.
#
# One key observation we'll use is that the images start as 28x28 grayscale images. When we loaded our dataset, we stuck with defaults, which were 256x256 and color. You may have noticed that the images were a bit blurry. In the next section we'll explore the benefits that can come from matching your data to the right model.
#
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  2 19:04:45 2018

@author: Gaston Guillaux
"""
#TO GET THE FILE DIRECTORY USED BY THE NOTEBOOK IN THE REMOTE SERVER
import os
print(os.getcwd())

#TO GET THE REMOTE HOST SERVER NAME
import socket
print(socket.gethostname())

#TO SHOW ALL AVAILABLE FILES IN THE PROJECT
from IPython.display import FileLink, FileLinks
FileLinks('.')  #lists all downloadable files on server
Пример #8
0
# We run the bash script by specifying the working directory and the genome directory and pipe the log into a `analyze_sra.log` file

#%%
get_ipython().system(
    'bash analyze_sra.sh -w $WORKDIR -g $GENOMEDIR | tee analyze_sra.log')

#%% [markdown]
# Step 5 is done with this R script [`normalize.R`](https://github.com/MaayanLab/Zika-RNAseq-Pipeline/blob/master/normalize.R)

#%%
get_ipython().system('Rscript normalize.R $WORKDIR')

#%%
## We can examine the QC reports from the FastQC program to evaluate the quality of the data
from IPython.display import FileLinks
FileLinks(os.path.join(os.environ['WORKDIR'], 'fastQC_output'),
          included_suffixes=['.html'])

#%%
## Check the alignment stats
## This will output the first 10 lines of all summary files from the featureCounts folder
get_ipython().system('head $WORKDIR/featureCount_output/*.summary ')

#%% [markdown]
# After you completed successfully the above steps, you can start to analyze the processed expression matrix of gene expression in Python

#%%
## Load the expression matrix
expr_df = pd.read_csv(
    os.path.join(os.environ['WORKDIR'], 'repCpmMatrix_featureCounts.csv'))
expr_df = expr_df.set_index(expr_df.columns[0])
expr_df.head()
Пример #9
0
def make_excel_download(df):
    Path('./output').mkdir(exist_ok=True)

    df.to_excel('./output/active_hospo_catalogue.xlsx')

    return FileLinks(str(Path('./output')))
Пример #10
0
    def pylatex(self, line, cell=None, local_ns=None):
        '''
        '''
        args = parse_argstring(self.pylatex, line)

        # arguments 'code' in line are prepended to the cell lines
        if cell is None:
            code = ''
        else:
            code = cell

        # generate plots in a temporary directory
        self.plot_dir = tempfile.mkdtemp(dir=getcwd()).replace('\\', '/')
        chmod(self.plot_dir, 0o777)

        # add plotting function to code
        generator = """
def generate_document(doc):
    doc.generate_pdf('""" + self.plot_dir + """' + '/tikz', clean_tex=False)

"""
        code = generator  + ' '.join(args.code) + code

        # if there is no local namespace then default to an empty dict
        if local_ns is None:
            local_ns = {}


        if args.size is not None:
            size = args.size
        else:
            size = '400,240'

        width, height = size.split(',')

        key = 'PyLaTeX.Tikz'
        display_data = []


        # Execute PyLaTeX code
        ns = {}
        exec code in self.shell.user_ns, ns

        self._convert_pdf_to_svg(self.plot_dir)
        self._convert_pdf_to_jpg(self.plot_dir)
        self._convert_pdf_to_png(self.plot_dir)

        image_filename = "%s/tikz.svg" % (self.plot_dir)

        # Publish image
        try:
            image = open(image_filename, 'rb').read()
            plot_mime_type = _mimetypes.get('svg', 'image/svg')
            width, height = [int(s) for s in size.split(',')]
            image = self._fix_gnuplot_svg_size(image, size=(width, height))
            display_data.append((key, {plot_mime_type: image}))

        except IOError:
            print("No image generated.", file=sys.stderr)

        # Copy output file if requested
        if args.save is not None:
            self._copy_result_files(args.save)

        for tag, disp_d in display_data:
            self._publish_display_data(source=tag, data=disp_d, metadata={'isolated' : 'true'})

        # file downloads
        strg = './%s' % self.plot_dir.split("/")[-1]
        local_file = FileLinks(strg)
        display(local_file)
Пример #11
0
print("cv scores : ", cv_scores)
out_df = pd.DataFrame(pred_full_test)
out_df.columns = ['EAP', 'HPL', 'MWS']
out_df.insert(0, 'id', test_id)
out_df.to_csv("output.csv", index=False)

# In[33]:
#create a folder name output in Documents.

from IPython.display import FileLink, FileLinks

#FileLinks('.')
out_df.to_csv(
    'C:/Users/yourname/Documents/spooky-author-identification/output/output.csv',
    index=False)
FileLinks('C:/Users/yourname/Documents/spooky-author-identification/output')

# In[34]:

cnf_matrix = confusion_matrix(val_y, np.argmax(pred_val_y, axis=1))
np.set_printoptions(precision=2)

# Plot non-normalized confusion matrix
plt.figure(figsize=(8, 8))
plot_confusion_matrix(cnf_matrix,
                      classes=['EAP', 'HPL', 'MWS'],
                      title='Confusion matrix of XGB, without normalization')
plt.show()

# In[35]:
Пример #12
0
def export_to_csv(da_locals, selection_widget, out):
    df_name = selection_widget.value
    da_locals[df_name].to_csv('growthviz-data/output/{}.csv'.format(df_name),
                              index=False)
    out.clear_output()
    out.append_display_data(FileLinks('growthviz-data/output'))