{ "collab_server" : "", "contents" : "# NS41 Satellite Data\n# Michael D Cayton\n# December 22, 2018\n# Last update 12-23-18\n\n#### Load the libraries ###\n\nlibrary(tidyverse)\nlibrary(RCurl)\nlibrary(lubridate)\n\n# Set the url for the ftp site working directory.\n# This is where the origianal data is stored.\nurl <- 'ftp://ftp.ngdc.noaa.gov/STP/space-weather/satellite-data/satellite-systems/gps/data/ns41/'\n\n# Create a vector of file names from the directory\n# This will allow us to extract the dates and will be used to create a master file. \nfilename <- getURL(url, dirlistonly = TRUE)\nfilename\n\n# Clean up the file list\ndestnames <- strsplit(filename, \"\\r*\\n\")[[1]]\ndestnames\n\n# Create data frame for the data.\nns41 = NULL\nns41 <- tbl_df(ns41)\n\n# For loop to access each file, combine into one dataframe, and add a column for the filename date\nl <- length(destnames)\ndata <- NULL\ni <- NULL\n\nfor (i in 1:l) {\n data <- read.table(file = paste(url, destnames[i], sep=\"\"))\n data$Date <- as.Date(str_sub(destnames[i], start=6, end=11), \"%y%m%d\")\n ns41 <- rbind(ns41, data)\n print(paste(i, \"of\", l, \"complete\"))\n}\n\n# Save table. \nwrite_csv(ns41, path=\"/Users/mdcay/Documents/Happy Dad/ns41.csv\")\n\n#Import raw data as needed. \nns41 <- read_csv(file=\"/Users/mdcay/Documents/Happy Dad/ns41.csv\")\nns41 <- tbl_df(ns41)\n\n# Select for V21 = 240\nns41 <- ns41 %>% filter(V21 == 240)\n# Create table, grouped by unique week, and sum of V81 through V99\nns41_sums <- ns41 %>% group_by(Date) %>%\n select(Date, V81:V99) %>%\n summarise(n=n(),\n V81=sum(V81),\n V82=sum(V82),\n V83=sum(V83),\n V84=sum(V84),\n V85=sum(V85),\n V86=sum(V86),\n V87=sum(V87),\n V88=sum(V88),\n V89=sum(V89),\n V90=sum(V90),\n V91=sum(V91),\n V92=sum(V92),\n V93=sum(V93),\n V94=sum(V94),\n V95=sum(V95),\n V96=sum(V96),\n V97=sum(V97),\n V98=sum(V98),\n V99=sum(V99)\n )\n\nwrite_csv(ns41_sums, path='ns41_sums.csv')\n\n# Create a list of the energy levels. These can be found in V100 through V130. \nenergies <- c(.6, .7, .8, .9, 1, 1.25, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 6, 7, 8, 9, 10)\n\n\n### JSON with table info ###\n# test <- fromJSON('{\n# \"decimal_day\": { \"DESCRIPTION\":\"Decimal Day of year\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"days\",\n# \"START_COLUMN\": 0\n# },\n# \n# \"Geographic_Latitude\": { \"DESCRIPTION\":\"Geographic_Latitude\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"degrees\",\n# \"START_COLUMN\": 1\n# },\n# \"Geographic_Longitude\": { \"DESCRIPTION\":\"Geographic_Longitude\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"degrees\",\n# \"START_COLUMN\": 2\n# },\n# \"Rad_Re\": { \"DESCRIPTION\":\"Radius (earth radii)\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"R_E\",\n# \"START_COLUMN\": 3\n# },\n# \"rate_electron_measured\": { \"DESCRIPTION\":\"rate_electron_measured\",\n# \"DIMENSION\": [8],\n# \"UNITS\": \"hertz\",\n# \"START_COLUMN\": 4\n# },\n# \"rate_proton_measured\": { \"DESCRIPTION\":\"rate_proton_measured\",\n# \"DIMENSION\": [8],\n# \"UNITS\": \"hertz\",\n# \"START_COLUMN\": 12\n# },\n# \"collection_interval\": { \"DESCRIPTION\":\"collection_interval\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"seconds\",\n# \"START_COLUMN\": 20\n# },\n# \"year\": { \"DESCRIPTION\":\"year eg 2015\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"years\",\n# \"START_COLUMN\": 21\n# },\n# \"decimal_year\": { \"DESCRIPTION\":\"decimal_year contains fractional part of year\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"years\",\n# \"START_COLUMN\": 22\n# },\n# \"svn_number\": { \"DESCRIPTION\":\"SVN number\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"none\",\n# \"START_COLUMN\": 23\n# },\n# \"dropped_data\": { \"DESCRIPTION\":\"dropped_data=1 means ignore data\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"none\",\n# \"START_COLUMN\": 24\n# },\n# \"b_coord_radius\": { \"DESCRIPTION\":\"radius from earths dipole axis\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"R_E\",\n# \"START_COLUMN\": 25\n# },\n# \"b_coord_height\": { \"DESCRIPTION\":\"height above earths equatorial plane\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"R_E\",\n# \"START_COLUMN\": 26\n# },\n# \"magnetic_longitude\": { \"DESCRIPTION\":\"magnetic longitude\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"degrees\",\n# \"START_COLUMN\": 27\n# },\n# \"L_shell\": { \"DESCRIPTION\":\"L shell, dipole file, T89\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"R_E\",\n# \"START_COLUMN\": 28\n# },\n# \"bfield_ratio\": { \"DESCRIPTION\":\"Bsatellite/Bequator\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"none\",\n# \"START_COLUMN\": 29\n# },\n# \"local_time\": { \"DESCRIPTION\":\"Magnetic local time\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"h\",\n# \"START_COLUMN\": 30\n# },\n# \"b_sattelite\": { \"DESCRIPTION\":\" field at satellite\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"gauss\",\n# \"START_COLUMN\": 31\n# },\n# \"b_equator\": { \"DESCRIPTION\":\"B field at equator\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"gauss\",\n# \"START_COLUMN\": 32\n# },\n# \"diffp\": { \"DESCRIPTION\":\"not sure what this is\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"gauss\",\n# \"START_COLUMN\": 33\n# },\n# \"sigmap\": { \"DESCRIPTION\":\"not sure what this is\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"gauss\",\n# \"START_COLUMN\": 34\n# },\n# \"electron_background\": { \"DESCRIPTION\":\"electron_background estimated\",\n# \"DIMENSION\": [8],\n# \"UNITS\": \"hertz\",\n# \"START_COLUMN\": 35\n# },\n# \"proton_background\": { \"DESCRIPTION\":\"proton_background estimated\",\n# \"DIMENSION\": [8],\n# \"UNITS\": \"hertz\",\n# \"START_COLUMN\": 43\n# },\n# \"proton_activity\": { \"DESCRIPTION\":\"proton_activity=1 if proton activity is occurring\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"none\",\n# \"START_COLUMN\": 51\n# },\n# \"electron_temperature_fit\": { \"DESCRIPTION\":\"electron temperature from Maxwellian fit\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"MeV\",\n# \"START_COLUMN\": 52\n# },\n# \"electron_density_fit\": { \"DESCRIPTION\":\"electron number density fit\",\n# \"DIMENSION\": [1],\n# \"UNITS\": \"cm^-3\",\n# \"START_COLUMN\": 53\n# },\n# \"model_counts_electron_fit\": { \"DESCRIPTION\":\"E1-E8 rates from Maxwellian fit\",\n# \"DIMENSION\": [8],\n# \"UNITS\": \"hertz\",\n# \"START_COLUMN\": 54\n# },\n# \"dtc_counts_electron\": { \"DESCRIPTION\":\"E1-E8 rates dead time corrected\",\n# \"DIMENSION\": [8],\n# \"UNITS\": \"hertz\",\n# \"START_COLUMN\": 62\n# },\n# \"integral_flux_instrument\": { \"DESCRIPTION\":\"integral of electron flux fit above integral_flux_energy[i]\",\n# \"DIMENSION\": [30],\n# \"UNITS\": \"cm^-2sec^-1sr^-1\",\n# \"START_COLUMN\": 70\n# },\n# \"integral_flux_energy\": { \"DESCRIPTION\":\"energies for integral_flux_instrument\",\n# \"DIMENSION\": [30],\n# \"UNITS\": \"MeV\",\n# \"START_COLUMN\": 100\n# },\n# \"electron_diff_flux_energy\": { \"DESCRIPTION\":\"energies for the fluxes in electron_diff_flux_energy\",\n# \"DIMENSION\": [15],\n# \"UNITS\": \"MeV\",\n# \"START_COLUMN\": 130\n# },\n# \"electron_diff_flux\": { \"DESCRIPTION\":\"electron flux at energies electron_diff_flux[i]\",\n# \"DIMENSION\": [15],\n# \"UNITS\": \"cm^-2sec^-1sr^-1MeV^-1\",\n# \"START_COLUMN\": 145\n# }\n# }')\n\n\n", "created" : 1545529021890.000, "dirty" : false, "encoding" : "UTF-8", "folds" : "", "hash" : "994852793", "id" : "1F08B666", "lastKnownWriteTime" : 1545618654, "last_content_update" : 1545618654152, "path" : "~/Happy Dad/HD2.R", "project_path" : "HD2.R", "properties" : { }, "relative_order" : 2, "source_on_save" : false, "source_window" : "", "type" : "r_source" }