QuantEcon.notebooks
QuantEcon.notebooks copied to clipboard
Adding notebook and codes for Krusell and Smith (1998)
This PR adds the directory krusell_smith_98_deps
in dependencies
. Such directory contains 2 Julia files with the programs to solve the model and replicate some results from Krusell and Smith (1998). These programs are run in the notebook krusell_smith_98.ipynb
- also added through this commit - with extensive descriptions.
@albep Great. This is very nice.
@mmcky How would you like to handle these dependencies?
Given this is a Julia project -- and the current notebook dependency tools support python only -- for now we should just add them in the dependencies
folder and then ask Julia to include them from the github repo url directly. I will check with Spencer for the appropriate snippet. We will need to add a utility to QuantEcon.jl
I think this is a great time to write up some code for a proper solution in Julia. @mmcky can you summarize all the things the python dependency system currently does?
It is pretty basic -- it just uses requests to fetch a file and place it in the cwd
.
It is written on the keep it simple philosophy for now. It is not automatic and requires a single line specifying the file name -- and that file needs to be in QuantEcon.notebooks/dependencies
import os
import requests
#-Remote Structure-#
REPO = "https://github.com/QuantEcon/QuantEcon.notebooks"
RAW = "raw"
BRANCH = "master"
DEPS = "dependencies" #Hard Coded Dependencies Folder on QuantEcon.notebooks
def fetch_nb_dependencies(files, repo=REPO, raw=RAW, branch=BRANCH, deps=DEPS, overwrite=False, verbose=True):
"""
Retrieve raw files from QuantEcon.notebooks or any other Github repo
Parameters
----------
file_list list or dict
A list of files to specify a collection of filenames
A dict of dir : list(files) to specify a directory
repo str, optional(default=REPO)
branch str, optional(default=BRANCH)
deps str, optional(default=DEPS)
overwrite bool, optional(default=False)
verbose bool, optional(default=True)
TODO
----
1. Should we update this to allow people to specify their own folders on a different GitHub repo?
"""
#-Generate Common Data Structure-#
if type(files) == list:
files = {"" : files}
#-Obtain each requested file-#
for directory in files.keys():
if directory != "":
if verbose: print("Parsing directory: %s")
for fl in files[directory]:
if directory != "":
fl = directory+"/"+fl
#-Check for Local Copy of File (Default Behaviour is to Skip)-#
if not overwrite:
if os.path.isfile(fl):
if verbose: print("A file named %s already exists in the specified directory ... skipping download."%fl)
continue
else:
if verbose: print("Overwriting file %s ..."%fl)
if verbose: print("Fetching file: %s"%fl)
#-Get file in OS agnostic way using requests-#
url = "/".join([repo,raw,branch,deps,fl])
r = requests.get(url)
with open(fl, "wb") as fl:
fl.write(r.content)