{ "cells": [ { "cell_type": "code", "execution_count": 110, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "58\n", "['\\n///// ', '\\n// Band Arithmetic ', '\\n///// ', '\\n// Calculate NDVI using Sentinel 2 ', '\\n// Import and filter imagery by location and date. ', '\\n// Display the image as a false color composite. ', '\\n// Extract the near infrared and red bands. ', '\\n// Calculate the numerator and the denominator using subtraction and addition respectively. ', '\\n// Now calculate NDVI. ', '\\n// Add the layer to our map with a palette. ', '\\n// Now use the built-in normalizedDifference function to achieve the same outcome. ', '\\n// Use normalizedDifference to calculate NDWI ', '\\n// Create an NDVI image using Sentinel 2. ', '\\n// And map it. ', '\\n// Implement a threshold. ', '\\n// Map the threshold. ', '\\n// Implement .where. ', '\\n// Create a starting image with all values = 1. ', '\\n// Make all NDVI values less than -0.1 equal 0. ', '\\n// Make all NDVI values greater than 0.5 equal 2. ', '\\n// Map our layer that has been divided into three classes. ', '\\n// Implement masking. ', \"\\n// View the seaVeg layer's current mask. \", '\\n// Create a binary mask of non-forest. ', '\\n// Update the seaVeg mask with the non-forest mask. ', '\\n// Map the updated Veg layer ', '\\n// Map the updated mask ', '\\n// Implement remapping. ', '\\n// Remap the values from the seaWhere layer. ', '\\n// Create an Earth Engine Point object over Milan. ', '\\n// Filter the Landsat 8 collection and select the least cloudy image. ', '\\n// Center the map on that image. ', '\\n// Add Landsat image to the map. ', '\\n// Combine training feature collections. ', '\\n// Define prediction bands. ', '\\n// Sample training points. ', '\\n//////////////// CART Classifier /////////////////// ', '\\n// Train a CART Classifier. ', '\\n// Classify the Landsat image. ', '\\n// Define classification image visualization parameters. ', '\\n// Add the classified image to the map. ', '\\n/////////////// Random Forest Classifier ///////////////////// ', '\\n// Train RF classifier. ', '\\n// Classify Landsat image. ', '\\n// Add classified image to the map. ', '\\n//////////////// Unsupervised classification //////////////// ', '\\n// Make the training dataset. ', '\\n// Instantiate the clusterer and train it. ', '\\n// Cluster the input using the trained clusterer. ', '\\n// Display the clusters with random colors. ', '\\n// Import the reference dataset. ', '\\n// Define the prediction bands. ', '\\n// Split the dataset into training and testing sets. ', '\\n// Train the Random Forest Classifier with the trainingSet. ', \"\\n// Now, to test the classification (verify model's accuracy), \", '\\n// we classify the testingSet and get a confusion matrix. ', '\\n// Print the results. ', '\\n// Hyperparameter tuning. ']\n" ] } ], "source": [ "import re\n", "\n", "def captions(f):\n", " regex=r'(!\\[\\].+\\))\\n(\\nFig\\..*)'\n", "\n", " figures=re.findall(regex, f)\n", " print(len(figures))\n", " sub=[]\n", " for fig in figures:\n", " formatted=fig[0].replace('[]','[{}]'.format(fig[1].replace('\\n','')))\n", " f=f.replace(fig[0],formatted)\n", " f=f.replace(fig[1],\"\")\n", " return f\n", "\n", "def codeblocks(f):\n", " \n", " regex=r'(\\n//.*)'\n", " code=re.findall(regex, f)\n", " print(len(code))\n", " print(code)\n", " return f\n", "\n", "for i in [2]:#,4,5,6]:\n", " f = open(\"F{}.qmd\".format(i), \"r\").read().replace('\\xa0', ' ')\n", " #f = captions(f)\n", " f = codeblocks(f)\n", "\n" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'urllib2' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m/var/folders/6q/jt4x0r8n1rs0kbrrqrbj61fr0000gn/T/ipykernel_60302/1639298892.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0murllib\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0murllib2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'F2.qmd'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfind\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'text/javascript'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"It has js.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mNameError\u001b[0m: name 'urllib2' is not defined" ] } ], "source": [ "import urllib\n", "if urllib2.open('F2.qmd').read().find('text/javascript') == 0:\n", " print(\"It has js.\")\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 64-bit ('3.9.5')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.5" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "d34fbd810dd9652f8e464616181cf14dbb258b5c046bed5c2f54c6b5e518fed2" } } }, "nbformat": 4, "nbformat_minor": 2 }