Wednesday, March 18, 2026

Hysplit: To test Dry Deposition of Gases in HYSPLIT using a built-in example

  1. Prepare the Basic Run Setup (if not already done)
    • Open the main Setup Run window.
    • Set Total run time (hrs): e.g., 12 or 25 (tutorial uses 25 h for noticeable deposition).
    • Set Direction: Fwd (forward).
    • Add meteorology: Click Add Meteorology Files and select your file (e.g., oct1618.BIN).
    • Click Setup starting locations → define 1 source (e.g., lat 40.0, lon -90.0, height 50 m, emission rate suitable for test).
  2. Set Pollutant & Deposition (Gas Dry Deposition)
    • In main setup → click Pollutant, Concentration Grid, and Deposition setup.
    • Under Pollutant: Num=1, select Specie 1.
    • Under Deposition: Num=1, select Specie 1 → this opens the Deposition Definition window.
    • In Deposition window:
      • Particle or Gas: Gas.
      • Dry Deposition: Yes.
      • Wet Deposition: No.
      • Preconfigure: Select I131g (built-in gaseous I-131 example; auto-loads realistic parameters like Vd ~0.006 m/s, molecular weight, Henry's law constants).
        • Or manually: Set Vel(m/s) to 0.01 (1 cm/s, tutorial value for strong test).
      • Leave other fields default/zero unless needed.
    • Click green Save → close window.
  3. Add Ground Deposition Level to Concentration Grid
    • In the same Pollutant, Concentration Grid, and Deposition setup window:
      • Under Grids: Num=1 → click radio for Grid 1 (or double-click/label) → opens Definition of Concentration Grid 1.
    • In Grid Definition window:
      • Num of vertical levels: Change from 1 to 2.
      • Height of levels(M Agl): Change to 0 100 (space-separated; 0 first for deposition accumulation, 100 for air concentration layer).
      • Optional: Update Center of Lat and Lon to match your source (e.g., 40.0 -90.0).
      • Keep spacing/span reasonable (e.g., 0.05 deg, 30 deg span).
      • Output grid file name: Keep cdump or change.
    • Click green Save → close.
  4. Run the Model
    • Back in main Concentration Setup window → Save.
    • Click Run Model (or equivalent button to execute HYSPLIT).
    • Wait for completion → open the MESSAGE file in your working directory (text file named MESSAGE):
      • Note the final total mass (near end, often in a NOTICE or summary line).
      • Compare to initial emitted mass (early in file or from your emission setup: rate × duration).
      • Look for vertical mass distribution tables (e.g., %Mass by height layer) — reduced low-level % indicates dry removal to ground.
      • Compute % mass lost = (initial - final) / initial × 100. Tutorial expects ~10-14% for Vd=0.01 m/s over longer runs; shorter runs or lower Vd (like 0.006) show less.
    • This confirms dry deposition occurred (mass removed from atmosphere).
  5. Display the Results (Air Concentration + Deposition Footprint)
    • Go to Display → Concentration Contours (opens your Concentration Display window).
    • Key settings:
      • Input File: cdump (or your output name).
      • Select Pollutant: All or your species (e.g., I131 / II131).
      • Vertical Display: Show Each Level.
      • From Bottom Level: 0 (deposition/surface).
      • Through Top Level: 100 (air layer).
      • Deposition Multiplier: Select Total (shows cumulative/total deposited mass over entire run; critical for seeing the full footprint instead of incremental amounts).
        • Keep numeric field 1.0 (unless scaling units).
      • Concentration Multiplier: 1.0.
      • Uncheck Exposure if checked.
      • Contour drawing options: Dyn-Exp (dynamic exponential; best for plumes).
      • Label Source Rings: On (shows distance rings around source; set Number=4, Dist=100 km, Center to your source lat/lon).
      • Output File: e.g., dry_depo_plot (unique name).
      • View On: Checked.
    • Click green Execute Display.
    • What you'll see (sequence through frames):
      • Air concentration frames (at 100 m level): Reduced plume due to deposition loss.
      • Final/cumulative frame (level 0 with Total): Colored deposition footprint on ground (accumulated mass deposited as plume passed).
    • If blank: Confirm level 0 in grid, Vd > 0, re-run if needed.

Monday, March 9, 2026

Matlab: Compress the file size for gif files

% ────────────────────────────────────────────────
% Compress large GIF → smaller GIF (same size, fewer colors)
% ────────────────────────────────────────────────

inputGif  = 'original.gif';      % ← change this
outputGif = 'compressed_version.gif';

[frames, map] = imread(inputGif, 'Frames', 'all');

if size(frames,3) == 3
    isRGB = true;
else
    isRGB = false;
end

nFrames = size(frames, 4);

% ── Super aggressive settings ──
nColors     = 16;          % try 12 or 8 if still too big
useDither   = false;       % no dither = smaller
delayFactor = 4.0;         % 4× slower → big size win
frameStep   = 3;           % keep only every 3rd frame (big reduction)

newFrames = cell(1, floor(nFrames / frameStep));
globalMap = [];

k = 1;
for i = 1:frameStep:nFrames
    if isRGB
        thisFrame = frames(:,:,:,i);
    else
        thisIndexed = frames(:,:,:,i);
        thisFrame   = ind2rgb(thisIndexed, map);
    end
    
    if k == 1
        if useDither
            [indexed, globalMap] = rgb2ind(thisFrame, nColors);
        else
            [indexed, globalMap] = rgb2ind(thisFrame, nColors, 'nodither');
        end
    else
        if useDither
            indexed = rgb2ind(thisFrame, globalMap);
        else
            indexed = rgb2ind(thisFrame, globalMap, 'nodither');
        end
    end
    
    newFrames{k} = indexed;
    k = k + 1;
end

% Timing – slow it down a lot
info      = imfinfo(inputGif);
origDelay = info(1).DelayTime / 100;
newDelay  = origDelay * delayFactor;
if newDelay < 0.05, newDelay = 0.05; end  % reasonable min

% Write
imwrite(newFrames{1}, globalMap, outputGif, 'gif', ...
    'LoopCount', Inf, ...
    'DelayTime', newDelay);

for kk = 2:numel(newFrames)
    imwrite(newFrames{kk}, globalMap, outputGif, 'gif', ...
        'WriteMode', 'append', ...
        'DelayTime', newDelay);
end

% Report
origSize = dir(inputGif).bytes  / 1e6;
newSize  = dir(outputGif).bytes / 1e6;
fprintf('MATLAB: %.0f MB → %.0f MB (%.0f%% smaller)\n', origSize, newSize, (origSize-newSize)/origSize*100);
disp(['Saved: ' outputGif]);