From 53175adbdb19273ceeddb096f14d63313ebde8bb Mon Sep 17 00:00:00 2001 From: siddjain444 Date: Tue, 3 Oct 2023 08:18:23 +0000 Subject: [PATCH 1/3] This is a test commit --- src/data.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/data.jl b/src/data.jl index d480a21..927db64 100644 --- a/src/data.jl +++ b/src/data.jl @@ -106,4 +106,6 @@ end # read_the_map = st_read(dsn=dsn_for_maps, layer = aggregation.layer) # TODO: figure out why this doesn't work -# dataset = ArchGDAL.read("MySQL:maps;host=data.mayin.org;user=$(maps_user);password=$(maps_password)") \ No newline at end of file +# dataset = ArchGDAL.read("MySQL:maps;host=data.mayin.org;user=$(maps_user);password=$(maps_password)") +# my name is siddhant + From 6214951af548d8b940775db859453fb9f03c0bfe Mon Sep 17 00:00:00 2001 From: siddjain444 Date: Thu, 11 Apr 2024 08:31:50 +0000 Subject: [PATCH 2/3] Updating the shapefile in data.jl, and accordingly making the changes to the Karmana.jl and indiaoutline.jl --- src/Karmana.jl | 26 +++++++++++--------------- src/data.jl | 10 ++-------- src/plotting/indiaoutline.jl | 12 +++++------- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/Karmana.jl b/src/Karmana.jl index 92c30d0..bb1aa04 100644 --- a/src/Karmana.jl +++ b/src/Karmana.jl @@ -133,7 +133,7 @@ function __init__() district_df[][302, :HR_Nmbr] = 3 # Kinnaur - district name not assigned HR_Name district_df[][413, :HR_Nmbr] = 3 # North Sikkim - district not assigned HR_Name nor district name # 104 end - hr_df[] = _prepare_merged_geom_dataframe(district_df[], :HR_Nmbr, :ST_NM; capture_fields = (:ST_NM, :ST_CD, :HR_Name)) + hr_df[] = _prepare_merged_geom_dataframe(district_df[], :HR_Nmbr, :ST_NM; capture_fields = (:ST_NM, :ST_CD, :HR_Nmbr)) state_df[] = _prepare_merged_geom_dataframe(district_df[], :ST_NM; capture_fields = (:ST_CD,)) # finally, patch the loaded dataframes, to match the maps database @@ -147,20 +147,16 @@ function __init__() has_india_data = true elseif has_maps_db_config - try - _state_df, _hr_df, _district_df = state_hr_district_dfs() - - # _district_df[302, :hr_nmbr] = 3 # Kinnaur - district name not assigned HR_Name - # _district_df[413, :hr_nmbr] = 3 # North Sikkim - district not assigned HR_Name nor district name - state_df[] = _state_df - hr_df[] = _hr_df - district_df[] = _district_df - has_india_data = true - catch e - @warn "Failed to load data from maps database. Falling back to shapefile." - @warn e - has_india_data = false - end + # try + _district_df = state_hr_district_dfs() + district_df[] = _district_df + district_df[].geometry = GeoInterface.convert.((GeometryBasics,), district_df[].geometry) + # apply certain patches here, if needed + district_df[][302, :hr_nmbr] = 3 # Kinnaur - district name not assigned HR_Name + district_df[][413, :hr_nmbr] = 3 # North Sikkim - district not assigned HR_Name nor district name # 104 + hr_df[] = _prepare_merged_geom_dataframe(district_df[], :hr_nmbr, :st_nm; capture_fields = (:st_nm, :st_cd, :hr_name)) + state_df[] = _prepare_merged_geom_dataframe(district_df[], :st_nm; capture_fields = (:st_cd,)) + hr_df[].hr_nmbr_str = ("HR ",) .* string.(hr_df[].hr_nmbr) end if !has_india_data # no shapefile path, no maps db access ⟹ use the artifact! diff --git a/src/data.jl b/src/data.jl index 927db64..03c5b6a 100644 --- a/src/data.jl +++ b/src/data.jl @@ -84,21 +84,15 @@ function state_hr_district_dfs() spatial_ref_df = DBInterface.execute(connection, "SELECT * from spatial_ref_sys") |> DataFrame db_crs = spatial_ref_df.SRTEXT[begin] # TODO: use this when converting. # get tables for each admin level - state_table = do_geoquery(connection, "states") - hr_table = do_geoquery(connection, "homogeneous_regions") - district_table = do_geoquery(connection, "districts_2011") + district_table = do_geoquery(connection,"districts_states_hr" ) # get rivers etc - shape_wkb_to_module_geom!(GeometryBasics, state_table) - shape_wkb_to_module_geom!(GeometryBasics, hr_table) shape_wkb_to_module_geom!(GeometryBasics, district_table) # drop missing values, since we shouldn't have any at this stage. - dropmissing!(state_table) - dropmissing!(hr_table) dropmissing!(district_table) # clean up by closing the connection DBInterface.close!(connection) - return state_table, hr_table, district_table + return district_table end diff --git a/src/plotting/indiaoutline.jl b/src/plotting/indiaoutline.jl index 21068da..214782d 100644 --- a/src/plotting/indiaoutline.jl +++ b/src/plotting/indiaoutline.jl @@ -34,7 +34,7 @@ function id_key_for_admin_level(admin_level::Symbol) elseif admin_level == :HR :hr_nmbr elseif admin_level == :District - :dt_cen_cd + :censuscode else @error("The admin code `$admin_code` which you passed is invalid. Valid admin codes are `:State`, `:HR`, and `:District`.") end @@ -261,16 +261,14 @@ function Makie.plot!(plot::IndiaOutline) end notify(plot.converted[2]) - state_plot = poly!(plot, plot.State, state_geoms; color = state_colors, colormap = plot.colormap, highclip = plot.highclip, lowclip = plot.lowclip) - hr_plot = poly!(plot, hr_geoms; color = hr_colors, colorrange = get(plot, :colorrange, (0, 1)), colormap = plot.colormap, highclip = plot.highclip, lowclip = plot.lowclip, plot.HR...) - district_plot = poly!(plot, district_geoms; color = district_colors, colormap = plot.colormap, colorrange = get(plot, :colorrange, (0, 1)), highclip = plot.highclip, lowclip = plot.lowclip, plot.District...) - river_plot = lines!(plot, GeoInterface.convert(GeometryBasics, Karmana.india_rivers[]); inspectable = false, xautolimits = false, yautolimits = false, plot.River...) - + state_plot = poly!(plot, plot.State, state_geoms; color = state_colors, colormap = plot.colormap) + hr_plot = poly!(plot, hr_geoms; color = hr_colors, colorrange = get(plot, :colorrange, (0, 1)), colormap = plot.colormap, plot.HR...) + district_plot = poly!(plot, district_geoms; color = district_colors, colormap = plot.colormap, colorrange = get(plot, :colorrange, (0, 1)), plot.District...) + on(Base.Fix1(_set_plot_z, state_plot), plot.State.zlevel; update = true) on(Base.Fix1(_set_plot_z, hr_plot), plot.HR.zlevel; update = true) on(Base.Fix1(_set_plot_z, district_plot), plot.District.zlevel; update = true) - on(Base.Fix1(_set_plot_z, river_plot), plot.River.zlevel; update = true) return plot end From 8d545fba011fcbc8d3327a8addcb6c1b8bc5507f Mon Sep 17 00:00:00 2001 From: ayushpatnaikgit Date: Wed, 17 Apr 2024 08:13:56 +0000 Subject: [PATCH 3/3] checking difference with root --- src/readnl.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/readnl.jl b/src/readnl.jl index 2295158..4e309aa 100644 --- a/src/readnl.jl +++ b/src/readnl.jl @@ -38,7 +38,7 @@ start_date = Date(2015, 01) end_date = Date(2020, 12) rad_dc, cf_dc = readnl(xlims, ylims, start_date, end_date) """ -function readnl(xlims = X(Rasters.Between(65.39, 99.94)), ylims = Y(Rasters.Between(5.34, 39.27)), start_date = Date(2012, 04), end_date = Date(2023, 01)) +function readnl(xlims = X(Rasters.Between(65.39, 99.94)), ylims = Y(Rasters.Between(5.34, 39.27)), start_date = Date(2012, 04), end_date = Date(today())) lims = xlims, ylims rad_path = "/mnt/giant-disk/nighttimelights/monthly/rad/" rad_files, sorted_dates = sort_files_by_date(rad_path, start_date, end_date) @@ -48,8 +48,9 @@ function readnl(xlims = X(Rasters.Between(65.39, 99.94)), ylims = Y(Rasters.Betw cf_raster_list = [Raster(i, lazy = true)[lims...] for i in cf_path .* cf_files] rad_series = RasterSeries(rad_raster_list, Ti(sorted_dates)) cf_series = RasterSeries(cf_raster_list, Ti(sorted_dates)) - rad_datacube = Rasters.combine(rad_series, Ti) - cf_datacube = Rasters.combine(cf_series, Ti) + rad_datacube = Float16.(Rasters.combine(rad_series, Ti)) + cf_datacube = Int8.(Rasters.combine(cf_series, Ti)) + replace!(rad_datacube, Inf => prevfloat(typemax(rad_datacube[1,1,1]))) return rad_datacube, cf_datacube end @@ -75,7 +76,7 @@ end_date = Date(2020, 12) rad_dc, cf_dc = readnl(geom, start_date, end_date) ``` """ -function readnl(geom, start_date = Date(2012, 04), end_date = Date(2023, 01)) +function readnl(geom, start_date = Date(2012, 04), end_date = today()) rad_path = "/mnt/giant-disk/nighttimelights/monthly/rad/" rad_files, sorted_dates = sort_files_by_date(rad_path, start_date, end_date) cf_path = "/mnt/giant-disk/nighttimelights/monthly/cf/" @@ -84,7 +85,8 @@ function readnl(geom, start_date = Date(2012, 04), end_date = Date(2023, 01)) cf_raster_list = [crop(Raster(i, lazy = true), to = geom) for i in cf_path .* cf_files] rad_series = RasterSeries(rad_raster_list, Ti(sorted_dates)) cf_series = RasterSeries(cf_raster_list, Ti(sorted_dates)) - rad_datacube = Rasters.combine(rad_series, Ti) - cf_datacube = Rasters.combine(cf_series, Ti) + rad_datacube = Float16.(Rasters.combine(rad_series, Ti)) + cf_datacube = Int8.(Rasters.combine(cf_series, Ti)) + replace!(rad_datacube, Inf => prevfloat(typemax(rad_datacube[1,1,1]))) return rad_datacube, cf_datacube end